summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@owncloud.com>2016-02-04 13:05:05 +0100
committerRoeland Jago Douma <rullzer@owncloud.com>2016-02-04 13:05:05 +0100
commite0bc128eb55cb2cde1a28545a9e2e12bdcd8d53a (patch)
treef7cd34615c15b14fb9c527fbe7d87db922f0784d /tests
parentfc215d0980ec3cfa21ac64119bcec614cc1323bb (diff)
downloadnextcloud-server-e0bc128eb55cb2cde1a28545a9e2e12bdcd8d53a.tar.gz
nextcloud-server-e0bc128eb55cb2cde1a28545a9e2e12bdcd8d53a.zip
Add unit tests
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/share20/defaultshareprovidertest.php79
1 files changed, 79 insertions, 0 deletions
diff --git a/tests/lib/share20/defaultshareprovidertest.php b/tests/lib/share20/defaultshareprovidertest.php
index 1f3fa9af32e..86b89351611 100644
--- a/tests/lib/share20/defaultshareprovidertest.php
+++ b/tests/lib/share20/defaultshareprovidertest.php
@@ -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();