Trailing WS crusade - got to save them bits
[dbsrgits/DBIx-Class.git] / t / cdbi / sweet / 08pager.t
CommitLineData
4f99ad18 1use strict;
2use warnings;
3
4use Test::More;
5
4bea1fe7 6use lib 't/lib';
7use DBICTest;
8
289ba852 9BEGIN {
10 eval "use DBIx::Class::CDBICompat;";
11 if ($@) {
12 plan (skip_all => 'Class::Trigger and DBIx::ContextualFetch required');
13 next;
14 }
4bea1fe7 15 plan tests => 9;
289ba852 16}
4f99ad18 17
5e7ac8f9 18DBICTest::Schema::CD->load_components(qw/CDBICompat CDBICompat::Pager/);
19
9b0d64fc 20my $schema = DBICTest->init_schema(compose_connection => 1);
c216324a 21
9b0d64fc 22DBICTest::CD->result_source_instance->schema->storage($schema->storage);
4f99ad18 23
24my ( $pager, $it ) = DBICTest::CD->page(
25 {},
26 { order_by => 'title',
27 rows => 3,
28 page => 1 } );
8273e845 29
4f99ad18 30cmp_ok( $pager->entries_on_this_page, '==', 3, "entries_on_this_page ok" );
31
32cmp_ok( $pager->next_page, '==', 2, "next_page ok" );
33
34is( $it->next->title, "Caterwaulin' Blues", "iterator->next ok" );
35
36$it->next;
37$it->next;
38
39is( $it->next, undef, "next past end of page ok" );
40
41( $pager, $it ) = DBICTest::CD->page(
42 {},
43 { rows => 2,
44 page => 2,
45 disable_sql_paging => 1 } );
46
47cmp_ok( $pager->total_entries, '==', 5, "disable_sql_paging total_entries ok" );
48
49cmp_ok( $pager->previous_page, '==', 1, "disable_sql_paging previous_page ok" );
50
51is( $it->next->title, "Caterwaulin' Blues", "disable_sql_paging iterator->next ok" );
52
53$it->next;
54
55is( $it->next, undef, "disable_sql_paging next past end of page ok" );
56
57# based on a failing criteria submitted by waswas
58( $pager, $it ) = DBICTest::CD->page(
59 { title => [
8273e845 60 -and =>
4f99ad18 61 {
62 -like => '%bees'
63 },
64 {
65 -not_like => 'Forkful%'
66 }
67 ]
68 },
69 { rows => 5 }
70);
71is( $it->count, 1, "complex abstract count ok" );