DBIx-Custom / t / dbix-custom-core.t /
Newer Older
103 lines | 2.314kb
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',
29
    filters => {
30
        f => 3,
31
    },
cleanup
yuki-kimoto authored on 2010-04-28
32
    default_bind_filter => 'f',
33
    default_fetch_filter => 'g',
packaging one directory
yuki-kimoto authored on 2009-11-16
34
    result_class => 'g',
removed register_format()
yuki-kimoto authored on 2010-05-26
35
    sql_template => $SQL_TMPL->{0},
packaging one directory
yuki-kimoto authored on 2009-11-16
36
);
37
is_deeply($dbi,{user => 'a', database => 'a', password => 'b', data_source => 'c', 
update document
yuki-kimoto authored on 2010-05-27
38
                filters => {f => 3}, default_bind_filter => 'f',
cleanup
yuki-kimoto authored on 2010-04-28
39
                default_fetch_filter => 'g', result_class => 'g',
removed register_format()
yuki-kimoto authored on 2010-05-26
40
                sql_template => $SQL_TMPL->{0}}, $test);
packaging one directory
yuki-kimoto authored on 2009-11-16
41
isa_ok($dbi, 'DBIx::Custom');
42

            
43

            
44
test 'Sub class constructor';
45
{
46
    package DBIx::Custom::T1;
47
    use base 'DBIx::Custom';
48
    
49
    __PACKAGE__
catch up with Object::Simple...
yuki-kimoto authored on 2010-01-18
50
      ->filters({f => 3})
packaging one directory
yuki-kimoto authored on 2009-11-16
51
    ;
52
}
53
$dbi = DBIx::Custom::T1->new(
54
    filters => {
55
        fo => 30,
56
    },
57
);
58
is_deeply(scalar $dbi->filters, {fo => 30}, "$test : filters");
59

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

            
65

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

            
75

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

            
89

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

            
99

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