diff --git a/build/integration/features/bootstrap/CommentsContext.php b/build/integration/features/bootstrap/CommentsContext.php index ad2d752b4dd9d..dde5e863cdae5 100644 --- a/build/integration/features/bootstrap/CommentsContext.php +++ b/build/integration/features/bootstrap/CommentsContext.php @@ -175,7 +175,7 @@ public function asLoadloadAllTheCommentsOfTheFileNamedItShouldReturn($user, $fil if ($res->getStatusCode() === 207) { $service = new Sabre\Xml\Service(); $this->response = $service->parse($res->getBody()->getContents()); - $this->commentId = (int) ($this->response[0]['value'][2]['value'][0]['value'][0]['value'] ?? 0); + $this->commentId = (int) ($this->getValueFromNamedEntries('{DAV:}response.{DAV:}propstat.{DAV:}prop', $this->response ?? []) ?? 0); } } @@ -238,7 +238,7 @@ public function asDeleteTheCreatedCommentItShouldReturn($user, $statusCode) { * @throws \Exception */ public function theResponseShouldContainAPropertyWithValue($key, $value) { - $keys = $this->response[0]['value'][2]['value'][0]['value']; + $keys = $this->getValueFromNamedEntries('{DAV:}response.{DAV:}propstat.{DAV:}prop', $this->response); $found = false; foreach ($keys as $singleKey) { if ($singleKey['name'] === '{http://owncloud.org/ns}' . substr($key, 3)) { @@ -296,4 +296,34 @@ public function asEditTheLastCreatedCommentAndSetTextToItShouldReturn($user, $te throw new \Exception("Response status code was not $statusCode (" . $res->getStatusCode() . ")"); } } + + + /** + * get a named entry from response instead of picking a random entry from values + * + * @param string $path + * + * @return array|string + * @throws Exception + */ + private function getValueFromNamedEntries(string $path, array $response): mixed { + $next = ''; + if (str_contains($path, '.')) { + [$key, $next] = explode('.', $path, 2); + } else { + $key = $path; + } + + foreach ($response as $entry) { + if ($entry['name'] === $key) { + if ($next !== '') { + return $this->getValueFromNamedEntries($next, $entry['value']); + } else { + return $entry['value']; + } + } + } + + return null; + } }