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