Refactored pagination into search method, Sweet syntax is now in Compat
[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 $it = DBICTest::CD->search(
11     {},
12     { order_by => 'title',
13       rows => 3,
14       page => 1 }
15 );
16 my $pager = DBICTest::CD->page;
17
18 is( $pager->entries_on_this_page, 3, "entries_on_this_page ok" );
19
20 is( $pager->next_page, 2, "next_page ok" );
21
22 is( $it->next->title, "Caterwaulin' Blues", "iterator->next ok" );
23
24 $it->next;
25 $it->next;
26
27 is( $it->next, undef, "next past end of page ok" );
28
29 # second page, testing with array 
30 my @page2 = DBICTest::CD->search( 
31     {},
32     { order_by => 'title',
33       rows => 3,
34       page => 2 }
35 );
36 $pager = DBICTest::CD->page;
37
38 is( $pager->entries_on_this_page, 2, "entries on second page ok" );
39
40 is( $page2[0]->title, "Generic Manufactured Singles", "second page first title ok" );
41
42 # based on a failing criteria submitted by waswas
43 # requires SQL::Abstract >= 1.20
44 $it = DBICTest::CD->search(
45     { title => [
46         -and => 
47             {
48                 -like => '%bees'
49             },
50             {
51                 -not_like => 'Forkful%'
52             }
53         ]
54     },
55     { rows => 5 }
56 );
57 is( $it->count, 1, "complex abstract count ok" );