X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F17sqlfxml-producer.t;h=29acb01ab47ecd8e5b8eeddea7f7d8cf9e8da71f;hb=4783cccd73482042c5abd9f08790cc35dd09a4ba;hp=db14a10bde6676e4b2ac3aee46b04f339e11f01f;hpb=11a08bd9efc6d465e6935648832df987f4c416e3;p=dbsrgits%2FSQL-Translator.git diff --git a/t/17sqlfxml-producer.t b/t/17sqlfxml-producer.t index db14a10..29acb01 100644 --- a/t/17sqlfxml-producer.t +++ b/t/17sqlfxml-producer.t @@ -33,19 +33,21 @@ if ($@ && $@ =~ m!locate Test/Differences.pm in!) { plan skip_all => "You need Test::Differences for this test."; } use Test::Differences; -plan tests => 6; - +plan tests => 18; + use SQL::Translator; use SQL::Translator::Producer::XML::SQLFairy; -my ($obj,$ans,$xml); - # # emit_empty_tags => 0 # +{ +my ($obj,$ans,$xml); $ans = < + + Basic 1 @@ -53,82 +55,82 @@ $ans = < id integer + 10 + 0 1 1 - 0 0 - 1 - 10 comment on id field + 1 title varchar + 100 + 0 hello 0 0 - 0 0 - 2 - 100 + 2 description text + 65535 + 1 0 0 - 1 0 - 3 - 65535 + 3 email varchar + 255 + 1 0 0 - 1 0 - 4 - 255 + 4 - title titleindex - NORMAL + title + - 1 - - id - - + PRIMARY KEY + id + - - PRIMARY KEY + + + + 1 - 1 - - email - - + UNIQUE + email + - - UNIQUE + + + + 1 @@ -143,19 +145,25 @@ $obj = SQL::Translator->new( from => 'MySQL', to => 'XML-SQLFairy', ); -lives_ok { $xml = $obj->translate($file); } "Translate ran"; +lives_ok {$xml = $obj->translate($file);} "Translate (emit_empty_tags=>0) ran"; ok("$xml" ne "" ,"Produced something!"); print "XML:\n$xml" if DEBUG; # Strip sqlf header with its variable date so we diff safely $xml =~ s/^([^\n]*\n){7}//m; eq_or_diff $xml, $ans ,"XML looks right"; +} # end emit_empty_tags=>0 + # # emit_empty_tags => 1 # +{ +my ($obj,$ans,$xml); $ans = < + + Basic 2 @@ -163,93 +171,92 @@ $ans = < id integer + 10 + 0 1 1 - 0 0 - 5 - 10 comment on id field + 5 title varchar + 100 + 0 hello 0 0 - 0 0 - 6 - 100 + 6 description text + 65535 + 1 0 0 - 1 0 - 7 - 65535 + 7 email varchar + 255 + 1 0 0 - 1 0 - 8 - 255 + 8 - title titleindex - NORMAL + title + - 1 - - id - - + PRIMARY KEY + id + + - - - PRIMARY KEY + + + + 1 - 1 - - email - - + UNIQUE + email + + - - - UNIQUE + + + + 1 EOXML -undef $obj; $obj = SQL::Translator->new( debug => DEBUG, trace => TRACE, @@ -259,23 +266,212 @@ $obj = SQL::Translator->new( to => 'XML-SQLFairy', producer_args => { emit_empty_tags => 1 }, ); -lives_ok { $xml = $obj->translate($file); } "Translate ran"; +lives_ok { $xml=$obj->translate($file); } "Translate (emit_empty_tags=>1) ran"; ok("$xml" ne "" ,"Produced something!"); print "XML emit_empty_tags=>1:\n$xml" if DEBUG; # Strip sqlf header with its variable date so we diff safely $xml =~ s/^([^\n]*\n){7}//m; eq_or_diff $xml, $ans ,"XML looks right"; - # This diff probably isn't a very good test! Should really check the - # result with XPath or something, but that would take ages to write ;-) - -# TODO Make this a real test of attrib_values -# $obj = SQL::Translator->new( -# debug => DEBUG, -# trace => TRACE, -# show_warnings => 1, -# add_drop_table => 1, -# from => "MySQL", -# to => "XML-SQLFairy", -# producer_args => { attrib_values => 1 }, -# ); -# print $obj->translate($file); + +} # end emit_empty_tags => 1 + +# +# attrib_values => 1 +# +{ +my ($obj,$ans,$xml); + +$ans = < + + + + + + + + + + + + + + + + +EOXML + +$obj = SQL::Translator->new( + debug => DEBUG, + trace => TRACE, + show_warnings => 1, + add_drop_table => 1, + from => "MySQL", + to => "XML-SQLFairy", + producer_args => { attrib_values => 1 }, +); +lives_ok {$xml = $obj->translate($file);} "Translate (attrib_values=>1) ran"; +ok("$xml" ne "" ,"Produced something!"); +print "XML attrib_values=>1:\n$xml" if DEBUG; +# Strip sqlf header with its variable date so we diff safely +$xml =~ s/^([^\n]*\n){7}//m; +eq_or_diff $xml, $ans ,"XML looks right"; + +} # end attrib_values => 1 + +# +# View +# +# Thanks to Ken for the schema setup lifted from 13schema.t +{ +my ($obj,$ans,$xml); + +$ans = < + + + + foo_view + select name, age from person + name,age + 1 + + +EOXML + + $obj = SQL::Translator->new( + debug => DEBUG, + trace => TRACE, + show_warnings => 1, + add_drop_table => 1, + from => "MySQL", + to => "XML-SQLFairy", + ); + my $s = $obj->schema; + my $name = 'foo_view'; + my $sql = 'select name, age from person'; + my $fields = 'name, age'; + my $v = $s->add_view( + name => $name, + sql => $sql, + fields => $fields, + schema => $s, + ) or die $s->error; + + # As we have created a Schema we give translate a dummy string so that + # it will run the produce. + lives_ok {$xml =$obj->translate("FOO");} "Translate (View) ran"; + ok("$xml" ne "" ,"Produced something!"); + print "XML attrib_values=>1:\n$xml" if DEBUG; + # Strip sqlf header with its variable date so we diff safely + $xml =~ s/^([^\n]*\n){7}//m; + eq_or_diff $xml, $ans ,"XML looks right"; +} # end View + +# +# Trigger +# +# Thanks to Ken for the schema setup lifted from 13schema.t +{ +my ($obj,$ans,$xml); + +$ans = < + + + + foo_trigger + insert + update modified=timestamp(); + foo + after + 1 + + +EOXML + + $obj = SQL::Translator->new( + debug => DEBUG, + trace => TRACE, + show_warnings => 1, + add_drop_table => 1, + from => "MySQL", + to => "XML-SQLFairy", + ); + my $s = $obj->schema; + my $name = 'foo_trigger'; + my $perform_action_when = 'after'; + my $database_event = 'insert'; + my $on_table = 'foo'; + my $action = 'update modified=timestamp();'; + my $t = $s->add_trigger( + name => $name, + perform_action_when => $perform_action_when, + database_event => $database_event, + on_table => $on_table, + action => $action, + ) or die $s->error; + + # As we have created a Schema we give translate a dummy string so that + # it will run the produce. + lives_ok {$xml =$obj->translate("FOO");} "Translate (Trigger) ran"; + ok("$xml" ne "" ,"Produced something!"); + print "XML attrib_values=>1:\n$xml" if DEBUG; + # Strip sqlf header with its variable date so we diff safely + $xml =~ s/^([^\n]*\n){7}//m; + eq_or_diff $xml, $ans ,"XML looks right"; +} # end Trigger + +# +# Procedure +# +# Thanks to Ken for the schema setup lifted from 13schema.t +{ +my ($obj,$ans,$xml); + +$ans = < + + + + foo_proc + select foo from bar + foo,bar + Nomar + Go Sox! + 1 + + +EOXML + + $obj = SQL::Translator->new( + debug => DEBUG, + trace => TRACE, + show_warnings => 1, + add_drop_table => 1, + from => "MySQL", + to => "XML-SQLFairy", + ); + my $s = $obj->schema; + my $name = 'foo_proc'; + my $sql = 'select foo from bar'; + my $parameters = 'foo, bar'; + my $owner = 'Nomar'; + my $comments = 'Go Sox!'; + my $p = $s->add_procedure( + name => $name, + sql => $sql, + parameters => $parameters, + owner => $owner, + comments => $comments, + ) or die $s->error; + + # As we have created a Schema we give translate a dummy string so that + # it will run the produce. + lives_ok {$xml =$obj->translate("FOO");} "Translate (Procedure) ran"; + ok("$xml" ne "" ,"Produced something!"); + print "XML attrib_values=>1:\n$xml" if DEBUG; + # Strip sqlf header with its variable date so we diff safely + $xml =~ s/^([^\n]*\n){7}//m; + eq_or_diff $xml, $ans ,"XML looks right"; +} # end Procedure