Massive cleanup of DateTime test dependencies, other interim
[dbsrgits/DBIx-Class.git] / t / cdbi / sweet / 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 }
68de9438 12 plan tests => 10;
289ba852 13}
4f99ad18 14
15use lib 't/lib';
16
58d387fe 17use_ok('DBICTest');
4f99ad18 18
5e7ac8f9 19DBICTest::Schema::CD->load_components(qw/CDBICompat CDBICompat::Pager/);
20
9b0d64fc 21my $schema = DBICTest->init_schema(compose_connection => 1);
c216324a 22
9b0d64fc 23DBICTest::CD->result_source_instance->schema->storage($schema->storage);
4f99ad18 24
25my ( $pager, $it ) = DBICTest::CD->page(
26 {},
27 { order_by => 'title',
28 rows => 3,
29 page => 1 } );
30
31cmp_ok( $pager->entries_on_this_page, '==', 3, "entries_on_this_page ok" );
32
33cmp_ok( $pager->next_page, '==', 2, "next_page ok" );
34
35is( $it->next->title, "Caterwaulin' Blues", "iterator->next ok" );
36
37$it->next;
38$it->next;
39
40is( $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
48cmp_ok( $pager->total_entries, '==', 5, "disable_sql_paging total_entries ok" );
49
50cmp_ok( $pager->previous_page, '==', 1, "disable_sql_paging previous_page ok" );
51
52is( $it->next->title, "Caterwaulin' Blues", "disable_sql_paging iterator->next ok" );
53
54$it->next;
55
56is( $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);
72is( $it->count, 1, "complex abstract count ok" );