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