67083c65163b0558f61a7179e7cf3c7bd1c4696c
[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 use HTML::Zoom;
6 my $root = HTML::Zoom
7     ->from_html(<<MAIN);
8 <html>
9   <head>
10     <title>Default Title</title>
11   </head>
12   <body>
13     Default Content
14   </body>
15 </html>
16 MAIN
17
18 my $body = HTML::Zoom
19     ->from_html(<<BODY);
20 <div id="stuff">
21     <p>Well Now</p>
22     <p id="p2">Is the Time</p>
23 </div>
24 BODY
25
26 my $output =  $root
27   ->select('title')
28   ->replace_content('Hello World')
29   ->select('body')
30   ->replace_content($body)
31   ->then
32   ->set_attribute(class=>'main')
33   ->then
34   ->add_to_attribute(class=>'one-column')
35   ->then
36   ->set_attribute(id=>'top')
37   ->then
38   ->add_to_attribute(id=>'deleteme')
39   ->then
40   ->remove_attribute({name=>'id', value=>'deleteme'})
41   ->select('p')
42   ->set_attribute(class=>'para')
43   ->select('#p2')
44   ->set_attribute(class=>'para2')
45   ->to_html;
46
47
48 my $expect = <<HTML;
49 <html>
50   <head>
51     <title>Hello World</title>
52   </head>
53   <body class="main one-column" id="top"><div id="stuff">
54     <p class="para">Well Now</p>
55     <p id="p2" class="para2">Is the Time</p>
56 </div>
57 </body>
58 </html>
59 HTML
60 is($output, $expect, 'Synopsis code works ok');
61