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