示例#1
0
 private function createTestNode($class)
 {
     $node = $this->getMockBuilder($class)->disableOriginalConstructor()->getMock();
     $node->expects($this->any())->method('getId')->will($this->returnValue(123));
     $this->tree->expects($this->any())->method('getNodeForPath')->with('/dummypath')->will($this->returnValue($node));
     $node->expects($this->any())->method('getFileId')->will($this->returnValue(123));
     $node->expects($this->any())->method('getEtag')->will($this->returnValue('"abc"'));
     $node->expects($this->any())->method('getDavPermissions')->will($this->returnValue('DWCKMSR'));
     return $node;
 }
示例#2
0
 function testTreeMove()
 {
     mkdir(SABRE_TEMPDIR . '/issue33');
     $dir = new FS\Directory(SABRE_TEMPDIR . '/issue33');
     $dir->createDirectory('bar');
     $tree = new Tree($dir);
     $tree->move('bar', urldecode('%C3%A0fo%C3%B3'));
     $node = $tree->getNodeForPath(urldecode('%C3%A0fo%C3%B3'));
     $this->assertEquals(urldecode('%C3%A0fo%C3%B3'), $node->getName());
 }
示例#3
0
 public function releaseLock(RequestInterface $request)
 {
     if ($request->getMethod() !== 'PUT' || isset($_SERVER['HTTP_OC_CHUNKED'])) {
         return;
     }
     try {
         $node = $this->tree->getNodeForPath($request->getPath());
     } catch (NotFound $e) {
         return;
     }
     if ($node instanceof Node) {
         $node->releaseLock(ILockingProvider::LOCK_SHARED);
     }
 }
示例#4
0
 /**
  * Update ownCloud-specific properties
  *
  * @param string $path
  * @param PropPatch $propPatch
  *
  * @return void
  */
 public function handleUpdateProperties($path, PropPatch $propPatch)
 {
     $propPatch->handle(self::GETLASTMODIFIED_PROPERTYNAME, function ($time) use($path) {
         if (empty($time)) {
             return false;
         }
         $node = $this->tree->getNodeForPath($path);
         if (is_null($node)) {
             return 404;
         }
         $node->touch($time);
         return true;
     });
     $propPatch->handle(self::GETETAG_PROPERTYNAME, function ($etag) use($path) {
         if (empty($etag)) {
             return false;
         }
         $node = $this->tree->getNodeForPath($path);
         if (is_null($node)) {
             return 404;
         }
         if ($node->setEtag($etag) !== -1) {
             return true;
         }
         return false;
     });
 }
示例#5
0
文件: tagsplugin.php 项目: kenwi/core
 /**
  * Updates tags and favorites properties, if applicable.
  *
  * @param string $path
  * @param PropPatch $propPatch
  *
  * @return void
  */
 public function handleUpdateProperties($path, PropPatch $propPatch)
 {
     $propPatch->handle(self::TAGS_PROPERTYNAME, function ($tagList) use($path) {
         $node = $this->tree->getNodeForPath($path);
         if (is_null($node)) {
             return 404;
         }
         $this->updateTags($node->getId(), $tagList->getTags());
         return true;
     });
     $propPatch->handle(self::FAVORITE_PROPERTYNAME, function ($favState) use($path) {
         $node = $this->tree->getNodeForPath($path);
         if (is_null($node)) {
             return 404;
         }
         if ((int) $favState === 1 || $favState === 'true') {
             $this->getTagger()->tagAs($node->getId(), self::TAG_FAVORITE);
         } else {
             $this->getTagger()->unTag($node->getId(), self::TAG_FAVORITE);
         }
         if (is_null($favState)) {
             // confirm deletion
             return 204;
         }
         return 200;
     });
 }
示例#6
0
 public function testUpdateFav()
 {
     // this test will replace the existing tags "tagremove" with "tag1" and "tag2"
     // and keep "tagkeep"
     $node = $this->getMockBuilder('\\OCA\\DAV\\Connector\\Sabre\\Node')->disableOriginalConstructor()->getMock();
     $node->expects($this->any())->method('getId')->will($this->returnValue(123));
     $this->tree->expects($this->any())->method('getNodeForPath')->with('/dummypath')->will($this->returnValue($node));
     // set favorite tag
     $this->tagger->expects($this->once())->method('tagAs')->with(123, self::TAG_FAVORITE);
     // properties to set
     $propPatch = new \Sabre\DAV\PropPatch(array(self::FAVORITE_PROPERTYNAME => true));
     $this->plugin->handleUpdateProperties('/dummypath', $propPatch);
     $propPatch->commit();
     // all requested properties removed, as they were processed already
     $this->assertEmpty($propPatch->getRemainingMutations());
     $result = $propPatch->getResult();
     $this->assertFalse(false, isset($result[self::TAGS_PROPERTYNAME]));
     $this->assertEquals(200, isset($result[self::FAVORITE_PROPERTYNAME]));
     // unfavorite now
     // set favorite tag
     $this->tagger->expects($this->once())->method('unTag')->with(123, self::TAG_FAVORITE);
     // properties to set
     $propPatch = new \Sabre\DAV\PropPatch(array(self::FAVORITE_PROPERTYNAME => false));
     $this->plugin->handleUpdateProperties('/dummypath', $propPatch);
     $propPatch->commit();
     // all requested properties removed, as they were processed already
     $this->assertEmpty($propPatch->getRemainingMutations());
     $result = $propPatch->getResult();
     $this->assertFalse(false, isset($result[self::TAGS_PROPERTYNAME]));
     $this->assertEquals(200, isset($result[self::FAVORITE_PROPERTYNAME]));
 }
 /**
  * Updates properties for a path
  *
  * @param string $path
  * @param PropPatch $propPatch
  *
  * @return void
  */
 public function propPatch($path, PropPatch $propPatch)
 {
     $node = $this->tree->getNodeForPath($path);
     if (!$node instanceof Node) {
         return;
     }
     $propPatch->handleRemaining(function ($changedProps) use($node) {
         return $this->updateProperties($node, $changedProps);
     });
 }
 /**
  * Test delete property
  */
 public function testDeleteProperty()
 {
     $node = $this->createTestNode('\\OCA\\DAV\\Connector\\Sabre\\File');
     $this->tree->expects($this->any())->method('getNodeForPath')->with('/dummypath')->will($this->returnValue($node));
     $this->applyDefaultProps();
     $propPatch = new \Sabre\DAV\PropPatch(array('customprop' => null));
     $this->plugin->propPatch('/dummypath', $propPatch);
     $propPatch->commit();
     $this->assertEmpty($propPatch->getRemainingMutations());
     $result = $propPatch->getResult();
     $this->assertEquals(204, $result['customprop']);
 }
示例#9
0
 /**
  * @dataProvider nodeClassProvider
  * @expectedException Sabre\DAV\Exception\Conflict
  */
 public function testCreateTagConflict($nodeClass)
 {
     $requestData = json_encode(['name' => 'Test', 'userVisible' => true, 'userAssignable' => false]);
     $node = $this->getMockBuilder($nodeClass)->disableOriginalConstructor()->getMock();
     $this->tagManager->expects($this->once())->method('createTag')->with('Test', true, false)->will($this->throwException(new TagAlreadyExistsException('Tag already exists')));
     $this->tree->expects($this->any())->method('getNodeForPath')->with('/systemtags')->will($this->returnValue($node));
     $request = $this->getMockBuilder('Sabre\\HTTP\\RequestInterface')->disableOriginalConstructor()->getMock();
     $response = $this->getMockBuilder('Sabre\\HTTP\\ResponseInterface')->disableOriginalConstructor()->getMock();
     $request->expects($this->once())->method('getPath')->will($this->returnValue('/systemtags'));
     $request->expects($this->once())->method('getBodyAsString')->will($this->returnValue($requestData));
     $request->expects($this->once())->method('getHeader')->with('Content-Type')->will($this->returnValue('application/json'));
     $this->plugin->httpPost($request, $response);
 }
 public function testOnReport()
 {
     $path = 'comments/files/42';
     $parameters = [['name' => '{http://owncloud.org/ns}limit', 'value' => 5], ['name' => '{http://owncloud.org/ns}offset', 'value' => 10], ['name' => '{http://owncloud.org/ns}datetime', 'value' => '2016-01-10 18:48:00']];
     $node = $this->getMockBuilder('\\OCA\\DAV\\Comments\\EntityCollection')->disableOriginalConstructor()->getMock();
     $node->expects($this->once())->method('findChildren')->with(5, 10, new \DateTime($parameters[2]['value']))->will($this->returnValue([]));
     $response = $this->getMockBuilder('Sabre\\HTTP\\ResponseInterface')->disableOriginalConstructor()->getMock();
     $response->expects($this->once())->method('setHeader')->with('Content-Type', 'application/xml; charset=utf-8');
     $response->expects($this->once())->method('setStatus')->with(207);
     $response->expects($this->once())->method('setBody');
     $this->tree->expects($this->any())->method('getNodeForPath')->with('/' . $path)->will($this->returnValue($node));
     $this->server->expects($this->any())->method('getRequestUri')->will($this->returnValue($path));
     $this->server->httpResponse = $response;
     $this->plugin->initialize($this->server);
     $this->plugin->onReport(CommentsPluginImplementation::REPORT_NAME, $parameters, '/' . $path);
 }
示例#11
0
 public function testOnReport()
 {
     $path = 'test';
     $parameters = [['name' => '{DAV:}prop', 'value' => [['name' => '{DAV:}getcontentlength', 'value' => ''], ['name' => '{http://owncloud.org/ns}size', 'value' => '']]], ['name' => '{http://owncloud.org/ns}filter-rules', 'value' => [['name' => '{http://owncloud.org/ns}systemtag', 'value' => '123'], ['name' => '{http://owncloud.org/ns}systemtag', 'value' => '456']]]];
     $this->groupManager->expects($this->any())->method('isAdmin')->will($this->returnValue(true));
     $this->tagMapper->expects($this->at(0))->method('getObjectIdsForTags')->with('123', 'files')->will($this->returnValue(['111', '222']));
     $this->tagMapper->expects($this->at(1))->method('getObjectIdsForTags')->with('456', 'files')->will($this->returnValue(['111', '222', '333']));
     $reportTargetNode = $this->getMockBuilder('\\OCA\\DAV\\Connector\\Sabre\\Directory')->disableOriginalConstructor()->getMock();
     $response = $this->getMockBuilder('Sabre\\HTTP\\ResponseInterface')->disableOriginalConstructor()->getMock();
     $response->expects($this->once())->method('setHeader')->with('Content-Type', 'application/xml; charset=utf-8');
     $response->expects($this->once())->method('setStatus')->with(207);
     $response->expects($this->once())->method('setBody');
     $this->tree->expects($this->any())->method('getNodeForPath')->with('/' . $path)->will($this->returnValue($reportTargetNode));
     $filesNode1 = $this->getMockBuilder('\\OCP\\Files\\Folder')->disableOriginalConstructor()->getMock();
     $filesNode2 = $this->getMockBuilder('\\OCP\\Files\\File')->disableOriginalConstructor()->getMock();
     $this->userFolder->expects($this->at(0))->method('getById')->with('111')->will($this->returnValue([$filesNode1]));
     $this->userFolder->expects($this->at(1))->method('getById')->with('222')->will($this->returnValue([$filesNode2]));
     $this->server->expects($this->any())->method('getRequestUri')->will($this->returnValue($path));
     $this->server->httpResponse = $response;
     $this->plugin->initialize($this->server);
     $this->plugin->onReport(FilesReportPluginImplementation::REPORT_NAME, $parameters, '/' . $path);
 }