add test
|
1 |
use Test::More 'no_plan'; |
2 |
use strict; |
|
3 |
use warnings; |
|
4 | ||
5 |
use DBI::Custom; |
|
add tests
|
6 |
use DBI::Custom::SQL::Template; |
add test
|
7 | |
cleanup
|
8 |
# Function for test name |
9 |
my $test; |
|
10 |
sub test { |
|
11 |
$test = shift; |
|
12 |
} |
|
13 | ||
cleanup
|
14 |
# Variables for test |
15 |
our $SQL_TMPL = { |
|
16 |
0 => DBI::Custom::SQL::Template->new->tag_start(0), |
|
17 |
1 => DBI::Custom::SQL::Template->new->tag_start(1), |
|
18 |
2 => DBI::Custom::SQL::Template->new->tag_start(2) |
|
19 |
}; |
|
cleanup
|
20 |
my $dbi; |
21 | ||
cleanup
|
22 | |
cleanup
|
23 |
test 'Constructor'; |
cleanup
|
24 |
$dbi = DBI::Custom->new( |
25 |
user => 'a', |
|
add database method
|
26 |
database => 'a', |
cleanup
|
27 |
password => 'b', |
28 |
data_source => 'c', |
|
29 |
dbi_options => {d => 1, e => 2}, |
|
30 |
filters => { |
|
31 |
f => 3, |
|
32 |
}, |
|
33 |
bind_filter => 'f', |
|
34 |
fetch_filter => 'g', |
|
35 |
result_class => 'g', |
|
cleanup
|
36 |
sql_template => $SQL_TMPL->{0}, |
cleanup
|
37 |
); |
add database method
|
38 |
is_deeply($dbi,{user => 'a', database => 'a', password => 'b', data_source => 'c', |
cleanup
|
39 |
dbi_options => {d => 1, e => 2}, filters => {f => 3}, bind_filter => 'f', |
40 |
fetch_filter => 'g', result_class => 'g', |
|
cleanup
|
41 |
sql_template => $SQL_TMPL->{0}}, $test); |
cleanup
|
42 |
isa_ok($dbi, 'DBI::Custom'); |
add test
|
43 | |
cleanup
|
44 | |
cleanup
|
45 |
test 'Sub class constructor'; |
add test
|
46 |
{ |
47 |
package DBI::Custom::T1; |
|
48 |
use base 'DBI::Custom'; |
|
49 |
|
|
cleanup
|
50 |
__PACKAGE__ |
update document
|
51 |
->user('a') |
add database method
|
52 |
->database('a') |
update document
|
53 |
->password('b') |
54 |
->data_source('c') |
|
cleanup
|
55 |
->dbi_options({d => 1, e => 2}) |
cleanup
|
56 |
->filters( |
57 |
f => 3 |
|
58 |
) |
|
add formats add_format
|
59 |
->formats( |
60 |
f => 3 |
|
61 |
) |
|
cleanup
|
62 |
->bind_filter('f') |
63 |
->fetch_filter('g') |
|
64 |
->result_class('DBI::Custom::Result') |
|
cleanup
|
65 |
->sql_template($SQL_TMPL->{0}) |
cleanup
|
66 |
; |
add test
|
67 |
} |
cleanup
|
68 |
$dbi = DBI::Custom::T1->new( |
69 |
user => 'ao', |
|
add database method
|
70 |
database => 'ao', |
cleanup
|
71 |
password => 'bo', |
72 |
data_source => 'co', |
|
73 |
dbi_options => {do => 10, eo => 20}, |
|
74 |
filters => { |
|
75 |
fo => 30, |
|
76 |
}, |
|
add formats add_format
|
77 |
formats => { |
78 |
fo => 30, |
|
79 |
}, |
|
cleanup
|
80 |
bind_filter => 'fo', |
81 |
fetch_filter => 'go', |
|
82 |
result_class => 'ho', |
|
cleanup
|
83 |
sql_template => $SQL_TMPL->{0}, |
cleanup
|
84 |
); |
85 |
is($dbi->user, 'ao', "$test : user"); |
|
add database method
|
86 |
is($dbi->database, 'ao', "$test : database"); |
cleanup
|
87 |
is($dbi->password, 'bo', "$test : passowr"); |
88 |
is($dbi->data_source, 'co', "$test : data_source"); |
|
89 |
is_deeply($dbi->dbi_options, {do => 10, eo => 20}, "$test : dbi_options"); |
|
90 |
is_deeply(scalar $dbi->filters, {fo => 30}, "$test : filters"); |
|
add formats add_format
|
91 |
is_deeply(scalar $dbi->formats, {fo => 30}, "$test : formats"); |
cleanup
|
92 |
is($dbi->bind_filter, 'fo', "$test : bind_filter"); |
93 |
is($dbi->fetch_filter, 'go', "$test : fetch_filter"); |
|
94 |
is($dbi->result_class, 'ho', "$test : result_class"); |
|
95 |
is($dbi->sql_template->tag_start, 0, "$test : sql_template"); |
|
96 |
isa_ok($dbi, 'DBI::Custom::T1'); |
|
add test
|
97 | |
cleanup
|
98 |
test 'Sub class constructor default'; |
99 |
$dbi = DBI::Custom::T1->new; |
|
100 |
is($dbi->user, 'a', "$test : user"); |
|
add database method
|
101 |
is($dbi->database, 'a', "$test : database"); |
cleanup
|
102 |
is($dbi->password, 'b', "$test : password"); |
103 |
is($dbi->data_source, 'c', "$test : data_source"); |
|
104 |
is_deeply($dbi->dbi_options, {d => 1, e => 2}, "$test : dbi_options"); |
|
105 |
is_deeply({$dbi->filters}, {f => 3}, "$test : filters"); |
|
add formats add_format
|
106 |
is_deeply({$dbi->formats}, {f => 3}, "$test : formats"); |
cleanup
|
107 |
is($dbi->bind_filter, 'f', "$test : bind_filter"); |
108 |
is($dbi->fetch_filter, 'g', "$test : fetch_filter"); |
|
109 |
is($dbi->result_class, 'DBI::Custom::Result', "$test : result_class"); |
|
110 |
is($dbi->sql_template->tag_start, 0, "$test : sql_template"); |
|
111 |
isa_ok($dbi, 'DBI::Custom::T1'); |
|
add test
|
112 | |
cleanup
|
113 | |
cleanup
|
114 |
test 'Sub sub class constructor default'; |
add test
|
115 |
{ |
116 |
package DBI::Custom::T1_2; |
|
117 |
use base 'DBI::Custom::T1'; |
|
118 |
} |
|
cleanup
|
119 |
$dbi = DBI::Custom::T1_2->new; |
120 |
is($dbi->user, 'a', "$test : user"); |
|
add database method
|
121 |
is($dbi->database, 'a', "$test : database"); |
cleanup
|
122 |
is($dbi->password, 'b', "$test : passowrd"); |
123 |
is($dbi->data_source, 'c', "$test : data_source"); |
|
124 |
is_deeply($dbi->dbi_options, {d => 1, e => 2}, "$test : dbi_options"); |
|
125 |
is_deeply(scalar $dbi->filters, {f => 3}, "$test : filters"); |
|
add formats add_format
|
126 |
is_deeply(scalar $dbi->formats, {f => 3}, "$test : formats"); |
cleanup
|
127 |
is($dbi->bind_filter, 'f', "$test : bind_filter"); |
128 |
is($dbi->fetch_filter, 'g', "$test : fetch_filter"); |
|
129 |
is($dbi->result_class, 'DBI::Custom::Result', "$test : result_class"); |
|
130 |
is($dbi->sql_template->tag_start, 0, "$test sql_template"); |
|
131 |
isa_ok($dbi, 'DBI::Custom::T1_2'); |
|
add test
|
132 | |
cleanup
|
133 | |
134 |
test 'Customized sub class constructor default'; |
|
add test
|
135 |
{ |
136 |
package DBI::Custom::T1_3; |
|
137 |
use base 'DBI::Custom::T1'; |
|
138 |
|
|
cleanup
|
139 |
__PACKAGE__ |
update document
|
140 |
->user('ao') |
add database method
|
141 |
->database('ao') |
update document
|
142 |
->password('bo') |
143 |
->data_source('co') |
|
cleanup
|
144 |
->dbi_options({do => 10, eo => 20}) |
cleanup
|
145 |
->filters( |
146 |
fo => 30 |
|
147 |
) |
|
add formats add_format
|
148 |
->formats( |
149 |
fo => 30 |
|
150 |
) |
|
cleanup
|
151 |
->bind_filter('fo') |
152 |
->fetch_filter('go') |
|
153 |
->result_class('ho') |
|
cleanup
|
154 |
->sql_template($SQL_TMPL->{1}) |
cleanup
|
155 |
; |
add test
|
156 |
} |
cleanup
|
157 |
$dbi = DBI::Custom::T1_3->new; |
158 |
is($dbi->user, 'ao', "$test : user"); |
|
add database method
|
159 |
is($dbi->database, 'ao', "$test : database"); |
cleanup
|
160 |
is($dbi->password, 'bo', "$test : password"); |
161 |
is($dbi->data_source, 'co', "$test : data_source"); |
|
162 |
is_deeply($dbi->dbi_options, {do => 10, eo => 20}, "$test : dbi_options"); |
|
163 |
is_deeply(scalar $dbi->filters, {fo => 30}, "$test : filters"); |
|
add formats add_format
|
164 |
is_deeply(scalar $dbi->formats, {fo => 30}, "$test : formats"); |
cleanup
|
165 |
is($dbi->bind_filter, 'fo', "$test : bind_filter"); |
166 |
is($dbi->fetch_filter, 'go', "$test : fetch_filter"); |
|
167 |
is($dbi->result_class, 'ho', "$test : result_class"); |
|
168 |
is($dbi->sql_template->tag_start, 1, "$test : sql_template"); |
|
169 |
isa_ok($dbi, 'DBI::Custom::T1_3'); |
|
add test
|
170 | |
171 | ||
cleanup
|
172 |
test 'Customized sub class constructor'; |
173 |
$dbi = DBI::Custom::T1_3->new( |
|
174 |
user => 'a', |
|
add database method
|
175 |
database => 'a', |
cleanup
|
176 |
password => 'b', |
177 |
data_source => 'c', |
|
178 |
dbi_options => {d => 1, e => 2}, |
|
179 |
filters => { |
|
180 |
f => 3, |
|
181 |
}, |
|
add formats add_format
|
182 |
formats => { |
183 |
f => 3, |
|
184 |
}, |
|
cleanup
|
185 |
bind_filter => 'f', |
186 |
fetch_filter => 'g', |
|
187 |
result_class => 'h', |
|
cleanup
|
188 |
sql_template => $SQL_TMPL->{2}, |
cleanup
|
189 |
); |
190 |
is($dbi->user, 'a', "$test : user"); |
|
add database method
|
191 |
is($dbi->database, 'a', "$test : database"); |
cleanup
|
192 |
is($dbi->password, 'b', "$test : password"); |
193 |
is($dbi->data_source, 'c', "$test : data_source"); |
|
194 |
is_deeply($dbi->dbi_options, {d => 1, e => 2}, "$test : dbi_options"); |
|
195 |
is_deeply({$dbi->filters}, {f => 3}, "$test : filters"); |
|
add formats add_format
|
196 |
is_deeply({$dbi->formats}, {f => 3}, "$test : formats"); |
cleanup
|
197 |
is($dbi->bind_filter, 'f', "$test : bind_filter"); |
198 |
is($dbi->fetch_filter, 'g', "$test : fetch_filter"); |
|
199 |
is($dbi->result_class, 'h', "$test : result_class"); |
|
200 |
is($dbi->sql_template->tag_start, 2, "$test : sql_template"); |
|
201 |
isa_ok($dbi, 'DBI::Custom'); |
|
add test
|
202 | |
cleanup
|
203 | |
204 |
test 'add_filters'; |
|
205 |
$dbi = DBI::Custom->new; |
|
206 |
$dbi->add_filter(a => sub {1}); |
|
207 |
is($dbi->filters->{a}->(), 1, $test); |
|
208 | ||
add formats add_format
|
209 |
test 'add_formats'; |
210 |
$dbi = DBI::Custom->new; |
|
211 |
$dbi->add_format(a => sub {1}); |
|
212 |
is($dbi->formats->{a}->(), 1, $test); |
|
213 |