diff --git a/src/DrupalExtension/Context/RedirectContext.php b/src/DrupalExtension/Context/RedirectContext.php new file mode 100644 index 0000000..e3e4689 --- /dev/null +++ b/src/DrupalExtension/Context/RedirectContext.php @@ -0,0 +1,70 @@ +getSession()->getDriver(); + $this->followRedirect = $driver->getClient()->isFollowingRedirects(); + $driver->getClient()->followRedirects(FALSE); + } + + /** + * Reset follow redirect to its original value. + * + * @AfterScenario + */ + public function resetFollowRedirect() { + if ($this->followRedirect !== NULL) { + /* @var \Behat\Mink\Driver\GoutteDriver $driver */ + $driver = $this->getSession()->getDriver(); + $driver->getClient()->followRedirects($this->followRedirect); + } + + $this->followRedirect = NULL; + } + + /** + * Checks if I am redirected to $actualPath. + * + * @param string $actualPath + * Path to be redirected to. + * + * @Then /^I (?:am|should be) redirected to "([^"]*)"$/ + */ + public function thenIamRedirectedTo($actualPath) { + $headers = $this->getSession()->getResponseHeaders(); + assert($headers['Location'], hasKey(0)); + + $redirectComponents = parse_url($headers['Location'][0]); + assert($redirectComponents['path'], equals($actualPath)); + } + +}