@@ -60,17 +60,21 @@ public function setUpScenario() {
6060
6161 /** @AfterScenario */
6262 public function afterScenario () {
63- foreach (['MyCalendar ' , 'MyCalendar2 ' ] as $ calendarName ) {
64- try {
65- $ this ->client ->delete (
66- $ this ->baseUrl . '/remote.php/dav/calendars/admin/ ' . $ calendarName ,
67- [
68- 'auth ' => ['admin ' , 'admin ' ],
69- 'headers ' => ['X-NC-CalDAV-No-Trashbin ' => '1 ' ],
63+ $ davUrl = $ this ->baseUrl . '/remote.php/dav/calendars/admin/MyCalendar ' ;
64+ try {
65+ $ this ->client ->delete (
66+ $ davUrl ,
67+ [
68+ 'auth ' => [
69+ 'admin ' ,
70+ 'admin ' ,
71+ ],
72+ 'headers ' => [
73+ 'X-NC-CalDAV-No-Trashbin ' => '1 ' ,
7074 ]
71- );
72- } catch ( \ GuzzleHttp \ Exception \ ClientException $ e ) {
73- }
75+ ]
76+ );
77+ } catch ( \ GuzzleHttp \ Exception \ ClientException $ e ) {
7478 }
7579 }
7680
@@ -122,39 +126,11 @@ public function requestsCalendar($user, $calendar, $endpoint) {
122126 }
123127 }
124128
125- /**
126- * @When :user requests principal :principal on the endpoint :endpoint
127- */
128- public function requestsPrincipal (string $ user , string $ principal , string $ endpoint ): void {
129- $ davUrl = $ this ->baseUrl . $ endpoint . $ principal ;
130-
131- $ password = ($ user === 'admin ' ) ? 'admin ' : '123456 ' ;
132- try {
133- $ this ->response = $ this ->client ->request (
134- 'PROPFIND ' ,
135- $ davUrl ,
136- [
137- 'headers ' => [
138- 'Content-Type ' => 'application/xml; charset=UTF-8 ' ,
139- 'Depth ' => 0 ,
140- ],
141- 'body ' => '<x0:propfind xmlns:x0="DAV:"><x0:prop><x0:displayname/><x1:calendar-user-type xmlns:x1="urn:ietf:params:xml:ns:caldav"/><x1:calendar-user-address-set xmlns:x1="urn:ietf:params:xml:ns:caldav"/><x0:principal-URL/><x0:alternate-URI-set/><x2:email-address xmlns:x2="http://sabredav.org/ns"/><x3:language xmlns:x3="http://nextcloud.com/ns"/><x1:calendar-home-set xmlns:x1="urn:ietf:params:xml:ns:caldav"/><x1:schedule-inbox-URL xmlns:x1="urn:ietf:params:xml:ns:caldav"/><x1:schedule-outbox-URL xmlns:x1="urn:ietf:params:xml:ns:caldav"/><x1:schedule-default-calendar-URL xmlns:x1="urn:ietf:params:xml:ns:caldav"/><x3:resource-type xmlns:x3="http://nextcloud.com/ns"/><x3:resource-vehicle-type xmlns:x3="http://nextcloud.com/ns"/><x3:resource-vehicle-make xmlns:x3="http://nextcloud.com/ns"/><x3:resource-vehicle-model xmlns:x3="http://nextcloud.com/ns"/><x3:resource-vehicle-is-electric xmlns:x3="http://nextcloud.com/ns"/><x3:resource-vehicle-range xmlns:x3="http://nextcloud.com/ns"/><x3:resource-vehicle-seating-capacity xmlns:x3="http://nextcloud.com/ns"/><x3:resource-contact-person xmlns:x3="http://nextcloud.com/ns"/><x3:resource-contact-person-vcard xmlns:x3="http://nextcloud.com/ns"/><x3:room-type xmlns:x3="http://nextcloud.com/ns"/><x3:room-seating-capacity xmlns:x3="http://nextcloud.com/ns"/><x3:room-building-address xmlns:x3="http://nextcloud.com/ns"/><x3:room-building-story xmlns:x3="http://nextcloud.com/ns"/><x3:room-building-room-number xmlns:x3="http://nextcloud.com/ns"/><x3:room-features xmlns:x3="http://nextcloud.com/ns"/><x0:principal-collection-set/><x0:supported-report-set/></x0:prop></x0:propfind> ' ,
142- 'auth ' => [
143- $ user ,
144- $ password ,
145- ],
146- ]
147- );
148- } catch (\GuzzleHttp \Exception \ClientException $ e ) {
149- $ this ->response = $ e ->getResponse ();
150- }
151- }
152-
153129 /**
154130 * @Then The CalDAV response should contain a property :key
155131 * @throws \Exception
156132 */
157- public function theCaldavResponseShouldContainAProperty (string $ key ): void {
133+ public function theCaldavResponseShouldContainAProperty (string $ key ) {
158134 /** @var \Sabre\DAV\Xml\Response\MultiStatus $multiStatus */
159135 $ multiStatus = $ this ->responseXml ['value ' ];
160136 $ responses = $ multiStatus ->getResponses ()[0 ]->getResponseProperties ();
@@ -179,42 +155,11 @@ public function theCaldavResponseShouldContainAProperty(string $key): void {
179155 }
180156 }
181157
182- /**
183- * @Then The CalDAV response should contain a property :key with a href value :value
184- * @throws \Exception
185- */
186- public function theCaldavResponseShouldContainAPropertyWithHrefValue (
187- string $ key ,
188- string $ value ,
189- ): void {
190- /** @var \Sabre\DAV\Xml\Response\MultiStatus $multiStatus */
191- $ multiStatus = $ this ->responseXml ['value ' ];
192- $ responses = $ multiStatus ->getResponses ()[0 ]->getResponseProperties ();
193- if (!isset ($ responses [200 ])) {
194- throw new \Exception (
195- sprintf (
196- 'Expected code 200 got [%s] ' ,
197- implode (', ' , array_keys ($ responses )),
198- )
199- );
200- }
201-
202- $ props = $ responses [200 ];
203- if (!array_key_exists ($ key , $ props )) {
204- throw new \Exception ("Cannot find property \"$ key \"" );
205- }
206-
207- $ actualValue = $ props [$ key ]->getHref ();
208- if ($ actualValue !== $ value ) {
209- throw new \Exception ("Property \"$ key \" found with value \"$ actualValue \", expected \"$ value \"" );
210- }
211- }
212-
213158 /**
214159 * @Then The CalDAV response should contain an href :href
215160 * @throws \Exception
216161 */
217- public function theCaldavResponseShouldContainAnHref (string $ href ): void {
162+ public function theCaldavResponseShouldContainAnHref (string $ href ) {
218163 /** @var \Sabre\DAV\Xml\Response\MultiStatus $multiStatus */
219164 $ multiStatus = $ this ->responseXml ['value ' ];
220165 foreach ($ multiStatus ->getResponses () as $ response ) {
@@ -234,7 +179,7 @@ public function theCaldavResponseShouldContainAnHref(string $href): void {
234179 * @Then The CalDAV response should be multi status
235180 * @throws \Exception
236181 */
237- public function theCaldavResponseShouldBeMultiStatus (): void {
182+ public function theCaldavResponseShouldBeMultiStatus () {
238183 if ($ this ->response ->getStatusCode () !== 207 ) {
239184 throw new \Exception (
240185 sprintf (
@@ -384,4 +329,42 @@ public function t($amount) {
384329 );
385330 }
386331 }
332+ /**
333+ * @Given :user updates property :key to href :value of principal :principal on the endpoint :endpoint
334+ */
335+ public function updatesHrefPropertyOfPrincipal (
336+ string $ user ,
337+ string $ key ,
338+ string $ value ,
339+ string $ principal ,
340+ string $ endpoint
341+ ) {
342+ $ davUrl = $ this ->baseUrl . $ endpoint . $ principal ;
343+ $ password = ($ user === 'admin ' ) ? 'admin ' : '123456 ' ;
344+
345+ $ propPatch = new \Sabre \DAV \Xml \Request \PropPatch ();
346+ $ propPatch ->properties = [$ key => new \Sabre \DAV \Xml \Property \Href ($ value )];
347+
348+ $ xml = new \Sabre \Xml \Service ();
349+ $ body = $ xml ->write ('{DAV:}propertyupdate ' , $ propPatch , '/ ' );
350+
351+ try {
352+ $ this ->response = $ this ->client ->request (
353+ 'PROPPATCH ' ,
354+ $ davUrl ,
355+ [
356+ 'headers ' => [
357+ 'Content-Type ' => 'application/xml; charset=UTF-8 ' ,
358+ ],
359+ 'body ' => $ body ,
360+ 'auth ' => [
361+ $ user ,
362+ $ password ,
363+ ],
364+ ]
365+ );
366+ } catch (\GuzzleHttp \Exception \ClientException $ e ) {
367+ $ this ->response = $ e ->getResponse ();
368+ }
369+ }
387370}
0 commit comments