new config option to DBICTest to let you set an alternative storage type, start on...
[dbsrgits/DBIx-Class.git] / t / cdbi-abstract / search_where.t
CommitLineData
e60dc79f 1#!/usr/bin/perl -w
2
3use Test::More;
4
5use strict;
6use warnings;
7
8BEGIN {
9 eval "use DBIx::Class::CDBICompat;";
10 if ($@) {
11 plan (skip_all => "Class::Trigger and DBIx::ContextualFetch required: $@");
12 next;
13 }
14 eval "use DBD::SQLite";
d37c21dc 15 plan $@ ? (skip_all => 'needs DBD::SQLite for testing') : (tests => 10);
e60dc79f 16}
17
18INIT {
19 use lib 't/testlib';
20 use Film;
21}
22
23
24Film->create({ Title => $_, Rating => "PG" }) for ("Superman", "Super Fuzz");
25Film->create({ Title => "Batman", Rating => "PG13" });
26
27my $superman = Film->search_where( Title => "Superman" );
28is $superman->next->Title, "Superman", "search_where() as iterator";
29is $superman->next, undef;
30
d37c21dc 31{
32 my @supers = Film->search_where({ title => { 'like' => 'Super%' } });
33 is_deeply [sort map $_->Title, @supers],
34 [sort ("Super Fuzz", "Superman")], 'like';
35}
36
37
e60dc79f 38my @all = Film->search_where({}, { order_by => "Title ASC" });
39is_deeply ["Batman", "Super Fuzz", "Superman"],
40 [map $_->Title, @all],
41 "order_by ASC";
42
43@all = Film->search_where({}, { order_by => "Title DESC" });
44is_deeply ["Superman", "Super Fuzz", "Batman"],
45 [map $_->Title, @all],
46 "order_by DESC";
47
48@all = Film->search_where({ Rating => "PG" }, { limit => 1, order_by => "Title ASC" });
49is_deeply ["Super Fuzz"],
50 [map $_->Title, @all],
51 "where, limit";
52
53@all = Film->search_where({}, { limit => 2, order_by => "Title ASC" });
54is_deeply ["Batman", "Super Fuzz"],
55 [map $_->Title, @all],
56 "limit";
57
58@all = Film->search_where({}, { offset => 1, order_by => "Title ASC" });
59is_deeply ["Super Fuzz", "Superman"],
60 [map $_->Title, @all],
61 "offset";
62
63@all = Film->search_where({}, { limit => 1, offset => 1, order_by => "Title ASC" });
64is_deeply ["Super Fuzz"],
65 [map $_->Title, @all],
66 "limit + offset";
67
68@all = Film->search_where({}, { limit => 2, offset => 1,
69 limit_dialect => "Top", order_by => "Title ASC"
70 });
71is_deeply ["Super Fuzz", "Superman"],
72 [map $_->Title, @all],
73 "limit_dialect ignored";
74