Trailing WS crusade - got to save them bits
[dbsrgits/DBIx-Class.git] / t / cdbi / sweet / 08pager.t
1 use strict;
2 use warnings;
3
4 use Test::More;
5
6 use lib 't/lib';
7 use DBICTest;
8
9 BEGIN {
10   eval "use DBIx::Class::CDBICompat;";
11   if ($@) {
12     plan (skip_all => 'Class::Trigger and DBIx::ContextualFetch required');
13     next;
14   }
15   plan tests => 9;
16 }
17
18 DBICTest::Schema::CD->load_components(qw/CDBICompat CDBICompat::Pager/);
19
20 my $schema = DBICTest->init_schema(compose_connection => 1);
21
22 DBICTest::CD->result_source_instance->schema->storage($schema->storage);
23
24 my ( $pager, $it ) = DBICTest::CD->page(
25     {},
26     { order_by => 'title',
27       rows => 3,
28       page => 1 } );
29
30 cmp_ok( $pager->entries_on_this_page, '==', 3, "entries_on_this_page ok" );
31
32 cmp_ok( $pager->next_page, '==', 2, "next_page ok" );
33
34 is( $it->next->title, "Caterwaulin' Blues", "iterator->next ok" );
35
36 $it->next;
37 $it->next;
38
39 is( $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
47 cmp_ok( $pager->total_entries, '==', 5, "disable_sql_paging total_entries ok" );
48
49 cmp_ok( $pager->previous_page, '==', 1, "disable_sql_paging previous_page ok" );
50
51 is( $it->next->title, "Caterwaulin' Blues", "disable_sql_paging iterator->next ok" );
52
53 $it->next;
54
55 is( $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 => [
60         -and =>
61             {
62                 -like => '%bees'
63             },
64             {
65                 -not_like => 'Forkful%'
66             }
67         ]
68     },
69     { rows => 5 }
70 );
71 is( $it->count, 1, "complex abstract count ok" );