Merge 'trunk' into 'DBIx-Class-current'
[dbsrgits/DBIx-Class-Historic.git] / t / run / 07pager.tl
CommitLineData
0567538f 1sub run_tests {
1edaf6fe 2my $schema = shift;
0567538f 3
4plan tests => 12;
5
6# first page
f9db5527 7my $it = $schema->resultset("CD")->search(
0567538f 8 {},
9 { order_by => 'title',
10 rows => 3,
11 page => 1 }
12);
13
14is( $it->pager->entries_on_this_page, 3, "entries_on_this_page ok" );
15
16is( $it->pager->next_page, 2, "next_page ok" );
17
18is( $it->count, 3, "count on paged rs ok" );
19
20is( $it->next->title, "Caterwaulin' Blues", "iterator->next ok" );
21
22$it->next;
23$it->next;
24
25is( $it->next, undef, "next past end of page ok" );
26
27# second page, testing with array
f9db5527 28my @page2 = $schema->resultset("CD")->search(
0567538f 29 {},
30 { order_by => 'title',
31 rows => 3,
32 page => 2 }
33);
34
35is( $page2[0]->title, "Generic Manufactured Singles", "second page first title ok" );
36
37# page a standard resultset
f9db5527 38$it = $schema->resultset("CD")->search(
0567538f 39 {},
40 { order_by => 'title',
41 rows => 3 }
42);
43my $page = $it->page(2);
44
45is( $page->count, 2, "standard resultset paged rs count ok" );
46
47is( $page->next->title, "Generic Manufactured Singles", "second page of standard resultset ok" );
48
49# test software-based limit paging
f9db5527 50$it = $schema->resultset("CD")->search(
0567538f 51 {},
52 { order_by => 'title',
53 rows => 3,
54 page => 2,
55 software_limit => 1 }
56);
57is( $it->pager->entries_on_this_page, 2, "software entries_on_this_page ok" );
58
59is( $it->pager->previous_page, 1, "software previous_page ok" );
60
61is( $it->count, 2, "software count on paged rs ok" );
62
63is( $it->next->title, "Generic Manufactured Singles", "software iterator->next ok" );
64
65}
66
671;