Switch the shortener (used only by oracle) reqs to an optional dependency
[dbsrgits/DBIx-Class.git] / t / sqlmaker / oraclejoin.t
1 use strict;
2 use warnings;
3
4 use Test::More;
5
6 BEGIN {
7   require DBIx::Class::Optional::Dependencies;
8   plan skip_all => 'Test needs ' . DBIx::Class::Optional::Dependencies->req_missing_for ('id_shortener')
9     unless DBIx::Class::Optional::Dependencies->req_ok_for ('id_shortener');
10 }
11
12 use lib qw(t/lib);
13 use DBIx::Class::SQLMaker::OracleJoins;
14 use DBICTest;
15 use DBIC::SqlMakerTest;
16
17 my $sa = DBIx::Class::SQLMaker::OracleJoins->new;
18
19 #  my ($self, $table, $fields, $where, $order, @rest) = @_;
20 my ($sql, @bind) = $sa->select(
21     [
22         { me => "cd" },
23         [
24             { "-join_type" => "LEFT", artist => "artist" },
25             { "artist.artistid" => "me.artist" },
26         ],
27     ],
28     [ 'cd.cdid', 'cd.artist', 'cd.title', 'cd.year', 'artist.artistid', 'artist.name' ],
29     undef,
30     undef
31 );
32 is_same_sql_bind(
33   $sql, \@bind,
34   'SELECT cd.cdid, cd.artist, cd.title, cd.year, artist.artistid, artist.name FROM cd me, artist artist WHERE ( artist.artistid(+) = me.artist )', [],
35   'WhereJoins search with empty where clause'
36 );
37
38 ($sql, @bind) = $sa->select(
39     [
40         { me => "cd" },
41         [
42             { "-join_type" => "", artist => "artist" },
43             { "artist.artistid" => "me.artist" },
44         ],
45     ],
46     [ 'cd.cdid', 'cd.artist', 'cd.title', 'cd.year', 'artist.artistid', 'artist.name' ],
47     { 'artist.artistid' => 3 },
48     undef
49 );
50 is_same_sql_bind(
51   $sql, \@bind,
52   'SELECT cd.cdid, cd.artist, cd.title, cd.year, artist.artistid, artist.name FROM cd me, artist artist WHERE ( ( ( artist.artistid = me.artist ) AND ( artist.artistid = ? ) ) )', [3],
53   'WhereJoins search with where clause'
54 );
55
56 ($sql, @bind) = $sa->select(
57     [
58         { me => "cd" },
59         [
60             { "-join_type" => "LEFT", artist => "artist" },
61             { "artist.artistid" => "me.artist" },
62         ],
63     ],
64     [ 'cd.cdid', 'cd.artist', 'cd.title', 'cd.year', 'artist.artistid', 'artist.name' ],
65     [{ 'artist.artistid' => 3 }, { 'me.cdid' => 5 }],
66     undef
67 );
68 is_same_sql_bind(
69   $sql, \@bind,
70   'SELECT cd.cdid, cd.artist, cd.title, cd.year, artist.artistid, artist.name FROM cd me, artist artist WHERE ( ( ( artist.artistid(+) = me.artist ) AND ( ( ( artist.artistid = ? ) OR ( me.cdid = ? ) ) ) ) )', [3, 5],
71   'WhereJoins search with or in where clause'
72 );
73
74 done_testing;
75