Commit | Line | Data |
83eef562 |
1 | use DBIx::Class::Optional::Dependencies -skip_all_without => 'cdbicompat'; |
2 | |
4f99ad18 |
3 | use strict; |
4 | use warnings; |
5 | |
6 | use Test::More; |
7 | |
83eef562 |
8 | use lib 't/lib'; |
9 | use DBICTest; |
4f99ad18 |
10 | |
5e7ac8f9 |
11 | DBICTest::Schema::CD->load_components(qw/CDBICompat CDBICompat::Pager/); |
12 | |
9b0d64fc |
13 | my $schema = DBICTest->init_schema(compose_connection => 1); |
c216324a |
14 | |
9b0d64fc |
15 | DBICTest::CD->result_source_instance->schema->storage($schema->storage); |
4f99ad18 |
16 | |
17 | my ( $pager, $it ) = DBICTest::CD->page( |
18 | {}, |
19 | { order_by => 'title', |
20 | rows => 3, |
21 | page => 1 } ); |
8273e845 |
22 | |
4f99ad18 |
23 | cmp_ok( $pager->entries_on_this_page, '==', 3, "entries_on_this_page ok" ); |
24 | |
25 | cmp_ok( $pager->next_page, '==', 2, "next_page ok" ); |
26 | |
27 | is( $it->next->title, "Caterwaulin' Blues", "iterator->next ok" ); |
28 | |
29 | $it->next; |
30 | $it->next; |
31 | |
32 | is( $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 | |
40 | cmp_ok( $pager->total_entries, '==', 5, "disable_sql_paging total_entries ok" ); |
41 | |
42 | cmp_ok( $pager->previous_page, '==', 1, "disable_sql_paging previous_page ok" ); |
43 | |
44 | is( $it->next->title, "Caterwaulin' Blues", "disable_sql_paging iterator->next ok" ); |
45 | |
46 | $it->next; |
47 | |
48 | is( $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 | ); |
64 | is( $it->count, 1, "complex abstract count ok" ); |
65d35121 |
65 | |
66 | # cleanup globals so we do not trigger the leaktest |
67 | for ( 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 | |
77 | done_testing; |