Re-added ttvars. Added docs and test for ttvars.
[dbsrgits/SQL-Translator.git] / t / 18ttschema-producer.t
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
7 use strict;
8 use Test::More;
9 use Test::Exception;
10 use Test::SQL::Translator qw(maybe_plan);
11
12 use Data::Dumper;
13 use vars '%opt';
14 BEGIN { map { $opt{$_}=1 if s/^-// } @ARGV; }
15 use constant DEBUG => (exists $opt{d} ? 1 : 0);
16
17 use FindBin qw/$Bin/;
18
19 # Testing 1,2,3,4...
20 #=============================================================================
21
22 BEGIN {
23     maybe_plan(3, 
24         'XML::XPath', 
25         'SQL::Translator::Parser::XML::SQLFairy',
26         'Template', 
27         'Test::Differences'
28     )
29 }
30 use Test::Differences;
31
32 use SQL::Translator;
33 use SQL::Translator::Producer::TTSchema;
34
35 # Parse the test XML schema
36 my $obj;
37 $obj = SQL::Translator->new(
38     debug          => DEBUG, #$opt{d},
39     show_warnings  => 1,
40     add_drop_table => 1,
41     from           => "XML-SQLFairy",
42     filename       => "$Bin/data/xml/schema.xml",
43     to             => "TTSchema",
44     producer_args  => {
45         ttfile => "$Bin/data/template/basic.tt",
46         ttargs => {
47             foo   => 'bar',
48             hello => 'world',
49         },
50     },
51 );
52 my $out;
53 lives_ok { $out = $obj->translate; }  "Translate ran";
54 ok $out ne ""                        ,"Produced something!";
55 local $/ = undef; # slurp
56 eq_or_diff $out, <DATA>              ,"Output looks right";
57
58 print $out if DEBUG;
59 #print "Debug:", Dumper($obj) if DEBUG;
60
61 __DATA__
62 Schema: 
63 Database: 
64
65 Foo: bar
66 Hello: world
67
68 Table: Basic
69 ==========================================================================
70
71 Fields
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
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
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
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
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
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
154         table:                 Basic
155     
156     emptytagdef
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
168         table:                 Basic
169     
170
171 Indices
172     titleindex
173         table:    Basic
174         fields:   title
175         type:     NORMAL
176         options:  
177         is_valid: 1
178     
179     
180 Constraints
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