|
Line 0
Link Here
|
| 0 |
- |
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 <https://www.gnu.org/licenses>. |
| 17 |
|
| 18 |
use Modern::Perl; |
| 19 |
|
| 20 |
use Test::NoWarnings; |
| 21 |
use Test::More tests => 3; |
| 22 |
|
| 23 |
use_ok("Koha::Patrons::DataTables"); |
| 24 |
|
| 25 |
subtest 'Preprocessor tests' => sub { |
| 26 |
plan tests => 2; |
| 27 |
my $q_params = [ |
| 28 |
{ |
| 29 |
'-and' => [ |
| 30 |
[ |
| 31 |
{ 'me.phone' => { 'like' => '%2345678901%' } }, |
| 32 |
{ 'me.phonepro' => { 'like' => '%2345678901%' } }, |
| 33 |
{ 'me.B_phone' => { 'like' => '%2345678901%' } }, |
| 34 |
{ 'me.altcontactphone' => { 'like' => '%2345678901%' } }, |
| 35 |
{ 'me.mobile' => { 'like' => '%2345678901%' } } |
| 36 |
] |
| 37 |
] |
| 38 |
}, |
| 39 |
{ |
| 40 |
'-or' => [ |
| 41 |
{ 'me.phone' => { 'like' => '%234 567 8901%' } }, |
| 42 |
{ 'me.phonepro' => { 'like' => '%234 567 8901%' } }, |
| 43 |
{ 'me.B_phone' => { 'like' => '%234 567 8901%' } }, |
| 44 |
{ 'me.altcontactphone' => { 'like' => '%234 567 8901%' } }, |
| 45 |
{ 'me.mobile' => { 'like' => '%234 567 8901%' } } |
| 46 |
] |
| 47 |
} |
| 48 |
]; |
| 49 |
my $attributes = { |
| 50 |
'prefetch' => [ |
| 51 |
'extended_attributes', |
| 52 |
'library' |
| 53 |
], |
| 54 |
'order_by' => [ |
| 55 |
{ '-asc' => 'me.surname' }, |
| 56 |
{ '-asc' => 'me.preferred_name' }, |
| 57 |
{ '-asc' => 'me.firstname' }, |
| 58 |
{ '-asc' => 'me.middle_name' }, |
| 59 |
{ '-asc' => 'me.othernames' }, |
| 60 |
{ '-asc' => 'me.streetnumber' }, |
| 61 |
{ '-asc' => 'me.address' }, |
| 62 |
{ '-asc' => 'me.address2' }, |
| 63 |
{ '-asc' => 'me.city' }, |
| 64 |
{ '-asc' => 'me.state' }, |
| 65 |
{ '-asc' => 'me.zipcode' }, |
| 66 |
{ '-asc' => 'me.country' } |
| 67 |
], |
| 68 |
'page' => 1, |
| 69 |
'rows' => 20 |
| 70 |
}; |
| 71 |
my $expected_params = [ |
| 72 |
{ |
| 73 |
'-and' => [ |
| 74 |
[ |
| 75 |
{}, |
| 76 |
{}, |
| 77 |
{}, |
| 78 |
{}, |
| 79 |
{} |
| 80 |
] |
| 81 |
] |
| 82 |
}, |
| 83 |
{ |
| 84 |
'-or' => [ |
| 85 |
{}, |
| 86 |
{}, |
| 87 |
{}, |
| 88 |
{}, |
| 89 |
{} |
| 90 |
] |
| 91 |
} |
| 92 |
]; |
| 93 |
my $expected_attributes = { |
| 94 |
'order_by' => [ |
| 95 |
{ '-asc' => 'me.surname' }, |
| 96 |
{ '-asc' => 'me.preferred_name' }, |
| 97 |
{ '-asc' => 'me.firstname' }, |
| 98 |
{ '-asc' => 'me.middle_name' }, |
| 99 |
{ '-asc' => 'me.othernames' }, |
| 100 |
{ '-asc' => 'me.streetnumber' }, |
| 101 |
{ '-asc' => 'me.address' }, |
| 102 |
{ '-asc' => 'me.address2' }, |
| 103 |
{ '-asc' => 'me.city' }, |
| 104 |
{ '-asc' => 'me.state' }, |
| 105 |
{ '-asc' => 'me.zipcode' }, |
| 106 |
{ '-asc' => 'me.country' } |
| 107 |
], |
| 108 |
'page' => 1, |
| 109 |
'rows' => 20, |
| 110 |
'prefetch' => [ |
| 111 |
'extended_attributes', |
| 112 |
'library' |
| 113 |
], |
| 114 |
'where' => [ |
| 115 |
\[ |
| 116 |
'regexp_replace(me.phone,?,?) LIKE ?', |
| 117 |
'[^0-9]', |
| 118 |
'', |
| 119 |
'%2345678901%' |
| 120 |
], |
| 121 |
\[ |
| 122 |
'regexp_replace(me.phonepro,?,?) LIKE ?', |
| 123 |
'[^0-9]', |
| 124 |
'', |
| 125 |
'%2345678901%' |
| 126 |
], |
| 127 |
\[ |
| 128 |
'regexp_replace(me.B_phone,?,?) LIKE ?', |
| 129 |
'[^0-9]', |
| 130 |
'', |
| 131 |
'%2345678901%' |
| 132 |
], |
| 133 |
\[ |
| 134 |
'regexp_replace(me.altcontactphone,?,?) LIKE ?', |
| 135 |
'[^0-9]', |
| 136 |
'', |
| 137 |
'%2345678901%' |
| 138 |
], |
| 139 |
\[ |
| 140 |
'regexp_replace(me.mobile,?,?) LIKE ?', |
| 141 |
'[^0-9]', |
| 142 |
'', |
| 143 |
'%2345678901%' |
| 144 |
], |
| 145 |
\[ |
| 146 |
'regexp_replace(me.phone,?,?) LIKE ?', |
| 147 |
'[^0-9]', |
| 148 |
'', |
| 149 |
'%234 567 8901%' |
| 150 |
], |
| 151 |
\[ |
| 152 |
'regexp_replace(me.phonepro,?,?) LIKE ?', |
| 153 |
'[^0-9]', |
| 154 |
'', |
| 155 |
'%234 567 8901%' |
| 156 |
], |
| 157 |
\[ |
| 158 |
'regexp_replace(me.B_phone,?,?) LIKE ?', |
| 159 |
'[^0-9]', |
| 160 |
'', |
| 161 |
'%234 567 8901%' |
| 162 |
], |
| 163 |
\[ |
| 164 |
'regexp_replace(me.altcontactphone,?,?) LIKE ?', |
| 165 |
'[^0-9]', |
| 166 |
'', |
| 167 |
'%234 567 8901%' |
| 168 |
], |
| 169 |
\[ |
| 170 |
'regexp_replace(me.mobile,?,?) LIKE ?', |
| 171 |
'[^0-9]', |
| 172 |
'', |
| 173 |
'%234 567 8901%' |
| 174 |
] |
| 175 |
] |
| 176 |
}; |
| 177 |
Koha::Patrons::DataTables->preprocess_dbic_for_datatables( $q_params, $attributes ); |
| 178 |
is_deeply( $q_params, $expected_params, "Params preprocessed as expected" ); |
| 179 |
is_deeply( $attributes, $expected_attributes, "Attributes preprocessed as expected" ); |
| 180 |
}; |