MountProviderTest.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. /**
  3. * @author Vincent Petry <pvince81@owncloud.com>
  4. *
  5. * @copyright Copyright (c) 2016, ownCloud, Inc.
  6. * @license AGPL-3.0
  7. *
  8. * This code is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License, version 3,
  10. * as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU Affero General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Affero General Public License, version 3,
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>
  19. *
  20. */
  21. namespace OCA\Files_Sharing\Tests;
  22. use OCA\Files_Sharing\MountProvider;
  23. use OCP\Files\Storage\IStorageFactory;
  24. use OCP\IConfig;
  25. use OCP\ILogger;
  26. use OCP\IUser;
  27. use OCP\Share\IShare;
  28. use OCP\Share\IManager;
  29. use OCP\Files\Mount\IMountPoint;
  30. class MountProviderTest extends \Test\TestCase {
  31. /** @var MountProvider */
  32. private $provider;
  33. /** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
  34. private $config;
  35. /** @var IUser|\PHPUnit_Framework_MockObject_MockObject */
  36. private $user;
  37. /** @var IStorageFactory|\PHPUnit_Framework_MockObject_MockObject */
  38. private $loader;
  39. /** @var IManager|\PHPUnit_Framework_MockObject_MockObject */
  40. private $shareManager;
  41. /** @var ILogger | \PHPUnit_Framework_MockObject_MockObject */
  42. private $logger;
  43. public function setUp() {
  44. parent::setUp();
  45. $this->config = $this->getMock('OCP\IConfig');
  46. $this->user = $this->getMock('OCP\IUser');
  47. $this->loader = $this->getMock('OCP\Files\Storage\IStorageFactory');
  48. $this->shareManager = $this->getMock('\OCP\Share\IManager');
  49. $this->logger = $this->getMock('\OCP\ILogger');
  50. $this->provider = new MountProvider($this->config, $this->shareManager, $this->logger);
  51. }
  52. public function testExcludeShares() {
  53. /** @var IShare | \PHPUnit_Framework_MockObject_MockObject $share1 */
  54. $share1 = $this->getMock('\OCP\Share\IShare');
  55. $share1->expects($this->once())
  56. ->method('getPermissions')
  57. ->will($this->returnValue(0));
  58. $share2 = $this->getMock('\OCP\Share\IShare');
  59. $share2->expects($this->once())
  60. ->method('getPermissions')
  61. ->will($this->returnValue(31));
  62. $share2->expects($this->any())
  63. ->method('getShareOwner')
  64. ->will($this->returnValue('user2'));
  65. $share2->expects($this->any())
  66. ->method('getTarget')
  67. ->will($this->returnValue('/share2'));
  68. $share3 = $this->getMock('\OCP\Share\IShare');
  69. $share3->expects($this->once())
  70. ->method('getPermissions')
  71. ->will($this->returnValue(0));
  72. /** @var IShare | \PHPUnit_Framework_MockObject_MockObject $share4 */
  73. $share4 = $this->getMock('\OCP\Share\IShare');
  74. $share4->expects($this->once())
  75. ->method('getPermissions')
  76. ->will($this->returnValue(31));
  77. $share4->expects($this->any())
  78. ->method('getShareOwner')
  79. ->will($this->returnValue('user2'));
  80. $share4->expects($this->any())
  81. ->method('getTarget')
  82. ->will($this->returnValue('/share4'));
  83. $share5 = $this->getMock('\OCP\Share\IShare');
  84. $share5->expects($this->once())
  85. ->method('getPermissions')
  86. ->will($this->returnValue(31));
  87. $share5->expects($this->any())
  88. ->method('getShareOwner')
  89. ->will($this->returnValue('user1'));
  90. $userShares = [$share1, $share2];
  91. $groupShares = [$share3, $share4, $share5];
  92. $this->user->expects($this->any())
  93. ->method('getUID')
  94. ->will($this->returnValue('user1'));
  95. $this->shareManager->expects($this->at(0))
  96. ->method('getSharedWith')
  97. ->with('user1', \OCP\Share::SHARE_TYPE_USER)
  98. ->will($this->returnValue($userShares));
  99. $this->shareManager->expects($this->at(1))
  100. ->method('getSharedWith')
  101. ->with('user1', \OCP\Share::SHARE_TYPE_GROUP, null, -1)
  102. ->will($this->returnValue($groupShares));
  103. $mounts = $this->provider->getMountsForUser($this->user, $this->loader);
  104. $this->assertCount(2, $mounts);
  105. $this->assertSharedMount($share1, $mounts[0]);
  106. $this->assertSharedMount($share4, $mounts[1]);
  107. }
  108. private function assertSharedMount(IShare $share, IMountPoint $mount) {
  109. $this->assertInstanceOf('OCA\Files_Sharing\SharedMount', $mount);
  110. $this->assertEquals($share, $mount->getShare());
  111. }
  112. }