Skip to content

Commit

Permalink
fixing test
Browse files Browse the repository at this point in the history
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
  • Loading branch information
ArtificialOwl committed Nov 23, 2023
1 parent a93af13 commit fbe92d4
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions build/integration/features/bootstrap/CommentsContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,37 @@ public function __construct($baseUrl) {
}
}



/**
* 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;
}

/** @AfterScenario */
public function teardownScenario() {
$client = new \GuzzleHttp\Client();
Expand Down Expand Up @@ -175,7 +206,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 {http://owncloud.org/ns}id', $this->response ?? []) ?? 0);
}
}

Expand Down Expand Up @@ -238,7 +269,8 @@ public function asDeleteTheCreatedCommentItShouldReturn($user, $statusCode) {
* @throws \Exception
*/
public function theResponseShouldContainAPropertyWithValue($key, $value) {
$keys = $this->response[0]['value'][2]['value'][0]['value'];
// $keys = $this->response[0]['value'][1]['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)) {
Expand Down

0 comments on commit fbe92d4

Please sign in to comment.