aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/sabre/dav/tests/Sabre/DAVServerTest.php
diff options
context:
space:
mode:
authorMario Vavti <mario@mariovavti.com>2016-05-28 17:46:24 +0200
committerMario Vavti <mario@mariovavti.com>2016-05-28 17:46:24 +0200
commit66effbfe0827fc61fff6d248797a894213ad20d6 (patch)
tree0fbb5ca644e1140e5b3b44b1adc874043790c388 /vendor/sabre/dav/tests/Sabre/DAVServerTest.php
parentac4688eac087854bf8cb0c893d7a79052ad63a20 (diff)
downloadvolse-hubzilla-66effbfe0827fc61fff6d248797a894213ad20d6.tar.gz
volse-hubzilla-66effbfe0827fc61fff6d248797a894213ad20d6.tar.bz2
volse-hubzilla-66effbfe0827fc61fff6d248797a894213ad20d6.zip
upgrade to sabre32
Diffstat (limited to 'vendor/sabre/dav/tests/Sabre/DAVServerTest.php')
-rw-r--r--vendor/sabre/dav/tests/Sabre/DAVServerTest.php84
1 files changed, 68 insertions, 16 deletions
diff --git a/vendor/sabre/dav/tests/Sabre/DAVServerTest.php b/vendor/sabre/dav/tests/Sabre/DAVServerTest.php
index d329b5b05..35f240d23 100644
--- a/vendor/sabre/dav/tests/Sabre/DAVServerTest.php
+++ b/vendor/sabre/dav/tests/Sabre/DAVServerTest.php
@@ -27,6 +27,7 @@ abstract class DAVServerTest extends \PHPUnit_Framework_TestCase {
protected $setupCalDAVICSExport = false;
protected $setupLocks = false;
protected $setupFiles = false;
+ protected $setupSharing = false;
protected $setupPropertyStorage = false;
/**
@@ -90,6 +91,13 @@ abstract class DAVServerTest extends \PHPUnit_Framework_TestCase {
protected $locksPlugin;
/**
+ * Sharing plugin.
+ *
+ * @var \Sabre\DAV\Sharing\Plugin
+ */
+ protected $sharingPlugin;
+
+ /*
* @var Sabre\DAV\PropertyStorage\Plugin
*/
protected $propertyStoragePlugin;
@@ -102,6 +110,12 @@ abstract class DAVServerTest extends \PHPUnit_Framework_TestCase {
function setUp() {
+ $this->initializeEverything();
+
+ }
+
+ function initializeEverything() {
+
$this->setUpBackends();
$this->setUpTree();
@@ -113,6 +127,10 @@ abstract class DAVServerTest extends \PHPUnit_Framework_TestCase {
$this->caldavPlugin = new CalDAV\Plugin();
$this->server->addPlugin($this->caldavPlugin);
}
+ if ($this->setupCalDAVSharing || $this->setupSharing) {
+ $this->sharingPlugin = new DAV\Sharing\Plugin();
+ $this->server->addPlugin($this->sharingPlugin);
+ }
if ($this->setupCalDAVSharing) {
$this->caldavSharingPlugin = new CalDAV\SharingPlugin();
$this->server->addPlugin($this->caldavSharingPlugin);
@@ -132,10 +150,6 @@ abstract class DAVServerTest extends \PHPUnit_Framework_TestCase {
$this->carddavPlugin = new CardDAV\Plugin();
$this->server->addPlugin($this->carddavPlugin);
}
- if ($this->setupACL) {
- $this->aclPlugin = new DAVACL\Plugin();
- $this->server->addPlugin($this->aclPlugin);
- }
if ($this->setupLocks) {
$this->locksPlugin = new DAV\Locks\Plugin(
$this->locksBackend
@@ -149,13 +163,15 @@ abstract class DAVServerTest extends \PHPUnit_Framework_TestCase {
$this->server->addPlugin($this->propertyStoragePlugin);
}
if ($this->autoLogin) {
- $authBackend = new DAV\Auth\Backend\Mock();
- $authBackend->setPrincipal('principals/' . $this->autoLogin);
- $this->authPlugin = new DAV\Auth\Plugin($authBackend);
- $this->server->addPlugin($this->authPlugin);
-
- // This will trigger the actual login procedure
- $this->authPlugin->beforeMethod(new Request(), new Response());
+ $this->autoLogin($this->autoLogin);
+ }
+ if ($this->setupACL) {
+ $this->aclPlugin = new DAVACL\Plugin();
+ if (!$this->autoLogin) {
+ $this->aclPlugin->allowUnauthenticatedAccess = false;
+ }
+ $this->aclPlugin->adminPrincipals = ['principals/admin'];
+ $this->server->addPlugin($this->aclPlugin);
}
}
@@ -166,23 +182,55 @@ abstract class DAVServerTest extends \PHPUnit_Framework_TestCase {
* You can either pass an instance of Sabre\HTTP\Request, or an array,
* which will then be used as the _SERVER array.
*
+ * If $expectedStatus is set, we'll compare it with the HTTP status of
+ * the returned response. If it doesn't match, we'll immediately fail
+ * the test.
+ *
* @param array|\Sabre\HTTP\Request $request
+ * @param int $expectedStatus
* @return \Sabre\HTTP\Response
*/
- function request($request) {
+ function request($request, $expectedStatus = null) {
if (is_array($request)) {
$request = HTTP\Request::createFromServerArray($request);
}
+ $response = new HTTP\ResponseMock();
+
$this->server->httpRequest = $request;
- $this->server->httpResponse = new HTTP\ResponseMock();
+ $this->server->httpResponse = $response;
$this->server->exec();
+ if ($expectedStatus) {
+ $responseBody = $expectedStatus !== $response->getStatus() ? $response->getBodyAsString() : '';
+ $this->assertEquals($expectedStatus, $response->getStatus(), 'Incorrect HTTP status received for request. Response body: ' . $responseBody);
+ }
return $this->server->httpResponse;
}
/**
+ * This function takes a username and sets the server in a state where
+ * this user is logged in, and no longer requires an authentication check.
+ *
+ * @param string $userName
+ */
+ function autoLogin($userName) {
+ $authBackend = new DAV\Auth\Backend\Mock();
+ $authBackend->setPrincipal('principals/' . $userName);
+ $this->authPlugin = new DAV\Auth\Plugin($authBackend);
+
+ // If the auth plugin already exists, we're removing its hooks:
+ if ($oldAuth = $this->server->getPlugin('auth')) {
+ $this->server->removeListener('beforeMethod', [$oldAuth, 'beforeMethod']);
+ }
+ $this->server->addPlugin($this->authPlugin);
+
+ // This will trigger the actual login procedure
+ $this->authPlugin->beforeMethod(new Request(), new Response());
+ }
+
+ /**
* Override this to provide your own Tree for your test-case.
*/
function setUpTree() {
@@ -200,10 +248,14 @@ abstract class DAVServerTest extends \PHPUnit_Framework_TestCase {
);
}
- if ($this->setupCardDAV || $this->setupCalDAV) {
+ if ($this->setupCalDAV) {
$this->tree[] = new CalDAV\Principal\Collection(
$this->principalBackend
);
+ } elseif ($this->setupCardDAV || $this->setupACL) {
+ $this->tree[] = new DAVACL\PrincipalCollection(
+ $this->principalBackend
+ );
}
if ($this->setupFiles) {
@@ -231,7 +283,7 @@ abstract class DAVServerTest extends \PHPUnit_Framework_TestCase {
if ($this->setupCardDAV && is_null($this->carddavBackend)) {
$this->carddavBackend = new CardDAV\Backend\Mock($this->carddavAddressBooks, $this->carddavCards);
}
- if ($this->setupCardDAV || $this->setupCalDAV) {
+ if ($this->setupCardDAV || $this->setupCalDAV || $this->setupACL) {
$this->principalBackend = new DAVACL\PrincipalBackend\Mock();
}
if ($this->setupLocks) {
@@ -244,7 +296,7 @@ abstract class DAVServerTest extends \PHPUnit_Framework_TestCase {
}
- function assertHTTPStatus($expectedStatus, HTTP\Request $req) {
+ function assertHttpStatus($expectedStatus, HTTP\Request $req) {
$resp = $this->request($req);
$this->assertEquals((int)$expectedStatus, (int)$resp->status, 'Incorrect HTTP status received: ' . $resp->body);