[Pkg-owncloud-commits] [php-sabredav] 216/275: Test for #515.
David Prévot
taffit at moszumanska.debian.org
Thu Sep 25 14:56:10 UTC 2014
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository php-sabredav.
commit 997fa002d57754add5acafb5f007c336f0f914fa
Author: Evert Pot <evert at rooftopsolutions.nl>
Date: Thu Sep 11 13:37:39 2014 +0100
Test for #515.
---
tests/Sabre/DAV/ServerPreconditionTest.php | 81 ++++++++++++------------------
tests/Sabre/HTTP/SapiMock.php | 6 ++-
2 files changed, 36 insertions(+), 51 deletions(-)
diff --git a/tests/Sabre/DAV/ServerPreconditionTest.php b/tests/Sabre/DAV/ServerPreconditionTest.php
index 37a47f7..26912ac 100644
--- a/tests/Sabre/DAV/ServerPreconditionTest.php
+++ b/tests/Sabre/DAV/ServerPreconditionTest.php
@@ -15,10 +15,7 @@ class ServerPreconditionsTest extends \PHPUnit_Framework_TestCase {
$root = new SimpleCollection('root',array(new ServerPreconditionsNode()));
$server = new Server($root);
- $httpRequest = HTTP\Sapi::createFromServerArray(array(
- 'HTTP_IF_MATCH' => '*',
- 'REQUEST_URI' => '/bar'
- ));
+ $httpRequest = new HTTP\Request('GET', '/bar', ['If-Match' => '*']);
$httpResponse = new HTTP\Response();
$server->checkPreconditions($httpRequest, $httpResponse);
@@ -30,10 +27,7 @@ class ServerPreconditionsTest extends \PHPUnit_Framework_TestCase {
$root = new SimpleCollection('root',array(new ServerPreconditionsNode()));
$server = new Server($root);
- $httpRequest = HTTP\Sapi::createFromServerArray(array(
- 'HTTP_IF_MATCH' => '*',
- 'REQUEST_URI' => '/foo'
- ));
+ $httpRequest = new HTTP\Request('GET', '/foo', ['If-Match' => '*']);
$httpResponse = new HTTP\Response();
$this->assertTrue($server->checkPreconditions($httpRequest, $httpResponse));
@@ -46,10 +40,7 @@ class ServerPreconditionsTest extends \PHPUnit_Framework_TestCase {
$root = new SimpleCollection('root',array(new ServerPreconditionsNode()));
$server = new Server($root);
- $httpRequest = HTTP\Sapi::createFromServerArray(array(
- 'HTTP_IF_MATCH' => '1234',
- 'REQUEST_URI' => '/foo'
- ));
+ $httpRequest = new HTTP\Request('GET', '/foo', ['If-Match' => '1234']);
$httpResponse = new HTTP\Response();
$server->checkPreconditions($httpRequest, $httpResponse);
@@ -61,10 +52,7 @@ class ServerPreconditionsTest extends \PHPUnit_Framework_TestCase {
$root = new SimpleCollection('root',array(new ServerPreconditionsNode()));
$server = new Server($root);
- $httpRequest = HTTP\Sapi::createFromServerArray(array(
- 'HTTP_IF_MATCH' => '"abc123"',
- 'REQUEST_URI' => '/foo'
- ));
+ $httpRequest = new HTTP\Request('GET', '/foo', ['If-Match' => '"abc123"']);
$httpResponse = new HTTP\Response();
$this->assertTrue($server->checkPreconditions($httpRequest, $httpResponse));
@@ -79,11 +67,7 @@ class ServerPreconditionsTest extends \PHPUnit_Framework_TestCase {
$root = new SimpleCollection('root',array(new ServerPreconditionsNode()));
$server = new Server($root);
- $httpRequest = HTTP\Sapi::createFromServerArray(array(
- 'HTTP_IF_MATCH' => '\\"abc123\\"',
- 'REQUEST_URI' => '/foo'
- ));
-
+ $httpRequest = new HTTP\Request('GET', '/foo', ['If-Match' => '\\"abc123\\"']);
$httpResponse = new HTTP\Response();
$this->assertTrue($server->checkPreconditions($httpRequest, $httpResponse));
@@ -95,11 +79,7 @@ class ServerPreconditionsTest extends \PHPUnit_Framework_TestCase {
$root = new SimpleCollection('root',array(new ServerPreconditionsNode()));
$server = new Server($root);
- $httpRequest = HTTP\Sapi::createFromServerArray(array(
- 'HTTP_IF_MATCH' => '"hellothere", "abc123"',
- 'REQUEST_URI' => '/foo'
- ));
-
+ $httpRequest = new HTTP\Request('GET', '/foo', ['If-Match' => '"hellothere", "abc123"']);
$httpResponse = new HTTP\Response();
$this->assertTrue($server->checkPreconditions($httpRequest, $httpResponse));
@@ -111,10 +91,7 @@ class ServerPreconditionsTest extends \PHPUnit_Framework_TestCase {
$root = new SimpleCollection('root',array(new ServerPreconditionsNode()));
$server = new Server($root);
- $httpRequest = HTTP\Sapi::createFromServerArray(array(
- 'HTTP_IF_NONE_MATCH' => '*',
- 'REQUEST_URI' => '/bar'
- ));
+ $httpRequest = new HTTP\Request('GET', '/bar', ['If-None-Match' => '*']);
$httpResponse = new HTTP\Response();
$this->assertTrue($server->checkPreconditions($httpRequest, $httpResponse));
@@ -127,10 +104,7 @@ class ServerPreconditionsTest extends \PHPUnit_Framework_TestCase {
$root = new SimpleCollection('root',array(new ServerPreconditionsNode()));
$server = new Server($root);
- $httpRequest = HTTP\Sapi::createFromServerArray(array(
- 'HTTP_IF_NONE_MATCH' => '*',
- 'REQUEST_URI' => '/foo'
- ));
+ $httpRequest = new HTTP\Request('POST', '/foo', ['If-None-Match' => '*']);
$httpResponse = new HTTP\Response();
$server->checkPreconditions($httpRequest, $httpResponse);
@@ -142,10 +116,7 @@ class ServerPreconditionsTest extends \PHPUnit_Framework_TestCase {
$root = new SimpleCollection('root',array(new ServerPreconditionsNode()));
$server = new Server($root);
- $httpRequest = HTTP\Sapi::createFromServerArray(array(
- 'HTTP_IF_NONE_MATCH' => '"1234"',
- 'REQUEST_URI' => '/foo'
- ));
+ $httpRequest = new HTTP\Request('POST', '/foo', ['If-None-Match' => '"1234"']);
$httpResponse = new HTTP\Response();
$this->assertTrue($server->checkPreconditions($httpRequest, $httpResponse));
@@ -157,10 +128,7 @@ class ServerPreconditionsTest extends \PHPUnit_Framework_TestCase {
$root = new SimpleCollection('root',array(new ServerPreconditionsNode()));
$server = new Server($root);
- $httpRequest = HTTP\Sapi::createFromServerArray(array(
- 'HTTP_IF_NONE_MATCH' => '"1234", "5678"',
- 'REQUEST_URI' => '/foo'
- ));
+ $httpRequest = new HTTP\Request('POST', '/foo', ['If-None-Match' => '"1234", "5678"']);
$httpResponse = new HTTP\Response();
$this->assertTrue($server->checkPreconditions($httpRequest, $httpResponse));
@@ -173,10 +141,7 @@ class ServerPreconditionsTest extends \PHPUnit_Framework_TestCase {
$root = new SimpleCollection('root',array(new ServerPreconditionsNode()));
$server = new Server($root);
- $httpRequest = HTTP\Sapi::createFromServerArray(array(
- 'HTTP_IF_NONE_MATCH' => '"abc123"',
- 'REQUEST_URI' => '/foo'
- ));
+ $httpRequest = new HTTP\Request('POST', '/foo', ['If-None-Match' => '"abc123"']);
$httpResponse = new HTTP\Response();
$server->checkPreconditions($httpRequest, $httpResponse);
@@ -189,10 +154,7 @@ class ServerPreconditionsTest extends \PHPUnit_Framework_TestCase {
$root = new SimpleCollection('root',array(new ServerPreconditionsNode()));
$server = new Server($root);
- $httpRequest = HTTP\Sapi::createFromServerArray(array(
- 'HTTP_IF_NONE_MATCH' => '"1234", "abc123"',
- 'REQUEST_URI' => '/foo'
- ));
+ $httpRequest = new HTTP\Request('POST', '/foo', ['If-None-Match' => '"1234, "abc123"']);
$httpResponse = new HTTP\Response();
$server->checkPreconditions($httpRequest, $httpResponse);
@@ -213,6 +175,25 @@ class ServerPreconditionsTest extends \PHPUnit_Framework_TestCase {
}
+ public function testNoneMatchCorrectEtagEnsureSapiSent() {
+
+ $root = new SimpleCollection('root',array(new ServerPreconditionsNode()));
+ $server = new Server($root);
+ $server->sapi = new HTTP\SapiMock();
+ HTTP\SapiMock::$sent = 0;
+ $httpRequest = new HTTP\Request('GET', '/foo', ['If-None-Match' => '"abc123"']);
+ $server->httpRequest = $httpRequest;
+ $server->httpResponse = new HTTP\ResponseMock();
+
+ $server->exec();
+
+ $this->assertFalse($server->checkPreconditions($httpRequest, $server->httpResponse));
+ $this->assertEquals(304, $server->httpResponse->getStatus());
+ $this->assertEquals(['ETag' => '"abc123"'], $server->httpResponse->getHeaders());
+ $this->assertEquals(1, HTTP\SapiMock::$sent);
+
+ }
+
/**
*/
public function testIfModifiedSinceUnModified() {
diff --git a/tests/Sabre/HTTP/SapiMock.php b/tests/Sabre/HTTP/SapiMock.php
index b4cfa07..2f5860f 100644
--- a/tests/Sabre/HTTP/SapiMock.php
+++ b/tests/Sabre/HTTP/SapiMock.php
@@ -13,12 +13,16 @@ namespace Sabre\HTTP;
*/
class SapiMock extends Sapi {
+ static $sent = 0;
+
/**
* Overriding this so nothing is ever echo'd.
*
* @return void
*/
- static public function sendResponse(\Sabre\HTTP\ResponseInterface $r) {
+ static function sendResponse(\Sabre\HTTP\ResponseInterface $r) {
+
+ self::$sent++;
}
--
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