Merge 'DBIx-Class-current' into 'trunk'
[dbsrgits/DBIx-Class.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
58d387fe 18use_ok('DBICTest');
a47e1233 19DBICTest->init_schema();
4f99ad18 20
21DBICTest::CD->load_components(qw/CDBICompat::Pager/);
22
23my ( $pager, $it ) = DBICTest::CD->page(
24 {},
25 { order_by => 'title',
26 rows => 3,
27 page => 1 } );
28
29cmp_ok( $pager->entries_on_this_page, '==', 3, "entries_on_this_page ok" );
30
31cmp_ok( $pager->next_page, '==', 2, "next_page ok" );
32
33is( $it->next->title, "Caterwaulin' Blues", "iterator->next ok" );
34
35$it->next;
36$it->next;
37
38is( $it->next, undef, "next past end of page ok" );
39
40( $pager, $it ) = DBICTest::CD->page(
41 {},
42 { rows => 2,
43 page => 2,
44 disable_sql_paging => 1 } );
45
46cmp_ok( $pager->total_entries, '==', 5, "disable_sql_paging total_entries ok" );
47
48cmp_ok( $pager->previous_page, '==', 1, "disable_sql_paging previous_page ok" );
49
50is( $it->next->title, "Caterwaulin' Blues", "disable_sql_paging iterator->next ok" );
51
52$it->next;
53
54is( $it->next, undef, "disable_sql_paging next past end of page ok" );
55
56# based on a failing criteria submitted by waswas
57( $pager, $it ) = DBICTest::CD->page(
58 { title => [
59 -and =>
60 {
61 -like => '%bees'
62 },
63 {
64 -not_like => 'Forkful%'
65 }
66 ]
67 },
68 { rows => 5 }
69);
70is( $it->count, 1, "complex abstract count ok" );