AppsEnableTest.php 3.5 KB

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