Added pager support, same syntax as Sweet. Also fixed a few issues with ResultSet...
[dbsrgits/DBIx-Class.git] / t / 07pager.t
1 use Test::More;
2
3 plan tests => 8;
4
5 use lib qw(t/lib);
6
7 use_ok('DBICTest');
8
9 # first page
10 my ( $pager, $it ) = DBICTest::CD->page(
11     {},
12     { order_by => 'title',
13       rows => 3,
14       page => 1 }
15 );
16       
17 is( $pager->entries_on_this_page, 3, "entries_on_this_page ok" );
18
19 is( $pager->next_page, 2, "next_page ok" );
20
21 is( $it->next->title, "Caterwaulin' Blues", "iterator->next ok" );
22
23 $it->next;
24 $it->next;
25
26 is( $it->next, undef, "next past end of page ok" );
27
28 # second page
29 ( $pager, $it ) = DBICTest::CD->page( 
30     {},
31     { order_by => 'title',
32       rows => 3,
33       page => 2 }
34 );
35
36 is( $pager->entries_on_this_page, 2, "entries on second page ok" );
37
38 is( $it->next->title, "Generic Manufactured Singles", "second page first title ok" );
39
40 # XXX: Should we support disable_sql_paging?
41 #( $pager, $it ) = DBICTest::CD->page(
42 #    {},
43 #    { rows => 2,
44 #      page => 2,
45 #      disable_sql_paging => 1 } );
46 #
47 #cmp_ok( $pager->total_entries, '==', 5, "disable_sql_paging total_entries ok" );
48 #
49 #cmp_ok( $pager->previous_page, '==', 1, "disable_sql_paging previous_page ok" );
50 #
51 #is( $it->next->title, "Caterwaulin' Blues", "disable_sql_paging iterator->next ok" );
52 #
53 #$it->next;
54 #
55 #is( $it->next, undef, "disable_sql_paging next past end of page ok" );
56
57 # based on a failing criteria submitted by waswas
58 # requires SQL::Abstract >= 1.20
59 ( $pager, $it ) = DBICTest::CD->page(
60     { title => [
61         -and => 
62             {
63                 -like => '%bees'
64             },
65             {
66                 -not_like => 'Forkful%'
67             }
68         ]
69     },
70     { rows => 5 }
71 );
72 is( $it->count, 1, "complex abstract count ok" );