|
Lines 21-26
use Koha::Acquisition::Orders;
Link Here
|
| 21 |
use Koha::Cities; |
21 |
use Koha::Cities; |
| 22 |
use Koha::Holds; |
22 |
use Koha::Holds; |
| 23 |
use Koha::Biblios; |
23 |
use Koha::Biblios; |
|
|
24 |
use Koha::AuthorisedValueCategories; |
| 25 |
use Koha::AuthorisedValues; |
| 24 |
|
26 |
|
| 25 |
# Dummy app for testing the plugin |
27 |
# Dummy app for testing the plugin |
| 26 |
use Mojolicious::Lite; |
28 |
use Mojolicious::Lite; |
|
Lines 77-83
get '/biblios' => sub {
Link Here
|
| 77 |
|
79 |
|
| 78 |
|
80 |
|
| 79 |
# The tests |
81 |
# The tests |
| 80 |
use Test::More tests => 10; |
82 |
use Test::More tests => 11; |
| 81 |
use Test::Mojo; |
83 |
use Test::Mojo; |
| 82 |
|
84 |
|
| 83 |
use t::lib::Mocks; |
85 |
use t::lib::Mocks; |
|
Lines 305-311
subtest 'objects.search helper, with path parameters and _match' => sub {
Link Here
|
| 305 |
$schema->storage->txn_rollback; |
307 |
$schema->storage->txn_rollback; |
| 306 |
}; |
308 |
}; |
| 307 |
|
309 |
|
| 308 |
subtest 'object.search helper with query parameter' => sub { |
310 |
subtest 'objects.search helper with query parameter' => sub { |
| 309 |
plan tests => 4; |
311 |
plan tests => 4; |
| 310 |
|
312 |
|
| 311 |
$schema->storage->txn_begin; |
313 |
$schema->storage->txn_begin; |
|
Lines 328-334
subtest 'object.search helper with query parameter' => sub {
Link Here
|
| 328 |
$schema->storage->txn_rollback; |
330 |
$schema->storage->txn_rollback; |
| 329 |
}; |
331 |
}; |
| 330 |
|
332 |
|
| 331 |
subtest 'object.search helper with q parameter' => sub { |
333 |
subtest 'objects.search helper with q parameter' => sub { |
| 332 |
plan tests => 4; |
334 |
plan tests => 4; |
| 333 |
|
335 |
|
| 334 |
$schema->storage->txn_begin; |
336 |
$schema->storage->txn_begin; |
|
Lines 351-357
subtest 'object.search helper with q parameter' => sub {
Link Here
|
| 351 |
$schema->storage->txn_rollback; |
353 |
$schema->storage->txn_rollback; |
| 352 |
}; |
354 |
}; |
| 353 |
|
355 |
|
| 354 |
subtest 'object.search helper with x-koha-query header' => sub { |
356 |
subtest 'objects.search helper with x-koha-query header' => sub { |
| 355 |
plan tests => 4; |
357 |
plan tests => 4; |
| 356 |
|
358 |
|
| 357 |
$schema->storage->txn_begin; |
359 |
$schema->storage->txn_begin; |
|
Lines 374-380
subtest 'object.search helper with x-koha-query header' => sub {
Link Here
|
| 374 |
$schema->storage->txn_rollback; |
376 |
$schema->storage->txn_rollback; |
| 375 |
}; |
377 |
}; |
| 376 |
|
378 |
|
| 377 |
subtest 'object.search helper with all query methods' => sub { |
379 |
subtest 'objects.search helper with all query methods' => sub { |
| 378 |
plan tests => 6; |
380 |
plan tests => 6; |
| 379 |
|
381 |
|
| 380 |
$schema->storage->txn_begin; |
382 |
$schema->storage->txn_begin; |
|
Lines 400-408
subtest 'object.search helper with all query methods' => sub {
Link Here
|
| 400 |
$schema->storage->txn_rollback; |
402 |
$schema->storage->txn_rollback; |
| 401 |
}; |
403 |
}; |
| 402 |
|
404 |
|
| 403 |
subtest 'object.search helper order by embedded columns' => sub { |
405 |
subtest 'objects.search helper order by embedded columns' => sub { |
| 404 |
plan tests => 3; |
406 |
plan tests => 3; |
| 405 |
|
407 |
|
|
|
408 |
$schema->storage->txn_begin; |
| 409 |
|
| 406 |
my $patron1 = $builder->build_object( { class => "Koha::Patrons" , value => {firstname=>'patron1'} } ); |
410 |
my $patron1 = $builder->build_object( { class => "Koha::Patrons" , value => {firstname=>'patron1'} } ); |
| 407 |
my $patron2 = $builder->build_object( { class => "Koha::Patrons" , value => {firstname=>'patron2'} } ); |
411 |
my $patron2 = $builder->build_object( { class => "Koha::Patrons" , value => {firstname=>'patron2'} } ); |
| 408 |
my $biblio1 = $builder->build_sample_biblio; |
412 |
my $biblio1 = $builder->build_sample_biblio; |
|
Lines 414-418
subtest 'object.search helper order by embedded columns' => sub {
Link Here
|
| 414 |
->json_is('/biblios/0/biblio_id' => $biblio2->biblionumber, 'Biblio 2 should be first') |
418 |
->json_is('/biblios/0/biblio_id' => $biblio2->biblionumber, 'Biblio 2 should be first') |
| 415 |
->json_is('/biblios/1/biblio_id' => $biblio1->biblionumber, 'Biblio 1 should be second'); |
419 |
->json_is('/biblios/1/biblio_id' => $biblio1->biblionumber, 'Biblio 1 should be second'); |
| 416 |
|
420 |
|
|
|
421 |
$schema->storage->txn_rollback; |
| 422 |
}; |
| 423 |
|
| 424 |
subtest 'objects.search helper with expanded authorised values' => sub { |
| 425 |
plan tests => 11; |
| 426 |
|
| 417 |
$schema->storage->txn_begin; |
427 |
$schema->storage->txn_begin; |
| 418 |
} |
428 |
|
|
|
429 |
Koha::AuthorisedValues->search({category => 'Countries'})->delete; |
| 430 |
Koha::AuthorisedValueCategories->search({category_name =>'Countries'})->delete; |
| 431 |
|
| 432 |
my $cat = $builder->build_object({ class => 'Koha::AuthorisedValueCategories', value => {category_name =>'Countries'} }); |
| 433 |
my $fr = $builder->build_object({ class => 'Koha::AuthorisedValues', value => {authorised_value => 'FR', lib=>'France', category=>$cat->category_name} }); |
| 434 |
my $us = $builder->build_object({ class => 'Koha::AuthorisedValues', value => {authorised_value => 'US', lib=>'United States of America', category=>$cat->category_name} }); |
| 435 |
my $ar = $builder->build_object({ class => 'Koha::AuthorisedValues', value => {authorised_value => 'AR', lib=>'Argentina', category=>$cat->category_name} }); |
| 436 |
|
| 437 |
my $city_class = Test::MockModule->new('Koha::City'); |
| 438 |
$city_class->mock( '_fetch_authorised_values', |
| 439 |
sub { |
| 440 |
my ($self) = @_; |
| 441 |
use Koha::AuthorisedValues; |
| 442 |
my $av = Koha::AuthorisedValues->find({authorised_value => $self->city_country, category => 'Countries'}); |
| 443 |
return {country => $av->unblessed}; |
| 444 |
} |
| 445 |
); |
| 446 |
|
| 447 |
$builder->build_object({ |
| 448 |
class => 'Koha::Cities', |
| 449 |
value => { |
| 450 |
city_name => 'Manuel', |
| 451 |
city_country => 'AR' |
| 452 |
} |
| 453 |
}); |
| 454 |
$builder->build_object({ |
| 455 |
class => 'Koha::Cities', |
| 456 |
value => { |
| 457 |
city_name => 'Manuela', |
| 458 |
city_country => 'US' |
| 459 |
} |
| 460 |
}); |
| 461 |
|
| 462 |
$t->get_ok('/cities?name=manuel&_per_page=4&_page=1&_match=starts_with' => { 'x-koha-av' => 1 }) |
| 463 |
->status_is(200) |
| 464 |
->json_has('/0') |
| 465 |
->json_has('/1') |
| 466 |
->json_hasnt('/2') |
| 467 |
->json_is('/0/name' => 'Manuel') |
| 468 |
->json_has('/0/_authorised_values') |
| 469 |
->json_is('/0/_authorised_values/country/lib' => $ar->lib) |
| 470 |
->json_is('/1/name' => 'Manuela') |
| 471 |
->json_has('/1/_authorised_values') |
| 472 |
->json_is('/1/_authorised_values/country/lib' => $us->lib); |
| 473 |
|
| 474 |
$schema->storage->txn_rollback; |
| 475 |
}; |
| 419 |
- |
|
|