mirror of
https://github.com/nextcloud/server.git
synced 2026-02-20 00:12:30 -05:00
Add unit tests
This commit is contained in:
parent
fc215d0980
commit
e0bc128eb5
1 changed files with 79 additions and 0 deletions
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue