public function testSetAvatar() { $oldFile = $this->getMock('\\OCP\\Files\\File'); $this->folder->method('get')->will($this->returnValueMap([['avatar.jpg', $oldFile], ['avatar.png', $oldFile]])); $oldFile->expects($this->exactly(2))->method('delete'); $newFile = $this->getMock('\\OCP\\Files\\File'); $this->folder->expects($this->once())->method('newFile')->with('avatar.png')->willReturn($newFile); $image = new OC_Image(\OC::$SERVERROOT . '/tests/data/testavatar.png'); $newFile->expects($this->once())->method('putContent')->with($image->data()); $this->avatar->set($image->data()); }
public function testGetChildren() { $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('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(); // Get the id $qb = $this->dbConn->getQueryBuilder(); $cursor = $qb->select('id')->from('share')->setMaxResults(1)->orderBy('id', 'DESC')->execute(); $id = $cursor->fetch(); $id = $id['id']; $cursor->closeCursor(); $qb = $this->dbConn->getQueryBuilder(); $qb->insert('share')->values(['share_type' => $qb->expr()->literal(\OCP\Share::SHARE_TYPE_USER), 'share_with' => $qb->expr()->literal('user1'), 'uid_owner' => $qb->expr()->literal('user2'), 'item_type' => $qb->expr()->literal('file'), 'file_source' => $qb->expr()->literal(1), 'file_target' => $qb->expr()->literal('myTarget1'), 'permissions' => $qb->expr()->literal(2), 'parent' => $qb->expr()->literal($id)]); $qb->execute(); $qb = $this->dbConn->getQueryBuilder(); $qb->insert('share')->values(['share_type' => $qb->expr()->literal(\OCP\Share::SHARE_TYPE_GROUP), 'share_with' => $qb->expr()->literal('group1'), 'uid_owner' => $qb->expr()->literal('user3'), 'item_type' => $qb->expr()->literal('folder'), 'file_source' => $qb->expr()->literal(3), 'file_target' => $qb->expr()->literal('myTarget2'), 'permissions' => $qb->expr()->literal(4), 'parent' => $qb->expr()->literal($id)]); $qb->execute(); $storage = $this->getMock('OC\\Files\\Storage\\Storage'); $storage->method('getOwner')->willReturn('shareOwner'); $path1 = $this->getMock('OCP\\Files\\File'); $path1->expects($this->once())->method('getStorage')->willReturn($storage); $path2 = $this->getMock('OCP\\Files\\Folder'); $path2->expects($this->once())->method('getStorage')->willReturn($storage); $this->userFolder->method('getById')->will($this->returnValueMap([[1, [$path1]], [3, [$path2]]])); $shareOwner = $this->getMock('OCP\\IUser'); $user1 = $this->getMock('OCP\\IUser'); $user2 = $this->getMock('OCP\\IUser'); $user3 = $this->getMock('OCP\\IUser'); $this->userManager->method('get')->will($this->returnValueMap([['shareOwner', $shareOwner], ['user1', $user1], ['user2', $user2], ['user3', $user3]])); $group1 = $this->getMock('OCP\\IGroup'); $this->groupManager->method('get')->will($this->returnValueMap([['group1', $group1]])); $share = $this->getMock('\\OC\\Share20\\IShare'); $share->method('getId')->willReturn($id); $children = $this->provider->getChildren($share); $this->assertCount(2, $children); //Child1 $this->assertEquals(\OCP\Share::SHARE_TYPE_USER, $children[0]->getShareType()); $this->assertEquals($user1, $children[0]->getSharedWith()); $this->assertEquals($user2, $children[0]->getSharedBy()); $this->assertEquals($shareOwner, $children[0]->getShareOwner()); $this->assertEquals($path1, $children[0]->getPath()); $this->assertEquals(2, $children[0]->getPermissions()); $this->assertEquals(null, $children[0]->getToken()); $this->assertEquals(null, $children[0]->getExpirationDate()); $this->assertEquals('myTarget1', $children[0]->getTarget()); //Child2 $this->assertEquals(\OCP\Share::SHARE_TYPE_GROUP, $children[1]->getShareType()); $this->assertEquals($group1, $children[1]->getSharedWith()); $this->assertEquals($user3, $children[1]->getSharedBy()); $this->assertEquals($shareOwner, $children[1]->getShareOwner()); $this->assertEquals($path2, $children[1]->getPath()); $this->assertEquals(4, $children[1]->getPermissions()); $this->assertEquals(null, $children[1]->getToken()); $this->assertEquals(null, $children[1]->getExpirationDate()); $this->assertEquals('myTarget2', $children[1]->getTarget()); }
public function testDeleteNestedShares() { $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('sharedBy'), 'item_type' => $qb->expr()->literal('file'), 'file_source' => $qb->expr()->literal(42), 'file_target' => $qb->expr()->literal('myTarget'), 'permissions' => $qb->expr()->literal(13)]); $this->assertEquals(1, $qb->execute()); // Get the id $qb = $this->dbConn->getQueryBuilder(); $cursor = $qb->select('id')->from('share')->setMaxResults(1)->orderBy('id', 'DESC')->execute(); $id1 = $cursor->fetch(); $id1 = $id1['id']; $cursor->closeCursor(); $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('sharedBy'), 'item_type' => $qb->expr()->literal('file'), 'file_source' => $qb->expr()->literal(42), 'file_target' => $qb->expr()->literal('myTarget'), 'permissions' => $qb->expr()->literal(13), 'parent' => $qb->expr()->literal($id1)]); $this->assertEquals(1, $qb->execute()); // Get the id $qb = $this->dbConn->getQueryBuilder(); $cursor = $qb->select('id')->from('share')->setMaxResults(1)->orderBy('id', 'DESC')->execute(); $id2 = $cursor->fetch(); $id2 = $id2['id']; $cursor->closeCursor(); $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('sharedBy'), 'item_type' => $qb->expr()->literal('file'), 'file_source' => $qb->expr()->literal(42), 'file_target' => $qb->expr()->literal('myTarget'), 'permissions' => $qb->expr()->literal(13), 'parent' => $qb->expr()->literal($id2)]); $this->assertEquals(1, $qb->execute()); $storage = $this->getMock('OC\\Files\\Storage\\Storage'); $storage->method('getOwner')->willReturn('shareOwner'); $path = $this->getMock('OCP\\Files\\Node'); $path->method('getStorage')->wilLReturn($storage); $this->userFolder->method('getById')->with(42)->willReturn([$path]); $sharedWith = $this->getMock('OCP\\IUser'); $sharedWith->method('getUID')->willReturn('sharedWith'); $sharedBy = $this->getMock('OCP\\IUser'); $sharedBy->method('getUID')->willReturn('sharedBy'); $shareOwner = $this->getMock('OCP\\IUser'); $this->userManager->method('get')->will($this->returnValueMap([['sharedWith', $sharedWith], ['sharedBy', $sharedBy], ['shareOwner', $shareOwner]])); $share = $this->provider->getShareById($id1); $this->provider->delete($share); $qb = $this->dbConn->getQueryBuilder(); $qb->select('*')->from('share'); $cursor = $qb->execute(); $result = $cursor->fetchAll(); $cursor->closeCursor(); $this->assertEmpty($result); }
public function testSetAvatar() { $avatarFileJPG = $this->getMock('\\OCP\\Files\\File'); $avatarFileJPG->method('getName')->willReturn('avatar.jpg'); $avatarFileJPG->expects($this->once())->method('delete'); $avatarFilePNG = $this->getMock('\\OCP\\Files\\File'); $avatarFilePNG->method('getName')->willReturn('avatar.png'); $avatarFilePNG->expects($this->once())->method('delete'); $resizedAvatarFile = $this->getMock('\\OCP\\Files\\File'); $resizedAvatarFile->method('getName')->willReturn('avatar.32.jpg'); $resizedAvatarFile->expects($this->once())->method('delete'); $nonAvatarFile = $this->getMock('\\OCP\\Files\\File'); $nonAvatarFile->method('getName')->willReturn('avatarX'); $nonAvatarFile->expects($this->never())->method('delete'); $this->folder->method('search')->with('avatar')->willReturn([$avatarFileJPG, $avatarFilePNG, $resizedAvatarFile, $nonAvatarFile]); $newFile = $this->getMock('\\OCP\\Files\\File'); $this->folder->expects($this->once())->method('newFile')->with('avatar.png')->willReturn($newFile); $image = new OC_Image(\OC::$SERVERROOT . '/tests/data/testavatar.png'); $newFile->expects($this->once())->method('putContent')->with($image->data()); $this->avatar->set($image->data()); }