Institute a central "load this first in testing" package
[dbsrgits/DBIx-Class.git] / t / cdbi / sweet / 08pager.t
1 BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
2 use DBIx::Class::Optional::Dependencies -skip_all_without => 'cdbicompat';
3
4 use strict;
5 use warnings;
6
7 use Test::More;
8
9
10 use DBICTest;
11
12 DBICTest::Schema::CD->load_components(qw/CDBICompat CDBICompat::Pager/);
13
14 my $schema = DBICTest->init_schema(compose_connection => 1);
15
16 DBICTest::CD->result_source_instance->schema->storage($schema->storage);
17
18 my ( $pager, $it ) = DBICTest::CD->page(
19     {},
20     { order_by => 'title',
21       rows => 3,
22       page => 1 } );
23
24 cmp_ok( $pager->entries_on_this_page, '==', 3, "entries_on_this_page ok" );
25
26 cmp_ok( $pager->next_page, '==', 2, "next_page ok" );
27
28 is( $it->next->title, "Caterwaulin' Blues", "iterator->next ok" );
29
30 $it->next;
31 $it->next;
32
33 is( $it->next, undef, "next past end of page ok" );
34
35 ( $pager, $it ) = DBICTest::CD->page(
36     {},
37     { rows => 2,
38       page => 2,
39       disable_sql_paging => 1 } );
40
41 cmp_ok( $pager->total_entries, '==', 5, "disable_sql_paging total_entries ok" );
42
43 cmp_ok( $pager->previous_page, '==', 1, "disable_sql_paging previous_page ok" );
44
45 is( $it->next->title, "Caterwaulin' Blues", "disable_sql_paging iterator->next ok" );
46
47 $it->next;
48
49 is( $it->next, undef, "disable_sql_paging next past end of page ok" );
50
51 # based on a failing criteria submitted by waswas
52 ( $pager, $it ) = DBICTest::CD->page(
53     { title => [
54         -and =>
55             {
56                 -like => '%bees'
57             },
58             {
59                 -not_like => 'Forkful%'
60             }
61         ]
62     },
63     { rows => 5 }
64 );
65 is( $it->count, 1, "complex abstract count ok" );
66
67 done_testing;