Commit | Line | Data |
4f99ad18 |
1 | use strict; |
2 | use warnings; |
3 | |
4 | use Test::More; |
5 | |
4bea1fe7 |
6 | use lib 't/lib'; |
7 | use DBICTest; |
8 | |
289ba852 |
9 | BEGIN { |
10 | eval "use DBIx::Class::CDBICompat;"; |
11 | if ($@) { |
12 | plan (skip_all => 'Class::Trigger and DBIx::ContextualFetch required'); |
13 | next; |
14 | } |
4bea1fe7 |
15 | plan tests => 9; |
289ba852 |
16 | } |
4f99ad18 |
17 | |
5e7ac8f9 |
18 | DBICTest::Schema::CD->load_components(qw/CDBICompat CDBICompat::Pager/); |
19 | |
9b0d64fc |
20 | my $schema = DBICTest->init_schema(compose_connection => 1); |
c216324a |
21 | |
9b0d64fc |
22 | DBICTest::CD->result_source_instance->schema->storage($schema->storage); |
4f99ad18 |
23 | |
24 | my ( $pager, $it ) = DBICTest::CD->page( |
25 | {}, |
26 | { order_by => 'title', |
27 | rows => 3, |
28 | page => 1 } ); |
8273e845 |
29 | |
4f99ad18 |
30 | cmp_ok( $pager->entries_on_this_page, '==', 3, "entries_on_this_page ok" ); |
31 | |
32 | cmp_ok( $pager->next_page, '==', 2, "next_page ok" ); |
33 | |
34 | is( $it->next->title, "Caterwaulin' Blues", "iterator->next ok" ); |
35 | |
36 | $it->next; |
37 | $it->next; |
38 | |
39 | is( $it->next, undef, "next past end of page ok" ); |
40 | |
41 | ( $pager, $it ) = DBICTest::CD->page( |
42 | {}, |
43 | { rows => 2, |
44 | page => 2, |
45 | disable_sql_paging => 1 } ); |
46 | |
47 | cmp_ok( $pager->total_entries, '==', 5, "disable_sql_paging total_entries ok" ); |
48 | |
49 | cmp_ok( $pager->previous_page, '==', 1, "disable_sql_paging previous_page ok" ); |
50 | |
51 | is( $it->next->title, "Caterwaulin' Blues", "disable_sql_paging iterator->next ok" ); |
52 | |
53 | $it->next; |
54 | |
55 | is( $it->next, undef, "disable_sql_paging next past end of page ok" ); |
56 | |
57 | # based on a failing criteria submitted by waswas |
58 | ( $pager, $it ) = DBICTest::CD->page( |
59 | { title => [ |
8273e845 |
60 | -and => |
4f99ad18 |
61 | { |
62 | -like => '%bees' |
63 | }, |
64 | { |
65 | -not_like => 'Forkful%' |
66 | } |
67 | ] |
68 | }, |
69 | { rows => 5 } |
70 | ); |
71 | is( $it->count, 1, "complex abstract count ok" ); |