Fix incorrect whitespace test outside of checkouts
[dbsrgits/DBIx-Class.git] / t / count / grouped_pager.t
CommitLineData
c0329273 1BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
2
db326a59 3use strict;
4use warnings;
5
6use Test::More;
db326a59 7use DBICTest;
8
9plan tests => 7;
10
11my $schema = DBICTest->init_schema();
12
db326a59 13# add 2 extra artists
14$schema->populate ('Artist', [
15 [qw/name/],
16 [qw/ar_1/],
17 [qw/ar_2/],
18]);
19
20# add 3 extra cds to every artist
21for my $ar ($schema->resultset ('Artist')->all) {
22 for my $cdnum (1 .. 3) {
23 $ar->create_related ('cds', {
24 title => "bogon $cdnum",
25 year => 2000 + $cdnum,
26 });
27 }
28}
29
30my $cds = $schema->resultset ('CD')->search ({}, { group_by => 'artist' } );
31is ($cds->count, 5, 'Resultset collapses to 5 groups');
32
33my ($pg1, $pg2, $pg3) = map { $cds->search_rs ({}, {rows => 2, page => $_}) } (1..3);
34
35for ($pg1, $pg2, $pg3) {
36 is ($_->pager->total_entries, 5, 'Total count via pager correct');
37}
38
39is ($pg1->count, 2, 'First page has 2 groups');
40is ($pg2->count, 2, 'Second page has 2 groups');
41is ($pg3->count, 1, 'Third page has one group remaining');