Merge 'trunk' into 'multiple_version_upgrade'
[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: $@");
10 next;
11 }
12 eval "use DBD::SQLite";
d37c21dc 13 plan $@ ? (skip_all => 'needs DBD::SQLite for testing') : (tests => 10);
e60dc79f 14}
15
16INIT {
6a3bf251 17 use lib 't/cdbi/testlib';
18 use Film;
e60dc79f 19}
20
21
22Film->create({ Title => $_, Rating => "PG" }) for ("Superman", "Super Fuzz");
23Film->create({ Title => "Batman", Rating => "PG13" });
24
25my $superman = Film->search_where( Title => "Superman" );
26is $superman->next->Title, "Superman", "search_where() as iterator";
27is $superman->next, undef;
28
d37c21dc 29{
30 my @supers = Film->search_where({ title => { 'like' => 'Super%' } });
31 is_deeply [sort map $_->Title, @supers],
32 [sort ("Super Fuzz", "Superman")], 'like';
33}
34
35
e60dc79f 36my @all = Film->search_where({}, { order_by => "Title ASC" });
37is_deeply ["Batman", "Super Fuzz", "Superman"],
38 [map $_->Title, @all],
39 "order_by ASC";
40
41@all = Film->search_where({}, { order_by => "Title DESC" });
42is_deeply ["Superman", "Super Fuzz", "Batman"],
43 [map $_->Title, @all],
44 "order_by DESC";
45
46@all = Film->search_where({ Rating => "PG" }, { limit => 1, order_by => "Title ASC" });
47is_deeply ["Super Fuzz"],
48 [map $_->Title, @all],
49 "where, limit";
50
51@all = Film->search_where({}, { limit => 2, order_by => "Title ASC" });
52is_deeply ["Batman", "Super Fuzz"],
53 [map $_->Title, @all],
54 "limit";
55
56@all = Film->search_where({}, { offset => 1, order_by => "Title ASC" });
57is_deeply ["Super Fuzz", "Superman"],
58 [map $_->Title, @all],
59 "offset";
60
61@all = Film->search_where({}, { limit => 1, offset => 1, order_by => "Title ASC" });
62is_deeply ["Super Fuzz"],
63 [map $_->Title, @all],
64 "limit + offset";
65
66@all = Film->search_where({}, { limit => 2, offset => 1,
67 limit_dialect => "Top", order_by => "Title ASC"
68 });
69is_deeply ["Super Fuzz", "Superman"],
70 [map $_->Title, @all],
71 "limit_dialect ignored";
72