]> git.mxchange.org Git - friendica-addons.git/blob - dav/SabreDAV/tests/Sabre/DAVServerTest.php
Move friendica-specific parts into an own subdirectory
[friendica-addons.git] / dav / SabreDAV / tests / Sabre / DAVServerTest.php
1 <?php
2
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';
7
8 /**
9  * This class may be used as a basis for other webdav-related unittests.
10  *
11  * This class is supposed to provide a reasonably big framework to quickly get
12  * a testing environment running.
13  *
14  * @package Sabre
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
18  */
19 abstract class Sabre_DAVServerTest extends PHPUnit_Framework_TestCase {
20
21     protected $setupCalDAV = false;
22     protected $setupCardDAV = false;
23
24     protected $caldavCalendars = array();
25     protected $caldavCalendarObjects = array();
26
27     protected $carddavAddressBooks = array();
28     protected $carddavCards = array();
29
30     /**
31      * @var Sabre_DAV_Server
32      */
33     protected $server;
34     protected $tree = array();
35
36     protected $caldavBackend;
37     protected $carddavBackend;
38     protected $principalBackend;
39
40     /**
41      * @var Sabre_CalDAV_Plugin
42      */
43     protected $caldavPlugin;
44     protected $carddavPlugin;
45
46     function setUp() {
47
48         $this->setUpBackends();
49         $this->setUpTree();
50
51         $this->server = new Sabre_DAV_Server($this->tree);
52
53         if ($this->setupCalDAV) {
54             $this->caldavPlugin = new Sabre_CalDAV_Plugin();
55             $this->server->addPlugin($this->caldavPlugin);
56         }
57         if ($this->setupCardDAV) {
58             $this->carddavPlugin = new Sabre_CardDAV_Plugin();
59             $this->server->addPlugin($this->carddavPlugin);
60         }
61
62     }
63
64     /**
65      * Makes a request, and returns a response object.
66      *
67      * You can either pass an isntance of Sabre_HTTP_Request, or an array,
68      * which will then be used as the _SERVER array.
69      *
70      * @param array|Sabre_HTTP_Request $request
71      * @return Sabre_HTTP_Response
72      */
73     function request($request) {
74
75         if (is_array($request)) {
76             $request = new Sabre_HTTP_Request($request);
77         }
78         $this->server->httpRequest = $request;
79         $this->server->httpResponse = new Sabre_HTTP_ResponseMock();
80         $this->server->exec();
81
82         return $this->server->httpResponse;
83
84     }
85
86     function setUpTree() {
87
88         if ($this->setupCalDAV) {
89             $this->tree[] = new Sabre_CalDAV_CalendarRootNode(
90                 $this->principalBackend,
91                 $this->caldavBackend
92             );
93         }
94         if ($this->setupCardDAV) {
95             $this->tree[] = new Sabre_CardDAV_AddressBookRoot(
96                 $this->principalBackend,
97                 $this->carddavBackend
98             );
99         }
100
101         if ($this->setupCardDAV || $this->setupCalDAV) {
102             $this->tree[] = new Sabre_DAVACL_PrincipalCollection(
103                 $this->principalBackend
104             );
105         }
106
107     }
108
109     function setUpBackends() {
110
111         if ($this->setupCalDAV) {
112             $this->caldavBackend = new Sabre_CalDAV_Backend_Mock($this->caldavCalendars, $this->caldavCalendarObjects);
113         }
114         if ($this->setupCardDAV) {
115             $this->carddavBackend = new Sabre_CardDAV_Backend_Mock($this->carddavAddressBooks, $this->carddavCards);
116         }
117         if ($this->setupCardDAV || $this->setupCalDAV) {
118             $this->principalBackend = new Sabre_DAVACL_MockPrincipalBackend();
119         }
120
121     }
122
123
124     function assertHTTPStatus($expectedStatus, Sabre_HTTP_Request $req) {
125
126         $resp = $this->request($req);
127         $this->assertEquals($resp->getStatusMessage($expectedStatus), $resp->status,'Incorrect HTTP status received: ' . $resp->body);
128
129     }
130
131 }