Original tests from Class::DBI::Plugin::DeepAbstractSearch
[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";
15 plan $@ ? (skip_all => 'needs DBD::SQLite for testing') : (tests => 9);
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
31my @all = Film->search_where({}, { order_by => "Title ASC" });
32is_deeply ["Batman", "Super Fuzz", "Superman"],
33 [map $_->Title, @all],
34 "order_by ASC";
35
36@all = Film->search_where({}, { order_by => "Title DESC" });
37is_deeply ["Superman", "Super Fuzz", "Batman"],
38 [map $_->Title, @all],
39 "order_by DESC";
40
41@all = Film->search_where({ Rating => "PG" }, { limit => 1, order_by => "Title ASC" });
42is_deeply ["Super Fuzz"],
43 [map $_->Title, @all],
44 "where, limit";
45
46@all = Film->search_where({}, { limit => 2, order_by => "Title ASC" });
47is_deeply ["Batman", "Super Fuzz"],
48 [map $_->Title, @all],
49 "limit";
50
51@all = Film->search_where({}, { offset => 1, order_by => "Title ASC" });
52is_deeply ["Super Fuzz", "Superman"],
53 [map $_->Title, @all],
54 "offset";
55
56@all = Film->search_where({}, { limit => 1, offset => 1, order_by => "Title ASC" });
57is_deeply ["Super Fuzz"],
58 [map $_->Title, @all],
59 "limit + offset";
60
61@all = Film->search_where({}, { limit => 2, offset => 1,
62 limit_dialect => "Top", order_by => "Title ASC"
63 });
64is_deeply ["Super Fuzz", "Superman"],
65 [map $_->Title, @all],
66 "limit_dialect ignored";
67