AppsDisableTest.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace Tests\Core\Command\Config;
  8. use OC\Core\Command\App\Disable;
  9. use Symfony\Component\Console\Tester\CommandTester;
  10. use Test\TestCase;
  11. /**
  12. * Class AppsDisableTest
  13. *
  14. * @group DB
  15. */
  16. class AppsDisableTest extends TestCase {
  17. /** @var CommandTester */
  18. private $commandTester;
  19. protected function setUp(): void {
  20. parent::setUp();
  21. $command = new Disable(
  22. \OC::$server->getAppManager()
  23. );
  24. $this->commandTester = new CommandTester($command);
  25. \OC::$server->getAppManager()->enableApp('admin_audit');
  26. \OC::$server->getAppManager()->enableApp('comments');
  27. }
  28. /**
  29. * @dataProvider dataCommandInput
  30. * @param $appId
  31. * @param $groups
  32. * @param $statusCode
  33. * @param $pattern
  34. */
  35. public function testCommandInput($appId, $statusCode, $pattern): void {
  36. $input = ['app-id' => $appId];
  37. $this->commandTester->execute($input);
  38. $this->assertMatchesRegularExpression('/' . $pattern . '/', $this->commandTester->getDisplay());
  39. $this->assertSame($statusCode, $this->commandTester->getStatusCode());
  40. }
  41. public function dataCommandInput(): array {
  42. return [
  43. [['admin_audit'], 0, 'admin_audit ([\d\.]*) disabled'],
  44. [['comments'], 0, 'comments ([\d\.]*) disabled'],
  45. [['invalid_app'], 0, 'No such app enabled: invalid_app'],
  46. [['admin_audit', 'comments'], 0, "admin_audit ([\d\.]*) disabled\ncomments ([\d\.]*) disabled"],
  47. [['admin_audit', 'comments', 'invalid_app'], 0, "admin_audit ([\d\.]*) disabled\ncomments ([\d\.]*) disabled\nNo such app enabled: invalid_app"],
  48. [['files'], 2, "files can't be disabled"],
  49. [['provisioning_api'], 2, "provisioning_api can't be disabled"],
  50. [['files', 'admin_audit'], 2, "files can't be disabled.\nadmin_audit ([\d\.]*) disabled"],
  51. [['provisioning_api', 'comments'], 2, "provisioning_api can't be disabled.\ncomments ([\d\.]*) disabled"],
  52. ];
  53. }
  54. }