AppsEnableTest.php 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. public function setUp() {
  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 $output
  50. */
  51. public function testCommandInput($appId, $groups, $statusCode, $output): void {
  52. $input = ['app-id' => $appId];
  53. if (is_array($groups)) {
  54. $input['--groups'] = $groups;
  55. }
  56. $this->commandTester->execute($input);
  57. $this->assertContains($output, $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 enabled'],
  63. [['comments'], null, 0, 'comments enabled'],
  64. [['invalid_app'], null, 1, 'Could not download app invalid_app'],
  65. [['admin_audit', 'comments'], null, 0, "admin_audit enabled\ncomments enabled"],
  66. [['admin_audit', 'comments', 'invalid_app'], null, 1, "admin_audit enabled\ncomments enabled\nCould not download app invalid_app"],
  67. [['admin_audit'], ['admin'], 1, "admin_audit can't be enabled for groups"],
  68. [['comments'], ['admin'], 1, "comments can't be enabled for groups"],
  69. [['updatenotification'], ['admin'], 0, 'updatenotification enabled for groups: admin'],
  70. # TODO: not reliable due to dependency to appstore
  71. # [['updatenotification', 'contacts'], ['admin'], 0, "updatenotification enabled for groups: admin\ncontacts enabled for groups: admin"],
  72. [['updatenotification', 'accessibility'], ['admin'], 0, "updatenotification enabled for groups: admin\naccessibility enabled for groups: admin"],
  73. [['updatenotification'], ['admin', 'invalid_group'], 0, 'updatenotification enabled for groups: admin'],
  74. # TODO: not reliable due to dependency to appstore
  75. # [['updatenotification', 'contacts'], ['admin', 'invalid_group'], 0, "updatenotification enabled for groups: admin\ncontacts enabled for groups: admin"],
  76. # [['updatenotification', 'contacts', 'invalid_app'], ['admin', 'invalid_group'], 1, "updatenotification enabled for groups: admin\ncontacts enabled for groups: admin\nCould not download app invalid_app"],
  77. [['updatenotification', 'accessibility'], ['admin', 'invalid_group'], 0, "updatenotification enabled for groups: admin\naccessibility enabled for groups: admin"],
  78. [['updatenotification', 'accessibility', 'invalid_app'], ['admin', 'invalid_group'], 1, "updatenotification enabled for groups: admin\naccessibility enabled for groups: admin\nCould not download app invalid_app"],
  79. ];
  80. }
  81. }