[Pkg-owncloud-commits] [php-sabredav] 86/148: A bunch more unittests.
David Prévot
taffit at moszumanska.debian.org
Wed Apr 15 01:37:20 UTC 2015
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository php-sabredav.
commit 78a74e86d950b6cbca9bfb3a24ff1152435d6ff3
Author: Evert Pot <me at evertpot.com>
Date: Tue Mar 24 10:28:56 2015 -0400
A bunch more unittests.
---
lib/DAV/Xml/Element/Prop.php | 10 +-
.../PropertyStorage/Backend/AbstractPDOTest.php | 43 ++++++
tests/Sabre/DAV/PropertyStorage/PluginTest.php | 9 ++
tests/Sabre/DAV/Xml/Element/PropTest.php | 154 +++++++++++++++++++++
4 files changed, 207 insertions(+), 9 deletions(-)
diff --git a/lib/DAV/Xml/Element/Prop.php b/lib/DAV/Xml/Element/Prop.php
index 1ee02cb..9ae95fa 100644
--- a/lib/DAV/Xml/Element/Prop.php
+++ b/lib/DAV/Xml/Element/Prop.php
@@ -77,10 +77,9 @@ class Prop implements XmlDeserializable {
* top-level element it doesn't recognize into either a string, or an
* XmlFragment class.
*
- * This method returns arn array with 3 properties:
+ * This method returns arn array with 2 properties:
* * name - A clark-notation XML element name.
* * value - The parsed value.
- * * attributes - A key-value list of attributes.
*
* @return array
*/
@@ -88,12 +87,6 @@ class Prop implements XmlDeserializable {
$name = $reader->getClark();
- $attributes = [];
-
- if ($reader->hasAttributes) {
- $attributes = $reader->parseAttributes();
- }
-
if (array_key_exists($name, $reader->elementMap)) {
$deserializer = $reader->elementMap[$name];
if (is_subclass_of($deserializer, 'Sabre\\Xml\\XmlDeserializable')) {
@@ -116,7 +109,6 @@ class Prop implements XmlDeserializable {
return [
'name' => $name,
'value' => $value,
- 'attributes' => $attributes,
];
}
diff --git a/tests/Sabre/DAV/PropertyStorage/Backend/AbstractPDOTest.php b/tests/Sabre/DAV/PropertyStorage/Backend/AbstractPDOTest.php
index bb1f729..0edf8dd 100644
--- a/tests/Sabre/DAV/PropertyStorage/Backend/AbstractPDOTest.php
+++ b/tests/Sabre/DAV/PropertyStorage/Backend/AbstractPDOTest.php
@@ -4,6 +4,8 @@ namespace Sabre\DAV\PropertyStorage\Backend;
use Sabre\DAV\PropFind;
use Sabre\DAV\PropPatch;
+use Sabre\DAV\Xml\Property\Complex;
+use Sabre\DAV\Xml\Property\Href;
abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase {
@@ -61,6 +63,47 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase {
}
/**
+ * @depends testPropPatchUpdate
+ */
+ function testPropPatchComplex() {
+
+ $backend = $this->getBackend();
+
+ $complex = new Complex('<foo xmlns="DAV:">somevalue</foo>');
+
+ $propPatch = new PropPatch(['{DAV:}complex' => $complex]);
+ $backend->propPatch('dir', $propPatch);
+ $propPatch->commit();
+
+ $propFind = new PropFind('dir', ['{DAV:}complex']);
+ $backend->propFind('dir', $propFind);
+
+ $this->assertEquals($complex, $propFind->get('{DAV:}complex'));
+
+ }
+
+
+ /**
+ * @depends testPropPatchComplex
+ */
+ function testPropPatchCustom() {
+
+ $backend = $this->getBackend();
+
+ $custom = new Href('/foo/bar/');
+
+ $propPatch = new PropPatch(['{DAV:}custom' => $custom]);
+ $backend->propPatch('dir', $propPatch);
+ $propPatch->commit();
+
+ $propFind = new PropFind('dir', ['{DAV:}custom']);
+ $backend->propFind('dir', $propFind);
+
+ $this->assertEquals($custom, $propFind->get('{DAV:}custom'));
+
+ }
+
+ /**
* @depends testPropFind
*/
function testPropPatchRemove() {
diff --git a/tests/Sabre/DAV/PropertyStorage/PluginTest.php b/tests/Sabre/DAV/PropertyStorage/PluginTest.php
index d880427..3f93a95 100644
--- a/tests/Sabre/DAV/PropertyStorage/PluginTest.php
+++ b/tests/Sabre/DAV/PropertyStorage/PluginTest.php
@@ -21,6 +21,15 @@ class PluginTest extends \Sabre\DAVServerTest {
}
+ function testGetInfo() {
+
+ $this->assertArrayHasKey(
+ 'name',
+ $this->plugin->getPluginInfo()
+ );
+
+ }
+
function testSetProperty() {
$this->server->updateProperties('', ['{DAV:}displayname' => 'hi']);
diff --git a/tests/Sabre/DAV/Xml/Element/PropTest.php b/tests/Sabre/DAV/Xml/Element/PropTest.php
new file mode 100644
index 0000000..457abc8
--- /dev/null
+++ b/tests/Sabre/DAV/Xml/Element/PropTest.php
@@ -0,0 +1,154 @@
+<?php
+
+namespace Sabre\DAV\Xml\Element;
+
+use Sabre\DAV\Xml\XmlTest;
+use Sabre\DAV\Xml\Property\Complex;
+use Sabre\DAV\Xml\Property\Href;
+
+class PropTest extends XmlTest {
+
+ function testDeserializeSimple() {
+
+ $input = <<<XML
+<?xml version="1.0"?>
+<root xmlns="DAV:">
+ <foo>bar</foo>
+</root>
+XML;
+
+ $expected = [
+ '{DAV:}foo' => 'bar',
+ ];
+
+ $this->assertDecodeProp($input, $expected);
+
+ }
+ function testDeserializeEmpty() {
+
+ $input = <<<XML
+<?xml version="1.0"?>
+<root xmlns="DAV:" />
+XML;
+
+ $expected = [
+ ];
+
+ $this->assertDecodeProp($input, $expected);
+
+ }
+ function testDeserializeComplex() {
+
+ $input = <<<XML
+<?xml version="1.0"?>
+<root xmlns="DAV:">
+ <foo><no>yes</no></foo>
+</root>
+XML;
+
+ $expected = [
+ '{DAV:}foo' => new Complex('<no xmlns="DAV:">yes</no>')
+ ];
+
+ $this->assertDecodeProp($input, $expected);
+
+ }
+ function testDeserializeCustom() {
+
+ $input = <<<XML
+<?xml version="1.0"?>
+<root xmlns="DAV:">
+ <foo><href>/hello</href></foo>
+</root>
+XML;
+
+ $expected = [
+ '{DAV:}foo' => new Href('/hello')
+ ];
+
+ $elementMap = [
+ '{DAV:}foo' => 'Sabre\DAV\Xml\Property\Href'
+ ];
+
+ $this->assertDecodeProp($input, $expected, $elementMap);
+
+ }
+ function testDeserializeCustomCallback() {
+
+ $input = <<<XML
+<?xml version="1.0"?>
+<root xmlns="DAV:">
+ <foo>blabla</foo>
+</root>
+XML;
+
+ $expected = [
+ '{DAV:}foo' => 'zim',
+ ];
+
+ $elementMap = [
+ '{DAV:}foo' => function($reader) {
+ $reader->next();
+ return 'zim';
+ }
+ ];
+
+ $this->assertDecodeProp($input, $expected, $elementMap);
+
+ }
+
+ /**
+ * @expectedException \LogicException
+ */
+ function testDeserializeCustomBad() {
+
+ $input = <<<XML
+<?xml version="1.0"?>
+<root xmlns="DAV:">
+ <foo>blabla</foo>
+</root>
+XML;
+
+ $expected = [];
+
+ $elementMap = [
+ '{DAV:}foo' => 'idk?',
+ ];
+
+ $this->assertDecodeProp($input, $expected, $elementMap);
+
+ }
+
+ /**
+ * @expectedException \LogicException
+ */
+ function testDeserializeCustomBadObj() {
+
+ $input = <<<XML
+<?xml version="1.0"?>
+<root xmlns="DAV:">
+ <foo>blabla</foo>
+</root>
+XML;
+
+ $expected = [];
+
+ $elementMap = [
+ '{DAV:}foo' => new \StdClass(),
+ ];
+
+ $this->assertDecodeProp($input, $expected, $elementMap);
+
+ }
+
+ function assertDecodeProp($input, array $expected, array $elementMap = []) {
+
+ $elementMap['{DAV:}root'] = 'Sabre\DAV\Xml\Element\Prop';
+
+ $result = $this->parse($input, $elementMap);
+ $this->assertInternalType('array', $result);
+ $this->assertEquals($expected, $result['value']);
+
+ }
+
+}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/php-sabredav.git
More information about the Pkg-owncloud-commits
mailing list