3 require_once 'Sabre/HTTP/ResponseMock.php';
4 require_once 'Sabre/CalDAV/Backend/Mock.php';
5 require_once 'Sabre/CardDAV/Backend/Mock.php';
6 require_once 'Sabre/DAVACL/MockPrincipalBackend.php';
9 * This class may be used as a basis for other webdav-related unittests.
11 * This class is supposed to provide a reasonably big framework to quickly get
12 * a testing environment running.
15 * @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
16 * @author Evert Pot (http://www.rooftopsolutions.nl/)
17 * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
19 abstract class Sabre_DAVServerTest extends PHPUnit_Framework_TestCase {
21 protected $setupCalDAV = false;
22 protected $setupCardDAV = false;
24 protected $caldavCalendars = array();
25 protected $caldavCalendarObjects = array();
27 protected $carddavAddressBooks = array();
28 protected $carddavCards = array();
31 * @var Sabre_DAV_Server
34 protected $tree = array();
36 protected $caldavBackend;
37 protected $carddavBackend;
38 protected $principalBackend;
41 * @var Sabre_CalDAV_Plugin
43 protected $caldavPlugin;
44 protected $carddavPlugin;
48 $this->setUpBackends();
51 $this->server = new Sabre_DAV_Server($this->tree);
53 if ($this->setupCalDAV) {
54 $this->caldavPlugin = new Sabre_CalDAV_Plugin();
55 $this->server->addPlugin($this->caldavPlugin);
57 if ($this->setupCardDAV) {
58 $this->carddavPlugin = new Sabre_CardDAV_Plugin();
59 $this->server->addPlugin($this->carddavPlugin);
65 * Makes a request, and returns a response object.
67 * You can either pass an isntance of Sabre_HTTP_Request, or an array,
68 * which will then be used as the _SERVER array.
70 * @param array|Sabre_HTTP_Request $request
71 * @return Sabre_HTTP_Response
73 function request($request) {
75 if (is_array($request)) {
76 $request = new Sabre_HTTP_Request($request);
78 $this->server->httpRequest = $request;
79 $this->server->httpResponse = new Sabre_HTTP_ResponseMock();
80 $this->server->exec();
82 return $this->server->httpResponse;
86 function setUpTree() {
88 if ($this->setupCalDAV) {
89 $this->tree[] = new Sabre_CalDAV_CalendarRootNode(
90 $this->principalBackend,
94 if ($this->setupCardDAV) {
95 $this->tree[] = new Sabre_CardDAV_AddressBookRoot(
96 $this->principalBackend,
101 if ($this->setupCardDAV || $this->setupCalDAV) {
102 $this->tree[] = new Sabre_DAVACL_PrincipalCollection(
103 $this->principalBackend
109 function setUpBackends() {
111 if ($this->setupCalDAV) {
112 $this->caldavBackend = new Sabre_CalDAV_Backend_Mock($this->caldavCalendars, $this->caldavCalendarObjects);
114 if ($this->setupCardDAV) {
115 $this->carddavBackend = new Sabre_CardDAV_Backend_Mock($this->carddavAddressBooks, $this->carddavCards);
117 if ($this->setupCardDAV || $this->setupCalDAV) {
118 $this->principalBackend = new Sabre_DAVACL_MockPrincipalBackend();
124 function assertHTTPStatus($expectedStatus, Sabre_HTTP_Request $req) {
126 $resp = $this->request($req);
127 $this->assertEquals($resp->getStatusMessage($expectedStatus), $resp->status,'Incorrect HTTP status received: ' . $resp->body);