From e708854d2ef4db7e1f58337f44cc433f9b5a8bf8 Mon Sep 17 00:00:00 2001 From: otarza Date: Sat, 28 Jan 2017 21:47:28 +0400 Subject: [PATCH] RedirectContext added to test redirections Steps added: I do not follow redirects I (?:am|should be) redirected to --- .../Context/RedirectContext.php | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 src/DrupalExtension/Context/RedirectContext.php 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)); + } + +}