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