diff options
author | Roeland Jago Douma <rullzer@owncloud.com> | 2016-02-04 12:51:23 +0100 |
---|---|---|
committer | Roeland Jago Douma <rullzer@owncloud.com> | 2016-02-04 12:51:23 +0100 |
commit | fc215d0980ec3cfa21ac64119bcec614cc1323bb (patch) | |
tree | 4b4aac5a83f642f35404fc1be7a593d58d77e8c8 /tests | |
parent | cd16ba5cb3bf9333b0ecacab4bf152c1b692ed59 (diff) | |
download | nextcloud-server-fc215d0980ec3cfa21ac64119bcec614cc1323bb.tar.gz nextcloud-server-fc215d0980ec3cfa21ac64119bcec614cc1323bb.zip |
Make the share object lazy
Share providers can now just pass in a fileId. And the node will only be
created once needed.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/share20/defaultshareprovidertest.php | 6 | ||||
-rw-r--r-- | tests/lib/share20/managertest.php | 93 |
2 files changed, 50 insertions, 49 deletions
diff --git a/tests/lib/share20/defaultshareprovidertest.php b/tests/lib/share20/defaultshareprovidertest.php index 19f21fba7b1..1f3fa9af32e 100644 --- a/tests/lib/share20/defaultshareprovidertest.php +++ b/tests/lib/share20/defaultshareprovidertest.php @@ -561,7 +561,7 @@ class DefaultShareProviderTest extends \Test\TestCase { } public function testCreateUserShare() { - $share = new \OC\Share20\Share(); + $share = new \OC\Share20\Share($this->rootFolder); $shareOwner = $this->getMock('OCP\IUser'); $shareOwner->method('getUID')->WillReturn('shareOwner'); @@ -609,7 +609,7 @@ class DefaultShareProviderTest extends \Test\TestCase { } public function testCreateGroupShare() { - $share = new \OC\Share20\Share(); + $share = new \OC\Share20\Share($this->rootFolder); $shareOwner = $this->getMock('\OCP\IUser'); $shareOwner->method('getUID')->willReturn('shareOwner'); @@ -657,7 +657,7 @@ class DefaultShareProviderTest extends \Test\TestCase { } public function testCreateLinkShare() { - $share = new \OC\Share20\Share(); + $share = new \OC\Share20\Share($this->rootFolder); $shareOwner = $this->getMock('\OCP\IUser'); $shareOwner->method('getUID')->willReturn('shareOwner'); diff --git a/tests/lib/share20/managertest.php b/tests/lib/share20/managertest.php index aa286cc4719..01e5283fcf7 100644 --- a/tests/lib/share20/managertest.php +++ b/tests/lib/share20/managertest.php @@ -20,6 +20,7 @@ */ namespace Test\Share20; +use OCP\Files\IRootFolder; use OCP\IUserManager; use OCP\Share\IProviderFactory; use OCP\Share\IShare; @@ -35,7 +36,6 @@ use OCP\Security\ISecureRandom; use OCP\Security\IHasher; use OCP\Files\Mount\IMountManager; use OCP\IGroupManager; -use Sabre\VObject\Property\VCard\DateTime; /** * Class ManagerTest @@ -47,36 +47,28 @@ class ManagerTest extends \Test\TestCase { /** @var Manager */ protected $manager; - /** @var ILogger */ protected $logger; - /** @var IConfig */ protected $config; - /** @var ISecureRandom */ protected $secureRandom; - /** @var IHasher */ protected $hasher; - /** @var IShareProvider | \PHPUnit_Framework_MockObject_MockObject */ protected $defaultProvider; - /** @var IMountManager */ protected $mountManager; - /** @var IGroupManager */ protected $groupManager; - /** @var IL10N */ protected $l; - /** @var DummyFactory */ protected $factory; - /** @var IUserManager */ protected $userManager; + /** @var IRootFolder | \PHPUnit_Framework_MockObject_MockObject */ + protected $rootFolder; public function setUp() { @@ -87,6 +79,7 @@ class ManagerTest extends \Test\TestCase { $this->mountManager = $this->getMock('\OCP\Files\Mount\IMountManager'); $this->groupManager = $this->getMock('\OCP\IGroupManager'); $this->userManager = $this->getMock('\OCP\IUserManager'); + $this->rootFolder = $this->getMock('\OCP\Files\IRootFolder'); $this->l = $this->getMock('\OCP\IL10N'); $this->l->method('t') @@ -105,7 +98,8 @@ class ManagerTest extends \Test\TestCase { $this->groupManager, $this->l, $this->factory, - $this->userManager + $this->userManager, + $this->rootFolder ); $this->defaultProvider = $this->getMockBuilder('\OC\Share20\DefaultShareProvider') @@ -131,7 +125,8 @@ class ManagerTest extends \Test\TestCase { $this->groupManager, $this->l, $this->factory, - $this->userManager + $this->userManager, + $this->rootFolder ]); } @@ -792,7 +787,7 @@ class ManagerTest extends \Test\TestCase { * @expectedExceptionMessage Only sharing with group members is allowed */ public function testUserCreateChecksShareWithGroupMembersOnlyDifferentGroups() { - $share = new \OC\Share20\Share(); + $share = $this->manager->newShare(); $sharedBy = $this->getMock('\OCP\IUser'); $sharedWith = $this->getMock('\OCP\IUser'); @@ -822,7 +817,7 @@ class ManagerTest extends \Test\TestCase { } public function testUserCreateChecksShareWithGroupMembersOnlySharedGroup() { - $share = new \OC\Share20\Share(); + $share = $this->manager->newShare(); $sharedBy = $this->getMock('\OCP\IUser'); $sharedWith = $this->getMock('\OCP\IUser'); @@ -904,8 +899,7 @@ class ManagerTest extends \Test\TestCase { ->setProviderId('foo') ->setId('bar'); - $share2 = new \OC\Share20\Share(); - $owner2 = $this->getMock('\OCP\IUser'); + $share2 = $this->manager->newShare(); $share2->setShareType(\OCP\Share::SHARE_TYPE_GROUP) ->setShareOwner('shareOwner2') ->setProviderId('foo') @@ -928,7 +922,7 @@ class ManagerTest extends \Test\TestCase { } public function testUserCreateChecksIdenticalPathNotSharedWithUser() { - $share = new \OC\Share20\Share(); + $share = $this->manager->newShare(); $sharedWith = $this->getMock('\OCP\IUser'); $path = $this->getMock('\OCP\Files\Node'); $share->setSharedWith('sharedWith') @@ -939,7 +933,7 @@ class ManagerTest extends \Test\TestCase { $this->userManager->method('get')->with('sharedWith')->willReturn($sharedWith); - $share2 = new \OC\Share20\Share(); + $share2 = $this->manager->newShare(); $share2->setShareType(\OCP\Share::SHARE_TYPE_GROUP) ->setShareOwner('shareOwner2') ->setProviderId('foo') @@ -967,7 +961,7 @@ class ManagerTest extends \Test\TestCase { * @expectedExceptionMessage Only sharing within your own groups is allowed */ public function testGroupCreateChecksShareWithGroupMembersOnlyNotInGroup() { - $share = new \OC\Share20\Share(); + $share = $this->manager->newShare(); $user = $this->getMock('\OCP\IUser'); $group = $this->getMock('\OCP\IGroup'); @@ -988,7 +982,7 @@ class ManagerTest extends \Test\TestCase { } public function testGroupCreateChecksShareWithGroupMembersOnlyInGroup() { - $share = new \OC\Share20\Share(); + $share = $this->manager->newShare(); $user = $this->getMock('\OCP\IUser'); $group = $this->getMock('\OCP\IGroup'); @@ -1028,7 +1022,7 @@ class ManagerTest extends \Test\TestCase { ->setProviderId('foo') ->setId('bar'); - $share2 = new \OC\Share20\Share(); + $share2 = $this->manager->newShare(); $share2->setSharedWith('sharedWith') ->setProviderId('foo') ->setId('baz'); @@ -1041,14 +1035,14 @@ class ManagerTest extends \Test\TestCase { } public function testGroupCreateChecksPathAlreadySharedWithDifferentGroup() { - $share = new \OC\Share20\Share(); + $share = $this->manager->newShare(); $share->setSharedWith('sharedWith'); $path = $this->getMock('\OCP\Files\Node'); $share->setNode($path); - $share2 = new \OC\Share20\Share(); + $share2 = $this->manager->newShare(); $share2->setSharedWith('sharedWith2'); $this->defaultProvider->method('getSharesByPath') @@ -1063,7 +1057,7 @@ class ManagerTest extends \Test\TestCase { * @expectedExceptionMessage Link sharing not allowed */ public function testLinkCreateChecksNoLinkSharesAllowed() { - $share = new \OC\Share20\Share(); + $share = $this->manager->newShare(); $this->config ->method('getAppValue') @@ -1079,7 +1073,7 @@ class ManagerTest extends \Test\TestCase { * @expectedExceptionMessage Link shares can't have reshare permissions */ public function testLinkCreateChecksSharePermissions() { - $share = new \OC\Share20\Share(); + $share = $this->manager->newShare(); $share->setPermissions(\OCP\Constants::PERMISSION_SHARE); @@ -1097,7 +1091,7 @@ class ManagerTest extends \Test\TestCase { * @expectedExceptionMessage Link shares can't have delete permissions */ public function testLinkCreateChecksDeletePermissions() { - $share = new \OC\Share20\Share(); + $share = $this->manager->newShare(); $share->setPermissions(\OCP\Constants::PERMISSION_DELETE); @@ -1115,7 +1109,7 @@ class ManagerTest extends \Test\TestCase { * @expectedExceptionMessage Public upload not allowed */ public function testLinkCreateChecksNoPublicUpload() { - $share = new \OC\Share20\Share(); + $share = $this->manager->newShare(); $share->setPermissions(\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE); @@ -1130,7 +1124,7 @@ class ManagerTest extends \Test\TestCase { } public function testLinkCreateChecksPublicUpload() { - $share = new \OC\Share20\Share(); + $share = $this->manager->newShare(); $share->setPermissions(\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE); @@ -1145,7 +1139,7 @@ class ManagerTest extends \Test\TestCase { } public function testLinkCreateChecksReadOnly() { - $share = new \OC\Share20\Share(); + $share = $this->manager->newShare(); $share->setPermissions(\OCP\Constants::PERMISSION_READ); @@ -1316,7 +1310,7 @@ class ManagerTest extends \Test\TestCase { ->getMock(); $manager->expects($this->once())->method('canShare')->willReturn(false); - $share = new \OC\Share20\Share(); + $share = $this->manager->newShare(); $manager->createShare($share); } @@ -1610,7 +1604,8 @@ class ManagerTest extends \Test\TestCase { $this->groupManager, $this->l, $factory, - $this->userManager + $this->userManager, + $this->rootFolder ); $share = $this->getMock('\OCP\Share\IShare'); @@ -1695,7 +1690,7 @@ class ManagerTest extends \Test\TestCase { ->getMock(); $manager->expects($this->once())->method('canShare')->willReturn(false); - $share = new \OC\Share20\Share(); + $share = $this->manager->newShare(); $manager->updateShare($share); } @@ -1711,13 +1706,13 @@ class ManagerTest extends \Test\TestCase { ]) ->getMock(); - $originalShare = new \OC\Share20\Share(); + $originalShare = $this->manager->newShare(); $originalShare->setShareType(\OCP\Share::SHARE_TYPE_GROUP); $manager->expects($this->once())->method('canShare')->willReturn(true); $manager->expects($this->once())->method('getShareById')->with('foo:42')->willReturn($originalShare); - $share = new \OC\Share20\Share(); + $share = $this->manager->newShare(); $share->setProviderId('foo') ->setId('42') ->setShareType(\OCP\Share::SHARE_TYPE_USER); @@ -1737,14 +1732,14 @@ class ManagerTest extends \Test\TestCase { ]) ->getMock(); - $originalShare = new \OC\Share20\Share(); + $originalShare = $this->manager->newShare(); $originalShare->setShareType(\OCP\Share::SHARE_TYPE_GROUP) ->setSharedWith('origGroup'); $manager->expects($this->once())->method('canShare')->willReturn(true); $manager->expects($this->once())->method('getShareById')->with('foo:42')->willReturn($originalShare); - $share = new \OC\Share20\Share(); + $share = $this->manager->newShare(); $share->setProviderId('foo') ->setId('42') ->setShareType(\OCP\Share::SHARE_TYPE_GROUP) @@ -1765,14 +1760,14 @@ class ManagerTest extends \Test\TestCase { ]) ->getMock(); - $originalShare = new \OC\Share20\Share(); + $originalShare = $this->manager->newShare(); $originalShare->setShareType(\OCP\Share::SHARE_TYPE_USER) ->setSharedWith('sharedWith'); $manager->expects($this->once())->method('canShare')->willReturn(true); $manager->expects($this->once())->method('getShareById')->with('foo:42')->willReturn($originalShare); - $share = new \OC\Share20\Share(); + $share = $this->manager->newShare(); $share->setProviderId('foo') ->setId('42') ->setShareType(\OCP\Share::SHARE_TYPE_USER) @@ -1793,19 +1788,22 @@ class ManagerTest extends \Test\TestCase { ]) ->getMock(); - $originalShare = new \OC\Share20\Share(); + $originalShare = $this->manager->newShare(); $originalShare->setShareType(\OCP\Share::SHARE_TYPE_USER) ->setSharedWith('origUser'); $manager->expects($this->once())->method('canShare')->willReturn(true); $manager->expects($this->once())->method('getShareById')->with('foo:42')->willReturn($originalShare); - $share = new \OC\Share20\Share(); + $node = $this->getMock('\OCP\Files\File'); + + $share = $this->manager->newShare(); $share->setProviderId('foo') ->setId('42') ->setShareType(\OCP\Share::SHARE_TYPE_USER) ->setSharedWith('origUser') - ->setShareOwner('newUser'); + ->setShareOwner('newUser') + ->setNode($node); $this->defaultProvider->expects($this->once()) ->method('update') @@ -1831,19 +1829,22 @@ class ManagerTest extends \Test\TestCase { ]) ->getMock(); - $originalShare = new \OC\Share20\Share(); + $originalShare = $this->manager->newShare(); $originalShare->setShareType(\OCP\Share::SHARE_TYPE_GROUP) ->setSharedWith('origUser'); $manager->expects($this->once())->method('canShare')->willReturn(true); $manager->expects($this->once())->method('getShareById')->with('foo:42')->willReturn($originalShare); - $share = new \OC\Share20\Share(); + $node = $this->getMock('\OCP\Files\File'); + + $share = $this->manager->newShare(); $share->setProviderId('foo') ->setId('42') ->setShareType(\OCP\Share::SHARE_TYPE_GROUP) ->setSharedWith('origUser') - ->setShareOwner('owner'); + ->setShareOwner('owner') + ->setNode($node); $this->defaultProvider->expects($this->once()) ->method('update') @@ -1871,7 +1872,7 @@ class ManagerTest extends \Test\TestCase { ]) ->getMock(); - $originalShare = new \OC\Share20\Share(); + $originalShare = $this->manager->newShare(); $originalShare->setShareType(\OCP\Share::SHARE_TYPE_LINK); $tomorrow = new \DateTime(); |