Skip to content

Commit 7db786e

Browse files
authored
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
1 parent 602ec77 commit 7db786e

File tree

2 files changed

+71
-4
lines changed

2 files changed

+71
-4
lines changed

features/bootstrap/DoctrineContext.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -493,13 +493,17 @@ public function thereIsARouteWithRedirects(string $firstPath, string $redirectTo
493493
}
494494

495495
/**
496-
* @Given /^there is a Layout(?: with the reference "([^"]*)"|)$/
496+
* @Given /^there is a Layout(?: with the reference "([^"]+)")*[ and]*(?: with createdAt "([^"]+)")*(?: with the uiComponent "([^"]+)")*$/
497497
*/
498-
public function thereIsALayout(string $reference = 'no-reference'): void
498+
public function thereIsALayout(string $reference = 'no-reference', ?string $createdAt = null, ?string $uiComponent = null): void
499499
{
500500
$layout = new Layout();
501501
$layout->reference = $reference;
502-
$this->timestampedHelper->persistTimestampedFields($layout, true);
502+
$layout->uiComponent = $uiComponent;
503+
if (null !== $createdAt) {
504+
$layout->setCreatedAt(new \DateTimeImmutable($createdAt));
505+
}
506+
$this->timestampedHelper->persistTimestampedFields($layout, $createdAt === null);
503507
$this->manager->persist($layout);
504508
$this->manager->flush();
505509
$this->restContext->resources['layout'] = $this->iriConverter->getIriFromResource($layout);

features/main/layout.feature

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,67 @@ Feature: Layout resources
4545
When I send a "DELETE" request to the resource "layout"
4646
Then the response status code should be 204
4747

48-
# Todo: Order by and search filter tests needed to ensure it is implemented
48+
@loginUser
49+
Scenario: The layout resources can be filtered by reference
50+
Given there is a Layout with the reference "primary"
51+
And there is a Layout with the reference "secondary"
52+
When I send a "GET" request to "/_/layouts"
53+
Then the response status code should be 200
54+
And the JSON node "hydra:member" should have "2" elements
55+
56+
@loginUser
57+
Scenario: The layout resources can be filtered by reference
58+
Given there is a Layout with the reference "primary"
59+
And there is a Layout with the reference "secondary"
60+
When I send a "GET" request to "/_/layouts?reference=primary"
61+
Then the response status code should be 200
62+
And the JSON node "hydra:member" should have "1" element
63+
64+
@loginUser
65+
Scenario: The layout resources can be ordered ascending by reference
66+
Given there is a Layout with the reference "1"
67+
And there is a Layout with the reference "2"
68+
When I send a "GET" request to "/_/layouts?order[reference]=asc"
69+
Then the response status code should be 200
70+
And the JSON node "hydra:member" should have "2" elements
71+
And the JSON node "hydra:member[0].reference" should be equal to "1"
72+
And the JSON node "hydra:member[1].reference" should be equal to "2"
73+
74+
@loginUser
75+
Scenario: The layout resources can be ordered descending by reference
76+
Given there is a Layout with the reference "1"
77+
And there is a Layout with the reference "2"
78+
When I send a "GET" request to "/_/layouts?order[reference]=desc"
79+
Then the response status code should be 200
80+
And the JSON node "hydra:member" should have "2" elements
81+
And the JSON node "hydra:member[0].reference" should be equal to "2"
82+
And the JSON node "hydra:member[1].reference" should be equal to "1"
83+
84+
@loginUser
85+
Scenario: The layout resources can be ordered ascending by createdAt
86+
Given there is a Layout with the reference "layout_1" and with createdAt "now"
87+
And there is a Layout with the reference "layout_2" and with createdAt "+10 seconds"
88+
When I send a "GET" request to "/_/layouts?order[createdAt]=asc"
89+
Then the response status code should be 200
90+
And the JSON node "hydra:member" should have "2" elements
91+
And the JSON node "hydra:member[0].reference" should be equal to "layout_1"
92+
And the JSON node "hydra:member[1].reference" should be equal to "layout_2"
93+
94+
@loginUser
95+
Scenario: The layout resources can be ordered descending by createdAt
96+
Given there is a Layout with the reference "layout_1" and with createdAt "now"
97+
And there is a Layout with the reference "layout_2" and with createdAt "+10 seconds"
98+
When I send a "GET" request to "/_/layouts?order[createdAt]=desc"
99+
Then the response status code should be 200
100+
And the JSON node "hydra:member" should have "2" elements
101+
And the JSON node "hydra:member[0].reference" should be equal to "layout_2"
102+
And the JSON node "hydra:member[1].reference" should be equal to "layout_1"
103+
104+
@loginUser
105+
Scenario: The layout resources can be filtered by ui components
106+
Given there is a Layout with the reference "primary" and with the uiComponent "PrimaryLayout"
107+
And there is a Layout with the reference "secondary" and with the uiComponent "SecondaryLayout"
108+
When I send a "GET" request to "/_/layouts?uiComponent=PrimaryLayout"
109+
Then the response status code should be 200
110+
And the JSON node "hydra:member" should have "1" elements
111+
And the JSON node "hydra:member[0].reference" should be equal to "primary"

0 commit comments

Comments
 (0)