예제 #1
0
파일: avatartest.php 프로젝트: evanjt/core
 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 testGetShareByIdRemoteShare()
 {
     $qb = $this->dbConn->getQueryBuilder();
     $qb->insert('share')->values(['share_type' => $qb->expr()->literal(\OCP\Share::SHARE_TYPE_REMOTE), '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();
     $id = $cursor->fetch();
     $id = $id['id'];
     $cursor->closeCursor();
     $storage = $this->getMock('OC\\Files\\Storage\\Storage');
     $storage->expects($this->once())->method('getOwner')->willReturn('shareOwner');
     $path = $this->getMock('OCP\\Files\\Node');
     $path->expects($this->once())->method('getStorage')->wilLReturn($storage);
     $this->userFolder->expects($this->once())->method('getById')->with(42)->willReturn([$path]);
     $sharedBy = $this->getMock('OCP\\IUser');
     $shareOwner = $this->getMock('OCP\\IUser');
     $this->userManager->method('get')->will($this->returnValueMap([['sharedBy', $sharedBy], ['shareOwner', $shareOwner]]));
     $share = $this->provider->getShareById($id);
     $this->assertEquals($id, $share->getId());
     $this->assertEquals(\OCP\Share::SHARE_TYPE_REMOTE, $share->getShareType());
     $this->assertEquals('sharedWith', $share->getSharedWith());
     $this->assertEquals($sharedBy, $share->getSharedBy());
     $this->assertEquals($shareOwner, $share->getShareOwner());
     $this->assertEquals($path, $share->getPath());
     $this->assertEquals(13, $share->getPermissions());
     $this->assertEquals(null, $share->getToken());
     $this->assertEquals(null, $share->getExpirationDate());
     $this->assertEquals('myTarget', $share->getTarget());
 }
예제 #3
0
 public function testFindNodesByFileIdsSubDir()
 {
     $filesNode1 = $this->getMockBuilder('\\OCP\\Files\\Folder')->disableOriginalConstructor()->getMock();
     $filesNode1->expects($this->once())->method('getName')->will($this->returnValue('first node'));
     $filesNode2 = $this->getMockBuilder('\\OCP\\Files\\File')->disableOriginalConstructor()->getMock();
     $filesNode2->expects($this->once())->method('getName')->will($this->returnValue('second node'));
     $reportTargetNode = $this->getMockBuilder('\\OCA\\DAV\\Connector\\Sabre\\Directory')->disableOriginalConstructor()->getMock();
     $reportTargetNode->expects($this->any())->method('getPath')->will($this->returnValue('/sub1/sub2'));
     $subNode = $this->getMockBuilder('\\OCP\\Files\\Folder')->disableOriginalConstructor()->getMock();
     $this->userFolder->expects($this->at(0))->method('get')->with('/sub1/sub2')->will($this->returnValue($subNode));
     $subNode->expects($this->at(0))->method('getById')->with('111')->will($this->returnValue([$filesNode1]));
     $subNode->expects($this->at(1))->method('getById')->with('222')->will($this->returnValue([$filesNode2]));
     /** @var \OCA\DAV\Connector\Sabre\Directory|\PHPUnit_Framework_MockObject_MockObject $reportTargetNode */
     $result = $this->plugin->findNodesByFileIds($reportTargetNode, ['111', '222']);
     $this->assertCount(2, $result);
     $this->assertInstanceOf('\\OCA\\DAV\\Connector\\Sabre\\Directory', $result[0]);
     $this->assertEquals('first node', $result[0]->getName());
     $this->assertInstanceOf('\\OCA\\DAV\\Connector\\Sabre\\File', $result[1]);
     $this->assertEquals('second node', $result[1]->getName());
 }
예제 #4
0
파일: avatartest.php 프로젝트: kenwi/core
 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());
 }
예제 #5
0
 /**
  * @dataProvider sharesGetPropertiesDataProvider
  */
 public function testPreloadThenGetProperties($shareTypes)
 {
     $sabreNode1 = $this->getMockBuilder('\\OCA\\DAV\\Connector\\Sabre\\File')->disableOriginalConstructor()->getMock();
     $sabreNode1->expects($this->any())->method('getId')->will($this->returnValue(111));
     $sabreNode1->expects($this->never())->method('getPath');
     $sabreNode2 = $this->getMockBuilder('\\OCA\\DAV\\Connector\\Sabre\\File')->disableOriginalConstructor()->getMock();
     $sabreNode2->expects($this->any())->method('getId')->will($this->returnValue(222));
     $sabreNode2->expects($this->never())->method('getPath');
     $sabreNode = $this->getMockBuilder('\\OCA\\DAV\\Connector\\Sabre\\Directory')->disableOriginalConstructor()->getMock();
     $sabreNode->expects($this->any())->method('getId')->will($this->returnValue(123));
     // never, because we use getDirectoryListing from the Node API instead
     $sabreNode->expects($this->never())->method('getChildren');
     $sabreNode->expects($this->any())->method('getPath')->will($this->returnValue('/subdir'));
     // node API nodes
     $node = $this->getMock('\\OCP\\Files\\Folder');
     $node->expects($this->any())->method('getId')->will($this->returnValue(123));
     $node1 = $this->getMock('\\OCP\\Files\\File');
     $node1->expects($this->any())->method('getId')->will($this->returnValue(111));
     $node2 = $this->getMock('\\OCP\\Files\\File');
     $node2->expects($this->any())->method('getId')->will($this->returnValue(222));
     $node->expects($this->once())->method('getDirectoryListing')->will($this->returnValue([$node1, $node2]));
     $this->userFolder->expects($this->once())->method('get')->with('/subdir')->will($this->returnValue($node));
     $this->shareManager->expects($this->any())->method('getSharesBy')->with($this->equalTo('user1'), $this->anything(), $this->anything(), $this->equalTo(false), $this->equalTo(1))->will($this->returnCallback(function ($userId, $requestedShareType, $node, $flag, $limit) use($shareTypes) {
         if ($node->getId() === 111 && in_array($requestedShareType, $shareTypes)) {
             return ['dummyshare'];
         }
         return [];
     }));
     // simulate sabre recursive PROPFIND traversal
     $propFindRoot = new \Sabre\DAV\PropFind('/subdir', [self::SHARETYPES_PROPERTYNAME], 1);
     $propFind1 = new \Sabre\DAV\PropFind('/subdir/test.txt', [self::SHARETYPES_PROPERTYNAME], 0);
     $propFind2 = new \Sabre\DAV\PropFind('/subdir/test2.txt', [self::SHARETYPES_PROPERTYNAME], 0);
     $this->plugin->handleGetProperties($propFindRoot, $sabreNode);
     $this->plugin->handleGetProperties($propFind1, $sabreNode1);
     $this->plugin->handleGetProperties($propFind2, $sabreNode2);
     $result = $propFind1->getResultForMultiStatus();
     $this->assertEmpty($result[404]);
     unset($result[404]);
     $this->assertEquals($shareTypes, $result[200][self::SHARETYPES_PROPERTYNAME]->getShareTypes());
 }
예제 #6
0
 /**
  * @dataProvider showFileMethodProvider
  */
 public function testShowFileRouteWithTrashedFile($useShowFile)
 {
     $this->appManager->expects($this->once())->method('isEnabledForUser')->with('files_trashbin')->will($this->returnValue(true));
     $parentNode = $this->getMock('\\OCP\\Files\\Folder');
     $parentNode->expects($this->once())->method('getPath')->will($this->returnValue('testuser1/files_trashbin/files/test.d1462861890/sub'));
     $baseFolderFiles = $this->getMock('\\OCP\\Files\\Folder');
     $baseFolderTrash = $this->getMock('\\OCP\\Files\\Folder');
     $this->rootFolder->expects($this->at(0))->method('get')->with('testuser1/files/')->will($this->returnValue($baseFolderFiles));
     $this->rootFolder->expects($this->at(1))->method('get')->with('testuser1/files_trashbin/files/')->will($this->returnValue($baseFolderTrash));
     $baseFolderFiles->expects($this->once())->method('getById')->with(123)->will($this->returnValue([]));
     $node = $this->getMock('\\OCP\\Files\\File');
     $node->expects($this->once())->method('getParent')->will($this->returnValue($parentNode));
     $node->expects($this->once())->method('getName')->will($this->returnValue('somefile.txt'));
     $baseFolderTrash->expects($this->at(0))->method('getById')->with(123)->will($this->returnValue([$node]));
     $baseFolderTrash->expects($this->at(1))->method('getRelativePath')->with('testuser1/files_trashbin/files/test.d1462861890/sub')->will($this->returnValue('/test.d1462861890/sub'));
     $this->urlGenerator->expects($this->once())->method('linkToRoute')->with('files.view.index', ['view' => 'trashbin', 'dir' => '/test.d1462861890/sub', 'scrollto' => 'somefile.txt'])->will($this->returnValue('/apps/files/?view=trashbin&dir=/test.d1462861890/sub&scrollto=somefile.txt'));
     $expected = new Http\RedirectResponse('/apps/files/?view=trashbin&dir=/test.d1462861890/sub&scrollto=somefile.txt');
     if ($useShowFile) {
         $this->assertEquals($expected, $this->viewController->showFile(123));
     } else {
         $this->assertEquals($expected, $this->viewController->index('/whatever', '', '123'));
     }
 }
 public function testChildExistsWithoutAccess()
 {
     $this->userFolder->expects($this->once())->method('getById')->with('555')->will($this->returnValue([]));
     $this->assertFalse($this->node->childExists('555'));
 }