Bug 27715: Use $dbh->quote_identifier to quote untrusted input
[koha.git] / t / db_dependent / Utils / Datatables.t
1 #!/usr/bin/perl
2
3 # This file is part of Koha.
4 #
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18 use Modern::Perl;
19
20 use Test::More tests => 1;
21
22 use C4::Utils::DataTables;
23
24 use t::lib::Mocks;
25 use t::lib::TestBuilder;
26
27 use Koha::Database;
28
29 my $schema = Koha::Database->new->schema;
30 $schema->storage->txn_begin;
31
32 my $builder = t::lib::TestBuilder->new;
33
34 subtest 'dt_build_orderby' => sub {
35     plan tests => 2;
36
37     my $dt_params = {
38         iSortCol_0  => 5,
39         sSortDir_0  => "asc",
40         mDataProp_5 => "branch",
41         name_sorton => "borrowers.surname borrowers.firstname",
42
43         iSortCol_1    => 2,
44         sSortDir_1    => "desc",
45         mDataProp_2   => "name",
46         branch_sorton => "branches.branchname",
47     };
48
49     my $orderby = dt_build_orderby($dt_params);
50     is( $orderby, " ORDER BY `branches`.`branchname` ASC,`borrowers`.`surname` DESC,`borrowers`.`firstname` DESC ", 'ORDER BY has been correctly built' );
51
52     $dt_params = {
53         %$dt_params,
54         iSortCol_2                    => 3,
55         sSortDir_2                    => "asc",
56         mDataProp_3                   => "branch,somethingelse",
57     };
58
59     $orderby = dt_build_orderby($dt_params);
60     is( $orderby, " ORDER BY `branches`.`branchname` ASC,`borrowers`.`surname` DESC,`borrowers`.`firstname` DESC ", 'ORDER BY has been correctly built, even with invalid stuff');
61 };