4 # Before `make install' is performed this script should be runnable with
5 # `make test'. After `make install' it should work as `perl test.pl'
12 use Test::SQL::Translator qw(maybe_plan);
16 BEGIN { map { $opt{$_}=1 if s/^-// } @ARGV; }
17 use constant DEBUG => (exists $opt{d} ? 1 : 0);
18 use constant TRACE => (exists $opt{t} ? 1 : 0);
22 my $file = "$Bin/data/mysql/sqlfxml-producer-basic.sql";
24 local $SIG{__WARN__} = sub {
26 unless $_[0] =~ m#XML/Writer#;
30 #=============================================================================
36 'SQL::Translator::Producer::XML::SQLFairy');
39 use Test::Differences;
41 use SQL::Translator::Producer::XML::SQLFairy;
50 <schema name="" database="" xmlns="http://sqlfairy.sourceforge.net/sqlfairy.xml">
53 <table name="Basic" order="1">
56 <field name="id" data_type="integer" size="10" is_nullable="0" is_auto_increment="1" is_primary_key="1" is_foreign_key="0" order="1">
58 <comments>comment on id field</comments>
60 <field name="title" data_type="varchar" size="100" is_nullable="0" default_value="hello" is_auto_increment="0" is_primary_key="0" is_foreign_key="0" order="2">
64 <field name="description" data_type="text" size="65535" is_nullable="1" default_value="" is_auto_increment="0" is_primary_key="0" is_foreign_key="0" order="3">
68 <field name="email" data_type="varchar" size="255" is_nullable="1" is_auto_increment="0" is_primary_key="0" is_foreign_key="0" order="4">
74 <index name="titleindex" type="NORMAL" fields="title" options="">
79 <constraint name="" type="PRIMARY KEY" fields="id" reference_table="" reference_fields="" on_delete="" on_update="" match_type="" expression="" options="" deferrable="1">
82 <constraint name="" type="UNIQUE" fields="email" reference_table="" reference_fields="" on_delete="" on_update="" match_type="" expression="" options="" deferrable="1">
91 <procedures></procedures>
95 $obj = SQL::Translator->new(
101 to => "XML-SQLFairy",
103 $xml = $obj->translate($file) or die $obj->error;
104 ok("$xml" ne "" ,"Produced something!");
105 print "XML:\n$xml" if DEBUG;
106 # Strip sqlf header with its variable date so we diff safely
107 $xml =~ s/^([^\n]*\n){7}//m;
108 eq_or_diff $xml, $ans, "XML looks right";
115 # Thanks to Ken for the schema setup lifted from 13schema.t
120 <schema name="" database="" xmlns="http://sqlfairy.sourceforge.net/sqlfairy.xml">
124 <view name="foo_view" fields="name,age" order="1">
125 <sql>select name, age from person</sql>
126 <extra hello="world" />
129 <triggers></triggers>
130 <procedures></procedures>
134 $obj = SQL::Translator->new(
140 to => "XML-SQLFairy",
142 my $s = $obj->schema;
143 my $name = 'foo_view';
144 my $sql = 'select name, age from person';
145 my $fields = 'name, age';
146 my $v = $s->add_view(
150 extra => { hello => "world" },
154 # As we have created a Schema we give translate a dummy string so that
155 # it will run the produce.
156 lives_ok {$xml =$obj->translate("FOO");} "Translate (View) ran";
157 ok("$xml" ne "" ,"Produced something!");
158 print "XML attrib_values=>1:\n$xml" if DEBUG;
159 # Strip sqlf header with its variable date so we diff safely
160 $xml =~ s/^([^\n]*\n){7}//m;
161 eq_or_diff $xml, $ans ,"XML looks right";
167 # Thanks to Ken for the schema setup lifted from 13schema.t
172 <schema name="" database="" xmlns="http://sqlfairy.sourceforge.net/sqlfairy.xml">
177 <trigger name="foo_trigger" database_event="insert" on_table="foo" perform_action_when="after" order="1">
178 <action>update modified=timestamp();</action>
179 <extra hello="world" />
182 <procedures></procedures>
186 $obj = SQL::Translator->new(
192 to => "XML-SQLFairy",
194 my $s = $obj->schema;
195 my $name = 'foo_trigger';
196 my $perform_action_when = 'after';
197 my $database_event = 'insert';
198 my $on_table = 'foo';
199 my $action = 'update modified=timestamp();';
200 my $t = $s->add_trigger(
202 perform_action_when => $perform_action_when,
203 database_event => $database_event,
204 on_table => $on_table,
206 extra => { hello => "world" },
209 # As we have created a Schema we give translate a dummy string so that
210 # it will run the produce.
211 lives_ok {$xml =$obj->translate("FOO");} "Translate (Trigger) ran";
212 ok("$xml" ne "" ,"Produced something!");
213 print "XML attrib_values=>1:\n$xml" if DEBUG;
214 # Strip sqlf header with its variable date so we diff safely
215 $xml =~ s/^([^\n]*\n){7}//m;
216 eq_or_diff $xml, $ans ,"XML looks right";
222 # Thanks to Ken for the schema setup lifted from 13schema.t
227 <schema name="" database="" xmlns="http://sqlfairy.sourceforge.net/sqlfairy.xml">
231 <triggers></triggers>
233 <procedure name="foo_proc" parameters="foo,bar" owner="Nomar" order="1">
234 <sql>select foo from bar</sql>
235 <comments>Go Sox!</comments>
236 <extra hello="world" />
242 $obj = SQL::Translator->new(
248 to => "XML-SQLFairy",
250 my $s = $obj->schema;
251 my $name = 'foo_proc';
252 my $sql = 'select foo from bar';
253 my $parameters = 'foo, bar';
255 my $comments = 'Go Sox!';
256 my $p = $s->add_procedure(
259 parameters => $parameters,
261 comments => $comments,
262 extra => { hello => "world" },
265 # As we have created a Schema we give translate a dummy string so that
266 # it will run the produce.
267 lives_ok {$xml =$obj->translate("FOO");} "Translate (Procedure) ran";
268 ok("$xml" ne "" ,"Produced something!");
269 print "XML attrib_values=>1:\n$xml" if DEBUG;
270 # Strip sqlf header with its variable date so we diff safely
271 $xml =~ s/^([^\n]*\n){7}//m;
272 eq_or_diff $xml, $ans ,"XML looks right";
282 <schema name="" database="" xmlns="http://sqlfairy.sourceforge.net/sqlfairy.xml">
285 <table name="Basic" order="2">
288 <field name="foo" data_type="integer" size="10" is_nullable="1" is_auto_increment="0" is_primary_key="0" is_foreign_key="0" order="5">
289 <extra ZEROFILL="1" />
290 <comments></comments>
294 <constraints></constraints>
295 <comments></comments>
299 <triggers></triggers>
300 <procedures></procedures>
304 $obj = SQL::Translator->new(
310 to => "XML-SQLFairy",
312 my $s = $obj->schema;
313 my $t = $s->add_table( name => "Basic" ) or die $s->error;
314 my $f = $t->add_field(
316 data_type => "integer",
319 $f->extra(ZEROFILL => "1");
321 # As we have created a Schema we give translate a dummy string so that
322 # it will run the produce.
323 lives_ok {$xml =$obj->translate("FOO");} "Translate (Field.extra) ran";
324 ok("$xml" ne "" ,"Produced something!");
325 print "XML:\n$xml" if DEBUG;
326 # Strip sqlf header with its variable date so we diff safely
327 $xml =~ s/^([^\n]*\n){7}//m;
328 eq_or_diff $xml, $ans ,"XML looks right";