@@ -123,39 +123,11 @@ public function requestsCalendar($user, $calendar, $endpoint) {
123123 }
124124 }
125125
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-
154126 /**
155127 * @Then The CalDAV response should contain a property :key
156128 * @throws \Exception
157129 */
158- public function theCaldavResponseShouldContainAProperty (string $ key ): void {
130+ public function theCaldavResponseShouldContainAProperty (string $ key ) {
159131 /** @var \Sabre\DAV\Xml\Response\MultiStatus $multiStatus */
160132 $ multiStatus = $ this ->responseXml ['value ' ];
161133 $ responses = $ multiStatus ->getResponses ()[0 ]->getResponseProperties ();
@@ -180,42 +152,11 @@ public function theCaldavResponseShouldContainAProperty(string $key): void {
180152 }
181153 }
182154
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-
214155 /**
215156 * @Then The CalDAV response should contain an href :href
216157 * @throws \Exception
217158 */
218- public function theCaldavResponseShouldContainAnHref (string $ href ): void {
159+ public function theCaldavResponseShouldContainAnHref (string $ href ) {
219160 /** @var \Sabre\DAV\Xml\Response\MultiStatus $multiStatus */
220161 $ multiStatus = $ this ->responseXml ['value ' ];
221162 foreach ($ multiStatus ->getResponses () as $ response ) {
@@ -235,7 +176,7 @@ public function theCaldavResponseShouldContainAnHref(string $href): void {
235176 * @Then The CalDAV response should be multi status
236177 * @throws \Exception
237178 */
238- public function theCaldavResponseShouldBeMultiStatus (): void {
179+ public function theCaldavResponseShouldBeMultiStatus () {
239180 if ($ this ->response ->getStatusCode () !== 207 ) {
240181 throw new \Exception (
241182 sprintf (
@@ -409,4 +350,43 @@ public function sendsCreateCalendarRequest(string $user, string $calendar, strin
409350 $ this ->response = $ e ->getResponse ();
410351 }
411352 }
353+
354+ /**
355+ * @Given :user updates property :key to href :value of principal :principal on the endpoint :endpoint
356+ */
357+ public function updatesHrefPropertyOfPrincipal (
358+ string $ user ,
359+ string $ key ,
360+ string $ value ,
361+ string $ principal ,
362+ string $ endpoint ,
363+ ) {
364+ $ davUrl = $ this ->baseUrl . $ endpoint . $ principal ;
365+ $ password = ($ user === 'admin ' ) ? 'admin ' : '123456 ' ;
366+
367+ $ propPatch = new \Sabre \DAV \Xml \Request \PropPatch ();
368+ $ propPatch ->properties = [$ key => new \Sabre \DAV \Xml \Property \Href ($ value )];
369+
370+ $ xml = new \Sabre \Xml \Service ();
371+ $ body = $ xml ->write ('{DAV:}propertyupdate ' , $ propPatch , '/ ' );
372+
373+ try {
374+ $ this ->response = $ this ->client ->request (
375+ 'PROPPATCH ' ,
376+ $ davUrl ,
377+ [
378+ 'headers ' => [
379+ 'Content-Type ' => 'application/xml; charset=UTF-8 ' ,
380+ ],
381+ 'body ' => $ body ,
382+ 'auth ' => [
383+ $ user ,
384+ $ password ,
385+ ],
386+ ]
387+ );
388+ } catch (\GuzzleHttp \Exception \ClientException $ e ) {
389+ $ this ->response = $ e ->getResponse ();
390+ }
391+ }
412392}
0 commit comments