Skip to content

Commit

Permalink
Update acceptance and unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
VicDeo committed Apr 30, 2020
1 parent 18df40d commit 7c37dac
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
7 changes: 7 additions & 0 deletions apps/dav/tests/unit/DAV/FileCustomPropertiesBackendTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
use OCP\Files\Node;
use Sabre\DAV\PropFind;
use Sabre\DAV\SimpleCollection;
use Sabre\DAV\Xml\Property\Complex;

/**
* Class FileCustomPropertiesBackendTest
Expand Down Expand Up @@ -146,6 +147,7 @@ private function applyDefaultProps($path = '/dummypath') {
$propPatch = new \Sabre\DAV\PropPatch([
'customprop' => 'value1',
'customprop2' => 'value2',
'customprop3' => new Complex('<foo xmlns="http://bar"/>')
]);

$this->backend->propPatch(
Expand Down Expand Up @@ -253,6 +255,7 @@ public function testSetGetPropertiesForFile() {
[
'customprop',
'customprop2',
'customprop3',
'unsetprop',
],
0
Expand All @@ -265,6 +268,10 @@ public function testSetGetPropertiesForFile() {

$this->assertEquals('value1', $propFind->get('customprop'));
$this->assertEquals('value2', $propFind->get('customprop2'));
/** @var Complex $complexProp */
$complexProp = $propFind->get('customprop3');
$this->assertInstanceOf(Complex::class, $complexProp);
$this->assertEquals('<foo xmlns="http://bar"/>', $complexProp->getXml());
$this->assertEquals(['unsetprop'], $propFind->get404Properties());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Feature: set file properties
And user "user0" has uploaded file "filesForUpload/textfile.txt" to "/testcustomprop.txt"
And user "user0" has set property "very-custom-prop" with namespace "x1='http://whatever.org/ns'" of file "/testcustomprop.txt" to "<foo xmlns='http://bar'/>"
When user "user0" gets a custom property "very-custom-prop" with namespace "x1='http://whatever.org/ns'" of file "/testcustomprop.txt"
Then the response should contain a custom "very-custom-prop" property with namespace "x1='http://whatever.org/ns'" and value "<foo xmlns='http://bar'/>"
Then the response should contain a custom "very-custom-prop" property with namespace "x1='http://whatever.org/ns'" and complex value "<x2:foo xmlns:x2=\"http://bar\"/>"
Examples:
| dav_version |
| old |
Expand Down
40 changes: 40 additions & 0 deletions tests/acceptance/features/bootstrap/WebDavPropertiesContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,46 @@ public function theResponseShouldContainACustomPropertyWithValue(
);
}

/**
* @Then /^the response should contain a custom "([^"]*)" property with namespace "([^"]*)" and complex value "(([^"\\]|\\.)*)"$/
*
* @param string $propertyName
* @param string $namespaceString
* @param string $propertyValue
*
* @return void
* @throws \Exception
*/
public function theResponseShouldContainACustomPropertyWithComplexValue(
$propertyName, $namespaceString, $propertyValue
) {
// let's unescape quotes first
$propertyValue = \str_replace('\"', '"', $propertyValue);
$this->featureContext->setResponseXmlObject(
HttpRequestHelper::getResponseXml($this->featureContext->getResponse())
);
$responseXmlObject = $this->featureContext->getResponseXmlObject();
//calculate the namespace prefix and namespace
$matches = [];
\preg_match("/^(.*)='(.*)'$/", $namespaceString, $matches);
$nameSpace = $matches[2];
$nameSpacePrefix = $matches[1];
$responseXmlObject->registerXPathNamespace(
$nameSpacePrefix, $nameSpace
);
$xmlPart = $responseXmlObject->xpath(
"//d:prop/" . "$nameSpacePrefix:$propertyName" . "/*"
);
Assert::assertArrayHasKey(
0, $xmlPart, "Cannot find property \"$propertyName\""
);
Assert::assertEquals(
$propertyValue, $xmlPart[0]->asXML(),
"\"$propertyName\" has a value \"" .
$xmlPart[0]->asXML() . "\" but \"$propertyValue\" expected"
);
}

/**
* @Then the single response should contain a property :property with a child property :childProperty
*
Expand Down

0 comments on commit 7c37dac

Please sign in to comment.