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

WIP: BUGFIX: Create a 410-Gone redirect for deleted nodes #32

Closed
Closed
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
33 changes: 32 additions & 1 deletion Tests/Behavior/Features/Bootstrap/RedirectOperationTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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:$/
Expand All @@ -32,7 +43,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
);
}

Expand Down Expand Up @@ -73,6 +85,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 "([^"]*)"$/
*/
Expand Down
20 changes: 20 additions & 0 deletions Tests/Behavior/Features/Redirect.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -127,3 +128,22 @@ 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"
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"