trying to make the documentation a little more straightforward to setup
[catagits/HTML-Zoom.git] / t / synopsis / filterbuilder.t
1 use strict;
2 use warnings FATAL => 'all';
3 use Test::More qw(no_plan);
4
5
6
7 use HTML::Zoom;
8 my $root = HTML::Zoom
9     ->from_html(<<MAIN);
10 <html>
11   <head>
12     <title>Default Title</title>
13   </head>
14   <body bad_attr='junk'>
15     Default Content
16   </body>
17 </html>
18 MAIN
19
20
21
22 $root = $root
23   ->select('body')
24   ->set_attribute(class=>'main');
25
26
27
28 $root = $root
29   ->select('body')
30   ->add_to_attribute(class=>'one-column');
31
32
33
34 $root = $root
35   ->select('title')
36   ->replace_content('Hello World');
37
38
39
40 my $body = HTML::Zoom
41     ->from_html(<<BODY);
42 <div id="stuff">
43     <p>Well Now</p>
44     <p id="p2">Is the Time</p>
45 </div>
46 BODY
47
48 $root = $root
49   ->select('body')
50   ->replace_content($body);
51
52
53
54 $root = $root
55   ->select('p')
56   ->set_attribute(class=>'para');
57
58
59
60 $root = $root
61   ->select('body')
62   ->remove_attribute('bad_attr');
63
64
65 my $output = $root->to_html;
66 my $expect = <<HTML;
67 <html>
68   <head>
69     <title>Hello World</title>
70   </head>
71   <body class="main one-column"><div id="stuff">
72     <p class="para">Well Now</p>
73     <p id="p2" class="para">Is the Time</p>
74 </div>
75 </body>
76 </html>
77 HTML
78 is($output, $expect, 'Synopsis code works ok');
79