moved test method to XML::Tags and modified test
[catagits/HTML-Zoom.git] / t / tags_as_zoom_events.t
1 use strict;
2 use warnings FATAL => 'all';
3 use Test::More;
4 use HTML::Zoom;
5
6 {
7   package BasicPage;
8   use HTML::Tags;
9
10   sub show_landing_html {
11     as_html(\&landing, (
12       title => "Welcome to the Demo Home",
13       site_version => 10,
14       new_user_link => 'create_user.html',
15     ));
16   }
17
18   sub show_landing_events {
19     as_events(\&landing, (
20       title => "Welcome to the Demo Home",
21       site_version => 10,
22       new_user_link => 'create_user.html',
23     ));
24   }
25
26   sub layout {
27     my (%data) = @_;
28     \'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" ',
29     \'"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">',
30     <html>,
31       <head>,
32         <!-- here is a comment -->,
33         <title>, ($data{title} || 'Hello World'), </title>,
34       </head>,
35       <body>,
36         @{$data{content}},
37       </body>,
38     </html>;
39   }
40
41   sub landing {
42     my (%data) = @_;
43     <p>, "Hi, I'm version: $data{site_version}", </p>,
44     <p>, "Here's some interesting things about me", </p>,
45     <img src="smilyface.png" alt="smiles" />,
46     <ul>,
47       <li>, <a href="/user">, "My Users", </li>,
48       <li>, <a href="/user/$data{new_user_link}">, "Create", "New User", </li>,
49     </ul>;
50   }
51
52   sub process_templates {
53     my ($templates, %data) = @_;
54     for my $template(@$templates) {
55       my @processed = $template->(%data);
56       $data{content} = \@processed;
57     }
58     return @{$data{content}};
59   }
60
61   sub as_html {
62     my ($template, %data) = @_;
63     my @content = process_templates([$template, \&layout], %data);
64     return join '', HTML::Tags::to_html_string(@content);
65   }
66
67   sub as_events {
68     my ($template, %data) = @_;
69     my @content = process_templates([$template, \&layout], %data);
70     return [HTML::Tags::to_zoom_events(@content)];
71   }
72 }
73
74 ok my $html = BasicPage->show_landing_html;
75 ok my $zoom = HTML::Zoom->from_html($html);
76 ok my $events = BasicPage->show_landing_events;
77
78 is_deeply $zoom->to_events, $events,
79   'Made HZoom events from XMLTags';
80
81 #use Data::Dump 'dump';
82 #warn dump $html;
83 #warn dump $zoom->to_events;
84 #warn "======================";
85 #warn dump $events;
86
87 done_testing();