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