Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic filter test for layout resource #150

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions features/bootstrap/DoctrineContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
65 changes: 64 additions & 1 deletion features/main/layout.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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"