DBIx-Custom / t / 01-core.t /
Newer Older
203 lines | 6.001kb
add test
yuki-kimoto authored on 2009-10-16
1
use Test::More 'no_plan';
2
use strict;
3
use warnings;
4

            
5
use DBI::Custom;
add tests
yuki-kimoto authored on 2009-10-25
6
use DBI::Custom::SQL::Template;
add test
yuki-kimoto authored on 2009-10-16
7

            
cleanup
yuki-kimoto authored on 2009-10-31
8
# Function for test name
9
my $test;
10
sub test {
11
    $test = shift;
12
}
13

            
cleanup
yuki-kimoto authored on 2009-10-31
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
yuki-kimoto authored on 2009-10-31
20
my $dbi;
21

            
cleanup
yuki-kimoto authored on 2009-10-22
22

            
cleanup
yuki-kimoto authored on 2009-10-31
23
test 'Constructor';
cleanup
yuki-kimoto authored on 2009-10-31
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',
cleanup
yuki-kimoto authored on 2009-10-31
35
    sql_template => $SQL_TMPL->{0},
cleanup
yuki-kimoto authored on 2009-10-31
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',
cleanup
yuki-kimoto authored on 2009-10-31
40
                sql_template => $SQL_TMPL->{0}}, $test);
cleanup
yuki-kimoto authored on 2009-10-31
41
isa_ok($dbi, 'DBI::Custom');
add test
yuki-kimoto authored on 2009-10-16
42

            
cleanup
yuki-kimoto authored on 2009-10-22
43

            
cleanup
yuki-kimoto authored on 2009-10-31
44
test 'Sub class constructor';
add test
yuki-kimoto authored on 2009-10-16
45
{
46
    package DBI::Custom::T1;
47
    use base 'DBI::Custom';
48
    
cleanup
yuki-kimoto authored on 2009-10-31
49
    __PACKAGE__
update document
yuki-kimoto authored on 2009-10-27
50
      ->user('a')
51
      ->password('b')
52
      ->data_source('c')
cleanup
yuki-kimoto authored on 2009-10-29
53
      ->dbi_options({d => 1, e => 2})
cleanup
yuki-kimoto authored on 2009-10-22
54
      ->filters(
55
          f => 3
56
      )
add formats add_format
yuki-kimoto authored on 2009-11-06
57
      ->formats(
58
          f => 3
59
      )
cleanup
yuki-kimoto authored on 2009-10-22
60
      ->bind_filter('f')
61
      ->fetch_filter('g')
62
      ->result_class('DBI::Custom::Result')
cleanup
yuki-kimoto authored on 2009-10-31
63
      ->sql_template($SQL_TMPL->{0})
cleanup
yuki-kimoto authored on 2009-10-22
64
    ;
add test
yuki-kimoto authored on 2009-10-16
65
}
cleanup
yuki-kimoto authored on 2009-10-31
66
$dbi = DBI::Custom::T1->new(
67
    user => 'ao',
68
    password => 'bo',
69
    data_source => 'co',
70
    dbi_options => {do => 10, eo => 20},
71
    filters => {
72
        fo => 30,
73
    },
add formats add_format
yuki-kimoto authored on 2009-11-06
74
    formats => {
75
        fo => 30,
76
    },
cleanup
yuki-kimoto authored on 2009-10-31
77
    bind_filter => 'fo',
78
    fetch_filter => 'go',
79
    result_class => 'ho',
cleanup
yuki-kimoto authored on 2009-10-31
80
    sql_template => $SQL_TMPL->{0},
cleanup
yuki-kimoto authored on 2009-10-31
81
);
82
is($dbi->user, 'ao', "$test : user");
83
is($dbi->password, 'bo', "$test : passowr");
84
is($dbi->data_source, 'co', "$test : data_source");
85
is_deeply($dbi->dbi_options, {do => 10, eo => 20}, "$test : dbi_options");
86
is_deeply(scalar $dbi->filters, {fo => 30}, "$test : filters");
add formats add_format
yuki-kimoto authored on 2009-11-06
87
is_deeply(scalar $dbi->formats, {fo => 30}, "$test : formats");
cleanup
yuki-kimoto authored on 2009-10-31
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");
91
is($dbi->sql_template->tag_start, 0, "$test : sql_template");
92
isa_ok($dbi, 'DBI::Custom::T1');
add test
yuki-kimoto authored on 2009-10-16
93

            
cleanup
yuki-kimoto authored on 2009-10-31
94
test 'Sub class constructor default';
95
$dbi = DBI::Custom::T1->new;
96
is($dbi->user, 'a', "$test : user");
97
is($dbi->password, 'b', "$test : password");
98
is($dbi->data_source, 'c', "$test : data_source");
99
is_deeply($dbi->dbi_options, {d => 1, e => 2}, "$test : dbi_options");
100
is_deeply({$dbi->filters}, {f => 3}, "$test : filters");
add formats add_format
yuki-kimoto authored on 2009-11-06
101
is_deeply({$dbi->formats}, {f => 3}, "$test : formats");
cleanup
yuki-kimoto authored on 2009-10-31
102
is($dbi->bind_filter, 'f', "$test : bind_filter");
103
is($dbi->fetch_filter, 'g', "$test : fetch_filter");
104
is($dbi->result_class, 'DBI::Custom::Result', "$test : result_class");
105
is($dbi->sql_template->tag_start, 0, "$test : sql_template");
106
isa_ok($dbi, 'DBI::Custom::T1');
add test
yuki-kimoto authored on 2009-10-16
107

            
cleanup
yuki-kimoto authored on 2009-10-31
108

            
cleanup
yuki-kimoto authored on 2009-10-31
109
test 'Sub sub class constructor default';
add test
yuki-kimoto authored on 2009-10-16
110
{
111
    package DBI::Custom::T1_2;
112
    use base 'DBI::Custom::T1';
113
}
cleanup
yuki-kimoto authored on 2009-10-31
114
$dbi = DBI::Custom::T1_2->new;
115
is($dbi->user, 'a', "$test : user");
116
is($dbi->password, 'b', "$test : passowrd");
117
is($dbi->data_source, 'c', "$test : data_source");
118
is_deeply($dbi->dbi_options, {d => 1, e => 2}, "$test : dbi_options");
119
is_deeply(scalar $dbi->filters, {f => 3}, "$test : filters");
add formats add_format
yuki-kimoto authored on 2009-11-06
120
is_deeply(scalar $dbi->formats, {f => 3}, "$test : formats");
cleanup
yuki-kimoto authored on 2009-10-31
121
is($dbi->bind_filter, 'f', "$test : bind_filter");
122
is($dbi->fetch_filter, 'g', "$test : fetch_filter");
123
is($dbi->result_class, 'DBI::Custom::Result', "$test : result_class");
124
is($dbi->sql_template->tag_start, 0, "$test sql_template");
125
isa_ok($dbi, 'DBI::Custom::T1_2');
add test
yuki-kimoto authored on 2009-10-16
126

            
cleanup
yuki-kimoto authored on 2009-10-31
127

            
128
test 'Customized sub class constructor default';
add test
yuki-kimoto authored on 2009-10-16
129
{
130
    package DBI::Custom::T1_3;
131
    use base 'DBI::Custom::T1';
132
    
cleanup
yuki-kimoto authored on 2009-10-31
133
    __PACKAGE__
update document
yuki-kimoto authored on 2009-10-27
134
      ->user('ao')
135
      ->password('bo')
136
      ->data_source('co')
cleanup
yuki-kimoto authored on 2009-10-29
137
      ->dbi_options({do => 10, eo => 20})
cleanup
yuki-kimoto authored on 2009-10-22
138
      ->filters(
139
        fo => 30
140
      )
add formats add_format
yuki-kimoto authored on 2009-11-06
141
      ->formats(
142
        fo => 30
143
      )
cleanup
yuki-kimoto authored on 2009-10-22
144
      ->bind_filter('fo')
145
      ->fetch_filter('go')
146
      ->result_class('ho')
cleanup
yuki-kimoto authored on 2009-10-31
147
      ->sql_template($SQL_TMPL->{1})
cleanup
yuki-kimoto authored on 2009-10-22
148
    ;
add test
yuki-kimoto authored on 2009-10-16
149
}
cleanup
yuki-kimoto authored on 2009-10-31
150
$dbi = DBI::Custom::T1_3->new;
151
is($dbi->user, 'ao', "$test : user");
152
is($dbi->password, 'bo', "$test : password");
153
is($dbi->data_source, 'co', "$test : data_source");
154
is_deeply($dbi->dbi_options, {do => 10, eo => 20}, "$test : dbi_options");
155
is_deeply(scalar $dbi->filters, {fo => 30}, "$test : filters");
add formats add_format
yuki-kimoto authored on 2009-11-06
156
is_deeply(scalar $dbi->formats, {fo => 30}, "$test : formats");
cleanup
yuki-kimoto authored on 2009-10-31
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");
160
is($dbi->sql_template->tag_start, 1, "$test : sql_template");
161
isa_ok($dbi, 'DBI::Custom::T1_3');
add test
yuki-kimoto authored on 2009-10-16
162

            
163

            
cleanup
yuki-kimoto authored on 2009-10-31
164
test 'Customized sub class constructor';
165
$dbi = DBI::Custom::T1_3->new(
166
    user => 'a',
167
    password => 'b',
168
    data_source => 'c',
169
    dbi_options => {d => 1, e => 2},
170
    filters => {
171
        f => 3,
172
    },
add formats add_format
yuki-kimoto authored on 2009-11-06
173
    formats => {
174
        f => 3,
175
    },
cleanup
yuki-kimoto authored on 2009-10-31
176
    bind_filter => 'f',
177
    fetch_filter => 'g',
178
    result_class => 'h',
cleanup
yuki-kimoto authored on 2009-10-31
179
    sql_template => $SQL_TMPL->{2},
cleanup
yuki-kimoto authored on 2009-10-31
180
);
181
is($dbi->user, 'a', "$test : user");
182
is($dbi->password, 'b', "$test : password");
183
is($dbi->data_source, 'c', "$test : data_source");
184
is_deeply($dbi->dbi_options, {d => 1, e => 2}, "$test : dbi_options");
185
is_deeply({$dbi->filters}, {f => 3}, "$test : filters");
add formats add_format
yuki-kimoto authored on 2009-11-06
186
is_deeply({$dbi->formats}, {f => 3}, "$test : formats");
cleanup
yuki-kimoto authored on 2009-10-31
187
is($dbi->bind_filter, 'f', "$test : bind_filter");
188
is($dbi->fetch_filter, 'g', "$test : fetch_filter");
189
is($dbi->result_class, 'h', "$test : result_class");
190
is($dbi->sql_template->tag_start, 2, "$test : sql_template");
191
isa_ok($dbi, 'DBI::Custom');
add test
yuki-kimoto authored on 2009-10-16
192

            
cleanup
yuki-kimoto authored on 2009-10-31
193

            
194
test 'add_filters';
195
$dbi = DBI::Custom->new;
196
$dbi->add_filter(a => sub {1});
197
is($dbi->filters->{a}->(), 1, $test);
198

            
add formats add_format
yuki-kimoto authored on 2009-11-06
199
test 'add_formats';
200
$dbi = DBI::Custom->new;
201
$dbi->add_format(a => sub {1});
202
is($dbi->formats->{a}->(), 1, $test);
203