[Pkg-owncloud-commits] [php-sabredav] 69/163: Centralized precondition checking

David Prévot taffit at moszumanska.debian.org
Tue May 20 18:54:55 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 0fd7a15105a4ec7675b0d97f126a7624c53c77f4
Author: Evert Pot <evert at rooftopsolutions.nl>
Date:   Mon Apr 14 12:54:14 2014 -0400

    Centralized precondition checking
---
 lib/Sabre/CalDAV/Plugin.php                |  1 -
 lib/Sabre/DAV/CorePlugin.php               |  8 ---
 lib/Sabre/DAV/Locks/Plugin.php             | 35 +++++++----
 lib/Sabre/DAV/PartialUpdate/Plugin.php     |  3 -
 lib/Sabre/DAV/Server.php                   | 49 +++++++--------
 lib/Sabre/DAV/Sync/Plugin.php              |  7 ++-
 lib/Sabre/DAVACL/IPrincipalCollection.php  |  2 +-
 tests/Sabre/DAV/GetIfConditionsTest.php    | 51 ++++------------
 tests/Sabre/DAV/Locks/MSWordTest.php       |  2 +-
 tests/Sabre/DAV/Locks/PluginTest.php       | 22 ++-----
 tests/Sabre/DAV/ServerPreconditionTest.php | 97 +++++++++++++-----------------
 11 files changed, 113 insertions(+), 164 deletions(-)

diff --git a/lib/Sabre/CalDAV/Plugin.php b/lib/Sabre/CalDAV/Plugin.php
index 4579c07..4162e4e 100644
--- a/lib/Sabre/CalDAV/Plugin.php
+++ b/lib/Sabre/CalDAV/Plugin.php
@@ -830,7 +830,6 @@ class Plugin extends DAV\ServerPlugin {
         if (!$node instanceof Notifications\INode)
             return;
 
-        if (!$this->server->checkPreconditions(true)) return false;
         $dom = new \DOMDocument('1.0', 'UTF-8');
 
         $dom->formatOutput = true;
diff --git a/lib/Sabre/DAV/CorePlugin.php b/lib/Sabre/DAV/CorePlugin.php
index 329b31c..cdca51c 100644
--- a/lib/Sabre/DAV/CorePlugin.php
+++ b/lib/Sabre/DAV/CorePlugin.php
@@ -74,7 +74,6 @@ class CorePlugin extends ServerPlugin {
         $path = $request->getPath();
         $node = $this->server->tree->getNodeForPath($path,0);
 
-        if (!$this->server->checkPreconditions(true)) return false;
         if (!$node instanceof IFile) return;
 
         $body = $node->get();
@@ -280,7 +279,6 @@ class CorePlugin extends ServerPlugin {
 
         $path = $request->getPath();
 
-        $this->server->checkPreconditions();
         if (!$this->server->emit('beforeUnbind',[$path])) return false;
         $this->server->tree->delete($path);
         $this->server->emit('afterUnbind',[$path]);
@@ -363,7 +361,6 @@ class CorePlugin extends ServerPlugin {
     public function httpPropPatch(RequestInterface $request, ResponseInterface $response) {
 
         $path = $request->getPath();
-        $this->server->checkPreconditions();
 
         $newProperties = $this->server->parsePropPatchRequest(
             $request->getBodyAsString()
@@ -506,9 +503,6 @@ class CorePlugin extends ServerPlugin {
 
         }
 
-        // Checking If-None-Match and related headers.
-        if (!$this->server->checkPreconditions()) return false;
-
         if ($this->server->tree->nodeExists($path)) {
 
             $node = $this->server->tree->getNodeForPath($path);
@@ -632,7 +626,6 @@ class CorePlugin extends ServerPlugin {
 
         $path = $request->getPath();
 
-        $this->server->checkPreconditions();
         $moveInfo = $this->server->getCopyAndMoveInfo($request);
 
         if ($moveInfo['destinationExists']) {
@@ -673,7 +666,6 @@ class CorePlugin extends ServerPlugin {
 
         $path = $request->getPath();
 
-        $this->server->checkPreconditions();
         $copyInfo = $this->server->getCopyAndMoveInfo($request);
 
         if ($copyInfo['destinationExists']) {
diff --git a/lib/Sabre/DAV/Locks/Plugin.php b/lib/Sabre/DAV/Locks/Plugin.php
index fe7c28c..bb178cb 100644
--- a/lib/Sabre/DAV/Locks/Plugin.php
+++ b/lib/Sabre/DAV/Locks/Plugin.php
@@ -59,10 +59,10 @@ class Plugin extends DAV\ServerPlugin {
     public function initialize(DAV\Server $server) {
 
         $this->server = $server;
-        $server->on('method:LOCK',   [$this, 'httpLock']);
-        $server->on('method:UNLOCK', [$this, 'httpUnlock']);
-        $server->on('afterGetProperties',array($this,'afterGetProperties'));
-        $server->on('validateTokens', array($this, 'validateTokens'));
+        $server->on('method:LOCK',        [$this, 'httpLock']);
+        $server->on('method:UNLOCK',      [$this, 'httpUnlock']);
+        $server->on('afterGetProperties', [$this, 'afterGetProperties']);
+        $server->on('validateTokens',     [$this, 'validateTokens']);
 
     }
 
@@ -215,10 +215,9 @@ class Plugin extends DAV\ServerPlugin {
 
             // Gonna check if this was a lock refresh.
             $existingLocks = $this->getLocks($uri);
-            $conditions = $this->server->getIfConditions();
+            $conditions = $this->server->getIfConditions($request);
             $found = null;
 
-
             foreach($existingLocks as $existingLock) {
                 foreach($conditions as $condition) {
                     foreach($condition['tokens'] as $token) {
@@ -428,11 +427,11 @@ class Plugin extends DAV\ServerPlugin {
      * @param mixed $conditions
      * @return void
      */
-    public function validateTokens( &$conditions ) {
+    public function validateTokens( RequestInterface $request, &$conditions ) {
 
         // First we need to gather a list of locks that must be satisfied.
         $mustLocks = [];
-        $method = $this->server->httpRequest->getMethod();
+        $method = $request->getMethod();
 
         // Methods not in that list are operations that doesn't alter any
         // resources, and we don't need to check the lock-states for.
@@ -440,7 +439,7 @@ class Plugin extends DAV\ServerPlugin {
 
             case 'DELETE' :
                 $mustLocks = array_merge($mustLocks, $this->getLocks(
-                    $this->server->getRequestUri(),
+                    $request->getPath(),
                     true
                 ));
                 break;
@@ -450,26 +449,36 @@ class Plugin extends DAV\ServerPlugin {
             case 'PUT' :
             case 'PATCH' :
                 $mustLocks = array_merge($mustLocks, $this->getLocks(
-                    $this->server->getRequestUri(),
+                    $request->getPath(),
                     false
                 ));
                 break;
             case 'MOVE' :
                 $mustLocks = array_merge($mustLocks, $this->getLocks(
-                    $this->server->getRequestUri(),
+                    $request->getPath(),
                     true
                 ));
                 $mustLocks = array_merge($mustLocks, $this->getLocks(
-                    $this->server->calculateUri($this->server->httpRequest->getHeader('Destination')),
+                    $this->server->calculateUri($request->getHeader('Destination')),
                     false
                 ));
                 break;
             case 'COPY' :
                 $mustLocks = array_merge($mustLocks, $this->getLocks(
-                    $this->server->calculateUri($this->server->httpRequest->getHeader('Destination')),
+                    $this->server->calculateUri($request->getHeader('Destination')),
                     false
                 ));
                 break;
+            case 'LOCK' :
+                //Temporary measure.. figure out later why this is needed
+                // Here we basically ignore all incoming tokens...
+                foreach($conditions as $ii=>$condition) {
+                    foreach($condition['tokens'] as $jj=>$token) {
+                        $conditions[$ii]['tokens'][$jj]['validToken'] = true;
+                    }
+                }
+                return;
+
         }
 
         // It's possible that there's identical locks, because of shared
diff --git a/lib/Sabre/DAV/PartialUpdate/Plugin.php b/lib/Sabre/DAV/PartialUpdate/Plugin.php
index da92508..4c60a12 100644
--- a/lib/Sabre/DAV/PartialUpdate/Plugin.php
+++ b/lib/Sabre/DAV/PartialUpdate/Plugin.php
@@ -144,9 +144,6 @@ class Plugin extends DAV\ServerPlugin {
         if($end - $start + 1 != $len)
             throw new DAV\Exception\RequestedRangeNotSatisfiable('Actual data length (' . $len . ') is not consistent with begin (' . $range[0] . ') and end (' . $range[1] . ') offsets');
 
-        // Checking If-None-Match and related headers.
-        if (!$this->server->checkPreconditions()) return;
-
         if (!$this->server->emit('beforeWriteContent', [$path, $node, null]))
             return;
 
diff --git a/lib/Sabre/DAV/Server.php b/lib/Sabre/DAV/Server.php
index 56b2d49..ad7b5a2 100644
--- a/lib/Sabre/DAV/Server.php
+++ b/lib/Sabre/DAV/Server.php
@@ -444,6 +444,10 @@ class Server extends EventEmitter {
 
         $this->transactionType = strtolower($method);
 
+        if (!$this->checkPreconditions($request, $response)) {
+            return;
+        }
+
         if ($this->emit('method:' . $method, [$request, $response])) {
             if ($this->emit('method',[$request, $response])) {
                 // Unsupported method
@@ -1337,28 +1341,25 @@ class Server extends EventEmitter {
      * related to If-None-Match, If-Match and If-Unmodified Since. It will
      * set the status to 304 Not Modified for If-Modified_since.
      *
-     * If the $handleAsGET argument is set to true, it will also return 304
-     * Not Modified for failure of the If-None-Match precondition. This is the
-     * desired behaviour for HTTP GET and HTTP HEAD requests.
-     *
-     * @param bool $handleAsGET
+     * @param RequestInterface $request
+     * @param ResponseInterface $response
      * @return bool
      */
-    public function checkPreconditions($handleAsGET = false) {
+    public function checkPreconditions(RequestInterface $request, ResponseInterface $response) {
 
-        $uri = $this->getRequestUri();
+        $path = $request->getPath();
         $node = null;
         $lastMod = null;
         $etag = null;
 
-        if ($ifMatch = $this->httpRequest->getHeader('If-Match')) {
+        if ($ifMatch = $request->getHeader('If-Match')) {
 
             // If-Match contains an entity tag. Only if the entity-tag
             // matches we are allowed to make the request succeed.
             // If the entity-tag is '*' we are only allowed to make the
             // request succeed if a resource exists at that url.
             try {
-                $node = $this->tree->getNodeForPath($uri);
+                $node = $this->tree->getNodeForPath($path);
             } catch (Exception\NotFound $e) {
                 throw new Exception\PreconditionFailed('An If-Match header was specified and the resource did not exist','If-Match');
             }
@@ -1392,7 +1393,7 @@ class Server extends EventEmitter {
             }
         }
 
-        if ($ifNoneMatch = $this->httpRequest->getHeader('If-None-Match')) {
+        if ($ifNoneMatch = $request->getHeader('If-None-Match')) {
 
             // The If-None-Match header contains an etag.
             // Only if the ETag does not match the current ETag, the request will succeed
@@ -1401,7 +1402,7 @@ class Server extends EventEmitter {
             $nodeExists = true;
             if (!$node) {
                 try {
-                    $node = $this->tree->getNodeForPath($uri);
+                    $node = $this->tree->getNodeForPath($path);
                 } catch (Exception\NotFound $e) {
                     $nodeExists = false;
                 }
@@ -1427,8 +1428,8 @@ class Server extends EventEmitter {
                 }
 
                 if ($haveMatch) {
-                    if ($handleAsGET) {
-                        $this->httpResponse->setStatus(304);
+                    if ($request->getMethod()==='GET') {
+                        $response->setStatus(304);
                         return false;
                     } else {
                         throw new Exception\PreconditionFailed('An If-None-Match header was specified, but the ETag matched (or * was specified).','If-None-Match');
@@ -1438,7 +1439,7 @@ class Server extends EventEmitter {
 
         }
 
-        if (!$ifNoneMatch && ($ifModifiedSince = $this->httpRequest->getHeader('If-Modified-Since'))) {
+        if (!$ifNoneMatch && ($ifModifiedSince = $request->getHeader('If-Modified-Since'))) {
 
             // The If-Modified-Since header contains a date. We
             // will only return the entity if it has been changed since
@@ -1450,21 +1451,21 @@ class Server extends EventEmitter {
 
             if ($date) {
                 if (is_null($node)) {
-                    $node = $this->tree->getNodeForPath($uri);
+                    $node = $this->tree->getNodeForPath($path);
                 }
                 $lastMod = $node->getLastModified();
                 if ($lastMod) {
                     $lastMod = new \DateTime('@' . $lastMod);
                     if ($lastMod <= $date) {
-                        $this->httpResponse->setStatus(304);
-                        $this->httpResponse->setHeader('Last-Modified', HTTP\Util::toHTTPDate($lastMod));
+                        $response->setStatus(304);
+                        $response->setHeader('Last-Modified', HTTP\Util::toHTTPDate($lastMod));
                         return false;
                     }
                 }
             }
         }
 
-        if ($ifUnmodifiedSince = $this->httpRequest->getHeader('If-Unmodified-Since')) {
+        if ($ifUnmodifiedSince = $request->getHeader('If-Unmodified-Since')) {
 
             // The If-Unmodified-Since will allow allow the request if the
             // entity has not changed since the specified date.
@@ -1473,7 +1474,7 @@ class Server extends EventEmitter {
             // We must only check the date if it's valid
             if ($date) {
                 if (is_null($node)) {
-                    $node = $this->tree->getNodeForPath($uri);
+                    $node = $this->tree->getNodeForPath($path);
                 }
                 $lastMod = $node->getLastModified();
                 if ($lastMod) {
@@ -1494,7 +1495,7 @@ class Server extends EventEmitter {
         //
         // The only proper way to deal with these, is to emit events, that a
         // Sync and Lock plugin can pick up.
-        $ifConditions = $this->getIfConditions();
+        $ifConditions = $this->getIfConditions($request);
 
         foreach($ifConditions as $kk => $ifCondition) {
             foreach($ifCondition['tokens'] as $ii => $token) {
@@ -1505,7 +1506,7 @@ class Server extends EventEmitter {
         // Plugins are responsible for validating all the tokens.
         // If a plugin deemed a token 'valid', it will set 'validToken' to
         // true.
-        $this->emit('validateTokens', [ &$ifConditions ]);
+        $this->emit('validateTokens', [ $request, &$ifConditions ]);
 
         // Now we're going to analyze the result.
 
@@ -1625,9 +1626,9 @@ class Server extends EventEmitter {
      *
      * @return array
      */
-    public function getIfConditions() {
+    public function getIfConditions(RequestInterface $request) {
 
-        $header = $this->httpRequest->getHeader('If');
+        $header = $request->getHeader('If');
         if (!$header) return [];
 
         $matches = [];
@@ -1651,7 +1652,7 @@ class Server extends EventEmitter {
             } else {
 
                 if (!$match['uri']) {
-                    $realUri = $this->getRequestUri();
+                    $realUri = $request->getPath();
                 } else {
                     $realUri = $this->calculateUri($match['uri']);
                 }
diff --git a/lib/Sabre/DAV/Sync/Plugin.php b/lib/Sabre/DAV/Sync/Plugin.php
index 68076ec..02ba5b9 100644
--- a/lib/Sabre/DAV/Sync/Plugin.php
+++ b/lib/Sabre/DAV/Sync/Plugin.php
@@ -3,6 +3,7 @@
 namespace Sabre\DAV\Sync;
 
 use Sabre\DAV;
+use Sabre\HTTP\RequestInterface;
 
 /**
  * This plugin all WebDAV-sync capabilities to the Server.
@@ -65,8 +66,8 @@ class Plugin extends DAV\ServerPlugin {
 
         });
 
-        $server->on('beforeGetProperties', array($this, 'beforeGetProperties'));
-        $server->on('validateTokens',      array($this, 'validateTokens'));
+        $server->on('beforeGetProperties', [$this, 'beforeGetProperties']);
+        $server->on('validateTokens',      [$this, 'validateTokens']);
 
     }
 
@@ -311,7 +312,7 @@ class Plugin extends DAV\ServerPlugin {
      * @param mixed $conditions
      * @return void
      */
-    public function validateTokens( &$conditions ) {
+    public function validateTokens( RequestInterface $request, &$conditions ) {
 
         foreach($conditions as $kk=>$condition) {
 
diff --git a/lib/Sabre/DAVACL/IPrincipalCollection.php b/lib/Sabre/DAVACL/IPrincipalCollection.php
index 2c097f9..d09c9d6 100644
--- a/lib/Sabre/DAVACL/IPrincipalCollection.php
+++ b/lib/Sabre/DAVACL/IPrincipalCollection.php
@@ -14,7 +14,7 @@ use Sabre\DAV;
  * @author Evert Pot (http://evertpot.com/)
  * @license http://sabre.io/license/ Modified BSD License
  */
-interface IPrincipalCollection extends DAV\INode {
+interface IPrincipalCollection extends DAV\ICollection {
 
     /**
      * This method is used to search for principals matching a set of
diff --git a/tests/Sabre/DAV/GetIfConditionsTest.php b/tests/Sabre/DAV/GetIfConditionsTest.php
index 393e1f3..4e9ebaf 100644
--- a/tests/Sabre/DAV/GetIfConditionsTest.php
+++ b/tests/Sabre/DAV/GetIfConditionsTest.php
@@ -11,28 +11,17 @@ class GetIfConditionsTest extends AbstractServer {
 
     function testNoConditions() {
 
-        $serverVars = array(
-        );
+        $request = new HTTP\Request();
 
-        $request = HTTP\Sapi::createFromServerArray($serverVars);
-        $this->server->httpRequest = ($request);
-
-        $conditions = $this->server->getIfConditions();
+        $conditions = $this->server->getIfConditions($request);
         $this->assertEquals(array(),$conditions);
 
     }
 
     function testLockToken() {
 
-        $serverVars = array(
-            'HTTP_IF' => '(<opaquelocktoken:token1>)',
-            'REQUEST_URI' => '/path/',
-        );
-
-        $request = HTTP\Sapi::createFromServerArray($serverVars);
-        $this->server->httpRequest = ($request);
-
-        $conditions = $this->server->getIfConditions();
+        $request = new HTTP\Request('GET', '/path/', ['If' => '(<opaquelocktoken:token1>)']);
+        $conditions = $this->server->getIfConditions($request);
 
         $compare = array(
 
@@ -62,9 +51,7 @@ class GetIfConditionsTest extends AbstractServer {
         );
 
         $request = HTTP\Sapi::createFromServerArray($serverVars);
-        $this->server->httpRequest = ($request);
-
-        $conditions = $this->server->getIfConditions();
+        $conditions = $this->server->getIfConditions($request);
 
         $compare = array(
 
@@ -92,9 +79,7 @@ class GetIfConditionsTest extends AbstractServer {
         );
 
         $request = HTTP\Sapi::createFromServerArray($serverVars);
-        $this->server->httpRequest = ($request);
-
-        $conditions = $this->server->getIfConditions();
+        $conditions = $this->server->getIfConditions($request);
 
         $compare = array(
 
@@ -123,9 +108,7 @@ class GetIfConditionsTest extends AbstractServer {
         );
 
         $request = HTTP\Sapi::createFromServerArray($serverVars);
-        $this->server->httpRequest = ($request);
-
-        $conditions = $this->server->getIfConditions();
+        $conditions = $this->server->getIfConditions($request);
 
         $compare = array(
 
@@ -158,9 +141,7 @@ class GetIfConditionsTest extends AbstractServer {
         );
 
         $request = HTTP\Sapi::createFromServerArray($serverVars);
-        $this->server->httpRequest = ($request);
-
-        $conditions = $this->server->getIfConditions();
+        $conditions = $this->server->getIfConditions($request);
 
         $compare = array(
 
@@ -198,9 +179,7 @@ class GetIfConditionsTest extends AbstractServer {
         );
 
         $request = HTTP\Sapi::createFromServerArray($serverVars);
-        $this->server->httpRequest = ($request);
-
-        $conditions = $this->server->getIfConditions();
+        $conditions = $this->server->getIfConditions($request);
 
         $compare = array(
 
@@ -244,9 +223,7 @@ class GetIfConditionsTest extends AbstractServer {
         );
 
         $request = HTTP\Sapi::createFromServerArray($serverVars);
-        $this->server->httpRequest = ($request);
-
-        $conditions = $this->server->getIfConditions();
+        $conditions = $this->server->getIfConditions($request);
 
         $compare = array(
 
@@ -273,9 +250,7 @@ class GetIfConditionsTest extends AbstractServer {
         );
 
         $request = HTTP\Sapi::createFromServerArray($serverVars);
-        $this->server->httpRequest = ($request);
-
-        $conditions = $this->server->getIfConditions();
+        $conditions = $this->server->getIfConditions($request);
 
         $compare = array(
 
@@ -309,9 +284,7 @@ class GetIfConditionsTest extends AbstractServer {
         );
 
         $request = HTTP\Sapi::createFromServerArray($serverVars);
-        $this->server->httpRequest = ($request);
-
-        $conditions = $this->server->getIfConditions();
+        $conditions = $this->server->getIfConditions($request);
 
         $compare = array(
 
diff --git a/tests/Sabre/DAV/Locks/MSWordTest.php b/tests/Sabre/DAV/Locks/MSWordTest.php
index 792f449..1dd3420 100644
--- a/tests/Sabre/DAV/Locks/MSWordTest.php
+++ b/tests/Sabre/DAV/Locks/MSWordTest.php
@@ -28,7 +28,7 @@ class MSWordTest extends \PHPUnit_Framework_TestCase {
         $server->sapi = new HTTP\SapiMock();
         $server->exec();
 
-        $this->assertEquals(201, $server->httpResponse->status);
+        $this->assertEquals(201, $server->httpResponse->getStatus(), 'Full response body:' . $response1->getBodyAsString());
         $this->assertTrue(isset($server->httpResponse->headers['Lock-Token']));
         $lockToken = $server->httpResponse->headers['Lock-Token'];
 
diff --git a/tests/Sabre/DAV/Locks/PluginTest.php b/tests/Sabre/DAV/Locks/PluginTest.php
index 71f0924..ccb897c 100644
--- a/tests/Sabre/DAV/Locks/PluginTest.php
+++ b/tests/Sabre/DAV/Locks/PluginTest.php
@@ -164,12 +164,7 @@ class PluginTest extends DAV\AbstractServer {
      */
     function testLockRefresh() {
 
-        $serverVars = array(
-            'REQUEST_URI'    => '/test.txt',
-            'REQUEST_METHOD' => 'LOCK',
-        );
-
-        $request = HTTP\Sapi::createFromServerArray($serverVars);
+        $request = new HTTP\Request('LOCK', '/test.txt');
         $request->setBody('<?xml version="1.0"?>
 <D:lockinfo xmlns:D="DAV:">
     <D:lockscope><D:exclusive/></D:lockscope>
@@ -182,25 +177,20 @@ class PluginTest extends DAV\AbstractServer {
         $this->server->httpRequest = $request;
         $this->server->exec();
 
-        $lockToken = $this->response->headers['Lock-Token'];
+        $lockToken = $this->response->getHeader('Lock-Token');
 
         $this->response = new HTTP\ResponseMock();
         $this->server->httpResponse = $this->response;
 
-        $serverVars = array(
-            'REQUEST_URI' => '/test.txt',
-            'REQUEST_METHOD' => 'LOCK',
-            'HTTP_IF' => '(' . $lockToken . ')',
-        );
-        $request = HTTP\Sapi::createFromServerArray($serverVars);
+        $request = new HTTP\Request('LOCK', '/test.txt', ['If' => '(' . $lockToken . ')' ]);
         $request->setBody('');
-        $this->server->httpRequest = $request;
 
+        $this->server->httpRequest = $request;
         $this->server->exec();
 
-        $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']);
+        $this->assertEquals('application/xml; charset=utf-8',$this->response->getHeader('Content-Type'));
 
-        $this->assertEquals(200, $this->response->status,'We received an incorrect status code. Full response body: ' . $this->response->body);
+        $this->assertEquals(200, $this->response->status,'We received an incorrect status code. Full response body: ' . $this->response->getBody());
 
     }
 
diff --git a/tests/Sabre/DAV/ServerPreconditionTest.php b/tests/Sabre/DAV/ServerPreconditionTest.php
index 52defa0..a66e823 100644
--- a/tests/Sabre/DAV/ServerPreconditionTest.php
+++ b/tests/Sabre/DAV/ServerPreconditionTest.php
@@ -19,9 +19,8 @@ class ServerPreconditionsTest extends \PHPUnit_Framework_TestCase {
             'HTTP_IF_MATCH' => '*',
             'REQUEST_URI'   => '/bar'
         ));
-        $server->httpRequest = $httpRequest;
-
-        $server->checkPreconditions();
+        $httpResponse = new HTTP\Response();
+        $server->checkPreconditions($httpRequest, $httpResponse);
 
     }
 
@@ -35,9 +34,8 @@ class ServerPreconditionsTest extends \PHPUnit_Framework_TestCase {
             'HTTP_IF_MATCH' => '*',
             'REQUEST_URI'   => '/foo'
         ));
-        $server->httpRequest = $httpRequest;
-
-        $this->assertTrue($server->checkPreconditions());
+        $httpResponse = new HTTP\Response();
+        $this->assertTrue($server->checkPreconditions($httpRequest, $httpResponse));
 
     }
 
@@ -52,9 +50,8 @@ class ServerPreconditionsTest extends \PHPUnit_Framework_TestCase {
             'HTTP_IF_MATCH' => '1234',
             'REQUEST_URI'   => '/foo'
         ));
-        $server->httpRequest = $httpRequest;
-
-        $server->checkPreconditions();
+        $httpResponse = new HTTP\Response();
+        $server->checkPreconditions($httpRequest, $httpResponse);
 
     }
 
@@ -68,9 +65,8 @@ class ServerPreconditionsTest extends \PHPUnit_Framework_TestCase {
             'HTTP_IF_MATCH' => '"abc123"',
             'REQUEST_URI'   => '/foo'
         ));
-        $server->httpRequest = $httpRequest;
-
-        $this->assertTrue($server->checkPreconditions());
+        $httpResponse = new HTTP\Response();
+        $this->assertTrue($server->checkPreconditions($httpRequest, $httpResponse));
 
     }
 
@@ -87,9 +83,9 @@ class ServerPreconditionsTest extends \PHPUnit_Framework_TestCase {
             'HTTP_IF_MATCH' => '\\"abc123\\"',
             'REQUEST_URI'   => '/foo'
         ));
-        $server->httpRequest = $httpRequest;
 
-        $this->assertTrue($server->checkPreconditions());
+        $httpResponse = new HTTP\Response();
+        $this->assertTrue($server->checkPreconditions($httpRequest, $httpResponse));
 
     }
 
@@ -103,9 +99,9 @@ class ServerPreconditionsTest extends \PHPUnit_Framework_TestCase {
             'HTTP_IF_MATCH' => '"hellothere", "abc123"',
             'REQUEST_URI'   => '/foo'
         ));
-        $server->httpRequest = $httpRequest;
 
-        $this->assertTrue($server->checkPreconditions());
+        $httpResponse = new HTTP\Response();
+        $this->assertTrue($server->checkPreconditions($httpRequest, $httpResponse));
 
     }
 
@@ -119,9 +115,8 @@ class ServerPreconditionsTest extends \PHPUnit_Framework_TestCase {
             'HTTP_IF_NONE_MATCH' => '*',
             'REQUEST_URI'   => '/bar'
         ));
-        $server->httpRequest = $httpRequest;
-
-        $this->assertTrue($server->checkPreconditions());
+        $httpResponse = new HTTP\Response();
+        $this->assertTrue($server->checkPreconditions($httpRequest, $httpResponse));
 
     }
 
@@ -136,9 +131,8 @@ class ServerPreconditionsTest extends \PHPUnit_Framework_TestCase {
             'HTTP_IF_NONE_MATCH' => '*',
             'REQUEST_URI'   => '/foo'
         ));
-        $server->httpRequest = $httpRequest;
-
-        $server->checkPreconditions();
+        $httpResponse = new HTTP\Response();
+        $server->checkPreconditions($httpRequest, $httpResponse);
 
     }
 
@@ -152,9 +146,8 @@ class ServerPreconditionsTest extends \PHPUnit_Framework_TestCase {
             'HTTP_IF_NONE_MATCH' => '"1234"',
             'REQUEST_URI'   => '/foo'
         ));
-        $server->httpRequest = $httpRequest;
-
-        $this->assertTrue($server->checkPreconditions());
+        $httpResponse = new HTTP\Response();
+        $this->assertTrue($server->checkPreconditions($httpRequest, $httpResponse));
 
     }
 
@@ -168,9 +161,8 @@ class ServerPreconditionsTest extends \PHPUnit_Framework_TestCase {
             'HTTP_IF_NONE_MATCH' => '"1234", "5678"',
             'REQUEST_URI'   => '/foo'
         ));
-        $server->httpRequest = $httpRequest;
-
-        $this->assertTrue($server->checkPreconditions());
+        $httpResponse = new HTTP\Response();
+        $this->assertTrue($server->checkPreconditions($httpRequest, $httpResponse));
 
     }
 
@@ -185,9 +177,8 @@ class ServerPreconditionsTest extends \PHPUnit_Framework_TestCase {
             'HTTP_IF_NONE_MATCH' => '"abc123"',
             'REQUEST_URI'   => '/foo'
         ));
-        $server->httpRequest = $httpRequest;
-
-        $server->checkPreconditions();
+        $httpResponse = new HTTP\Response();
+        $server->checkPreconditions($httpRequest, $httpResponse);
 
     }
 
@@ -202,9 +193,8 @@ class ServerPreconditionsTest extends \PHPUnit_Framework_TestCase {
             'HTTP_IF_NONE_MATCH' => '"1234", "abc123"',
             'REQUEST_URI'   => '/foo'
         ));
-        $server->httpRequest = $httpRequest;
-
-        $server->checkPreconditions();
+        $httpResponse = new HTTP\Response();
+        $server->checkPreconditions($httpRequest, $httpResponse);
 
     }
 
@@ -215,13 +205,13 @@ class ServerPreconditionsTest extends \PHPUnit_Framework_TestCase {
         $root = new SimpleCollection('root',array(new ServerPreconditionsNode()));
         $server = new Server($root);
         $httpRequest = HTTP\Sapi::createFromServerArray(array(
+            'REQUEST_METHOD' => 'GET',
             'HTTP_IF_NONE_MATCH' => '"abc123"',
             'REQUEST_URI'   => '/foo'
         ));
-        $server->httpRequest = $httpRequest;
         $server->httpResponse = new HTTP\ResponseMock();
 
-        $this->assertFalse($server->checkPreconditions(true));
+        $this->assertFalse($server->checkPreconditions($httpRequest, $server->httpResponse));
         $this->assertEquals(304, $server->httpResponse->status);
 
     }
@@ -236,9 +226,8 @@ class ServerPreconditionsTest extends \PHPUnit_Framework_TestCase {
             'HTTP_IF_MODIFIED_SINCE' => 'Sun, 06 Nov 1994 08:49:37 GMT',
             'REQUEST_URI'   => '/foo'
         ));
-        $server->httpRequest = $httpRequest;
         $server->httpResponse = new HTTP\ResponseMock();
-        $this->assertFalse($server->checkPreconditions());
+        $this->assertFalse($server->checkPreconditions($httpRequest, $server->httpResponse));
 
         $this->assertEquals(304, $server->httpResponse->status);
         $this->assertEquals(array(
@@ -258,9 +247,10 @@ class ServerPreconditionsTest extends \PHPUnit_Framework_TestCase {
             'HTTP_IF_MODIFIED_SINCE' => 'Tue, 06 Nov 1984 08:49:37 GMT',
             'REQUEST_URI'   => '/foo'
         ));
-        $server->httpRequest = $httpRequest;
-        $server->httpResponse = new HTTP\ResponseMock();
-        $this->assertTrue($server->checkPreconditions());
+
+        $httpRequest = $httpRequest;
+        $httpResponse = new HTTP\ResponseMock();
+        $this->assertTrue($server->checkPreconditions($httpRequest, $httpResponse));
 
     }
 
@@ -274,11 +264,11 @@ class ServerPreconditionsTest extends \PHPUnit_Framework_TestCase {
             'HTTP_IF_MODIFIED_SINCE' => 'Your mother',
             'REQUEST_URI'   => '/foo'
         ));
-        $server->httpRequest = $httpRequest;
-        $server->httpResponse = new HTTP\ResponseMock();
+        $httpRequest = $httpRequest;
+        $httpResponse = new HTTP\ResponseMock();
 
         // Invalid dates must be ignored, so this should return true
-        $this->assertTrue($server->checkPreconditions());
+        $this->assertTrue($server->checkPreconditions($httpRequest, $httpResponse));
 
     }
 
@@ -292,9 +282,8 @@ class ServerPreconditionsTest extends \PHPUnit_Framework_TestCase {
             'HTTP_IF_MODIFIED_SINCE' => 'Sun, 06 Nov 1994 08:49:37 EST',
             'REQUEST_URI'   => '/foo'
         ));
-        $server->httpRequest = $httpRequest;
-        $server->httpResponse = new HTTP\ResponseMock();
-        $this->assertTrue($server->checkPreconditions());
+        $httpResponse = new HTTP\ResponseMock();
+        $this->assertTrue($server->checkPreconditions($httpRequest, $httpResponse));
 
     }
 
@@ -309,8 +298,8 @@ class ServerPreconditionsTest extends \PHPUnit_Framework_TestCase {
             'HTTP_IF_UNMODIFIED_SINCE' => 'Sun, 06 Nov 1994 08:49:37 GMT',
             'REQUEST_URI'   => '/foo'
         ));
-        $server->httpRequest = $httpRequest;
-        $this->assertTrue($server->checkPreconditions());
+        $httpResponse = new HTTP\Response();
+        $this->assertTrue($server->checkPreconditions($httpRequest, $httpResponse));
 
     }
 
@@ -326,9 +315,8 @@ class ServerPreconditionsTest extends \PHPUnit_Framework_TestCase {
             'HTTP_IF_UNMODIFIED_SINCE' => 'Tue, 06 Nov 1984 08:49:37 GMT',
             'REQUEST_URI'   => '/foo'
         ));
-        $server->httpRequest = $httpRequest;
-        $server->httpResponse = new HTTP\ResponseMock();
-        $server->checkPreconditions();
+        $httpResponse = new HTTP\ResponseMock();
+        $server->checkPreconditions($httpRequest, $httpResponse);
 
     }
 
@@ -342,9 +330,8 @@ class ServerPreconditionsTest extends \PHPUnit_Framework_TestCase {
             'HTTP_IF_UNMODIFIED_SINCE' => 'Sun, 06 Nov 1984 08:49:37 CET',
             'REQUEST_URI'   => '/foo'
         ));
-        $server->httpRequest = $httpRequest;
-        $server->httpResponse = new HTTP\ResponseMock();
-        $this->assertTrue($server->checkPreconditions());
+        $httpResponse = new HTTP\ResponseMock();
+        $this->assertTrue($server->checkPreconditions($httpRequest, $httpResponse));
 
     }
 

-- 
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