#201 assertLink by href value

open
Marcus Baker
Web tester (52)
5
2010-11-03
2010-11-03
Anonymous
No

assertLink check only one (first) link, selected by label. If page have 2,3,4,... links with indentical text, but witdth different "href", we can`t check all this links.

my variant WebTestCase::assertLink() method:

public function assertLink($label, $expected = true, $message = '%s')
{
if( !$expected )
{
$url = $this->browser->getLink($label);
return $this->assertTrue($url !== false,
sprintf($message, "Link [$label] should exist"));
}

//??? separate method?
$urls = $this->browser->getLinks($label);
$expectation = new IdenticalExpectation($expected);

foreach( $urls as $url )
{
//copypaste form SimpleTestCase::assert()
$compare = $url->asString();
if( $expectation->test( $compare ) )
{
$msg = $expectation->overlayMessage( $compare,
$this->reporter->getDumper() );
return $this->pass(sprintf( $message, $msg ));
}
}
return $this->fail( sprintf($message, "Link [$label] should exist") );
}

Discussion


  • Anonymous
    2010-11-03

    - if( !$expected )
    + if( true === $expected )