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