我正在使用带有FOSUserBundle和Behat的Symfony 3.4进行测试。
配置和代码:
Behat config:
extensions:
BehatMinkExtension:
sessions:
default:
symfony2: ~
javascript:
selenium2: ~
browser_name: firefox
show_auto: false
base_url: 'http://my-virutalhost.test'
BehatSymfony2Extension:
kernel:
env: "acceptance"
debug: "true"
Scenario: I execute enpoint address with wrong redirect code
When I go to the url "/redirect/code1code2"
Then I should be redirected to url "http://some-page-here.com"
/**
* @When /^I go to the url "([^"]+)"$/
*/
public function iGoToTheUrl($url) {
$this->lastResponse = $this->getSession()->visit($url);
$this->getSession()->getDriver()->getContent();
//var_dump($url, $this->getSession()->getDriver()->getCurrentUrl());
}
/**
* Checks, that current page PATH matches regular expression.
*
* @Then /^(?:|I )should be redirected to (?P<pattern>"(?:[^"]|\")*")$/
*/
public function iAmRedirectedToUrl($pattern) {
$this->assertSession()->addressMatches($this->fixStepArgument($pattern));
}
问题:
不知何故,Behat 从我的应用程序附加到我的重定向 url http://some-page-here.com/login,从而创建链接:http://some-page-here.com/login。我不知道为什么它会为重定向创建这样的地址。-- 编辑 --
当我检查页面的内容$this->getSession((->getDriver((->getContent((时,我看到登录页面的代码
--编辑--
- /login - 这是我的应用程序登录
- 我想重定向到外部页面,而不是在我的应用程序内部的页面中,并检查最终地址是否是来自外部重定向的页面地址
我的安全配置:
access_control:
- { path: ^/redirect, role: IS_AUTHENTICATED_ANONYMOUSLY }
仔细研究Firefox,因为我不认为Behat是这里的罪魁祸首。
据我所知,正在发生的事情是:
- Behat告诉Firefox导航到"http://my-virutalhost.test/redirect/code1code2">
- 此 URL 通过重定向到"http://some-page-here.com/"进行响应
- Firefox 支持 HTTP 重定向,但由于某种原因将/login 附加到 URL。
我会研究Firefox得到的响应,以确保返回正确的重定向URL。
你的重定向可以吗?如果您的内容页面显示/login,则必须When I go to the url "/redirect/code1code2"
发送到此页面。
当您使用 MinkExtension 时,您是否尝试过使用默认的步骤 When I go to '/redirect/code1code2'
?
或者,如果您直接访问该页面When I go to the url 'http://some-page-here.com'
,您是否可以访问该页面?
对于 http://some-page-here.com/login 的东西,这很奇怪...如果您的页面能够向您显示/login 内容,那么它必须说它有权访问 http://my-virutalhost.test/login