Massive cleanup of DateTime test dependencies, other interim
[dbsrgits/DBIx-Class.git] / t / cdbi / abstract / search_where.t
CommitLineData
e60dc79f 1use Test::More;
2
3use strict;
4use warnings;
5
6BEGIN {
7 eval "use DBIx::Class::CDBICompat;";
8 if ($@) {
9 plan (skip_all => "Class::Trigger and DBIx::ContextualFetch required: $@");
e60dc79f 10 }
68de9438 11 plan tests => 10;
e60dc79f 12}
13
14INIT {
6a3bf251 15 use lib 't/cdbi/testlib';
16 use Film;
e60dc79f 17}
18
19
20Film->create({ Title => $_, Rating => "PG" }) for ("Superman", "Super Fuzz");
21Film->create({ Title => "Batman", Rating => "PG13" });
22
23my $superman = Film->search_where( Title => "Superman" );
24is $superman->next->Title, "Superman", "search_where() as iterator";
25is $superman->next, undef;
26
d37c21dc 27{
28 my @supers = Film->search_where({ title => { 'like' => 'Super%' } });
29 is_deeply [sort map $_->Title, @supers],
30 [sort ("Super Fuzz", "Superman")], 'like';
31}
32
33
e60dc79f 34my @all = Film->search_where({}, { order_by => "Title ASC" });
35is_deeply ["Batman", "Super Fuzz", "Superman"],
36 [map $_->Title, @all],
37 "order_by ASC";
38
39@all = Film->search_where({}, { order_by => "Title DESC" });
40is_deeply ["Superman", "Super Fuzz", "Batman"],
41 [map $_->Title, @all],
42 "order_by DESC";
43
44@all = Film->search_where({ Rating => "PG" }, { limit => 1, order_by => "Title ASC" });
45is_deeply ["Super Fuzz"],
46 [map $_->Title, @all],
47 "where, limit";
48
49@all = Film->search_where({}, { limit => 2, order_by => "Title ASC" });
50is_deeply ["Batman", "Super Fuzz"],
51 [map $_->Title, @all],
52 "limit";
53
54@all = Film->search_where({}, { offset => 1, order_by => "Title ASC" });
55is_deeply ["Super Fuzz", "Superman"],
56 [map $_->Title, @all],
57 "offset";
58
59@all = Film->search_where({}, { limit => 1, offset => 1, order_by => "Title ASC" });
60is_deeply ["Super Fuzz"],
61 [map $_->Title, @all],
62 "limit + offset";
63
64@all = Film->search_where({}, { limit => 2, offset => 1,
65 limit_dialect => "Top", order_by => "Title ASC"
66 });
67is_deeply ["Super Fuzz", "Superman"],
68 [map $_->Title, @all],
69 "limit_dialect ignored";
70