Debian Codegraph @

t/06_web_query.t

raw symbols SCIP
1 use strict;
2 use warnings;
3 use Test::More;
4 use HTML::TreeBuilder::LibXML;
5
6 plan skip_all => "this test requires Web::Query" unless eval "use Web::Query; 1";
7 plan tests => 6;
8
9 can_ok 'HTML::TreeBuilder::LibXML', 'parse_content';
10 can_ok 'HTML::TreeBuilder::LibXML', 'elementify';
11
12 my $html = <<'...';
13 <html>
14 <body>
15 <div id="userbox">
16 <div id="user">
17 <a href="https://github.com/olegwtf"><img height="20" src="gravatar-140.png" width="20" /></a>
18 <a href="https://github.com/olegwtf" class="name">olegwtf</a>
19 </div>
20
21 <ul id="user-links">
22 <li>
23 <a href="/inbox/notifications" id="notifications" class="tooltipped downwards">
24 <span class="notifications"></span>
25 </a>
26 </li>
27 <li>
28 <a href="/settings/profile" id="settings" class="tooltipped downwards" title="Account Settings">
29 <span class="account-settings"></span>
30 </a>
31 </li>
32 <li>
33 <a href="/logout" data-method="post" id="logout" class="tooltipped downwards" title="Log Out">
34 <span class="logout">Log Out</span>
35 </a>
36 </li>
37 </ul>
38 </div>
39 </body>
40 </html>
41 ...
42
43 sub run {
44 my @classes;
45
46 my $text = wq($html)->find("ul#user-links li")->each(sub {
47 push @classes, $_->find("a span")->attr("class");
48 })->end->find(".logout")->text;
49
50 return (\@classes, $text);
51 }
52
53 isa_ok(HTML::TreeBuilder::XPath->new, 'HTML::TreeBuilder::XPath');
54 my ($their_classes, $their_text) = &run;
55
56 HTML::TreeBuilder::LibXML->replace_original();
57
58 isa_ok(HTML::TreeBuilder::XPath->new, 'HTML::TreeBuilder::LibXML');
59 my ($our_classes, $our_text) = &run;
60
61 is($our_text, $their_text);
62 is_deeply($our_classes, $their_classes);