|
Lines 20-25
use Modern::Perl;
Link Here
|
| 20 |
use Koha::Acquisition::Orders; |
20 |
use Koha::Acquisition::Orders; |
| 21 |
use Koha::Cities; |
21 |
use Koha::Cities; |
| 22 |
use Koha::Biblios; |
22 |
use Koha::Biblios; |
|
|
23 |
use Koha::AuthorisedValueCategories; |
| 24 |
use Koha::AuthorisedValues; |
| 23 |
|
25 |
|
| 24 |
# Dummy app for testing the plugin |
26 |
# Dummy app for testing the plugin |
| 25 |
use Mojolicious::Lite; |
27 |
use Mojolicious::Lite; |
|
Lines 80-86
get '/biblios' => sub {
Link Here
|
| 80 |
}; |
82 |
}; |
| 81 |
|
83 |
|
| 82 |
# The tests |
84 |
# The tests |
| 83 |
use Test::More tests => 12; |
85 |
use Test::More tests => 14; |
| 84 |
use Test::Mojo; |
86 |
use Test::Mojo; |
| 85 |
|
87 |
|
| 86 |
use t::lib::Mocks; |
88 |
use t::lib::Mocks; |
|
Lines 312-318
subtest 'objects.search helper, embed' => sub {
Link Here
|
| 312 |
$schema->storage->txn_rollback; |
314 |
$schema->storage->txn_rollback; |
| 313 |
}; |
315 |
}; |
| 314 |
|
316 |
|
| 315 |
subtest 'object.search helper with query parameter' => sub { |
317 |
subtest 'objects.search helper with query parameter' => sub { |
| 316 |
plan tests => 4; |
318 |
plan tests => 4; |
| 317 |
|
319 |
|
| 318 |
$schema->storage->txn_begin; |
320 |
$schema->storage->txn_begin; |
|
Lines 336-342
subtest 'object.search helper with query parameter' => sub {
Link Here
|
| 336 |
$schema->storage->txn_rollback; |
338 |
$schema->storage->txn_rollback; |
| 337 |
}; |
339 |
}; |
| 338 |
|
340 |
|
| 339 |
subtest 'object.search helper with q parameter' => sub { |
341 |
subtest 'objects.search helper with q parameter' => sub { |
| 340 |
plan tests => 4; |
342 |
plan tests => 4; |
| 341 |
|
343 |
|
| 342 |
$schema->storage->txn_begin; |
344 |
$schema->storage->txn_begin; |
|
Lines 360-366
subtest 'object.search helper with q parameter' => sub {
Link Here
|
| 360 |
$schema->storage->txn_rollback; |
362 |
$schema->storage->txn_rollback; |
| 361 |
}; |
363 |
}; |
| 362 |
|
364 |
|
| 363 |
subtest 'object.search helper with x-koha-query header' => sub { |
365 |
subtest 'objects.search helper with x-koha-query header' => sub { |
| 364 |
plan tests => 4; |
366 |
plan tests => 4; |
| 365 |
|
367 |
|
| 366 |
$schema->storage->txn_begin; |
368 |
$schema->storage->txn_begin; |
|
Lines 384-390
subtest 'object.search helper with x-koha-query header' => sub {
Link Here
|
| 384 |
$schema->storage->txn_rollback; |
386 |
$schema->storage->txn_rollback; |
| 385 |
}; |
387 |
}; |
| 386 |
|
388 |
|
| 387 |
subtest 'object.search helper with all query methods' => sub { |
389 |
subtest 'objects.search helper with all query methods' => sub { |
| 388 |
plan tests => 6; |
390 |
plan tests => 6; |
| 389 |
|
391 |
|
| 390 |
$schema->storage->txn_begin; |
392 |
$schema->storage->txn_begin; |
|
Lines 411-418
subtest 'object.search helper with all query methods' => sub {
Link Here
|
| 411 |
$schema->storage->txn_rollback; |
413 |
$schema->storage->txn_rollback; |
| 412 |
}; |
414 |
}; |
| 413 |
|
415 |
|
| 414 |
subtest 'object.search helper order by embedded columns' => sub { |
416 |
subtest 'objects.search helper order by embedded columns' => sub { |
| 415 |
|
|
|
| 416 |
plan tests => 3; |
417 |
plan tests => 3; |
| 417 |
|
418 |
|
| 418 |
$schema->storage->txn_begin; |
419 |
$schema->storage->txn_begin; |
|
Lines 476-478
subtest 'objects.find helper, embed' => sub {
Link Here
|
| 476 |
|
477 |
|
| 477 |
$schema->storage->txn_rollback; |
478 |
$schema->storage->txn_rollback; |
| 478 |
}; |
479 |
}; |
| 479 |
- |
480 |
|
|
|
481 |
subtest 'objects.find helper with expanded authorised values' => sub { |
| 482 |
plan tests => 10; |
| 483 |
|
| 484 |
$schema->storage->txn_begin; |
| 485 |
|
| 486 |
my $t = Test::Mojo->new; |
| 487 |
|
| 488 |
Koha::AuthorisedValues->search( { category => 'Countries' } )->delete; |
| 489 |
Koha::AuthorisedValueCategories->search( { category_name => 'Countries' } ) |
| 490 |
->delete; |
| 491 |
|
| 492 |
my $cat = $builder->build_object( |
| 493 |
{ |
| 494 |
class => 'Koha::AuthorisedValueCategories', |
| 495 |
value => { category_name => 'Countries' } |
| 496 |
} |
| 497 |
); |
| 498 |
my $fr = $builder->build_object( |
| 499 |
{ |
| 500 |
class => 'Koha::AuthorisedValues', |
| 501 |
value => { |
| 502 |
authorised_value => 'FR', |
| 503 |
lib => 'France', |
| 504 |
category => $cat->category_name |
| 505 |
} |
| 506 |
} |
| 507 |
); |
| 508 |
my $us = $builder->build_object( |
| 509 |
{ |
| 510 |
class => 'Koha::AuthorisedValues', |
| 511 |
value => { |
| 512 |
authorised_value => 'US', |
| 513 |
lib => 'United States of America', |
| 514 |
category => $cat->category_name |
| 515 |
} |
| 516 |
} |
| 517 |
); |
| 518 |
my $ar = $builder->build_object( |
| 519 |
{ |
| 520 |
class => 'Koha::AuthorisedValues', |
| 521 |
value => { |
| 522 |
authorised_value => 'AR', |
| 523 |
lib => 'Argentina', |
| 524 |
category => $cat->category_name |
| 525 |
} |
| 526 |
} |
| 527 |
); |
| 528 |
|
| 529 |
my $city_class = Test::MockModule->new('Koha::City'); |
| 530 |
$city_class->mock( |
| 531 |
'_fetch_authorised_values', |
| 532 |
sub { |
| 533 |
my ($self) = @_; |
| 534 |
use Koha::AuthorisedValues; |
| 535 |
my $av = Koha::AuthorisedValues->find( |
| 536 |
{ |
| 537 |
authorised_value => $self->city_country, |
| 538 |
category => 'Countries' |
| 539 |
} |
| 540 |
); |
| 541 |
return { country => $av->unblessed }; |
| 542 |
} |
| 543 |
); |
| 544 |
|
| 545 |
my $manuel = $builder->build_object( |
| 546 |
{ |
| 547 |
class => 'Koha::Cities', |
| 548 |
value => { |
| 549 |
city_name => 'Manuel', |
| 550 |
city_country => 'AR' |
| 551 |
} |
| 552 |
} |
| 553 |
); |
| 554 |
my $manuela = $builder->build_object( |
| 555 |
{ |
| 556 |
class => 'Koha::Cities', |
| 557 |
value => { |
| 558 |
city_name => 'Manuela', |
| 559 |
city_country => 'US' |
| 560 |
} |
| 561 |
} |
| 562 |
); |
| 563 |
|
| 564 |
$t->get_ok( '/cities/' . $manuel->cityid => { 'x-koha-av-expand' => 1 } ) |
| 565 |
->status_is(200)->json_is( '/name' => 'Manuel' ) |
| 566 |
->json_has('/_authorised_values') |
| 567 |
->json_is( '/_authorised_values/country/lib' => $ar->lib ); |
| 568 |
|
| 569 |
$t->get_ok( '/cities/' . $manuela->cityid => { 'x-koha-av-expand' => 1 } ) |
| 570 |
->status_is(200)->json_is( '/name' => 'Manuela' ) |
| 571 |
->json_has('/_authorised_values') |
| 572 |
->json_is( '/_authorised_values/country/lib' => $us->lib ); |
| 573 |
|
| 574 |
$schema->storage->txn_rollback; |
| 575 |
}; |
| 576 |
|
| 577 |
subtest 'objects.search helper with expanded authorised values' => sub { |
| 578 |
|
| 579 |
plan tests => 11; |
| 580 |
|
| 581 |
my $t = Test::Mojo->new; |
| 582 |
|
| 583 |
$schema->storage->txn_begin; |
| 584 |
|
| 585 |
Koha::AuthorisedValues->search( { category => 'Countries' } )->delete; |
| 586 |
Koha::AuthorisedValueCategories->search( { category_name => 'Countries' } ) |
| 587 |
->delete; |
| 588 |
|
| 589 |
my $cat = $builder->build_object( |
| 590 |
{ |
| 591 |
class => 'Koha::AuthorisedValueCategories', |
| 592 |
value => { category_name => 'Countries' } |
| 593 |
} |
| 594 |
); |
| 595 |
my $fr = $builder->build_object( |
| 596 |
{ |
| 597 |
class => 'Koha::AuthorisedValues', |
| 598 |
value => { |
| 599 |
authorised_value => 'FR', |
| 600 |
lib => 'France', |
| 601 |
category => $cat->category_name |
| 602 |
} |
| 603 |
} |
| 604 |
); |
| 605 |
my $us = $builder->build_object( |
| 606 |
{ |
| 607 |
class => 'Koha::AuthorisedValues', |
| 608 |
value => { |
| 609 |
authorised_value => 'US', |
| 610 |
lib => 'United States of America', |
| 611 |
category => $cat->category_name |
| 612 |
} |
| 613 |
} |
| 614 |
); |
| 615 |
my $ar = $builder->build_object( |
| 616 |
{ |
| 617 |
class => 'Koha::AuthorisedValues', |
| 618 |
value => { |
| 619 |
authorised_value => 'AR', |
| 620 |
lib => 'Argentina', |
| 621 |
category => $cat->category_name |
| 622 |
} |
| 623 |
} |
| 624 |
); |
| 625 |
|
| 626 |
my $city_class = Test::MockModule->new('Koha::City'); |
| 627 |
$city_class->mock( |
| 628 |
'_fetch_authorised_values', |
| 629 |
sub { |
| 630 |
my ($self) = @_; |
| 631 |
use Koha::AuthorisedValues; |
| 632 |
my $av = Koha::AuthorisedValues->find( |
| 633 |
{ |
| 634 |
authorised_value => $self->city_country, |
| 635 |
category => 'Countries' |
| 636 |
} |
| 637 |
); |
| 638 |
return { country => $av->unblessed }; |
| 639 |
} |
| 640 |
); |
| 641 |
|
| 642 |
$builder->build_object( |
| 643 |
{ |
| 644 |
class => 'Koha::Cities', |
| 645 |
value => { |
| 646 |
city_name => 'Manuel', |
| 647 |
city_country => 'AR' |
| 648 |
} |
| 649 |
} |
| 650 |
); |
| 651 |
$builder->build_object( |
| 652 |
{ |
| 653 |
class => 'Koha::Cities', |
| 654 |
value => { |
| 655 |
city_name => 'Manuela', |
| 656 |
city_country => 'US' |
| 657 |
} |
| 658 |
} |
| 659 |
); |
| 660 |
|
| 661 |
$t->get_ok( '/cities?name=manuel&_per_page=4&_page=1&_match=starts_with' => |
| 662 |
{ 'x-koha-av-expand' => 1 } )->status_is(200)->json_has('/0') |
| 663 |
->json_has('/1')->json_hasnt('/2')->json_is( '/0/name' => 'Manuel' ) |
| 664 |
->json_has('/0/_authorised_values') |
| 665 |
->json_is( '/0/_authorised_values/country/lib' => $ar->lib ) |
| 666 |
->json_is( '/1/name' => 'Manuela' )->json_has('/1/_authorised_values') |
| 667 |
->json_is( '/1/_authorised_values/country/lib' => $us->lib ); |
| 668 |
|
| 669 |
$schema->storage->txn_rollback; |
| 670 |
}; |