DBIx-Custom / t / 01-core.t /
Newer Older
181 lines | 5.415kb
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
      )
57
      ->bind_filter('f')
58
      ->fetch_filter('g')
59
      ->result_class('DBI::Custom::Result')
cleanup
yuki-kimoto authored on 2009-10-31
60
      ->sql_template($SQL_TMPL->{0})
cleanup
yuki-kimoto authored on 2009-10-22
61
    ;
add test
yuki-kimoto authored on 2009-10-16
62
}
cleanup
yuki-kimoto authored on 2009-10-31
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',
cleanup
yuki-kimoto authored on 2009-10-31
74
    sql_template => $SQL_TMPL->{0},
cleanup
yuki-kimoto authored on 2009-10-31
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
yuki-kimoto authored on 2009-10-16
86

            
cleanup
yuki-kimoto authored on 2009-10-31
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
yuki-kimoto authored on 2009-10-16
99

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

            
cleanup
yuki-kimoto authored on 2009-10-31
101
test 'Sub sub class constructor default';
add test
yuki-kimoto authored on 2009-10-16
102
{
103
    package DBI::Custom::T1_2;
104
    use base 'DBI::Custom::T1';
105
}
cleanup
yuki-kimoto authored on 2009-10-31
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
yuki-kimoto authored on 2009-10-16
117

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

            
119
test 'Customized sub class constructor default';
add test
yuki-kimoto authored on 2009-10-16
120
{
121
    package DBI::Custom::T1_3;
122
    use base 'DBI::Custom::T1';
123
    
cleanup
yuki-kimoto authored on 2009-10-31
124
    __PACKAGE__
update document
yuki-kimoto authored on 2009-10-27
125
      ->user('ao')
126
      ->password('bo')
127
      ->data_source('co')
cleanup
yuki-kimoto authored on 2009-10-29
128
      ->dbi_options({do => 10, eo => 20})
cleanup
yuki-kimoto authored on 2009-10-22
129
      ->filters(
130
        fo => 30
131
      )
132
      ->bind_filter('fo')
133
      ->fetch_filter('go')
134
      ->result_class('ho')
cleanup
yuki-kimoto authored on 2009-10-31
135
      ->sql_template($SQL_TMPL->{1})
cleanup
yuki-kimoto authored on 2009-10-22
136
    ;
add test
yuki-kimoto authored on 2009-10-16
137
}
cleanup
yuki-kimoto authored on 2009-10-31
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
yuki-kimoto authored on 2009-10-16
149

            
150

            
cleanup
yuki-kimoto authored on 2009-10-31
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',
cleanup
yuki-kimoto authored on 2009-10-31
163
    sql_template => $SQL_TMPL->{2},
cleanup
yuki-kimoto authored on 2009-10-31
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
yuki-kimoto authored on 2009-10-16
175

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

            
177
test 'add_filters';
178
$dbi = DBI::Custom->new;
179
$dbi->add_filter(a => sub {1});
180
is($dbi->filters->{a}->(), 1, $test);
181