Added tt-vars to pass variables to templates.
[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;
2e11379e 13use vars '%opt';
14BEGIN { map { $opt{$_}=1 if s/^-// } @ARGV; }
2b2601b5 15use constant DEBUG => (exists $opt{d} ? 1 : 0);
2b2601b5 16
17use FindBin qw/$Bin/;
18
19# Testing 1,2,3,4...
20#=============================================================================
21
2d691ec1 22BEGIN {
d2f0a9f6 23 maybe_plan(3,
24 'XML::XPath',
d55fe5ca 25 'SQL::Translator::Parser::XML::SQLFairy',
d2f0a9f6 26 'Template',
27 'Test::Differences'
28 )
2b2601b5 29}
30use Test::Differences;
a03aec42 31
2b2601b5 32use SQL::Translator;
33use SQL::Translator::Producer::TTSchema;
34
35# Parse the test XML schema
2e11379e 36my $obj;
2b2601b5 37$obj = SQL::Translator->new(
38 debug => DEBUG, #$opt{d},
39 show_warnings => 1,
40 add_drop_table => 1,
2e11379e 41 from => "XML-SQLFairy",
7266dab2 42 filename => "$Bin/data/xml/schema.xml",
2b2601b5 43 to => "TTSchema",
046d668a 44 producer_args => {
329fc3f0 45 ttfile => "$Bin/data/template/basic.tt",
46 tt_vars => {
046d668a 47 foo => 'bar',
48 hello => 'world',
49 },
2b2601b5 50 },
51);
52my $out;
0da6f155 53lives_ok { $out = $obj->translate; } "Translate ran";
54ok $out ne "" ,"Produced something!";
2b2601b5 55local $/ = undef; # slurp
56eq_or_diff $out, <DATA> ,"Output looks right";
2b2601b5 57
58print $out if DEBUG;
59#print "Debug:", Dumper($obj) if DEBUG;
60
61__DATA__
62Schema:
63Database:
64
046d668a 65Foo: bar
66Hello: world
67
2b2601b5 68Table: Basic
69==========================================================================
70
71Fields
72 id
73 data_type: int
74 size: 10
75 is_nullable: 0
76 default_value:
77 is_primary_key: 1
78 is_unique: 0
79 is_auto_increment: 1
80 is_foreign_key: 0
81 foreign_key_reference:
82 is_valid: 1
83 order: 1
2b2601b5 84 table: Basic
85
86 title
87 data_type: varchar
88 size: 100
89 is_nullable: 0
90 default_value: hello
91 is_primary_key: 0
92 is_unique: 0
93 is_auto_increment: 0
94 is_foreign_key: 0
95 foreign_key_reference:
96 is_valid: 1
97 order: 2
2b2601b5 98 table: Basic
99
100 description
101 data_type: text
102 size: 0
103 is_nullable: 1
104 default_value:
105 is_primary_key: 0
106 is_unique: 0
107 is_auto_increment: 0
108 is_foreign_key: 0
109 foreign_key_reference:
110 is_valid: 1
111 order: 3
2b2601b5 112 table: Basic
113
114 email
115 data_type: varchar
116 size: 255
117 is_nullable: 1
118 default_value:
119 is_primary_key: 0
120 is_unique: 1
121 is_auto_increment: 0
122 is_foreign_key: 0
123 foreign_key_reference:
124 is_valid: 1
125 order: 4
2b2601b5 126 table: Basic
127
128 explicitnulldef
129 data_type: varchar
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: 5
2b2601b5 140 table: Basic
141
142 explicitemptystring
143 data_type: varchar
144 size: 0
145 is_nullable: 1
146 default_value:
147 is_primary_key: 0
148 is_unique: 0
149 is_auto_increment: 0
150 is_foreign_key: 0
151 foreign_key_reference:
152 is_valid: 1
153 order: 6
2b2601b5 154 table: Basic
155
5952d39c 156 emptytagdef
b3530353 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: 7
b3530353 168 table: Basic
169
2b2601b5 170
171Indices
172 titleindex
173 table: Basic
174 fields: title
175 type: NORMAL
176 options:
177 is_valid: 1
178
179
180Constraints
181 ?
182 type: PRIMARY KEY
183 fields: id
184 expression:
185 match_type:
186 reference_fields:
187 reference_table:
188 deferrable: 1
189 on_delete:
190 on_update:
191 options:
192 is_valid: 1
193
194 emailuniqueindex
195 type: UNIQUE
196 fields: email
197 expression:
198 match_type:
199 reference_fields:
200 reference_table:
201 deferrable: 1
202 on_delete:
203 on_update:
204 options:
205 is_valid: 1
206