DBIx-Custom / t / 01-core.t /
Newer Older
180 lines | 4.555kb
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;
6
use Scalar::Util qw/blessed/;
add tests
yuki-kimoto authored on 2009-10-25
7
use DBI::Custom::SQL::Template;
add test
yuki-kimoto authored on 2009-10-16
8

            
cleanup
yuki-kimoto authored on 2009-10-29
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
yuki-kimoto authored on 2009-10-22
12

            
add test
yuki-kimoto authored on 2009-10-16
13
{
14
    my $dbi = DBI::Custom->new(
update document
yuki-kimoto authored on 2009-10-27
15
        user => 'a',
16
        password => 'b',
17
        data_source => 'c',
cleanup
yuki-kimoto authored on 2009-10-29
18
        dbi_options => {d => 1, e => 2},
add test
yuki-kimoto authored on 2009-10-16
19
        filters => {
20
            f => 3,
21
        },
22
        bind_filter => 'f',
23
        fetch_filter => 'g',
cleanup
yuki-kimoto authored on 2009-10-22
24
        result_class => 'g',
25
        sql_template => $sql_tmpl1,
add test
yuki-kimoto authored on 2009-10-16
26
    );
update document
yuki-kimoto authored on 2009-10-27
27
    is_deeply($dbi,{user => 'a', password => 'b', data_source => 'c', 
cleanup
yuki-kimoto authored on 2009-10-29
28
                    dbi_options => {d => 1, e => 2}, filters => {f => 3}, bind_filter => 'f',
add tests
yuki-kimoto authored on 2009-10-25
29
                    fetch_filter => 'g', result_class => 'g',
update document
yuki-kimoto authored on 2009-10-27
30
                    sql_template => $sql_tmpl1}, 'new');
add test
yuki-kimoto authored on 2009-10-16
31
    
32
    isa_ok($dbi, 'DBI::Custom');
33
}
34

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

            
add test
yuki-kimoto authored on 2009-10-16
36
{
37
    package DBI::Custom::T1;
38
    use base 'DBI::Custom';
39
    
add tests
yuki-kimoto authored on 2009-10-25
40
    my $class = __PACKAGE__;
cleanup
yuki-kimoto authored on 2009-10-22
41
    
add tests
yuki-kimoto authored on 2009-10-25
42
    $class
update document
yuki-kimoto authored on 2009-10-27
43
      ->user('a')
44
      ->password('b')
45
      ->data_source('c')
cleanup
yuki-kimoto authored on 2009-10-29
46
      ->dbi_options({d => 1, e => 2})
cleanup
yuki-kimoto authored on 2009-10-22
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
yuki-kimoto authored on 2009-10-16
55
}
56
{
57
    my $dbi = DBI::Custom::T1->new(
update document
yuki-kimoto authored on 2009-10-27
58
        user => 'ao',
59
        password => 'bo',
60
        data_source => 'co',
cleanup
yuki-kimoto authored on 2009-10-29
61
        dbi_options => {do => 10, eo => 20},
add test
yuki-kimoto authored on 2009-10-16
62
        filters => {
63
            fo => 30,
64
        },
65
        bind_filter => 'fo',
66
        fetch_filter => 'go',
cleanup
yuki-kimoto authored on 2009-10-22
67
        result_class => 'ho',
68
        sql_template => $sql_tmpl1,
add test
yuki-kimoto authored on 2009-10-16
69
    );
cleanup
yuki-kimoto authored on 2009-10-22
70
    my $sql_tmpl = delete $dbi->{sql_template};
cleanup
yuki-kimoto authored on 2009-10-29
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
yuki-kimoto authored on 2009-10-22
73
                    ,filters => {fo => 30}, bind_filter => 'fo', fetch_filter => 'go', result_class => 'ho',
74
                    }, 'new arguments');
add test
yuki-kimoto authored on 2009-10-16
75
    
76
    isa_ok($dbi, 'DBI::Custom::T1');
77
}
78

            
79
{
80
    my $dbi = DBI::Custom::T1->new;
81
    
update document
yuki-kimoto authored on 2009-10-27
82
    is($dbi->user, 'a');
83
    is($dbi->password, 'b');
84
    is($dbi->data_source, 'c');
cleanup
yuki-kimoto authored on 2009-10-29
85
    is_deeply($dbi->dbi_options, {d => 1, e => 2});
add tests
yuki-kimoto authored on 2009-10-25
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
yuki-kimoto authored on 2009-10-29
90
    is($dbi->sql_template->tag_start, 0);
add test
yuki-kimoto authored on 2009-10-16
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
yuki-kimoto authored on 2009-10-27
103
    is($dbi->user, 'a');
104
    is($dbi->password, 'b');
105
    is($dbi->data_source, 'c');
cleanup
yuki-kimoto authored on 2009-10-29
106
    is_deeply($dbi->dbi_options, {d => 1, e => 2});
add tests
yuki-kimoto authored on 2009-10-25
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
yuki-kimoto authored on 2009-10-29
111
    is($dbi->sql_template->tag_start, 0);
add test
yuki-kimoto authored on 2009-10-16
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
yuki-kimoto authored on 2009-10-25
120
    my $class = __PACKAGE__;
add test
yuki-kimoto authored on 2009-10-16
121
        
add tests
yuki-kimoto authored on 2009-10-25
122
    $class
update document
yuki-kimoto authored on 2009-10-27
123
      ->user('ao')
124
      ->password('bo')
125
      ->data_source('co')
cleanup
yuki-kimoto authored on 2009-10-29
126
      ->dbi_options({do => 10, eo => 20})
cleanup
yuki-kimoto authored on 2009-10-22
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
yuki-kimoto authored on 2009-10-16
135
}
136

            
137
{
138
    my $dbi = DBI::Custom::T1_3->new;
139
    
update document
yuki-kimoto authored on 2009-10-27
140
    is($dbi->user, 'ao');
141
    is($dbi->password, 'bo');
142
    is($dbi->data_source, 'co');
cleanup
yuki-kimoto authored on 2009-10-29
143
    is_deeply($dbi->dbi_options, {do => 10, eo => 20});
add tests
yuki-kimoto authored on 2009-10-25
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
yuki-kimoto authored on 2009-10-29
148
    is($dbi->sql_template->tag_start, 1);
add test
yuki-kimoto authored on 2009-10-16
149
    
150
    isa_ok($dbi, 'DBI::Custom::T1_3');
151
}
152

            
153
{
154
    my $dbi = DBI::Custom::T1_3->new(
update document
yuki-kimoto authored on 2009-10-27
155
        user => 'a',
156
        password => 'b',
157
        data_source => 'c',
cleanup
yuki-kimoto authored on 2009-10-29
158
        dbi_options => {d => 1, e => 2},
add test
yuki-kimoto authored on 2009-10-16
159
        filters => {
160
            f => 3,
161
        },
162
        bind_filter => 'f',
163
        fetch_filter => 'g',
cleanup
yuki-kimoto authored on 2009-10-22
164
        result_class => 'h',
165
        sql_template => $sql_tmpl3,
add test
yuki-kimoto authored on 2009-10-16
166
    );
167
    
update document
yuki-kimoto authored on 2009-10-27
168
    is($dbi->user, 'a');
169
    is($dbi->password, 'b');
170
    is($dbi->data_source, 'c');
cleanup
yuki-kimoto authored on 2009-10-29
171
    is_deeply($dbi->dbi_options, {d => 1, e => 2});
update document
yuki-kimoto authored on 2009-10-27
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
yuki-kimoto authored on 2009-10-29
176
    is($dbi->sql_template->tag_start, 2);
add test
yuki-kimoto authored on 2009-10-16
177
    
178
    isa_ok($dbi, 'DBI::Custom');
179
}
180