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