Reorganize CDBICompat tests - centralize prereq checks in one place
[dbsrgits/DBIx-Class.git] / t / cdbi / sweet / 08pager.t
CommitLineData
4f99ad18 1use strict;
2use warnings;
3
4use Test::More;
5
d9bd5195 6use lib 't/cdbi/testlib';
7use DBIC::Test::SQLite;
4f99ad18 8
5e7ac8f9 9DBICTest::Schema::CD->load_components(qw/CDBICompat CDBICompat::Pager/);
10
9b0d64fc 11my $schema = DBICTest->init_schema(compose_connection => 1);
c216324a 12
9b0d64fc 13DBICTest::CD->result_source_instance->schema->storage($schema->storage);
4f99ad18 14
15my ( $pager, $it ) = DBICTest::CD->page(
16 {},
17 { order_by => 'title',
18 rows => 3,
19 page => 1 } );
8273e845 20
4f99ad18 21cmp_ok( $pager->entries_on_this_page, '==', 3, "entries_on_this_page ok" );
22
23cmp_ok( $pager->next_page, '==', 2, "next_page ok" );
24
25is( $it->next->title, "Caterwaulin' Blues", "iterator->next ok" );
26
27$it->next;
28$it->next;
29
30is( $it->next, undef, "next past end of page ok" );
31
32( $pager, $it ) = DBICTest::CD->page(
33 {},
34 { rows => 2,
35 page => 2,
36 disable_sql_paging => 1 } );
37
38cmp_ok( $pager->total_entries, '==', 5, "disable_sql_paging total_entries ok" );
39
40cmp_ok( $pager->previous_page, '==', 1, "disable_sql_paging previous_page ok" );
41
42is( $it->next->title, "Caterwaulin' Blues", "disable_sql_paging iterator->next ok" );
43
44$it->next;
45
46is( $it->next, undef, "disable_sql_paging next past end of page ok" );
47
48# based on a failing criteria submitted by waswas
49( $pager, $it ) = DBICTest::CD->page(
50 { title => [
8273e845 51 -and =>
4f99ad18 52 {
53 -like => '%bees'
54 },
55 {
56 -not_like => 'Forkful%'
57 }
58 ]
59 },
60 { rows => 5 }
61);
62is( $it->count, 1, "complex abstract count ok" );
65d35121 63
64# cleanup globals so we do not trigger the leaktest
65for ( map { DBICTest->schema->class($_) } DBICTest->schema->sources ) {
66 $_->class_resolver(undef);
67 $_->resultset_instance(undef);
68 $_->result_source_instance(undef);
69}
70{
71 no warnings qw/redefine once/;
72 *DBICTest::schema = sub {};
73}
d9bd5195 74
75done_testing;