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