]> source.dussan.org Git - nextcloud-server.git/commitdiff
Add unit tests
authorRoeland Jago Douma <rullzer@owncloud.com>
Thu, 4 Feb 2016 12:05:05 +0000 (13:05 +0100)
committerRoeland Jago Douma <rullzer@owncloud.com>
Thu, 4 Feb 2016 12:05:05 +0000 (13:05 +0100)
tests/lib/share20/defaultshareprovidertest.php

index 1f3fa9af32e8533748eaad9563529e4c02e64a78..86b89351611c1327ece1e7d95c175826d1cc25fc 100644 (file)
@@ -171,6 +171,85 @@ class DefaultShareProviderTest extends \Test\TestCase {
                $this->assertEquals('myTarget', $share->getTarget());
        }
 
+       public function testGetShareByIdLazy() {
+               $qb = $this->dbConn->getQueryBuilder();
+
+               $qb->insert('share')
+                       ->values([
+                               'share_type'  => $qb->expr()->literal(\OCP\Share::SHARE_TYPE_USER),
+                               'share_with'  => $qb->expr()->literal('sharedWith'),
+                               'uid_owner'   => $qb->expr()->literal('shareOwner'),
+                               'uid_initiator' => $qb->expr()->literal('sharedBy'),
+                               'item_type'   => $qb->expr()->literal('file'),
+                               'file_source' => $qb->expr()->literal(42),
+                               'file_target' => $qb->expr()->literal('myTarget'),
+                               'permissions' => $qb->expr()->literal(13),
+                       ]);
+               $qb->execute();
+
+               $id = $qb->getLastInsertId();
+
+               $this->rootFolder->expects($this->never())->method('getUserFolder');
+
+               $share = $this->provider->getShareById($id);
+
+               // We do not fetch the node so the rootfolder is never called.
+
+               $this->assertEquals($id, $share->getId());
+               $this->assertEquals(\OCP\Share::SHARE_TYPE_USER, $share->getShareType());
+               $this->assertEquals('sharedWith', $share->getSharedWith());
+               $this->assertEquals('sharedBy', $share->getSharedBy());
+               $this->assertEquals('shareOwner', $share->getShareOwner());
+               $this->assertEquals(13, $share->getPermissions());
+               $this->assertEquals(null, $share->getToken());
+               $this->assertEquals(null, $share->getExpirationDate());
+               $this->assertEquals('myTarget', $share->getTarget());
+       }
+
+       public function testGetShareByIdLazy2() {
+               $qb = $this->dbConn->getQueryBuilder();
+
+               $qb->insert('share')
+                       ->values([
+                               'share_type'  => $qb->expr()->literal(\OCP\Share::SHARE_TYPE_USER),
+                               'share_with'  => $qb->expr()->literal('sharedWith'),
+                               'uid_owner'   => $qb->expr()->literal('shareOwner'),
+                               'uid_initiator' => $qb->expr()->literal('sharedBy'),
+                               'item_type'   => $qb->expr()->literal('file'),
+                               'file_source' => $qb->expr()->literal(42),
+                               'file_target' => $qb->expr()->literal('myTarget'),
+                               'permissions' => $qb->expr()->literal(13),
+                       ]);
+               $qb->execute();
+
+               $id = $qb->getLastInsertId();
+
+               $ownerPath = $this->getMock('\OCP\Files\File');
+
+               $shareOwnerFolder = $this->getMock('\OCP\Files\Folder');
+               $shareOwnerFolder->method('getById')->with(42)->willReturn([$ownerPath]);
+
+               $this->rootFolder
+                       ->method('getUserFolder')
+                       ->with('shareOwner')
+                       ->willReturn($shareOwnerFolder);
+
+               $share = $this->provider->getShareById($id);
+
+               // We fetch the node so the root folder is eventually called
+
+               $this->assertEquals($id, $share->getId());
+               $this->assertEquals(\OCP\Share::SHARE_TYPE_USER, $share->getShareType());
+               $this->assertEquals('sharedWith', $share->getSharedWith());
+               $this->assertEquals('sharedBy', $share->getSharedBy());
+               $this->assertEquals('shareOwner', $share->getShareOwner());
+               $this->assertEquals($ownerPath, $share->getNode());
+               $this->assertEquals(13, $share->getPermissions());
+               $this->assertEquals(null, $share->getToken());
+               $this->assertEquals(null, $share->getExpirationDate());
+               $this->assertEquals('myTarget', $share->getTarget());
+       }
+
        public function testGetShareByIdGroupShare() {
                $qb = $this->dbConn->getQueryBuilder();