cb1cee94a688e07529674ab741daa9750441698c
[dbsrgits/DBIx-Class.git] / t / cdbi / 30-pager.t
1 use strict;
2 use Test::More;
3
4 use lib 't/cdbi/testlib';
5 use Film;
6
7 my @film  = (
8   Film->create({ Title => 'Film 1' }),
9   Film->create({ Title => 'Film 2' }),
10   Film->create({ Title => 'Film 3' }),
11   Film->create({ Title => 'Film 4' }),
12   Film->create({ Title => 'Film 5' }),
13 );
14
15 # first page
16 my ( $pager, $it ) = Film->page(
17     {},
18     { rows => 3,
19       page => 1 }
20 );
21
22 is( $pager->entries_on_this_page, 3, "entries_on_this_page ok" );
23
24 is( $pager->next_page, 2, "next_page ok" );
25
26 is( $it->next->title, "Film 1", "iterator->next ok" );
27
28 $it->next;
29 $it->next;
30
31 is( $it->next, undef, "next past end of page ok" );
32
33 # second page
34 ( $pager, $it ) = Film->page(
35     {},
36     { rows => 3,
37       page => 2 }
38 );
39
40 is( $pager->entries_on_this_page, 2, "entries on second page ok" );
41
42 is( $it->next->title, "Film 4", "second page first title ok" );
43
44 done_testing;