ea77d81bbef6138fd343ab8975fde6907c3b0d93
[dbsrgits/DBIx-Class.git] / t / cdbi-sweet-t / 08pager.t
1 use strict;
2 use warnings;
3
4 use Test::More;
5
6 eval "use DBD::SQLite";
7 plan skip_all => 'needs DBD::SQLite for testing' if $@;
8
9 plan tests => 10;
10
11 use lib 't/lib';
12
13 use_ok('DBICTest::HelperRels');
14
15 DBICTest::CD->load_components(qw/CDBICompat::Pager/);
16
17 my ( $pager, $it ) = DBICTest::CD->page(
18     {},
19     { order_by => 'title',
20       rows => 3,
21       page => 1 } );
22       
23 cmp_ok( $pager->entries_on_this_page, '==', 3, "entries_on_this_page ok" );
24
25 cmp_ok( $pager->next_page, '==', 2, "next_page ok" );
26
27 is( $it->next->title, "Caterwaulin' Blues", "iterator->next ok" );
28
29 $it->next;
30 $it->next;
31
32 is( $it->next, undef, "next past end of page ok" );
33
34 ( $pager, $it ) = DBICTest::CD->page(
35     {},
36     { rows => 2,
37       page => 2,
38       disable_sql_paging => 1 } );
39
40 cmp_ok( $pager->total_entries, '==', 5, "disable_sql_paging total_entries ok" );
41
42 cmp_ok( $pager->previous_page, '==', 1, "disable_sql_paging previous_page ok" );
43
44 is( $it->next->title, "Caterwaulin' Blues", "disable_sql_paging iterator->next ok" );
45
46 $it->next;
47
48 is( $it->next, undef, "disable_sql_paging next past end of page ok" );
49
50 # based on a failing criteria submitted by waswas
51 ( $pager, $it ) = DBICTest::CD->page(
52     { title => [
53         -and => 
54             {
55                 -like => '%bees'
56             },
57             {
58                 -not_like => 'Forkful%'
59             }
60         ]
61     },
62     { rows => 5 }
63 );
64 is( $it->count, 1, "complex abstract count ok" );