[Pkg-owncloud-commits] [php-sabredav] 37/163: The new proppatch object is now fully tested.
David Prévot
taffit at moszumanska.debian.org
Tue May 20 18:54:51 UTC 2014
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to annotated tag upstream/2.0.0_beta1
in repository php-sabredav.
commit cd9d62b2e4825a7d1eb085690492ca8a3c72cc5e
Author: Evert Pot <evert at rooftopsolutions.nl>
Date: Sat Apr 5 00:00:53 2014 -0400
The new proppatch object is now fully tested.
---
lib/Sabre/DAV/PropPatch.php | 23 ++--
tests/Sabre/DAV/PropPatchTest.php | 234 +++++++++++++++++++++++++++++++++++++-
2 files changed, 246 insertions(+), 11 deletions(-)
diff --git a/lib/Sabre/DAV/PropPatch.php b/lib/Sabre/DAV/PropPatch.php
index 6379b0c..ec4c206 100644
--- a/lib/Sabre/DAV/PropPatch.php
+++ b/lib/Sabre/DAV/PropPatch.php
@@ -2,6 +2,8 @@
namespace Sabre\DAV;
+use UnexpectedValueException;
+
/**
* This class represents a set of properties that are going to be updated.
*
@@ -80,7 +82,7 @@ class PropPatch {
$usedProperties = [];
foreach((array)$properties as $propertyName) {
- if (isset($this->mutations[$propertyName]) && !isset($this->result[$propertyName])) {
+ if (array_key_exists($propertyName, $this->mutations) && !isset($this->result[$propertyName])) {
$usedProperties[] = $propertyName;
// HTTP Accepted
@@ -208,14 +210,14 @@ class PropPatch {
foreach($this->propertyUpdateCallbacks as $callbackInfo) {
+ if ($this->failed) {
+ break;
+ }
if (is_string($callbackInfo[0])) {
$this->doCallbackSingleProp($callbackInfo[0], $callbackInfo[1]);
} else {
$this->doCallbackMultiProp($callbackInfo[0], $callbackInfo[1]);
}
- if ($this->failed) {
- break;
- }
}
@@ -228,7 +230,7 @@ class PropPatch {
foreach($this->result as $propertyName=>$status) {
if ($status === 202) {
// Failed dependency
- $this->result[$propertyName][$status] = 424;
+ $this->result[$propertyName] = 424;
}
}
@@ -265,7 +267,7 @@ class PropPatch {
if (!is_int($result)) {
throw new UnexpectedValueException('A callback sent to handle() did not return an int or a bool');
}
- $this->mutations[$propertyName] = $result;
+ $this->result[$propertyName] = $result;
if ($result>=400) {
$this->failed = true;
}
@@ -286,14 +288,15 @@ class PropPatch {
$argument[$propertyName] = $this->mutations[$propertyName];
}
- $result = $callback($propertyName);
+ $result = $callback($argument);
if (is_array($result)) {
foreach($propertyList as $propertyName) {
if (!isset($result[$propertyName])) {
$resultCode = 500;
+ } else {
+ $resultCode = $result[$propertyName];
}
- $resultCode = $result[$propertyName];
if ($resultCode >= 400) {
$this->failed = true;
}
@@ -313,7 +316,9 @@ class PropPatch {
foreach($propertyList as $propertyName) {
$this->result[$propertyName] = 403;
}
- }
+ } else {
+ throw new UnexpectedValueException('A callback sent to handle() did not return an array or a bool');
+ }
}
diff --git a/tests/Sabre/DAV/PropPatchTest.php b/tests/Sabre/DAV/PropPatchTest.php
index 87233a1..21b45e7 100644
--- a/tests/Sabre/DAV/PropPatchTest.php
+++ b/tests/Sabre/DAV/PropPatchTest.php
@@ -11,10 +11,11 @@ class PropPatchTest extends \PHPUnit_Framework_TestCase {
$this->propPatch = new PropPatch([
'{DAV:}displayname' => 'foo',
]);
+ $this->assertEquals(['{DAV:}displayname' => 'foo'], $this->propPatch->getMutations());
}
- public function testHandleSuccess() {
+ public function testHandleSingleSuccess() {
$hasRan = false;
@@ -31,6 +32,63 @@ class PropPatchTest extends \PHPUnit_Framework_TestCase {
$this->assertTrue($hasRan);
}
+
+ public function testHandleSingleFail() {
+
+ $hasRan = false;
+
+ $this->propPatch->handle('{DAV:}displayname', function($value) use (&$hasRan) {
+ $hasRan = true;
+ $this->assertEquals('foo', $value);
+ return false;
+ });
+
+ $this->assertFalse($this->propPatch->commit());
+ $result = $this->propPatch->getResult();
+ $this->assertEquals(['{DAV:}displayname' => 403], $result);
+
+ $this->assertTrue($hasRan);
+
+ }
+
+ public function testHandleSingleCustomResult() {
+
+ $hasRan = false;
+
+ $this->propPatch->handle('{DAV:}displayname', function($value) use (&$hasRan) {
+ $hasRan = true;
+ $this->assertEquals('foo', $value);
+ return 201;
+ });
+
+ $this->assertTrue($this->propPatch->commit());
+ $result = $this->propPatch->getResult();
+ $this->assertEquals(['{DAV:}displayname' => 201], $result);
+
+ $this->assertTrue($hasRan);
+
+ }
+
+ public function testHandleSingleDeleteSuccess() {
+
+ $hasRan = false;
+
+ $this->propPatch = new PropPatch(['{DAV:}displayname' => null]);
+ $this->propPatch->handle('{DAV:}displayname', function($value) use (&$hasRan) {
+ $hasRan = true;
+ $this->assertNull($value);
+ return true;
+ });
+
+ $this->assertTrue($this->propPatch->commit());
+ $result = $this->propPatch->getResult();
+ $this->assertEquals(['{DAV:}displayname' => 204], $result);
+
+ $this->assertTrue($hasRan);
+
+ }
+
+
public function testHandleNothing() {
$hasRan = false;
@@ -43,6 +101,9 @@ class PropPatchTest extends \PHPUnit_Framework_TestCase {
}
+ /**
+ * @depends testHandleSingleSuccess
+ */
public function testHandleRemaining() {
$hasRan = false;
@@ -120,8 +181,177 @@ class PropPatchTest extends \PHPUnit_Framework_TestCase {
$this->propPatch->commit();
// The handler is not supposed to have ran
- $this->assertFalse($hasRan);
+ $this->assertFalse($hasRan);
+
+ }
+
+ public function testDependencyFail() {
+
+ $propPatch = new PropPatch([
+ '{DAV:}a' => 'foo',
+ '{DAV:}b' => 'bar',
+ ]);
+
+ $calledA = false;
+ $calledB = false;
+
+ $propPatch->handle('{DAV:}a', function() use (&$calledA) {
+ $calledA = true;
+ return false;
+ });
+ $propPatch->handle('{DAV:}b', function() use (&$calledB) {
+ $calledB = true;
+ return false;
+ });
+
+ $result = $propPatch->commit();
+ $this->assertTrue($calledA);
+ $this->assertFalse($calledB);
+
+ $this->assertFalse($result);
+
+ $this->assertEquals([
+ '{DAV:}a' => 403,
+ '{DAV:}b' => 424,
+ ], $propPatch->getResult());
}
+ /**
+ * @expectedException \UnexpectedValueException
+ */
+ public function testHandleSingleBrokenResult() {
+
+ $propPatch = new PropPatch([
+ '{DAV:}a' => 'foo',
+ ]);
+
+ $calledA = false;
+ $calledB = false;
+
+ $propPatch->handle('{DAV:}a', function() use (&$calledA) {
+ return [];
+ });
+ $propPatch->commit();
+
+ }
+
+ public function testHandleMultiValueSuccess() {
+
+ $propPatch = new PropPatch([
+ '{DAV:}a' => 'foo',
+ '{DAV:}b' => 'bar',
+ '{DAV:}c' => null,
+ ]);
+
+ $calledA = false;
+
+ $propPatch->handle(['{DAV:}a', '{DAV:}b', '{DAV:}c'], function($properties) use (&$calledA) {
+ $calledA = true;
+ $this->assertEquals([
+ '{DAV:}a' => 'foo',
+ '{DAV:}b' => 'bar',
+ '{DAV:}c' => null,
+ ], $properties);
+ return true;
+ });
+ $result = $propPatch->commit();
+ $this->assertTrue($calledA);
+ $this->assertTrue($result);
+
+ $this->assertEquals([
+ '{DAV:}a' => 200,
+ '{DAV:}b' => 200,
+ '{DAV:}c' => 204,
+ ], $propPatch->getResult());
+
+ }
+
+
+ public function testHandleMultiValueFail() {
+
+ $propPatch = new PropPatch([
+ '{DAV:}a' => 'foo',
+ '{DAV:}b' => 'bar',
+ '{DAV:}c' => null,
+ ]);
+
+ $calledA = false;
+
+ $propPatch->handle(['{DAV:}a', '{DAV:}b', '{DAV:}c'], function($properties) use (&$calledA) {
+ $calledA = true;
+ $this->assertEquals([
+ '{DAV:}a' => 'foo',
+ '{DAV:}b' => 'bar',
+ '{DAV:}c' => null,
+ ], $properties);
+ return false;
+ });
+ $result = $propPatch->commit();
+ $this->assertTrue($calledA);
+ $this->assertFalse($result);
+
+ $this->assertEquals([
+ '{DAV:}a' => 403,
+ '{DAV:}b' => 403,
+ '{DAV:}c' => 403,
+ ], $propPatch->getResult());
+
+ }
+
+ public function testHandleMultiValueCustomResult() {
+
+ $propPatch = new PropPatch([
+ '{DAV:}a' => 'foo',
+ '{DAV:}b' => 'bar',
+ '{DAV:}c' => null,
+ ]);
+
+ $calledA = false;
+
+ $propPatch->handle(['{DAV:}a', '{DAV:}b', '{DAV:}c'], function($properties) use (&$calledA) {
+ $calledA = true;
+ $this->assertEquals([
+ '{DAV:}a' => 'foo',
+ '{DAV:}b' => 'bar',
+ '{DAV:}c' => null,
+ ], $properties);
+
+ return [
+ '{DAV:}a' => 201,
+ '{DAV:}b' => 204,
+ ];
+ return false;
+ });
+ $result = $propPatch->commit();
+ $this->assertTrue($calledA);
+ $this->assertFalse($result);
+
+ $this->assertEquals([
+ '{DAV:}a' => 201,
+ '{DAV:}b' => 204,
+ '{DAV:}c' => 500,
+ ], $propPatch->getResult());
+
+ }
+
+ /**
+ * @expectedException \UnexpectedValueException
+ */
+ public function testHandleMultiValueBroken() {
+
+ $propPatch = new PropPatch([
+ '{DAV:}a' => 'foo',
+ '{DAV:}b' => 'bar',
+ '{DAV:}c' => null,
+ ]);
+
+ $calledA = false;
+
+ $propPatch->handle(['{DAV:}a', '{DAV:}b', '{DAV:}c'], function($properties) use (&$calledA) {
+ return 'hi';
+ });
+ $propPatch->commit();
+
+ }
}
--
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