File: 30-pager.t

package info (click to toggle)
libdbix-class-perl 0.08010-2
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 2,052 kB
  • ctags: 1,064
  • sloc: perl: 10,536; sql: 225; makefile: 45
file content (52 lines) | stat: -rwxr-xr-x 1,135 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
use strict;
use Test::More;

BEGIN {
  eval "use DBIx::Class::CDBICompat;";
  if ($@) {
    plan (skip_all => 'Class::Trigger and DBIx::ContextualFetch required');
    next;
  }
  eval "use DBD::SQLite";
  plan $@ ? (skip_all => 'needs DBD::SQLite for testing') : (tests => 6);
}

use lib 't/testlib';
use Film;

my @film  = (
	Film->create({ Title => 'Film 1' }),
	Film->create({ Title => 'Film 2' }),
	Film->create({ Title => 'Film 3' }),
	Film->create({ Title => 'Film 4' }),
	Film->create({ Title => 'Film 5' }),
);

# first page
my ( $pager, $it ) = Film->page(
    {},
    { rows => 3,
      page => 1 }
);

is( $pager->entries_on_this_page, 3, "entries_on_this_page ok" );

is( $pager->next_page, 2, "next_page ok" );

is( $it->next->title, "Film 1", "iterator->next ok" );

$it->next;
$it->next;

is( $it->next, undef, "next past end of page ok" );

# second page
( $pager, $it ) = Film->page( 
    {},
    { rows => 3,
      page => 2 }
);

is( $pager->entries_on_this_page, 2, "entries on second page ok" );

is( $it->next->title, "Film 4", "second page first title ok" );