Reorganize CDBICompat tests - centralize prereq checks in one place
[dbsrgits/DBIx-Class.git] / t / cdbi / abstract / search_where.t
CommitLineData
e60dc79f 1use Test::More;
2
3use strict;
4use warnings;
5
e60dc79f 6INIT {
6a3bf251 7 use lib 't/cdbi/testlib';
8 use Film;
e60dc79f 9}
10
11
12Film->create({ Title => $_, Rating => "PG" }) for ("Superman", "Super Fuzz");
13Film->create({ Title => "Batman", Rating => "PG13" });
14
15my $superman = Film->search_where( Title => "Superman" );
16is $superman->next->Title, "Superman", "search_where() as iterator";
17is $superman->next, undef;
18
d37c21dc 19{
20 my @supers = Film->search_where({ title => { 'like' => 'Super%' } });
21 is_deeply [sort map $_->Title, @supers],
22 [sort ("Super Fuzz", "Superman")], 'like';
23}
8273e845 24
d37c21dc 25
e60dc79f 26my @all = Film->search_where({}, { order_by => "Title ASC" });
27is_deeply ["Batman", "Super Fuzz", "Superman"],
28 [map $_->Title, @all],
29 "order_by ASC";
30
31@all = Film->search_where({}, { order_by => "Title DESC" });
32is_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" });
37is_deeply ["Super Fuzz"],
38 [map $_->Title, @all],
39 "where, limit";
40
41@all = Film->search_where({}, { limit => 2, order_by => "Title ASC" });
42is_deeply ["Batman", "Super Fuzz"],
43 [map $_->Title, @all],
44 "limit";
45
46@all = Film->search_where({}, { offset => 1, order_by => "Title ASC" });
47is_deeply ["Super Fuzz", "Superman"],
48 [map $_->Title, @all],
49 "offset";
50
51@all = Film->search_where({}, { limit => 1, offset => 1, order_by => "Title ASC" });
52is_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 });
59is_deeply ["Super Fuzz", "Superman"],
60 [map $_->Title, @all],
61 "limit_dialect ignored";
62
d9bd5195 63done_testing;