Fixed break due to XML Parser now supporting field.extra
[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, 'Template', 'Test::Differences')
24 }
25 use Test::Differences;
26
27 use SQL::Translator;
28 use SQL::Translator::Producer::TTSchema;
29
30 # Parse the test XML schema
31 my $obj;
32 $obj = SQL::Translator->new(
33     debug          => DEBUG, #$opt{d},
34     show_warnings  => 1,
35     add_drop_table => 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     },
42 );
43 my $out;
44 lives_ok { $out = $obj->translate; }  "Translate ran";
45 ok $out ne ""                        ,"Produced something!";
46 local $/ = undef; # slurp
47 eq_or_diff $out, <DATA>              ,"Output looks right";
48
49 print $out if DEBUG;
50 #print "Debug:", Dumper($obj) if DEBUG;
51
52 __DATA__
53 Schema: 
54 Database: 
55
56 Table: Basic
57 ==========================================================================
58
59 Fields
60     id
61         data_type:             int
62         size:                  10
63         is_nullable:           0
64         default_value:         
65         is_primary_key:        1
66         is_unique:             0
67         is_auto_increment:     1
68         is_foreign_key:        0
69         foreign_key_reference: 
70         is_valid:              1
71         order:                 1
72         table:                 Basic
73     
74     title
75         data_type:             varchar
76         size:                  100
77         is_nullable:           0
78         default_value:         hello
79         is_primary_key:        0
80         is_unique:             0
81         is_auto_increment:     0
82         is_foreign_key:        0
83         foreign_key_reference: 
84         is_valid:              1
85         order:                 2
86         table:                 Basic
87     
88     description
89         data_type:             text
90         size:                  0
91         is_nullable:           1
92         default_value:         
93         is_primary_key:        0
94         is_unique:             0
95         is_auto_increment:     0
96         is_foreign_key:        0
97         foreign_key_reference: 
98         is_valid:              1
99         order:                 3
100         table:                 Basic
101     
102     email
103         data_type:             varchar
104         size:                  255
105         is_nullable:           1
106         default_value:         
107         is_primary_key:        0
108         is_unique:             1
109         is_auto_increment:     0
110         is_foreign_key:        0
111         foreign_key_reference: 
112         is_valid:              1
113         order:                 4
114         table:                 Basic
115     
116     explicitnulldef
117         data_type:             varchar
118         size:                  0
119         is_nullable:           1
120         default_value:         
121         is_primary_key:        0
122         is_unique:             0
123         is_auto_increment:     0
124         is_foreign_key:        0
125         foreign_key_reference: 
126         is_valid:              1
127         order:                 5
128         table:                 Basic
129     
130     explicitemptystring
131         data_type:             varchar
132         size:                  0
133         is_nullable:           1
134         default_value:         
135         is_primary_key:        0
136         is_unique:             0
137         is_auto_increment:     0
138         is_foreign_key:        0
139         foreign_key_reference: 
140         is_valid:              1
141         order:                 6
142         table:                 Basic
143     
144     emptytagdef
145         data_type:             varchar
146         size:                  0
147         is_nullable:           1
148         default_value:         
149         is_primary_key:        0
150         is_unique:             0
151         is_auto_increment:     0
152         is_foreign_key:        0
153         foreign_key_reference: 
154         is_valid:              1
155         order:                 7
156         table:                 Basic
157     
158
159 Indices
160     titleindex
161         table:    Basic
162         fields:   title
163         type:     NORMAL
164         options:  
165         is_valid: 1
166     
167     
168 Constraints
169     ?
170         type:             PRIMARY KEY
171         fields:           id
172         expression:       
173         match_type:       
174         reference_fields: 
175         reference_table:  
176         deferrable:       1
177         on_delete:        
178         on_update:        
179         options:          
180         is_valid:         1
181     
182     emailuniqueindex
183         type:             UNIQUE
184         fields:           email
185         expression:       
186         match_type:       
187         reference_fields: 
188         reference_table:  
189         deferrable:       1
190         on_delete:        
191         on_update:        
192         options:          
193         is_valid:         1
194