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