f7cb86764743006dea16eb30e8fa531f6f547f5a
[dbsrgits/DBIx-Class.git] / t / cdbi / 30-pager.t
1 use strict;
2 use Test::More;
3
4 BEGIN {
5   eval "use DBIx::Class::CDBICompat;";
6   if ($@) {
7     plan (skip_all => 'Class::Trigger and DBIx::ContextualFetch required');
8     next;
9   }
10   eval "use DBD::SQLite";
11   plan $@ ? (skip_all => 'needs DBD::SQLite for testing') : (tests => 6);
12 }
13
14 use lib 't/cdbi/testlib';
15 use Film;
16
17 my @film  = (
18   Film->create({ Title => 'Film 1' }),
19   Film->create({ Title => 'Film 2' }),
20   Film->create({ Title => 'Film 3' }),
21   Film->create({ Title => 'Film 4' }),
22   Film->create({ Title => 'Film 5' }),
23 );
24
25 # first page
26 my ( $pager, $it ) = Film->page(
27     {},
28     { rows => 3,
29       page => 1 }
30 );
31
32 is( $pager->entries_on_this_page, 3, "entries_on_this_page ok" );
33
34 is( $pager->next_page, 2, "next_page ok" );
35
36 is( $it->next->title, "Film 1", "iterator->next ok" );
37
38 $it->next;
39 $it->next;
40
41 is( $it->next, undef, "next past end of page ok" );
42
43 # second page
44 ( $pager, $it ) = Film->page( 
45     {},
46     { rows => 3,
47       page => 2 }
48 );
49
50 is( $pager->entries_on_this_page, 2, "entries on second page ok" );
51
52 is( $it->next->title, "Film 4", "second page first title ok" );