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);
14 my ($p, $tables, $classes);
17 $p = HTML::Parser->new(api_version => 3);
21 plan skip_all => "Missing HTML::Parser";
26 int id PRIMARY KEY AUTO_INCREMENT NOT NULL,
31 my $tr = SQL::Translator->new(parser => 'MySQL', producer => 'HTML');
32 my $parsed = $tr->translate(data => $create);
36 $status = $p->parse($parsed);
40 fail("Unable to parse the output!");
47 ok($parsed, "Parsed table OK");
48 ok($status, "Parsed HTML OK");
50 $p->handler(start => @{$HANDLERS{count_tables}});
53 is($tables, 2, "One table in the SQL produces 2 <table> tags");
54 $tables = $classes = 0;
56 $p->handler(start => @{$HANDLERS{count_classes}});
59 is($classes, 1, "One 'LinkTable' class");
60 $tables = $classes = 0;
62 $p->handler(start => @{$HANDLERS{sqlfairy}});
65 is($classes, 1, "SQLfairy plug is alive and well ");
66 $tables = $classes = 0;
68 # Handler functions for the parser
74 $tables++ if ($tagname eq 'table');
80 my ($tagname, $attr) = @_;
81 if ($tagname eq 'table' &&
83 $attr->{'class'} eq 'LinkTable') {
91 my ($tagname, $attr) = @_;
92 if ($tagname eq 'a' &&
94 $attr->{'href'} =~ /sqlfairy/i) {