DBIx-Custom / t / dbix-custom-core.t /
Newer Older
217 lines | 6.563kb
packaging one directory
yuki-kimoto authored on 2009-11-16
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
yuki-kimoto authored on 2009-12-17
29
    options => {d => 1, e => 2},
packaging one directory
yuki-kimoto authored on 2009-11-16
30
    filters => {
31
        f => 3,
32
    },
33
    bind_filter => 'f',
34
    fetch_filter => 'g',
35
    result_class => 'g',
version 0.0901
yuki-kimoto authored on 2009-12-17
36
    sql_tmpl => $SQL_TMPL->{0},
packaging one directory
yuki-kimoto authored on 2009-11-16
37
);
38
is_deeply($dbi,{user => 'a', database => 'a', password => 'b', data_source => 'c', 
version 0.0901
yuki-kimoto authored on 2009-12-17
39
                options => {d => 1, e => 2}, filters => {f => 3}, bind_filter => 'f',
packaging one directory
yuki-kimoto authored on 2009-11-16
40
                fetch_filter => 'g', result_class => 'g',
version 0.0901
yuki-kimoto authored on 2009-12-17
41
                sql_tmpl => $SQL_TMPL->{0}}, $test);
packaging one directory
yuki-kimoto authored on 2009-11-16
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
yuki-kimoto authored on 2009-12-17
55
      ->options({d => 1, e => 2})
catch up with Object::Simple...
yuki-kimoto authored on 2010-01-18
56
      ->filters({f => 3})
57
      ->formats({f => 3})
packaging one directory
yuki-kimoto authored on 2009-11-16
58
      ->bind_filter('f')
59
      ->fetch_filter('g')
60
      ->result_class('DBIx::Custom::Result')
version 0.0901
yuki-kimoto authored on 2009-12-17
61
      ->sql_tmpl($SQL_TMPL->{0})
packaging one directory
yuki-kimoto authored on 2009-11-16
62
    ;
63
}
64
$dbi = DBIx::Custom::T1->new(
65
    user => 'ao',
66
    database => 'ao',
67
    password => 'bo',
68
    data_source => 'co',
version 0.0901
yuki-kimoto authored on 2009-12-17
69
    options => {do => 10, eo => 20},
packaging one directory
yuki-kimoto authored on 2009-11-16
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
yuki-kimoto authored on 2009-12-17
79
    sql_tmpl => $SQL_TMPL->{0},
packaging one directory
yuki-kimoto authored on 2009-11-16
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
yuki-kimoto authored on 2009-12-17
85
is_deeply($dbi->options, {do => 10, eo => 20}, "$test : options");
packaging one directory
yuki-kimoto authored on 2009-11-16
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
yuki-kimoto authored on 2009-12-17
91
is($dbi->sql_tmpl->tag_start, 0, "$test : sql_tmpl");
packaging one directory
yuki-kimoto authored on 2009-11-16
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
yuki-kimoto authored on 2009-12-17
100
is_deeply($dbi->options, {d => 1, e => 2}, "$test : options");
catch up with Object::Simple...
yuki-kimoto authored on 2010-01-18
101
is_deeply($dbi->filters, {f => 3}, "$test : filters");
102
is_deeply($dbi->formats, {f => 3}, "$test : formats");
packaging one directory
yuki-kimoto authored on 2009-11-16
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
yuki-kimoto authored on 2009-12-17
106
is($dbi->sql_tmpl->tag_start, 0, "$test : sql_tmpl");
packaging one directory
yuki-kimoto authored on 2009-11-16
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
yuki-kimoto authored on 2009-12-17
120
is_deeply($dbi->options, {d => 1, e => 2}, "$test : options");
packaging one directory
yuki-kimoto authored on 2009-11-16
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
yuki-kimoto authored on 2009-12-17
126
is($dbi->sql_tmpl->tag_start, 0, "$test sql_tmpl");
packaging one directory
yuki-kimoto authored on 2009-11-16
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
yuki-kimoto authored on 2009-12-17
140
      ->options({do => 10, eo => 20})
catch up with Object::Simple...
yuki-kimoto authored on 2010-01-18
141
      ->filters({fo => 30})
142
      ->formats({fo => 30})
packaging one directory
yuki-kimoto authored on 2009-11-16
143
      ->bind_filter('fo')
144
      ->fetch_filter('go')
145
      ->result_class('ho')
version 0.0901
yuki-kimoto authored on 2009-12-17
146
      ->sql_tmpl($SQL_TMPL->{1})
packaging one directory
yuki-kimoto authored on 2009-11-16
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
yuki-kimoto authored on 2009-12-17
154
is_deeply($dbi->options, {do => 10, eo => 20}, "$test : options");
packaging one directory
yuki-kimoto authored on 2009-11-16
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
yuki-kimoto authored on 2009-12-17
160
is($dbi->sql_tmpl->tag_start, 1, "$test : sql_tmpl");
packaging one directory
yuki-kimoto authored on 2009-11-16
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
yuki-kimoto authored on 2009-12-17
170
    options => {d => 1, e => 2},
packaging one directory
yuki-kimoto authored on 2009-11-16
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
yuki-kimoto authored on 2009-12-17
180
    sql_tmpl => $SQL_TMPL->{2},
packaging one directory
yuki-kimoto authored on 2009-11-16
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
yuki-kimoto authored on 2009-12-17
186
is_deeply($dbi->options, {d => 1, e => 2}, "$test : options");
catch up with Object::Simple...
yuki-kimoto authored on 2010-01-18
187
is_deeply($dbi->filters, {f => 3}, "$test : filters");
188
is_deeply($dbi->formats, {f => 3}, "$test : formats");
packaging one directory
yuki-kimoto authored on 2009-11-16
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
yuki-kimoto authored on 2009-12-17
192
is($dbi->sql_tmpl->tag_start, 2, "$test : sql_tmpl");
packaging one directory
yuki-kimoto authored on 2009-11-16
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
yuki-kimoto authored on 2009-12-17
213

            
214
test 'Accessor';
215
$dbi = DBIx::Custom->new;
catch up with Object::Simple...
yuki-kimoto authored on 2010-01-18
216
$dbi->options({opt1 => 1, opt2 => 2});
version 0.0901
yuki-kimoto authored on 2009-12-17
217
is_deeply(scalar $dbi->options, {opt1 => 1, opt2 => 2}, "$test : options");