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

            
Version 0.0101 release
yuki-kimoto authored on 2009-11-08
5
use DBIx::Custom;
6
use DBIx::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 = {
Version 0.0101 release
yuki-kimoto authored on 2009-11-08
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)
cleanup
yuki-kimoto authored on 2009-10-31
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';
Version 0.0101 release
yuki-kimoto authored on 2009-11-08
24
$dbi = DBIx::Custom->new(
cleanup
yuki-kimoto authored on 2009-10-31
25
    user => 'a',
add database method
yuki-kimoto authored on 2009-11-06
26
    database => 'a',
cleanup
yuki-kimoto authored on 2009-10-31
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
yuki-kimoto authored on 2009-10-31
36
    sql_template => $SQL_TMPL->{0},
cleanup
yuki-kimoto authored on 2009-10-31
37
);
add database method
yuki-kimoto authored on 2009-11-06
38
is_deeply($dbi,{user => 'a', database => 'a', password => 'b', data_source => 'c', 
cleanup
yuki-kimoto authored on 2009-10-31
39
                dbi_options => {d => 1, e => 2}, filters => {f => 3}, bind_filter => 'f',
40
                fetch_filter => 'g', result_class => 'g',
cleanup
yuki-kimoto authored on 2009-10-31
41
                sql_template => $SQL_TMPL->{0}}, $test);
Version 0.0101 release
yuki-kimoto authored on 2009-11-08
42
isa_ok($dbi, 'DBIx::Custom');
add test
yuki-kimoto authored on 2009-10-16
43

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

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

            
cleanup
yuki-kimoto authored on 2009-10-31
98
test 'Sub class constructor default';
Version 0.0101 release
yuki-kimoto authored on 2009-11-08
99
$dbi = DBIx::Custom::T1->new;
cleanup
yuki-kimoto authored on 2009-10-31
100
is($dbi->user, 'a', "$test : user");
add database method
yuki-kimoto authored on 2009-11-06
101
is($dbi->database, 'a', "$test : database");
cleanup
yuki-kimoto authored on 2009-10-31
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
yuki-kimoto authored on 2009-11-06
106
is_deeply({$dbi->formats}, {f => 3}, "$test : formats");
cleanup
yuki-kimoto authored on 2009-10-31
107
is($dbi->bind_filter, 'f', "$test : bind_filter");
108
is($dbi->fetch_filter, 'g', "$test : fetch_filter");
Version 0.0101 release
yuki-kimoto authored on 2009-11-08
109
is($dbi->result_class, 'DBIx::Custom::Result', "$test : result_class");
cleanup
yuki-kimoto authored on 2009-10-31
110
is($dbi->sql_template->tag_start, 0, "$test : sql_template");
Version 0.0101 release
yuki-kimoto authored on 2009-11-08
111
isa_ok($dbi, 'DBIx::Custom::T1');
add test
yuki-kimoto authored on 2009-10-16
112

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

            
cleanup
yuki-kimoto authored on 2009-10-31
114
test 'Sub sub class constructor default';
add test
yuki-kimoto authored on 2009-10-16
115
{
Version 0.0101 release
yuki-kimoto authored on 2009-11-08
116
    package DBIx::Custom::T1_2;
117
    use base 'DBIx::Custom::T1';
add test
yuki-kimoto authored on 2009-10-16
118
}
Version 0.0101 release
yuki-kimoto authored on 2009-11-08
119
$dbi = DBIx::Custom::T1_2->new;
cleanup
yuki-kimoto authored on 2009-10-31
120
is($dbi->user, 'a', "$test : user");
add database method
yuki-kimoto authored on 2009-11-06
121
is($dbi->database, 'a', "$test : database");
cleanup
yuki-kimoto authored on 2009-10-31
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
yuki-kimoto authored on 2009-11-06
126
is_deeply(scalar $dbi->formats, {f => 3}, "$test : formats");
cleanup
yuki-kimoto authored on 2009-10-31
127
is($dbi->bind_filter, 'f', "$test : bind_filter");
128
is($dbi->fetch_filter, 'g', "$test : fetch_filter");
Version 0.0101 release
yuki-kimoto authored on 2009-11-08
129
is($dbi->result_class, 'DBIx::Custom::Result', "$test : result_class");
cleanup
yuki-kimoto authored on 2009-10-31
130
is($dbi->sql_template->tag_start, 0, "$test sql_template");
Version 0.0101 release
yuki-kimoto authored on 2009-11-08
131
isa_ok($dbi, 'DBIx::Custom::T1_2');
add test
yuki-kimoto authored on 2009-10-16
132

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

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

            
171

            
cleanup
yuki-kimoto authored on 2009-10-31
172
test 'Customized sub class constructor';
Version 0.0101 release
yuki-kimoto authored on 2009-11-08
173
$dbi = DBIx::Custom::T1_3->new(
cleanup
yuki-kimoto authored on 2009-10-31
174
    user => 'a',
add database method
yuki-kimoto authored on 2009-11-06
175
    database => 'a',
cleanup
yuki-kimoto authored on 2009-10-31
176
    password => 'b',
177
    data_source => 'c',
178
    dbi_options => {d => 1, e => 2},
179
    filters => {
180
        f => 3,
181
    },
add formats add_format
yuki-kimoto authored on 2009-11-06
182
    formats => {
183
        f => 3,
184
    },
cleanup
yuki-kimoto authored on 2009-10-31
185
    bind_filter => 'f',
186
    fetch_filter => 'g',
187
    result_class => 'h',
cleanup
yuki-kimoto authored on 2009-10-31
188
    sql_template => $SQL_TMPL->{2},
cleanup
yuki-kimoto authored on 2009-10-31
189
);
190
is($dbi->user, 'a', "$test : user");
add database method
yuki-kimoto authored on 2009-11-06
191
is($dbi->database, 'a', "$test : database");
cleanup
yuki-kimoto authored on 2009-10-31
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
yuki-kimoto authored on 2009-11-06
196
is_deeply({$dbi->formats}, {f => 3}, "$test : formats");
cleanup
yuki-kimoto authored on 2009-10-31
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");
Version 0.0101 release
yuki-kimoto authored on 2009-11-08
201
isa_ok($dbi, 'DBIx::Custom');
add test
yuki-kimoto authored on 2009-10-16
202

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

            
204
test 'add_filters';
Version 0.0101 release
yuki-kimoto authored on 2009-11-08
205
$dbi = DBIx::Custom->new;
cleanup
yuki-kimoto authored on 2009-10-31
206
$dbi->add_filter(a => sub {1});
207
is($dbi->filters->{a}->(), 1, $test);
208

            
add formats add_format
yuki-kimoto authored on 2009-11-06
209
test 'add_formats';
Version 0.0101 release
yuki-kimoto authored on 2009-11-08
210
$dbi = DBIx::Custom->new;
add formats add_format
yuki-kimoto authored on 2009-11-06
211
$dbi->add_format(a => sub {1});
212
is($dbi->formats->{a}->(), 1, $test);
213