@@ -61,17 +61,21 @@ public function setUpScenario() {
6161
6262 /** @AfterScenario */
6363 public function afterScenario () {
64- foreach (['MyCalendar ' , 'MyCalendar2 ' ] as $ calendarName ) {
65- try {
66- $ this ->client ->delete (
67- $ this ->baseUrl . '/remote.php/dav/calendars/admin/ ' . $ calendarName ,
68- [
69- 'auth ' => ['admin ' , 'admin ' ],
70- 'headers ' => ['X-NC-CalDAV-No-Trashbin ' => '1 ' ],
64+ $ davUrl = $ this ->baseUrl . '/remote.php/dav/calendars/admin/MyCalendar ' ;
65+ try {
66+ $ this ->client ->delete (
67+ $ davUrl ,
68+ [
69+ 'auth ' => [
70+ 'admin ' ,
71+ 'admin ' ,
72+ ],
73+ 'headers ' => [
74+ 'X-NC-CalDAV-No-Trashbin ' => '1 ' ,
7175 ]
72- );
73- } catch ( \ GuzzleHttp \ Exception \ ClientException $ e ) {
74- }
76+ ]
77+ );
78+ } catch ( \ GuzzleHttp \ Exception \ ClientException $ e ) {
7579 }
7680 }
7781
@@ -123,39 +127,11 @@ public function requestsCalendar($user, $calendar, $endpoint) {
123127 }
124128 }
125129
126- /**
127- * @When :user requests principal :principal on the endpoint :endpoint
128- */
129- public function requestsPrincipal (string $ user , string $ principal , string $ endpoint ): void {
130- $ davUrl = $ this ->baseUrl . $ endpoint . $ principal ;
131-
132- $ password = ($ user === 'admin ' ) ? 'admin ' : '123456 ' ;
133- try {
134- $ this ->response = $ this ->client ->request (
135- 'PROPFIND ' ,
136- $ davUrl ,
137- [
138- 'headers ' => [
139- 'Content-Type ' => 'application/xml; charset=UTF-8 ' ,
140- 'Depth ' => 0 ,
141- ],
142- '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> ' ,
143- 'auth ' => [
144- $ user ,
145- $ password ,
146- ],
147- ]
148- );
149- } catch (\GuzzleHttp \Exception \ClientException $ e ) {
150- $ this ->response = $ e ->getResponse ();
151- }
152- }
153-
154130 /**
155131 * @Then The CalDAV response should contain a property :key
156132 * @throws \Exception
157133 */
158- public function theCaldavResponseShouldContainAProperty (string $ key ): void {
134+ public function theCaldavResponseShouldContainAProperty (string $ key ) {
159135 /** @var \Sabre\DAV\Xml\Response\MultiStatus $multiStatus */
160136 $ multiStatus = $ this ->responseXml ['value ' ];
161137 $ responses = $ multiStatus ->getResponses ()[0 ]->getResponseProperties ();
@@ -180,42 +156,11 @@ public function theCaldavResponseShouldContainAProperty(string $key): void {
180156 }
181157 }
182158
183- /**
184- * @Then The CalDAV response should contain a property :key with a href value :value
185- * @throws \Exception
186- */
187- public function theCaldavResponseShouldContainAPropertyWithHrefValue (
188- string $ key ,
189- string $ value ,
190- ): void {
191- /** @var \Sabre\DAV\Xml\Response\MultiStatus $multiStatus */
192- $ multiStatus = $ this ->responseXml ['value ' ];
193- $ responses = $ multiStatus ->getResponses ()[0 ]->getResponseProperties ();
194- if (!isset ($ responses [200 ])) {
195- throw new \Exception (
196- sprintf (
197- 'Expected code 200 got [%s] ' ,
198- implode (', ' , array_keys ($ responses )),
199- )
200- );
201- }
202-
203- $ props = $ responses [200 ];
204- if (!array_key_exists ($ key , $ props )) {
205- throw new \Exception ("Cannot find property \"$ key \"" );
206- }
207-
208- $ actualValue = $ props [$ key ]->getHref ();
209- if ($ actualValue !== $ value ) {
210- throw new \Exception ("Property \"$ key \" found with value \"$ actualValue \", expected \"$ value \"" );
211- }
212- }
213-
214159 /**
215160 * @Then The CalDAV response should contain an href :href
216161 * @throws \Exception
217162 */
218- public function theCaldavResponseShouldContainAnHref (string $ href ): void {
163+ public function theCaldavResponseShouldContainAnHref (string $ href ) {
219164 /** @var \Sabre\DAV\Xml\Response\MultiStatus $multiStatus */
220165 $ multiStatus = $ this ->responseXml ['value ' ];
221166 foreach ($ multiStatus ->getResponses () as $ response ) {
@@ -235,7 +180,7 @@ public function theCaldavResponseShouldContainAnHref(string $href): void {
235180 * @Then The CalDAV response should be multi status
236181 * @throws \Exception
237182 */
238- public function theCaldavResponseShouldBeMultiStatus (): void {
183+ public function theCaldavResponseShouldBeMultiStatus () {
239184 if ($ this ->response ->getStatusCode () !== 207 ) {
240185 throw new \Exception (
241186 sprintf (
@@ -385,4 +330,42 @@ public function t($amount) {
385330 );
386331 }
387332 }
333+ /**
334+ * @Given :user updates property :key to href :value of principal :principal on the endpoint :endpoint
335+ */
336+ public function updatesHrefPropertyOfPrincipal (
337+ string $ user ,
338+ string $ key ,
339+ string $ value ,
340+ string $ principal ,
341+ string $ endpoint
342+ ) {
343+ $ davUrl = $ this ->baseUrl . $ endpoint . $ principal ;
344+ $ password = ($ user === 'admin ' ) ? 'admin ' : '123456 ' ;
345+
346+ $ propPatch = new \Sabre \DAV \Xml \Request \PropPatch ();
347+ $ propPatch ->properties = [$ key => new \Sabre \DAV \Xml \Property \Href ($ value )];
348+
349+ $ xml = new \Sabre \Xml \Service ();
350+ $ body = $ xml ->write ('{DAV:}propertyupdate ' , $ propPatch , '/ ' );
351+
352+ try {
353+ $ this ->response = $ this ->client ->request (
354+ 'PROPPATCH ' ,
355+ $ davUrl ,
356+ [
357+ 'headers ' => [
358+ 'Content-Type ' => 'application/xml; charset=UTF-8 ' ,
359+ ],
360+ 'body ' => $ body ,
361+ 'auth ' => [
362+ $ user ,
363+ $ password ,
364+ ],
365+ ]
366+ );
367+ } catch (\GuzzleHttp \Exception \ClientException $ e ) {
368+ $ this ->response = $ e ->getResponse ();
369+ }
370+ }
388371}
0 commit comments