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