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