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