Update TODO file
[dbsrgits/SQL-Translator.git] / t / 18ttschema-producer.t
CommitLineData
2b2601b5 1#!/usr/bin/perl -w
2# vim:filetype=perl
3
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'
6
2e11379e 7use strict;
2b2601b5 8use Test::More;
9use Test::Exception;
2d691ec1 10use Test::SQL::Translator qw(maybe_plan);
2b2601b5 11
12use Data::Dumper;
2b2601b5 13use FindBin qw/$Bin/;
14
15# Testing 1,2,3,4...
16#=============================================================================
17
2d691ec1 18BEGIN {
9d6bd3c7 19 maybe_plan(6,
d2f0a9f6 20 'XML::XPath',
d55fe5ca 21 'SQL::Translator::Parser::XML::SQLFairy',
d2f0a9f6 22 'Template',
23 'Test::Differences'
24 )
2b2601b5 25}
26use Test::Differences;
a03aec42 27
2b2601b5 28use SQL::Translator;
29use SQL::Translator::Producer::TTSchema;
30
9d6bd3c7 31# Main test. Template whole schema and test tt_vars
32{
33 my $obj;
34 $obj = SQL::Translator->new(
35 show_warnings => 1,
36 from => "XML-SQLFairy",
37 filename => "$Bin/data/xml/schema.xml",
38 to => "TTSchema",
39 producer_args => {
40 ttfile => "$Bin/data/template/basic.tt",
bced3fa7 41# ttfile => "$Bin/data/template/test.tt",
9d6bd3c7 42 tt_vars => {
43 foo => 'bar',
44 hello => 'world',
45 },
046d668a 46 },
9d6bd3c7 47 );
48 my $out;
49 lives_ok { $out = $obj->translate; } "Translate ran";
bced3fa7 50# print STDERR "Output: $out\n";
9d6bd3c7 51 ok $out ne "" ,"Produced something!";
52 local $/ = undef; # slurp
53 eq_or_diff $out, <DATA> ,"Output looks right";
54}
55
56# Test passing of Template config
57{
58 my $tmpl = q{
59 [%- FOREACH table = schema.get_tables %]
60 Table: $table
61 [%- END %]};
62 my $obj;
63 $obj = SQL::Translator->new(
64 show_warnings => 1,
65 from => "XML-SQLFairy",
66 filename => "$Bin/data/xml/schema.xml",
67 to => "TTSchema",
68 producer_args => {
69 ttfile => \$tmpl,
70 tt_conf => {
71 INTERPOLATE => 1,
72 },
73 tt_vars => {
74 foo => 'bar',
75 hello => 'world',
76 },
77 },
78 );
79 my $out;
80 lives_ok { $out = $obj->translate; } "Translate ran";
81 ok $out ne "" ,"Produced something!";
82 local $/ = undef; # slurp
83 eq_or_diff $out, q{
84 Table: Basic}
85 ,"Output looks right";
86}
2b2601b5 87
2b2601b5 88
89__DATA__
90Schema:
91Database:
92
046d668a 93Foo: bar
94Hello: world
95
2b2601b5 96Table: Basic
97==========================================================================
98
99Fields
100 id
101 data_type: int
102 size: 10
103 is_nullable: 0
104 default_value:
105 is_primary_key: 1
106 is_unique: 0
107 is_auto_increment: 1
108 is_foreign_key: 0
109 foreign_key_reference:
110 is_valid: 1
111 order: 1
2b2601b5 112 table: Basic
113
114 title
115 data_type: varchar
116 size: 100
117 is_nullable: 0
118 default_value: hello
119 is_primary_key: 0
120 is_unique: 0
121 is_auto_increment: 0
122 is_foreign_key: 0
123 foreign_key_reference:
124 is_valid: 1
125 order: 2
2b2601b5 126 table: Basic
127
128 description
129 data_type: text
130 size: 0
131 is_nullable: 1
132 default_value:
133 is_primary_key: 0
134 is_unique: 0
135 is_auto_increment: 0
136 is_foreign_key: 0
137 foreign_key_reference:
138 is_valid: 1
139 order: 3
2b2601b5 140 table: Basic
141
142 email
143 data_type: varchar
144 size: 255
145 is_nullable: 1
146 default_value:
147 is_primary_key: 0
148 is_unique: 1
149 is_auto_increment: 0
150 is_foreign_key: 0
151 foreign_key_reference:
152 is_valid: 1
153 order: 4
2b2601b5 154 table: Basic
155
156 explicitnulldef
157 data_type: varchar
158 size: 0
159 is_nullable: 1
160 default_value:
161 is_primary_key: 0
162 is_unique: 0
163 is_auto_increment: 0
164 is_foreign_key: 0
165 foreign_key_reference:
166 is_valid: 1
167 order: 5
2b2601b5 168 table: Basic
169
170 explicitemptystring
171 data_type: varchar
172 size: 0
173 is_nullable: 1
174 default_value:
175 is_primary_key: 0
176 is_unique: 0
177 is_auto_increment: 0
178 is_foreign_key: 0
179 foreign_key_reference:
180 is_valid: 1
181 order: 6
2b2601b5 182 table: Basic
183
5952d39c 184 emptytagdef
b3530353 185 data_type: varchar
186 size: 0
187 is_nullable: 1
188 default_value:
189 is_primary_key: 0
190 is_unique: 0
191 is_auto_increment: 0
192 is_foreign_key: 0
193 foreign_key_reference:
194 is_valid: 1
195 order: 7
b3530353 196 table: Basic
197
08d91aad 198 timest
199 data_type: timestamp
200 size: 0
201 is_nullable: 1
202 default_value:
203 is_primary_key: 0
204 is_unique: 0
205 is_auto_increment: 0
206 is_foreign_key: 0
207 foreign_key_reference:
208 is_valid: 1
209 order: 8
210 table: Basic
211
2b2601b5 212
213Indices
214 titleindex
215 table: Basic
216 fields: title
217 type: NORMAL
218 options:
219 is_valid: 1
220
221
222Constraints
223 ?
224 type: PRIMARY KEY
225 fields: id
226 expression:
227 match_type:
228 reference_fields:
229 reference_table:
230 deferrable: 1
231 on_delete:
232 on_update:
233 options:
234 is_valid: 1
235
236 emailuniqueindex
237 type: UNIQUE
238 fields: email
239 expression:
240 match_type:
241 reference_fields:
242 reference_table:
243 deferrable: 1
244 on_delete:
245 on_update:
246 options:
247 is_valid: 1
248