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