Skip to main content

Redirects

DrevOps\BehatSteps\Steps\Drupal\RedirectTrait - Source, Example, Helpers

Manage Drupal redirect entities provided by the contrib redirect module.

  • Create 1 or more redirects from a table of source/destination/status.
  • Delete redirects by source path.
  • Assert that redirects do or do not exist for given source paths.
  • Created redirects are automatically removed at the end of the scenario.

Prerequisites​

PrerequisiteCapability
A backend in the scenario's list provides "RedirectCapabilityInterface"RedirectCapabilityInterface
The "redirect" module from the "drupal/redirect" package is enabledModuleCapabilityInterface

Steps​

@Given the following redirects exist:

Create 1 or more redirects

Given the following redirects exist:
| from | to | status_code |
| /old/about | /about | 301 |
| /promo | https://example.com/promo | 302 |
| /legacy/contact | /contact | |
@Given the following redirects do not exist:

Delete redirects by source path

Given the following redirects do not exist:
| /old/about |
| /legacy/contact |
@Then the following redirects should exist:

Assert that 1 or more redirects exist

Then the following redirects should exist:
| from | to | status_code |
| /old/about | /about | 301 |
| /promo | https://example.com/promo | |
| /legacy/contact | | |
@Then the following redirects should not exist:

Assert that no redirect exists for 1 or more source paths

Then the following redirects should not exist:
| /old/about |
| /legacy/contact |