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

accepting hashtag navigation #357

Merged
merged 1 commit into from
Jun 27, 2013
Merged
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
14 changes: 7 additions & 7 deletions src/Behat/Mink/WebAssert.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function __construct(Session $session)
*/
public function addressEquals($page)
{
$expected = $this->cleanScriptnameFromPath(parse_url($page, PHP_URL_PATH));
$expected = $this->cleanUrl($page);
$actual = $this->getCurrentUrlPath();

if ($actual !== $expected) {
Expand All @@ -64,7 +64,7 @@ public function addressEquals($page)
*/
public function addressNotEquals($page)
{
$expected = $this->cleanScriptnameFromPath(parse_url($page, PHP_URL_PATH));
$expected = $this->cleanUrl($page);
$actual = $this->getCurrentUrlPath();

if ($actual === $expected) {
Expand Down Expand Up @@ -574,9 +574,7 @@ public function checkboxNotChecked($field, Element $container = null)
*/
protected function getCurrentUrlPath()
{
return $this->cleanScriptnameFromPath(
parse_url($this->session->getCurrentUrl(), PHP_URL_PATH)
);
return $this->cleanUrl($this->session->getCurrentUrl());
}

/**
Expand All @@ -586,8 +584,10 @@ protected function getCurrentUrlPath()
*
* @return string
*/
protected function cleanScriptnameFromPath($path)
protected function cleanUrl($url)
{
return preg_replace('/^\/[^\.\/]+\.php/', '', $path);
$parts = parse_url($url);
$fragment = empty($parts['fragment']) ? '' : '#' . $parts['fragment'];
return preg_replace('/^\/[^\.\/]+\.php/', '', $parts['path']) . $fragment;
}
}
8 changes: 4 additions & 4 deletions tests/Behat/Mink/WebAssertTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ public function testAddressEquals()
$this->session
->expects($this->exactly(2))
->method('getCurrentUrl')
->will($this->returnValue('http://example.com/script.php/sub/url'))
->will($this->returnValue('http://example.com/script.php/sub/url?param=true#webapp/nav'))
;

$this->assertCorrectAssertion('addressEquals', array('/sub/url'));
$this->assertCorrectAssertion('addressEquals', array('/sub/url#webapp/nav'));
$this->assertWrongAssertion(
'addressEquals', array('sub_url'),
'Behat\\Mink\\Exception\\ExpectationException',
'Current page is "/sub/url", but "sub_url" expected.'
'Current page is "/sub/url#webapp/nav", but "sub_url" expected.'
);
}

Expand Down Expand Up @@ -848,4 +848,4 @@ protected function assertWrongAssertion($assertion, $arguments, $exceptionClass,
$this->assertSame($exceptionMessage, $e->getMessage());
}
}
}
}