Lines 196-202
subtest 'objects.search helper' => sub {
Link Here
|
196 |
|
196 |
|
197 |
subtest 'objects.search helper, sorting on mapped column' => sub { |
197 |
subtest 'objects.search helper, sorting on mapped column' => sub { |
198 |
|
198 |
|
199 |
plan tests => 14; |
199 |
plan tests => 35; |
200 |
|
200 |
|
201 |
$schema->storage->txn_begin; |
201 |
$schema->storage->txn_begin; |
202 |
|
202 |
|
Lines 205-227
subtest 'objects.search helper, sorting on mapped column' => sub {
Link Here
|
205 |
|
205 |
|
206 |
$builder->build_object({ class => 'Koha::Cities', value => { city_name => 'A', city_country => 'Argentina' } }); |
206 |
$builder->build_object({ class => 'Koha::Cities', value => { city_name => 'A', city_country => 'Argentina' } }); |
207 |
$builder->build_object({ class => 'Koha::Cities', value => { city_name => 'B', city_country => 'Argentina' } }); |
207 |
$builder->build_object({ class => 'Koha::Cities', value => { city_name => 'B', city_country => 'Argentina' } }); |
|
|
208 |
$builder->build_object({ class => 'Koha::Cities', value => { city_name => 'C', city_country => 'Argentina' } }); |
209 |
$builder->build_object({ class => 'Koha::Cities', value => { city_name => 'C', city_country => 'Belarus' } }); |
208 |
|
210 |
|
209 |
my $t = Test::Mojo->new; |
211 |
my $t = Test::Mojo->new; |
210 |
$t->get_ok('/cities?_order_by=%2Bname&_order_by=+country') |
212 |
diag("CSV-param"); |
|
|
213 |
$t->get_ok('/cities?_order_by=%2Bname,-country') |
211 |
->status_is(200) |
214 |
->status_is(200) |
212 |
->json_has('/0') |
215 |
->json_has('/0') |
213 |
->json_has('/1') |
216 |
->json_has('/1') |
214 |
->json_hasnt('/2') |
|
|
215 |
->json_is('/0/name' => 'A') |
217 |
->json_is('/0/name' => 'A') |
216 |
->json_is('/1/name' => 'B'); |
218 |
->json_is('/1/name' => 'B') |
217 |
|
219 |
->json_is('/2/name' => 'C') |
|
|
220 |
->json_is('/2/country' => 'Belarus') |
221 |
->json_is('/3/name' => 'C') |
222 |
->json_is('/3/country' => 'Argentina') |
223 |
->json_hasnt('/4'); |
224 |
|
225 |
diag("Multi-param: traditional"); |
226 |
$t->get_ok('/cities?_order_by=%2Bname&_order_by=-country') |
227 |
->status_is(200) |
228 |
->json_has('/0') |
229 |
->json_has('/1') |
230 |
->json_is('/0/name' => 'A') |
231 |
->json_is('/1/name' => 'B') |
232 |
->json_is('/2/name' => 'C') |
233 |
->json_is('/2/country' => 'Belarus') |
234 |
->json_is('/3/name' => 'C') |
235 |
->json_is('/3/country' => 'Argentina') |
236 |
->json_hasnt('/4'); |
237 |
|
238 |
diag("Pipe-param: Passes validation (treated as a 'single value array or one string), subsequently explodes"); |
239 |
$t->get_ok('/cities?_order_by=%2Bname|-country') |
240 |
->status_is(500); |
241 |
|
242 |
diag("Multi-param: PHP Style, Passes validation as above, subsequntly explodes"); |
243 |
$t->get_ok('/cities?_order_by[]=%2Bname&_order_by[]=-country') |
244 |
->status_is(500); |
245 |
|
246 |
diag("Single-param"); |
218 |
$t->get_ok('/cities?_order_by=-name') |
247 |
$t->get_ok('/cities?_order_by=-name') |
219 |
->status_is(200) |
248 |
->status_is(200) |
220 |
->json_has('/0') |
249 |
->json_has('/0') |
221 |
->json_has('/1') |
250 |
->json_has('/1') |
222 |
->json_hasnt('/2') |
251 |
->json_is('/0/name' => 'C') |
223 |
->json_is('/0/name' => 'B') |
252 |
->json_is('/1/name' => 'C') |
224 |
->json_is('/1/name' => 'A'); |
253 |
->json_is('/2/name' => 'B') |
|
|
254 |
->json_is('/3/name' => 'A') |
255 |
->json_hasnt('/4'); |
225 |
|
256 |
|
226 |
$schema->storage->txn_rollback; |
257 |
$schema->storage->txn_rollback; |
227 |
}; |
258 |
}; |
228 |
- |
|
|