Massive cleanup of DateTime test dependencies, other interim
[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   }
9   plan tests => 6;
10 }
11
12 use lib 't/cdbi/testlib';
13 use Film;
14
15 my @film  = (
16   Film->create({ Title => 'Film 1' }),
17   Film->create({ Title => 'Film 2' }),
18   Film->create({ Title => 'Film 3' }),
19   Film->create({ Title => 'Film 4' }),
20   Film->create({ Title => 'Film 5' }),
21 );
22
23 # first page
24 my ( $pager, $it ) = Film->page(
25     {},
26     { rows => 3,
27       page => 1 }
28 );
29
30 is( $pager->entries_on_this_page, 3, "entries_on_this_page ok" );
31
32 is( $pager->next_page, 2, "next_page ok" );
33
34 is( $it->next->title, "Film 1", "iterator->next ok" );
35
36 $it->next;
37 $it->next;
38
39 is( $it->next, undef, "next past end of page ok" );
40
41 # second page
42 ( $pager, $it ) = Film->page( 
43     {},
44     { rows => 3,
45       page => 2 }
46 );
47
48 is( $pager->entries_on_this_page, 2, "entries on second page ok" );
49
50 is( $it->next->title, "Film 4", "second page first title ok" );