Commit | Line | Data |
70350518 |
1 | use strict; |
2 | use warnings; |
3 | |
4 | use Test::More; |
5 | use lib qw(t/lib); |
6 | use DBICTest; |
7 | |
a47e1233 |
8 | my $schema = DBICTest->init_schema(); |
0567538f |
9 | |
4d993a62 |
10 | plan tests => 13; |
0567538f |
11 | |
12 | # first page |
f9db5527 |
13 | my $it = $schema->resultset("CD")->search( |
0567538f |
14 | {}, |
15 | { order_by => 'title', |
16 | rows => 3, |
17 | page => 1 } |
18 | ); |
19 | |
20 | is( $it->pager->entries_on_this_page, 3, "entries_on_this_page ok" ); |
21 | |
22 | is( $it->pager->next_page, 2, "next_page ok" ); |
23 | |
24 | is( $it->count, 3, "count on paged rs ok" ); |
25 | |
26 | is( $it->next->title, "Caterwaulin' Blues", "iterator->next ok" ); |
27 | |
28 | $it->next; |
29 | $it->next; |
30 | |
31 | is( $it->next, undef, "next past end of page ok" ); |
32 | |
33 | # second page, testing with array |
f9db5527 |
34 | my @page2 = $schema->resultset("CD")->search( |
0567538f |
35 | {}, |
36 | { order_by => 'title', |
37 | rows => 3, |
38 | page => 2 } |
39 | ); |
40 | |
41 | is( $page2[0]->title, "Generic Manufactured Singles", "second page first title ok" ); |
42 | |
43 | # page a standard resultset |
f9db5527 |
44 | $it = $schema->resultset("CD")->search( |
0567538f |
45 | {}, |
46 | { order_by => 'title', |
47 | rows => 3 } |
48 | ); |
49 | my $page = $it->page(2); |
50 | |
51 | is( $page->count, 2, "standard resultset paged rs count ok" ); |
52 | |
53 | is( $page->next->title, "Generic Manufactured Singles", "second page of standard resultset ok" ); |
54 | |
55 | # test software-based limit paging |
f9db5527 |
56 | $it = $schema->resultset("CD")->search( |
0567538f |
57 | {}, |
58 | { order_by => 'title', |
59 | rows => 3, |
60 | page => 2, |
61 | software_limit => 1 } |
62 | ); |
63 | is( $it->pager->entries_on_this_page, 2, "software entries_on_this_page ok" ); |
64 | |
65 | is( $it->pager->previous_page, 1, "software previous_page ok" ); |
66 | |
67 | is( $it->count, 2, "software count on paged rs ok" ); |
68 | |
69 | is( $it->next->title, "Generic Manufactured Singles", "software iterator->next ok" ); |
70 | |
4d993a62 |
71 | # test paging with chained searches |
72 | $it = $schema->resultset("CD")->search( |
73 | {}, |
74 | { rows => 2, |
75 | page => 2 } |
76 | )->search( undef, { order_by => 'title' } ); |
77 | |
78 | is( $it->count, 2, "chained searches paging ok" ); |