1 #!/usr/local/bin/perl -w
4 # This test creates an HTML::Parser instance and uses it to selectively
5 # parse the output of the HTML producer. Rather than try to ensure
6 # that the produced HTML turns into a particular parse tree or anything
7 # like that, it performs some heuristics on the output.
10 use vars qw(%HANDLERS);
13 use Data::Dump qw(dump);
15 my ($p, $tables, $classes);
18 $p = HTML::Parser->new(api_version => 3);
22 plan skip_all => "Missing HTML::Parser";
27 int id PRIMARY KEY AUTO_INCREMENT NOT NULL,
32 my $tr = SQL::Translator->new(parser => 'MySQL', producer => 'HTML');
33 my $parsed = $tr->translate(data => $create);
37 $status = $p->parse($parsed);
41 fail("Unable to parse the output!");
48 ok($parsed, "Parsed table OK");
49 ok($status, "Parsed HTML OK");
51 $p->handler(start => @{$HANDLERS{count_tables}});
54 is($tables, 2, "One table in the SQL produces 2 <table> tags");
55 $tables = $classes = 0;
57 $p->handler(start => @{$HANDLERS{count_classes}});
60 is($classes, 1, "One 'LinkTable' class");
61 $tables = $classes = 0;
63 $p->handler(start => @{$HANDLERS{sqlfairy}});
66 is($classes, 1, "SQLfairy plug is alive and well ");
67 $tables = $classes = 0;
69 # Handler functions for the parser
75 $tables++ if ($tagname eq 'table');
81 my ($tagname, $attr) = @_;
82 if ($tagname eq 'table' &&
84 $attr->{'class'} eq 'LinkTable') {
92 my ($tagname, $attr) = @_;
93 if ($tagname eq 'a' &&
95 $attr->{'href'} =~ /sqlfairy/i) {