Commit | Line | Data |
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 |
7 | use strict; |
2b2601b5 |
8 | use Test::More; |
9 | use Test::Exception; |
2d691ec1 |
10 | use Test::SQL::Translator qw(maybe_plan); |
2b2601b5 |
11 | |
12 | use Data::Dumper; |
2b2601b5 |
13 | use FindBin qw/$Bin/; |
14 | |
15 | # Testing 1,2,3,4... |
16 | #============================================================================= |
17 | |
2d691ec1 |
18 | BEGIN { |
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 | } |
26 | use Test::Differences; |
a03aec42 |
27 | |
2b2601b5 |
28 | use SQL::Translator; |
29 | use 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__ |
88 | Schema: |
89 | Database: |
90 | |
046d668a |
91 | Foo: bar |
92 | Hello: world |
93 | |
2b2601b5 |
94 | Table: Basic |
95 | ========================================================================== |
96 | |
97 | Fields |
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 | |
2b2601b5 |
196 | |
197 | Indices |
198 | titleindex |
199 | table: Basic |
200 | fields: title |
201 | type: NORMAL |
202 | options: |
203 | is_valid: 1 |
204 | |
205 | |
206 | Constraints |
207 | ? |
208 | type: PRIMARY KEY |
209 | fields: id |
210 | expression: |
211 | match_type: |
212 | reference_fields: |
213 | reference_table: |
214 | deferrable: 1 |
215 | on_delete: |
216 | on_update: |
217 | options: |
218 | is_valid: 1 |
219 | |
220 | emailuniqueindex |
221 | type: UNIQUE |
222 | fields: email |
223 | expression: |
224 | match_type: |
225 | reference_fields: |
226 | reference_table: |
227 | deferrable: 1 |
228 | on_delete: |
229 | on_update: |
230 | options: |
231 | is_valid: 1 |
232 | |