Remove TODO labels from blocks not using todo_skip() - no test changes
[dbsrgits/DBIx-Class.git] / t / sqlmaker / order_by_bindtransport.t
1 use strict;
2 use warnings;
3
4 use Test::More;
5 use Test::Exception;
6 use Data::Dumper::Concise;
7 use lib qw(t/lib);
8 use DBICTest;
9 use DBIC::SqlMakerTest;
10
11 sub test_order {
12     my $rs = shift;
13     my $args = shift;
14
15     local $TODO = "Not implemented" if $args->{todo};
16
17     lives_ok {
18       is_same_sql_bind(
19         $rs->search(
20             { foo => 'bar' },
21             {
22                 order_by => $args->{order_by},
23                 having =>
24                   [ { read_count => { '>' => 5 } }, \[ 'read_count < ?', [ read_count => 8  ] ] ]
25             }
26           )->as_query,
27         "(
28           SELECT me.foo, me.bar, me.hello, me.goodbye, me.sensors, me.read_count
29           FROM fourkeys me
30           WHERE ( foo = ? )
31           HAVING read_count > ? OR read_count < ?
32           ORDER BY $args->{order_req}
33         )",
34         [
35             [ { sqlt_datatype => 'integer', dbic_colname => 'foo' }
36                 => 'bar' ],
37             [ { sqlt_datatype => 'int', dbic_colname => 'read_count' }
38                 => 5 ],
39             [ { sqlt_datatype => 'int', dbic_colname => 'read_count' }
40                 => 8 ],
41             $args->{bind}
42               ? map { [ { dbic_colname => $_->[0] } => $_->[1] ] } @{ $args->{bind} }
43               : ()
44         ],
45       ) || diag Dumper $args->{order_by};
46     };
47 }
48
49 my @tests = (
50     {
51         order_by  => \'foo DESC',
52         order_req => 'foo DESC',
53         bind      => [],
54     },
55     {
56         order_by  => { -asc => 'foo' },
57         order_req => 'foo ASC',
58         bind      => [],
59     },
60     {
61         order_by  => { -desc => \[ 'colA LIKE ?', [ colA => 'test' ] ] },
62         order_req => 'colA LIKE ? DESC',
63         bind      => [ [ colA => 'test' ] ],
64     },
65     {
66         order_by  => \[ 'colA LIKE ? DESC', [ colA => 'test' ] ],
67         order_req => 'colA LIKE ? DESC',
68         bind      => [ [ colA => 'test' ] ],
69     },
70     {
71         order_by => [
72             { -asc  => \['colA'] },
73             { -desc => \[ 'colB LIKE ?', [ colB => 'test' ] ] },
74             { -asc  => \[ 'colC LIKE ?', [ colC => 'tost' ] ] },
75         ],
76         order_req => 'colA ASC, colB LIKE ? DESC, colC LIKE ? ASC',
77         bind      => [ [ colB => 'test' ], [ colC => 'tost' ] ],
78     },
79     {
80         todo => 1,
81         order_by => [
82             { -asc  => 'colA' },
83             { -desc => { colB => { 'LIKE' => 'test' } } },
84             { -asc  => { colC => { 'LIKE' => 'tost' } } }
85         ],
86         order_req => 'colA ASC, colB LIKE ? DESC, colC LIKE ? ASC',
87         bind      => [ [ colB => 'test' ], [ colC => 'tost' ] ],
88     },
89     {
90         todo => 1,
91         order_by  => { -desc => { colA  => { LIKE  => 'test' } } },
92         order_req => 'colA LIKE ? DESC',
93         bind      => [ [ colA => 'test' ] ],
94     },
95 );
96
97 my $rs = DBICTest->init_schema->resultset('FourKeys');
98 test_order($rs, $_) for @tests;
99
100 done_testing;