From 7db786e060b5b72da8b5d4dc7d11f1221f3d5372 Mon Sep 17 00:00:00 2001 From: bofalke <54977705+bofalke@users.noreply.github.com> Date: Wed, 26 Oct 2022 16:03:03 +0200 Subject: [PATCH] Add basic filter test for layout resource (#150) * Add basic filter test for layout resource * Split basic filter test for layout * Add order by reference tests * Add tests to order layout by createdAt * Add test to filter layout by uiComponent --- features/bootstrap/DoctrineContext.php | 10 ++-- features/main/layout.feature | 65 +++++++++++++++++++++++++- 2 files changed, 71 insertions(+), 4 deletions(-) diff --git a/features/bootstrap/DoctrineContext.php b/features/bootstrap/DoctrineContext.php index bed5806f..1a5e145d 100644 --- a/features/bootstrap/DoctrineContext.php +++ b/features/bootstrap/DoctrineContext.php @@ -493,13 +493,17 @@ public function thereIsARouteWithRedirects(string $firstPath, string $redirectTo } /** - * @Given /^there is a Layout(?: with the reference "([^"]*)"|)$/ + * @Given /^there is a Layout(?: with the reference "([^"]+)")*[ and]*(?: with createdAt "([^"]+)")*(?: with the uiComponent "([^"]+)")*$/ */ - public function thereIsALayout(string $reference = 'no-reference'): void + public function thereIsALayout(string $reference = 'no-reference', ?string $createdAt = null, ?string $uiComponent = null): void { $layout = new Layout(); $layout->reference = $reference; - $this->timestampedHelper->persistTimestampedFields($layout, true); + $layout->uiComponent = $uiComponent; + if (null !== $createdAt) { + $layout->setCreatedAt(new \DateTimeImmutable($createdAt)); + } + $this->timestampedHelper->persistTimestampedFields($layout, $createdAt === null); $this->manager->persist($layout); $this->manager->flush(); $this->restContext->resources['layout'] = $this->iriConverter->getIriFromResource($layout); diff --git a/features/main/layout.feature b/features/main/layout.feature index 783b0a5d..e210099b 100644 --- a/features/main/layout.feature +++ b/features/main/layout.feature @@ -45,4 +45,67 @@ Feature: Layout resources When I send a "DELETE" request to the resource "layout" Then the response status code should be 204 - # Todo: Order by and search filter tests needed to ensure it is implemented + @loginUser + Scenario: The layout resources can be filtered by reference + Given there is a Layout with the reference "primary" + And there is a Layout with the reference "secondary" + When I send a "GET" request to "/_/layouts" + Then the response status code should be 200 + And the JSON node "hydra:member" should have "2" elements + + @loginUser + Scenario: The layout resources can be filtered by reference + Given there is a Layout with the reference "primary" + And there is a Layout with the reference "secondary" + When I send a "GET" request to "/_/layouts?reference=primary" + Then the response status code should be 200 + And the JSON node "hydra:member" should have "1" element + + @loginUser + Scenario: The layout resources can be ordered ascending by reference + Given there is a Layout with the reference "1" + And there is a Layout with the reference "2" + When I send a "GET" request to "/_/layouts?order[reference]=asc" + Then the response status code should be 200 + And the JSON node "hydra:member" should have "2" elements + And the JSON node "hydra:member[0].reference" should be equal to "1" + And the JSON node "hydra:member[1].reference" should be equal to "2" + + @loginUser + Scenario: The layout resources can be ordered descending by reference + Given there is a Layout with the reference "1" + And there is a Layout with the reference "2" + When I send a "GET" request to "/_/layouts?order[reference]=desc" + Then the response status code should be 200 + And the JSON node "hydra:member" should have "2" elements + And the JSON node "hydra:member[0].reference" should be equal to "2" + And the JSON node "hydra:member[1].reference" should be equal to "1" + + @loginUser + Scenario: The layout resources can be ordered ascending by createdAt + Given there is a Layout with the reference "layout_1" and with createdAt "now" + And there is a Layout with the reference "layout_2" and with createdAt "+10 seconds" + When I send a "GET" request to "/_/layouts?order[createdAt]=asc" + Then the response status code should be 200 + And the JSON node "hydra:member" should have "2" elements + And the JSON node "hydra:member[0].reference" should be equal to "layout_1" + And the JSON node "hydra:member[1].reference" should be equal to "layout_2" + + @loginUser + Scenario: The layout resources can be ordered descending by createdAt + Given there is a Layout with the reference "layout_1" and with createdAt "now" + And there is a Layout with the reference "layout_2" and with createdAt "+10 seconds" + When I send a "GET" request to "/_/layouts?order[createdAt]=desc" + Then the response status code should be 200 + And the JSON node "hydra:member" should have "2" elements + And the JSON node "hydra:member[0].reference" should be equal to "layout_2" + And the JSON node "hydra:member[1].reference" should be equal to "layout_1" + + @loginUser + Scenario: The layout resources can be filtered by ui components + Given there is a Layout with the reference "primary" and with the uiComponent "PrimaryLayout" + And there is a Layout with the reference "secondary" and with the uiComponent "SecondaryLayout" + When I send a "GET" request to "/_/layouts?uiComponent=PrimaryLayout" + Then the response status code should be 200 + And the JSON node "hydra:member" should have "1" elements + And the JSON node "hydra:member[0].reference" should be equal to "primary"