public function testGetProperties() { $systemTag = new SystemTag(1, 'Test', true, true); $requestedProperties = [self::ID_PROPERTYNAME, self::DISPLAYNAME_PROPERTYNAME, self::USERVISIBLE_PROPERTYNAME, self::USERASSIGNABLE_PROPERTYNAME]; $expectedProperties = [200 => [self::ID_PROPERTYNAME => '1', self::DISPLAYNAME_PROPERTYNAME => 'Test', self::USERVISIBLE_PROPERTYNAME => 1, self::USERASSIGNABLE_PROPERTYNAME => 1]]; $node = $this->getMockBuilder('\\OCA\\DAV\\SystemTag\\SystemTagNode')->disableOriginalConstructor()->getMock(); $node->expects($this->any())->method('getSystemTag')->will($this->returnValue($systemTag)); $this->tree->expects($this->any())->method('getNodeForPath')->with('/systemtag/1')->will($this->returnValue($node)); $propFind = new \Sabre\DAV\PropFind('/systemtag/1', $requestedProperties, 0); $this->plugin->handleGetProperties($propFind, $node); $result = $propFind->getResultForMultiStatus(); $this->assertEmpty($result[404]); unset($result[404]); $this->assertEquals($expectedProperties, $result); }
/** * @dataProvider tagsGetPropertiesDataProvider */ public function testPreloadThenGetProperties($tags, $requestedProperties, $expectedProperties) { $node1 = $this->getMockBuilder('\\OCA\\DAV\\Connector\\Sabre\\File')->disableOriginalConstructor()->getMock(); $node1->expects($this->any())->method('getId')->will($this->returnValue(111)); $node2 = $this->getMockBuilder('\\OCA\\DAV\\Connector\\Sabre\\File')->disableOriginalConstructor()->getMock(); $node2->expects($this->any())->method('getId')->will($this->returnValue(222)); $expectedCallCount = 0; if (count($requestedProperties) > 0) { // this guarantees that getTagsForObjects // is only called once and then the tags // are cached $expectedCallCount = 1; } $node = $this->getMockBuilder('\\OCA\\DAV\\Connector\\Sabre\\Directory')->disableOriginalConstructor()->getMock(); $node->expects($this->any())->method('getId')->will($this->returnValue(123)); $node->expects($this->exactly($expectedCallCount))->method('getChildren')->will($this->returnValue(array($node1, $node2))); $this->tagger->expects($this->exactly($expectedCallCount))->method('getTagsForObjects')->with($this->equalTo(array(123, 111, 222)))->will($this->returnValue(array(111 => $tags, 123 => $tags))); // simulate sabre recursive PROPFIND traversal $propFindRoot = new \Sabre\DAV\PropFind('/subdir', $requestedProperties, 1); $propFind1 = new \Sabre\DAV\PropFind('/subdir/test.txt', $requestedProperties, 0); $propFind2 = new \Sabre\DAV\PropFind('/subdir/test2.txt', $requestedProperties, 0); $this->plugin->handleGetProperties($propFindRoot, $node); $this->plugin->handleGetProperties($propFind1, $node1); $this->plugin->handleGetProperties($propFind2, $node2); $result = $propFind1->getResultForMultiStatus(); $this->assertEmpty($result[404]); unset($result[404]); $this->assertEquals($expectedProperties, $result); }