Skip to content

Commit

Permalink
fix: order url parameters of pagination
Browse files Browse the repository at this point in the history
Signed-off-by: Vitor Mattos <vitor@php.rio>
  • Loading branch information
vitormattos committed Nov 5, 2024
1 parent 430b947 commit 940f018
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
14 changes: 14 additions & 0 deletions lib/Helper/Pagination.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,20 @@ private function linkToRoute(bool $condition, int|string $page, int $length, arr
$this->routeName,
array_merge(['page' => $page, 'length' => $length, 'apiVersion' => 'v1'], $filter)
);
$url = $this->sortParameters($url);
return $url;
}

/**
* This is necessary to fix problem at integration tests because the method linkToRoute change the order of parameters
*/
private function sortParameters(?string $url): ?string {
if (!$url) {
return $url;
}
parse_str(parse_url($url, PHP_URL_QUERY), $query);
ksort($query);
$url = strtok($url, '?') . '?' . http_build_query($query);
return $url;
}
}
14 changes: 7 additions & 7 deletions tests/integration/features/file/list.feature
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ Feature: file-list
| key | value |
| (jq).ocs.data.data[0].name | document |
| (jq).ocs.data.pagination.total | 5 |
| (jq).ocs.data.pagination.current | <BASE_URL>/ocsapp/apps/libresign/api/v1/file/list?page=1&length=2 |
| (jq).ocs.data.pagination.next | <BASE_URL>/ocsapp/apps/libresign/api/v1/file/list?page=2&length=2 |
| (jq).ocs.data.pagination.current | <BASE_URL>/ocsapp/apps/libresign/api/v1/file/list?length=2&page=1 |
| (jq).ocs.data.pagination.next | <BASE_URL>/ocsapp/apps/libresign/api/v1/file/list?length=2&page=2 |
| (jq).ocs.data.pagination.prev | null |
| (jq).ocs.data.pagination.last | <BASE_URL>/ocsapp/apps/libresign/api/v1/file/list?length=2&page=3 |
| (jq).ocs.data.pagination.first | null |
Expand All @@ -86,11 +86,11 @@ Feature: file-list
| key | value |
| (jq).ocs.data.data[0].name | document |
| (jq).ocs.data.pagination.total | 5 |
| (jq).ocs.data.pagination.current | <BASE_URL>/ocsapp/apps/libresign/api/v1/file/list?page=2&length=2 |
| (jq).ocs.data.pagination.current | <BASE_URL>/ocsapp/apps/libresign/api/v1/file/list?length=2&page=2 |
| (jq).ocs.data.pagination.next | <BASE_URL>/ocsapp/apps/libresign/api/v1/file/list?length=2&page=3 |
| (jq).ocs.data.pagination.prev | <BASE_URL>/ocsapp/apps/libresign/api/v1/file/list?page=1&length=2 |
| (jq).ocs.data.pagination.prev | <BASE_URL>/ocsapp/apps/libresign/api/v1/file/list?length=2&page=1 |
| (jq).ocs.data.pagination.last | <BASE_URL>/ocsapp/apps/libresign/api/v1/file/list?length=2&page=3 |
| (jq).ocs.data.pagination.first | <BASE_URL>/ocsapp/apps/libresign/api/v1/file/list?page=1&length=2 |
| (jq).ocs.data.pagination.first | <BASE_URL>/ocsapp/apps/libresign/api/v1/file/list?length=2&page=1 |
# last page
When sending "get" to ocs "/apps/libresign/api/v1/file/list?page=3&length=2"
Then the response should be a JSON array with the following mandatory values
Expand All @@ -99,6 +99,6 @@ Feature: file-list
| (jq).ocs.data.pagination.total | 5 |
| (jq).ocs.data.pagination.current | <BASE_URL>/ocsapp/apps/libresign/api/v1/file/list?length=2&page=3 |
| (jq).ocs.data.pagination.next | null |
| (jq).ocs.data.pagination.prev | <BASE_URL>/ocsapp/apps/libresign/api/v1/file/list?page=2&length=2 |
| (jq).ocs.data.pagination.prev | <BASE_URL>/ocsapp/apps/libresign/api/v1/file/list?length=2&page=2 |
| (jq).ocs.data.pagination.last | null |
| (jq).ocs.data.pagination.first | <BASE_URL>/ocsapp/apps/libresign/api/v1/file/list?page=1&length=2 |
| (jq).ocs.data.pagination.first | <BASE_URL>/ocsapp/apps/libresign/api/v1/file/list?length=2&page=1 |

0 comments on commit 940f018

Please sign in to comment.