Skip to content

Commit

Permalink
Check link text in search result tests
Browse files Browse the repository at this point in the history
rather than the href which recently changed
  • Loading branch information
rwstauner committed May 8, 2013
1 parent 2145c37 commit 6d77029
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
12 changes: 11 additions & 1 deletion lib/MetaCPAN/Web/Test.pm
Expand Up @@ -51,7 +51,17 @@ sub tx {
my $tree = HTML::TreeBuilder->new_from_content( shift->content );
my $xml = $tree->as_XML;
$xml = decode_utf8($xml);
return Test::XPath->new( xml => $xml );
my $tx = Test::XPath->new( xml => $xml );
# https://metacpan.org/module/DWHEELER/Test-XPath-0.16/lib/Test/XPath.pm#xpc
$tx->xpc->registerFunction( grep => sub {
my ($nodelist, $regex) = @_;
my $result = XML::LibXML::NodeList->new;
for my $node ($nodelist->get_nodelist) {
$result->push($node) if $node->textContent =~ $regex;
}
return $result;
} );
return $tx;
}

1;
Expand Down
6 changes: 3 additions & 3 deletions t/controller/search.t
Expand Up @@ -76,9 +76,9 @@ sub search_and_find_module {
$query = encode("UTF-8" => $query) if is_utf8($query);
my $res = req_200_ok( $cb, GET("/search?q=$query"), $desc);
my $tx = tx($res);
$tx->is(
qq!//div[\@class="search-results"]//div[\@class="module-result"]//a[\@href="/module/$exp_mod"]!,
$exp_mod,
# make sure there is a link tag whose content is the module name
$tx->ok(
qq!grep(//div[\@class="search-results"]//div[\@class="module-result"]//a[1], "^\Q$exp_mod\E\$")!,
"$desc: found expected module",
);
}

0 comments on commit 6d77029

Please sign in to comment.