Merge 'trunk' into 'handle_all_storage_methods_in_replicated'
[dbsrgits/DBIx-Class.git] / t / cdbi / 30-pager.t
CommitLineData
50891152 1use strict;
2use Test::More;
3
4BEGIN {
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
14use lib 't/cdbi/testlib';
15use Film;
16
17my @film = (
6a3bf251 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' }),
50891152 23);
24
25# first page
26my ( $pager, $it ) = Film->page(
27 {},
28 { rows => 3,
29 page => 1 }
30);
31
32is( $pager->entries_on_this_page, 3, "entries_on_this_page ok" );
33
34is( $pager->next_page, 2, "next_page ok" );
35
36is( $it->next->title, "Film 1", "iterator->next ok" );
37
38$it->next;
39$it->next;
40
41is( $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
50is( $pager->entries_on_this_page, 2, "entries on second page ok" );
51
52is( $it->next->title, "Film 4", "second page first title ok" );