AppsDisableTest.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2019, Daniel Kesselberg (mail@danielkesselberg.de)
  5. *
  6. * @license GNU AGPL version 3 or any later version
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License as
  10. * published by the Free Software Foundation, either version 3 of the
  11. * License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. namespace Tests\Core\Command\Config;
  23. use OC\Core\Command\App\Disable;
  24. use Symfony\Component\Console\Tester\CommandTester;
  25. use Test\TestCase;
  26. /**
  27. * Class AppsDisableTest
  28. *
  29. * @group DB
  30. */
  31. class AppsDisableTest extends TestCase {
  32. /** @var CommandTester */
  33. private $commandTester;
  34. protected function setUp(): void {
  35. parent::setUp();
  36. $command = new Disable(
  37. \OC::$server->getAppManager()
  38. );
  39. $this->commandTester = new CommandTester($command);
  40. \OC::$server->getAppManager()->enableApp('admin_audit');
  41. \OC::$server->getAppManager()->enableApp('comments');
  42. }
  43. /**
  44. * @dataProvider dataCommandInput
  45. * @param $appId
  46. * @param $groups
  47. * @param $statusCode
  48. * @param $pattern
  49. */
  50. public function testCommandInput($appId, $statusCode, $pattern): void {
  51. $input = ['app-id' => $appId];
  52. $this->commandTester->execute($input);
  53. $this->assertMatchesRegularExpression('/' . $pattern . '/', $this->commandTester->getDisplay());
  54. $this->assertSame($statusCode, $this->commandTester->getStatusCode());
  55. }
  56. public function dataCommandInput(): array {
  57. return [
  58. [['admin_audit'], 0, 'admin_audit ([\d\.]*) disabled'],
  59. [['comments'], 0, 'comments ([\d\.]*) disabled'],
  60. [['invalid_app'], 0, 'No such app enabled: invalid_app'],
  61. [['admin_audit', 'comments'], 0, "admin_audit ([\d\.]*) disabled\ncomments ([\d\.]*) disabled"],
  62. [['admin_audit', 'comments', 'invalid_app'], 0, "admin_audit ([\d\.]*) disabled\ncomments ([\d\.]*) disabled\nNo such app enabled: invalid_app"],
  63. [['files'], 2, "files can't be disabled"],
  64. [['provisioning_api'], 2, "provisioning_api can't be disabled"],
  65. [['files', 'admin_audit'], 2, "files can't be disabled.\nadmin_audit ([\d\.]*) disabled"],
  66. [['provisioning_api', 'comments'], 2, "provisioning_api can't be disabled.\ncomments ([\d\.]*) disabled"],
  67. ];
  68. }
  69. }