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])); }
/** * @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); }