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