DBIx-Custom / t / dbix-custom-core.t /
Newer Older
109 lines | 2.535kb
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;
add all tests
yuki-kimoto authored on 2010-05-01
6
use DBIx::Custom::SQLTemplate;
packaging one directory
yuki-kimoto authored on 2009-11-16
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 = {
add all tests
yuki-kimoto authored on 2010-05-01
16
    0 => DBIx::Custom::SQLTemplate->new->tag_start(0),
17
    1 => DBIx::Custom::SQLTemplate->new->tag_start(1),
18
    2 => DBIx::Custom::SQLTemplate->new->tag_start(2)
packaging one directory
yuki-kimoto authored on 2009-11-16
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',
removed register_format()
yuki-kimoto authored on 2010-05-26
36
    sql_template => $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',
removed register_format()
yuki-kimoto authored on 2010-05-26
41
                sql_template => $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})
packaging one directory
yuki-kimoto authored on 2009-11-16
52
    ;
53
}
54
$dbi = DBIx::Custom::T1->new(
55
    filters => {
56
        fo => 30,
57
    },
58
);
59
is_deeply(scalar $dbi->filters, {fo => 30}, "$test : filters");
60

            
61
test 'Sub class constructor default';
62
$dbi = DBIx::Custom::T1->new;
catch up with Object::Simple...
yuki-kimoto authored on 2010-01-18
63
is_deeply($dbi->filters, {f => 3}, "$test : filters");
packaging one directory
yuki-kimoto authored on 2009-11-16
64
isa_ok($dbi, 'DBIx::Custom::T1');
65

            
66

            
67
test 'Sub sub class constructor default';
68
{
69
    package DBIx::Custom::T1_2;
70
    use base 'DBIx::Custom::T1';
71
}
72
$dbi = DBIx::Custom::T1_2->new;
73
is_deeply(scalar $dbi->filters, {f => 3}, "$test : filters");
74
isa_ok($dbi, 'DBIx::Custom::T1_2');
75

            
76

            
77
test 'Customized sub class constructor default';
78
{
79
    package DBIx::Custom::T1_3;
80
    use base 'DBIx::Custom::T1';
81
    
82
    __PACKAGE__
catch up with Object::Simple...
yuki-kimoto authored on 2010-01-18
83
      ->filters({fo => 30})
packaging one directory
yuki-kimoto authored on 2009-11-16
84
    ;
85
}
86
$dbi = DBIx::Custom::T1_3->new;
87
is_deeply(scalar $dbi->filters, {fo => 30}, "$test : filters");
88
isa_ok($dbi, 'DBIx::Custom::T1_3');
89

            
90

            
91
test 'Customized sub class constructor';
92
$dbi = DBIx::Custom::T1_3->new(
93
    filters => {
94
        f => 3,
95
    },
96
);
catch up with Object::Simple...
yuki-kimoto authored on 2010-01-18
97
is_deeply($dbi->filters, {f => 3}, "$test : filters");
packaging one directory
yuki-kimoto authored on 2009-11-16
98
isa_ok($dbi, 'DBIx::Custom');
99

            
100

            
some changed
yuki-kimoto authored on 2010-05-02
101
test 'register_filters';
packaging one directory
yuki-kimoto authored on 2009-11-16
102
$dbi = DBIx::Custom->new;
some changed
yuki-kimoto authored on 2010-05-02
103
$dbi->register_filter(a => sub {1});
packaging one directory
yuki-kimoto authored on 2009-11-16
104
is($dbi->filters->{a}->(), 1, $test);
105

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