Introduce GOVERNANCE document and empty RESOLUTIONS file.
[dbsrgits/DBIx-Class.git] / t / cdbi / abstract / search_where.t
1 BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
2 use DBIx::Class::Optional::Dependencies -skip_all_without => 'cdbicompat';
3
4 use strict;
5 use warnings;
6
7 use Test::More;
8
9 use lib 't/cdbi/testlib';
10 use Film;
11
12 Film->create({ Title => $_, Rating => "PG" }) for ("Superman", "Super Fuzz");
13 Film->create({ Title => "Batman", Rating => "PG13" });
14
15 my $superman = Film->search_where( Title => "Superman" );
16 is $superman->next->Title, "Superman", "search_where() as iterator";
17 is $superman->next, undef;
18
19 {
20     my @supers = Film->search_where({ title => { 'like' => 'Super%' } });
21     is_deeply [sort map $_->Title, @supers],
22               [sort ("Super Fuzz", "Superman")], 'like';
23 }
24
25
26 my @all = Film->search_where({}, { order_by => "Title ASC" });
27 is_deeply ["Batman", "Super Fuzz", "Superman"],
28           [map $_->Title, @all],
29           "order_by ASC";
30
31 @all = Film->search_where({}, { order_by => "Title DESC" });
32 is_deeply ["Superman", "Super Fuzz", "Batman"],
33           [map $_->Title, @all],
34           "order_by DESC";
35
36 @all = Film->search_where({ Rating => "PG" }, { limit => 1, order_by => "Title ASC" });
37 is_deeply ["Super Fuzz"],
38           [map $_->Title, @all],
39           "where, limit";
40
41 @all = Film->search_where({}, { limit => 2, order_by => "Title ASC" });
42 is_deeply ["Batman", "Super Fuzz"],
43           [map $_->Title, @all],
44           "limit";
45
46 @all = Film->search_where({}, { offset => 1, order_by => "Title ASC" });
47 is_deeply ["Super Fuzz", "Superman"],
48           [map $_->Title, @all],
49           "offset";
50
51 @all = Film->search_where({}, { limit => 1, offset => 1, order_by => "Title ASC" });
52 is_deeply ["Super Fuzz"],
53           [map $_->Title, @all],
54           "limit + offset";
55
56 @all = Film->search_where({}, { limit => 2, offset => 1,
57                                 limit_dialect => "Top", order_by => "Title ASC"
58                               });
59 is_deeply ["Super Fuzz", "Superman"],
60           [map $_->Title, @all],
61           "limit_dialect ignored";
62
63 done_testing;