moved code to ::DBI::MSSQL and added DT inflation test
[dbsrgits/DBIx-Class-Historic.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
d759a1ee 24is( $it->pager->total_entries, 5, "total_entries ok" );
25
0567538f 26is( $it->next->title, "Caterwaulin' Blues", "iterator->next ok" );
27
28$it->next;
29$it->next;
30
31is( $it->next, undef, "next past end of page ok" );
32
33# second page, testing with array
f9db5527 34my @page2 = $schema->resultset("CD")->search(
0567538f 35 {},
36 { order_by => 'title',
37 rows => 3,
38 page => 2 }
39);
40
41is( $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);
49my $page = $it->page(2);
50
51is( $page->count, 2, "standard resultset paged rs count ok" );
52
53is( $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);
63is( $it->pager->entries_on_this_page, 2, "software entries_on_this_page ok" );
64
65is( $it->pager->previous_page, 1, "software previous_page ok" );
66
67is( $it->count, 2, "software count on paged rs ok" );
68
69is( $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
78is( $it->count, 2, "chained searches paging ok" );
e6c747fd 79
80my $p = sub { $schema->resultset("CD")->page(1)->pager->entries_per_page; };
81
82is($p->(), 10, 'default rows is 10');
83
84$schema->default_resultset_attributes({ rows => 5 });
85
86is($p->(), 5, 'default rows is 5');
5b1c7d7f 87
88# test page with offset
89$it = $schema->resultset('CD')->search({}, {
90 rows => 2,
91 page => 2,
92 offset => 1,
93 order_by => 'cdid'
94});
95
96my $row = $schema->resultset('CD')->search({}, {
97 order_by => 'cdid',
98 offset => 3,
99 rows => 1
100})->single;
101
102is($row->cdid, $it->first->cdid, 'page with offset');