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