You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ApplicableTest.php 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Robin Appelman <robin@icewind.nl>
  6. * @author Roeland Jago Douma <roeland@famdouma.nl>
  7. *
  8. * @license AGPL-3.0
  9. *
  10. * This code is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License, version 3,
  12. * as published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License, version 3,
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>
  21. *
  22. */
  23. namespace OCA\Files_External\Tests\Command;
  24. use OCA\Files_External\Command\Applicable;
  25. use OCP\IGroupManager;
  26. use OCP\IUserManager;
  27. class ApplicableTest extends CommandTest {
  28. private function getInstance($storageService) {
  29. /** @var \OCP\IUserManager|\PHPUnit_Framework_MockObject_MockObject $userManager */
  30. $userManager = $this->createMock(IUserManager::class);
  31. /** @var \OCP\IGroupManager|\PHPUnit_Framework_MockObject_MockObject $groupManager */
  32. $groupManager = $this->createMock(IGroupManager::class);
  33. $userManager->expects($this->any())
  34. ->method('userExists')
  35. ->will($this->returnValue(true));
  36. $groupManager->expects($this->any())
  37. ->method('groupExists')
  38. ->will($this->returnValue(true));
  39. return new Applicable($storageService, $userManager, $groupManager);
  40. }
  41. public function testListEmpty() {
  42. $mount = $this->getMount(1, '', '');
  43. $storageService = $this->getGlobalStorageService([$mount]);
  44. $command = $this->getInstance($storageService);
  45. $input = $this->getInput($command, [
  46. 'mount_id' => 1
  47. ], [
  48. 'output' => 'json'
  49. ]);
  50. $result = json_decode($this->executeCommand($command, $input), true);
  51. $this->assertEquals(['users' => [], 'groups' => []], $result);
  52. }
  53. public function testList() {
  54. $mount = $this->getMount(1, '', '', '', [], [], ['test', 'asd']);
  55. $storageService = $this->getGlobalStorageService([$mount]);
  56. $command = $this->getInstance($storageService);
  57. $input = $this->getInput($command, [
  58. 'mount_id' => 1
  59. ], [
  60. 'output' => 'json'
  61. ]);
  62. $result = json_decode($this->executeCommand($command, $input), true);
  63. $this->assertEquals(['users' => ['test', 'asd'], 'groups' => []], $result);
  64. }
  65. public function testAddSingle() {
  66. $mount = $this->getMount(1, '', '', '', [], [], []);
  67. $storageService = $this->getGlobalStorageService([$mount]);
  68. $command = $this->getInstance($storageService);
  69. $input = $this->getInput($command, [
  70. 'mount_id' => 1
  71. ], [
  72. 'output' => 'json',
  73. 'add-user' => ['foo']
  74. ]);
  75. $this->executeCommand($command, $input);
  76. $this->assertEquals(['foo'], $mount->getApplicableUsers());
  77. }
  78. public function testAddDuplicate() {
  79. $mount = $this->getMount(1, '', '', '', [], [], ['foo']);
  80. $storageService = $this->getGlobalStorageService([$mount]);
  81. $command = $this->getInstance($storageService);
  82. $input = $this->getInput($command, [
  83. 'mount_id' => 1
  84. ], [
  85. 'output' => 'json',
  86. 'add-user' => ['foo', 'bar']
  87. ]);
  88. $this->executeCommand($command, $input);
  89. $this->assertEquals(['foo', 'bar'], $mount->getApplicableUsers());
  90. }
  91. public function testRemoveSingle() {
  92. $mount = $this->getMount(1, '', '', '', [], [], ['foo', 'bar']);
  93. $storageService = $this->getGlobalStorageService([$mount]);
  94. $command = $this->getInstance($storageService);
  95. $input = $this->getInput($command, [
  96. 'mount_id' => 1
  97. ], [
  98. 'output' => 'json',
  99. 'remove-user' => ['bar']
  100. ]);
  101. $this->executeCommand($command, $input);
  102. $this->assertEquals(['foo'], $mount->getApplicableUsers());
  103. }
  104. public function testRemoveNonExisting() {
  105. $mount = $this->getMount(1, '', '', '', [], [], ['foo', 'bar']);
  106. $storageService = $this->getGlobalStorageService([$mount]);
  107. $command = $this->getInstance($storageService);
  108. $input = $this->getInput($command, [
  109. 'mount_id' => 1
  110. ], [
  111. 'output' => 'json',
  112. 'remove-user' => ['bar', 'asd']
  113. ]);
  114. $this->executeCommand($command, $input);
  115. $this->assertEquals(['foo'], $mount->getApplicableUsers());
  116. }
  117. public function testRemoveAddRemove() {
  118. $mount = $this->getMount(1, '', '', '', [], [], ['foo', 'bar']);
  119. $storageService = $this->getGlobalStorageService([$mount]);
  120. $command = $this->getInstance($storageService);
  121. $input = $this->getInput($command, [
  122. 'mount_id' => 1
  123. ], [
  124. 'output' => 'json',
  125. 'remove-user' => ['bar', 'asd'],
  126. 'add-user' => ['test']
  127. ]);
  128. $this->executeCommand($command, $input);
  129. $this->assertEquals(['foo', 'test'], $mount->getApplicableUsers());
  130. }
  131. }