ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
PluginTest.php
Go to the documentation of this file.
1<?php
2
4
7use Sabre\DAV;
9use Sabre\HTTP;
11
13
17 protected $server;
21 protected $plugin;
22 protected $response;
26 protected $caldavBackend;
27
28 function setup() {
29
30 $this->caldavBackend = new CalDAV\Backend\MockSharing();
32 $calendars = new CalDAV\CalendarRoot($principalBackend, $this->caldavBackend);
34
35 $root = new DAV\SimpleCollection('root');
36 $root->addChild($calendars);
37 $root->addChild($principals);
38
39 $this->server = new DAV\Server($root);
40 $this->server->sapi = new HTTP\SapiMock();
41 $this->server->debugExceptions = true;
42 $this->server->setBaseUri('/');
43 $this->plugin = new Plugin();
44 $this->server->addPlugin($this->plugin);
45
46
47 // Adding ACL plugin
49 $aclPlugin->allowUnauthenticatedAccess = false;
50 $this->server->addPlugin($aclPlugin);
51
52 // CalDAV is also required.
53 $this->server->addPlugin(new CalDAV\Plugin());
54 // Adding Auth plugin, and ensuring that we are logged in.
57 $this->server->addPlugin($authPlugin);
58
59 // This forces a login
60 $authPlugin->beforeMethod(new HTTP\Request(), new HTTP\Response());
61
62 $this->response = new HTTP\ResponseMock();
63 $this->server->httpResponse = $this->response;
64
65 }
66
67 function testSimple() {
68
69 $this->assertEquals([], $this->plugin->getFeatures());
70 $this->assertEquals('notifications', $this->plugin->getPluginName());
71 $this->assertEquals(
72 'notifications',
73 $this->plugin->getPluginInfo()['name']
74 );
75
76 }
77
79
80 $httpRequest = new Request('GET', '/', ['Host' => 'sabredav.org']);
81 $this->server->httpRequest = $httpRequest;
82
83 $props = $this->server->getPropertiesForPath('principals/admin', [
84 '{' . Plugin::NS_CALENDARSERVER . '}notification-URL',
85 ]);
86
87 $this->assertArrayHasKey(0, $props);
88 $this->assertArrayHasKey(200, $props[0]);
89
90 $this->assertArrayHasKey('{' . Plugin::NS_CALENDARSERVER . '}notification-URL', $props[0][200]);
91 $prop = $props[0][200]['{' . Plugin::NS_CALENDARSERVER . '}notification-URL'];
92 $this->assertTrue($prop instanceof DAV\Xml\Property\Href);
93 $this->assertEquals('calendars/admin/notifications/', $prop->getHref());
94
95 }
96
98
99 $notification = new Node(
100 $this->caldavBackend,
101 'principals/user1',
102 new SystemStatus('foo', '"1"')
103 );
104 $propFind = new DAV\PropFind('calendars/user1/notifications', [
105 '{' . Plugin::NS_CALENDARSERVER . '}notificationtype',
106 ]);
107
108 $this->plugin->propFind($propFind, $notification);
109
110 $this->assertEquals(
111 $notification->getNotificationType(),
112 $propFind->get('{' . Plugin::NS_CALENDARSERVER . '}notificationtype')
113 );
114
115 }
116
118
119 $notification = new Node(
120 $this->caldavBackend,
121 'principals/user1',
122 new SystemStatus('foo', '"1"')
123 );
124
125 $server = new DAV\Server([$notification]);
126 $caldav = new Plugin();
127
128 $server->httpRequest = new Request('GET', '/foo.xml');
129 $httpResponse = new HTTP\ResponseMock();
130 $server->httpResponse = $httpResponse;
131
132 $server->addPlugin($caldav);
133
134 $caldav->httpGet($server->httpRequest, $server->httpResponse);
135
136 $this->assertEquals(200, $httpResponse->status);
137 $this->assertEquals([
138 'Content-Type' => ['application/xml'],
139 'ETag' => ['"1"'],
140 ], $httpResponse->getHeaders());
141
142 $expected =
143'<?xml version="1.0" encoding="UTF-8"?>
144<cs:notification xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns" xmlns:cs="http://calendarserver.org/ns/">
145 <cs:systemstatus type="high"/>
146</cs:notification>
147';
148
149 $this->assertXmlStringEqualsXmlString($expected, $httpResponse->getBodyAsString());
150
151 }
152
154
155 $server = new DAV\Server();
156 $caldav = new Plugin();
157
158 $httpResponse = new HTTP\ResponseMock();
159 $server->httpResponse = $httpResponse;
160
161 $server->addPlugin($caldav);
162
163 $this->assertNull($caldav->httpGet(new HTTP\Request('GET', '/foozz'), $server->httpResponse));
164
165 }
166
167
168}
$authBackend
$principalBackend
$aclPlugin
$authPlugin
An exception for terminatinating execution or to throw for unit testing.
Calendars collection.
This node represents a single notification.
Definition: Node.php:21
Notifications plugin.
Definition: Plugin.php:27
const NS_CALENDARSERVER
This is the namespace for the proprietary calendarserver extensions.
Definition: Plugin.php:32
SabreDAV ACL Plugin.
Definition: Plugin.php:31
This plugin provides Authentication for a WebDAV server.
Definition: Plugin.php:25
This class holds all the information about a PROPFIND request.
Definition: PropFind.php:11
Main DAV server class.
Definition: Server.php:23
Href property.
Definition: Href.php:26
The Request class represents a single HTTP request.
Definition: Request.php:18
This class represents a single HTTP response.
Definition: Response.php:12
$root
Definition: sabredav.php:45