DBIx-Custom / t / dbix-custom-core.t /
Newer Older
117 lines | 2.707kb
added experimental expand me...
yuki-kimoto authored on 2010-10-20
1
use Test::More tests => 15;
packaging one directory
yuki-kimoto authored on 2009-11-16
2
use strict;
3
use warnings;
4

            
5
use DBIx::Custom;
fixed tests
yuki-kimoto authored on 2010-08-06
6
use DBIx::Custom::QueryBuilder;
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
my $dbi;
removed DBIx::Custom::Query ...
yuki-kimoto authored on 2010-08-12
16
my $query_builder;
packaging one directory
yuki-kimoto authored on 2009-11-16
17

            
18
test 'Constructor';
removed DBIx::Custom::Query ...
yuki-kimoto authored on 2010-08-12
19
$query_builder = DBIx::Custom::QueryBuilder->new;
packaging one directory
yuki-kimoto authored on 2009-11-16
20
$dbi = DBIx::Custom->new(
21
    user => 'a',
22
    database => 'a',
23
    password => 'b',
24
    data_source => 'c',
25
    filters => {
26
        f => 3,
27
    },
cleanup
yuki-kimoto authored on 2010-04-28
28
    default_bind_filter => 'f',
29
    default_fetch_filter => 'g',
packaging one directory
yuki-kimoto authored on 2009-11-16
30
    result_class => 'g',
removed DBIx::Custom::Query ...
yuki-kimoto authored on 2010-08-12
31
    query_builder => $query_builder,
packaging one directory
yuki-kimoto authored on 2009-11-16
32
);
33
is_deeply($dbi,{user => 'a', database => 'a', password => 'b', data_source => 'c', 
update document
yuki-kimoto authored on 2010-05-27
34
                filters => {f => 3}, default_bind_filter => 'f',
cleanup
yuki-kimoto authored on 2010-04-28
35
                default_fetch_filter => 'g', result_class => 'g',
removed DBIx::Custom::Query ...
yuki-kimoto authored on 2010-08-12
36
                query_builder => $query_builder}, $test);
packaging one directory
yuki-kimoto authored on 2009-11-16
37
isa_ok($dbi, 'DBIx::Custom');
38

            
39

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

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

            
61

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

            
71

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

            
85

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

            
95

            
some changed
yuki-kimoto authored on 2010-05-02
96
test 'register_filters';
packaging one directory
yuki-kimoto authored on 2009-11-16
97
$dbi = DBIx::Custom->new;
some changed
yuki-kimoto authored on 2010-05-02
98
$dbi->register_filter(a => sub {1});
packaging one directory
yuki-kimoto authored on 2009-11-16
99
is($dbi->filters->{a}->(), 1, $test);
changed argument of tag proc...
yuki-kimoto authored on 2010-08-03
100
$dbi->register_filter({b => sub {2}});
101
is($dbi->filters->{b}->(), 2, $test);
102

            
103

            
added experimental expand me...
yuki-kimoto authored on 2010-10-20
104
test 'expand';
105
{
106
    $dbi = DBIx::Custom->new;
107
    my $source = {books => {title => 'Perl', author => 'Ken'}};
108
    is_deeply({$dbi->expand($source)}, 
109
              {'books.title' => 'Perl', 'books.author' => 'Ken'});
110
}
111
{
112
    $dbi = DBIx::Custom->new;
113
    my %source = (books => {title => 'Perl', author => 'Ken'});
114
    is_deeply({$dbi->expand(%source)}, 
115
              {'books.title' => 'Perl', 'books.author' => 'Ken'});
116
}
117