Skip to content

Commit

Permalink
Merge pull request #357 from jrgensen/develop
Browse files Browse the repository at this point in the history
accepting hashtag navigation
  • Loading branch information
everzet committed Jun 27, 2013
2 parents eca086e + 38928ce commit 4a1c50c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
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());
}
}
}
}

0 comments on commit 4a1c50c

Please sign in to comment.