DBIx-Custom / t / dbix-custom-core.t /
Newer Older
127 lines | 3.078kb
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
    },
cleanup
yuki-kimoto authored on 2010-04-28
33
    default_bind_filter => 'f',
34
    default_fetch_filter => 'g',
packaging one directory
yuki-kimoto authored on 2009-11-16
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', 
cleanup
yuki-kimoto authored on 2010-04-28
39
                options => {d => 1, e => 2}, filters => {f => 3}, default_bind_filter => 'f',
40
                default_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__
catch up with Object::Simple...
yuki-kimoto authored on 2010-01-18
51
      ->filters({f => 3})
52
      ->formats({f => 3})
packaging one directory
yuki-kimoto authored on 2009-11-16
53
    ;
54
}
55
$dbi = DBIx::Custom::T1->new(
56
    filters => {
57
        fo => 30,
58
    },
59
    formats => {
60
        fo => 30,
61
    },
62
);
63
is_deeply(scalar $dbi->filters, {fo => 30}, "$test : filters");
64
is_deeply(scalar $dbi->formats, {fo => 30}, "$test : formats");
65

            
66
test 'Sub class constructor default';
67
$dbi = DBIx::Custom::T1->new;
catch up with Object::Simple...
yuki-kimoto authored on 2010-01-18
68
is_deeply($dbi->filters, {f => 3}, "$test : filters");
69
is_deeply($dbi->formats, {f => 3}, "$test : formats");
packaging one directory
yuki-kimoto authored on 2009-11-16
70
isa_ok($dbi, 'DBIx::Custom::T1');
71

            
72

            
73
test 'Sub sub class constructor default';
74
{
75
    package DBIx::Custom::T1_2;
76
    use base 'DBIx::Custom::T1';
77
}
78
$dbi = DBIx::Custom::T1_2->new;
79
is_deeply(scalar $dbi->filters, {f => 3}, "$test : filters");
80
is_deeply(scalar $dbi->formats, {f => 3}, "$test : formats");
81
isa_ok($dbi, 'DBIx::Custom::T1_2');
82

            
83

            
84
test 'Customized sub class constructor default';
85
{
86
    package DBIx::Custom::T1_3;
87
    use base 'DBIx::Custom::T1';
88
    
89
    __PACKAGE__
catch up with Object::Simple...
yuki-kimoto authored on 2010-01-18
90
      ->filters({fo => 30})
91
      ->formats({fo => 30})
packaging one directory
yuki-kimoto authored on 2009-11-16
92
    ;
93
}
94
$dbi = DBIx::Custom::T1_3->new;
95
is_deeply(scalar $dbi->filters, {fo => 30}, "$test : filters");
96
is_deeply(scalar $dbi->formats, {fo => 30}, "$test : formats");
97
isa_ok($dbi, 'DBIx::Custom::T1_3');
98

            
99

            
100
test 'Customized sub class constructor';
101
$dbi = DBIx::Custom::T1_3->new(
102
    filters => {
103
        f => 3,
104
    },
105
    formats => {
106
        f => 3,
107
    },
108
);
catch up with Object::Simple...
yuki-kimoto authored on 2010-01-18
109
is_deeply($dbi->filters, {f => 3}, "$test : filters");
110
is_deeply($dbi->formats, {f => 3}, "$test : formats");
packaging one directory
yuki-kimoto authored on 2009-11-16
111
isa_ok($dbi, 'DBIx::Custom');
112

            
113

            
114
test 'add_filters';
115
$dbi = DBIx::Custom->new;
116
$dbi->add_filter(a => sub {1});
117
is($dbi->filters->{a}->(), 1, $test);
118

            
119
test 'add_formats';
120
$dbi = DBIx::Custom->new;
121
$dbi->add_format(a => sub {1});
122
is($dbi->formats->{a}->(), 1, $test);
123

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