From 4cbb1217ad3b842446b1ea131e1e149247298a89 Mon Sep 17 00:00:00 2001 From: Martin Ficzel Date: Wed, 30 Jan 2019 10:50:56 +0100 Subject: [PATCH 1/2] TASK: Create behat-test for creating 410 status of deleted documents --- .../Bootstrap/RedirectOperationTrait.php | 22 ++++++++++++++++++- Tests/Behavior/Features/Redirect.feature | 9 ++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/Tests/Behavior/Features/Bootstrap/RedirectOperationTrait.php b/Tests/Behavior/Features/Bootstrap/RedirectOperationTrait.php index 14f0b05..7541bb2 100755 --- a/Tests/Behavior/Features/Bootstrap/RedirectOperationTrait.php +++ b/Tests/Behavior/Features/Bootstrap/RedirectOperationTrait.php @@ -32,7 +32,8 @@ public function iHaveTheFollowingRedirects($table) foreach ($rows as $row) { $nodeRedirectStorage->addRedirect( $this->buildActualUriPath($row['sourceuripath']), - $this->buildActualUriPath($row['targeturipath']) + $this->buildActualUriPath($row['targeturipath']), + isset($row['statuscode']) ? (int)$row['statuscode'] : 307 ); } @@ -73,6 +74,25 @@ public function iShouldHaveARedirectWithSourceUriAndTargetUri($sourceUri, $targe } } + /** + * @Given /^I should have a redirect with sourceUri "([^"]*)" and statusCode "([^"]*)"$/ + */ + public function iShouldHaveARedirectWithSourceUriAndStatusCode($sourceUri, $statusCode) + { + $nodeRedirectStorage = $this->objectManager->get(RedirectStorage::class); + $sourceUri = $this->buildActualUriPath($sourceUri); + + $redirect = $nodeRedirectStorage->getOneBySourceUriPathAndHost($sourceUri); + + if ($redirect !== null) { + Assert::assertEquals((string)$statusCode, (string)$redirect->getStatusCode(), + 'A redirect was created, but the statusCode does not match' + ); + } else { + Assert::assertNotNull($redirect, 'No redirect was created for asserted sourceUri'); + } + } + /** * @Given /^I should have no redirect with sourceUri "([^"]*)" and targetUri "([^"]*)"$/ */ diff --git a/Tests/Behavior/Features/Redirect.feature b/Tests/Behavior/Features/Redirect.feature index d14265f..ecf65f4 100755 --- a/Tests/Behavior/Features/Redirect.feature +++ b/Tests/Behavior/Features/Redirect.feature @@ -127,3 +127,12 @@ Feature: Redirects are created automatically when the URI of an existing node is And I publish the node Then I should have a redirect with sourceUri "en/company.html" and targetUri "en/service/company.html" And I should have a redirect with sourceUri "de/company.html" and targetUri "de/service/company.html" + + @fixtures + Scenario: Deleted nodes create a redirect with 410 Status + When I get a node by path "/sites/behat/about" with the following context: + | Workspace | + | user-testaccount | + And I remove the node + And I publish the workspace "user-testaccount" + And I should have a redirect with sourceUri "en/about.html" and statusCode "410" From f48432ae5497a541f431a0cdae9aa20128a97500 Mon Sep 17 00:00:00 2001 From: Martin Ficzel Date: Fri, 1 Feb 2019 17:55:57 +0100 Subject: [PATCH 2/2] TASK: Reset redirects between tests --- .../Bootstrap/RedirectOperationTrait.php | 11 +++++++++++ Tests/Behavior/Features/Redirect.feature | 17 ++++++++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/Tests/Behavior/Features/Bootstrap/RedirectOperationTrait.php b/Tests/Behavior/Features/Bootstrap/RedirectOperationTrait.php index 7541bb2..fa62e43 100755 --- a/Tests/Behavior/Features/Bootstrap/RedirectOperationTrait.php +++ b/Tests/Behavior/Features/Bootstrap/RedirectOperationTrait.php @@ -19,6 +19,17 @@ trait RedirectOperationTrait { + /** + * @Given /^I have no redirects$/ + */ + public function iHaveNoRedirects() + { + $nodeRedirectStorage = $this->objectManager->get(RedirectStorage::class); + $redirectRepository = $this->objectManager->get(RedirectRepository::class); + $nodeRedirectStorage->removeAll(); + $redirectRepository->persistEntities(); + } + /** * @Given /^I have the following redirects:$/ * @When /^I create the following redirects:$/ diff --git a/Tests/Behavior/Features/Redirect.feature b/Tests/Behavior/Features/Redirect.feature index ecf65f4..65d9ea5 100755 --- a/Tests/Behavior/Features/Redirect.feature +++ b/Tests/Behavior/Features/Redirect.feature @@ -19,6 +19,7 @@ Feature: Redirects are created automatically when the URI of an existing node is | 4bba27c8-5029-4ae6-8371-0f2b3e1700a9 | /sites/behat/buy | Neos.Neos:Document | {"uriPathSegment": "kaufen"} | live | true | de | | 81dc6c8c-f478-434c-9ac9-bd5d1781cd95 | /sites/behat/mail | Neos.Neos:Document | {"uriPathSegment": "mail"} | live | | en | | 81dc6c8c-f478-434c-9ac9-bd5d1781cd95 | /sites/behat/mail | Neos.Neos:Document | {"uriPathSegment": "mail"} | live | true | de | + And I have no redirects @fixtures Scenario: Move a node into different node and a redirect will be created @@ -131,8 +132,18 @@ Feature: Redirects are created automatically when the URI of an existing node is @fixtures Scenario: Deleted nodes create a redirect with 410 Status When I get a node by path "/sites/behat/about" with the following context: - | Workspace | - | user-testaccount | + | Workspace | + | user-testaccount | And I remove the node And I publish the workspace "user-testaccount" - And I should have a redirect with sourceUri "en/about.html" and statusCode "410" + Then I should have a redirect with sourceUri "en/about.html" and statusCode "410" + + @fixtures + Scenario: Hidden nodes create no redirect + When I get a node by path "/sites/behat/about" with the following context: + | Workspace | + | user-testaccount | + And I hide the node + And I publish the workspace "user-testaccount" + Then I should have no redirect with sourceUri "en/about.html" +