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);
12 use Test::SQL::Translator qw(maybe_plan);
18 'SQL::Translator::Parser::MySQL',
19 'SQL::Translator::Producer::HTML');
22 my ($p, $tables, $classes);
23 $p = HTML::Parser->new(api_version => 3);
28 int id PRIMARY KEY AUTO_INCREMENT NOT NULL,
33 my $tr = SQL::Translator->new(parser => 'MySQL', producer => 'HTML');
34 my $parsed = $tr->translate(data => $create) or die $tr->error;
38 $status = $p->parse($parsed);
42 fail("Unable to parse the output!");
46 ok($parsed, "Parsed table OK");
47 ok($status, "Parsed HTML OK");
49 $p->handler(start => @{$HANDLERS{count_tables}});
52 is($tables, 3, "One table in the SQL produces 3 <table> tags");
53 $tables = $classes = 0;
55 $p->handler(start => @{$HANDLERS{count_classes}});
58 is($classes, 1, "One 'LinkTable' class");
59 $tables = $classes = 0;
61 $p->handler(start => @{$HANDLERS{sqlfairy}});
64 is($classes, 1, "SQLfairy plug is alive and well ");
65 $tables = $classes = 0;
67 # Handler functions for the parser
73 $tables++ if ($tagname eq 'table');
79 my ($tagname, $attr) = @_;
80 if ($tagname eq 'table' &&
82 $attr->{'class'} eq 'LinkTable') {
90 my ($tagname, $attr) = @_;
91 if ($tagname eq 'a' &&
93 $attr->{'href'} =~ /sqlfairy/i) {