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