1
0

AppsEnableTest.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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\Enable;
  9. use Symfony\Component\Console\Tester\CommandTester;
  10. use Test\TestCase;
  11. /**
  12. * Class AppsEnableTest
  13. *
  14. * @group DB
  15. */
  16. class AppsEnableTest extends TestCase {
  17. /** @var CommandTester */
  18. private $commandTester;
  19. protected function setUp(): void {
  20. parent::setUp();
  21. $command = new Enable(
  22. \OC::$server->getAppManager(),
  23. \OC::$server->getGroupManager()
  24. );
  25. $this->commandTester = new CommandTester($command);
  26. \OC::$server->getAppManager()->disableApp('admin_audit');
  27. \OC::$server->getAppManager()->disableApp('comments');
  28. }
  29. /**
  30. * @dataProvider dataCommandInput
  31. * @param $appId
  32. * @param $groups
  33. * @param $statusCode
  34. * @param $pattern
  35. */
  36. public function testCommandInput($appId, $groups, $statusCode, $pattern): void {
  37. $input = ['app-id' => $appId];
  38. if (is_array($groups)) {
  39. $input['--groups'] = $groups;
  40. }
  41. $this->commandTester->execute($input);
  42. $this->assertMatchesRegularExpression('/' . $pattern . '/', $this->commandTester->getDisplay());
  43. $this->assertSame($statusCode, $this->commandTester->getStatusCode());
  44. }
  45. public function dataCommandInput(): array {
  46. return [
  47. [['admin_audit'], null, 0, 'admin_audit ([\d\.]*) enabled'],
  48. [['comments'], null, 0, 'comments ([\d\.]*) enabled'],
  49. [['comments', 'comments'], null, 0, "comments ([\d\.]*) enabled\ncomments already enabled"],
  50. [['invalid_app'], null, 1, 'Could not download app invalid_app'],
  51. [['admin_audit', 'comments'], null, 0, "admin_audit ([\d\.]*) enabled\ncomments ([\d\.]*) enabled"],
  52. [['admin_audit', 'comments', 'invalid_app'], null, 1, "admin_audit ([\d\.]*) enabled\ncomments ([\d\.]*) enabled\nCould not download app invalid_app"],
  53. [['admin_audit'], ['admin'], 1, "admin_audit can't be enabled for groups"],
  54. [['comments'], ['admin'], 1, "comments can't be enabled for groups"],
  55. [['updatenotification'], ['admin'], 0, 'updatenotification ([\d\.]*) enabled for groups: admin'],
  56. [['updatenotification', 'dashboard'], ['admin'], 0, "updatenotification ([\d\.]*) enabled for groups: admin\ndashboard ([\d\.]*) enabled for groups: admin"],
  57. [['updatenotification'], ['admin', 'invalid_group'], 0, 'updatenotification ([\d\.]*) enabled for groups: admin'],
  58. [['updatenotification', 'dashboard'], ['admin', 'invalid_group'], 0, "updatenotification ([\d\.]*) enabled for groups: admin\ndashboard ([\d\.]*) enabled for groups: admin"],
  59. [['updatenotification', 'dashboard', 'invalid_app'], ['admin', 'invalid_group'], 1, "updatenotification ([\d\.]*) enabled for groups: admin\ndashboard ([\d\.]*) enabled for groups: admin\nCould not download app invalid_app"],
  60. ];
  61. }
  62. }