|
Lines 18-23
Link Here
|
| 18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
| 19 |
|
19 |
|
| 20 |
use Koha::Acquisition::Orders; |
20 |
use Koha::Acquisition::Orders; |
|
|
21 |
use Koha::AuthorisedValueCategories; |
| 22 |
use Koha::AuthorisedValues; |
| 21 |
use Koha::Cities; |
23 |
use Koha::Cities; |
| 22 |
use Koha::Biblios; |
24 |
use Koha::Biblios; |
| 23 |
use Koha::Patrons; |
25 |
use Koha::Patrons; |
|
Lines 117-123
get '/my_patrons' => sub {
Link Here
|
| 117 |
}; |
119 |
}; |
| 118 |
|
120 |
|
| 119 |
# The tests |
121 |
# The tests |
| 120 |
use Test::More tests => 14; |
122 |
use Test::More tests => 16; |
| 121 |
use Test::Mojo; |
123 |
use Test::Mojo; |
| 122 |
|
124 |
|
| 123 |
use t::lib::Mocks; |
125 |
use t::lib::Mocks; |
|
Lines 385-391
subtest 'objects.search helper, embed' => sub {
Link Here
|
| 385 |
$schema->storage->txn_rollback; |
387 |
$schema->storage->txn_rollback; |
| 386 |
}; |
388 |
}; |
| 387 |
|
389 |
|
| 388 |
subtest 'object.search helper with query parameter' => sub { |
390 |
subtest 'objects.search helper with query parameter' => sub { |
| 389 |
plan tests => 4; |
391 |
plan tests => 4; |
| 390 |
|
392 |
|
| 391 |
$schema->storage->txn_begin; |
393 |
$schema->storage->txn_begin; |
|
Lines 409-415
subtest 'object.search helper with query parameter' => sub {
Link Here
|
| 409 |
$schema->storage->txn_rollback; |
411 |
$schema->storage->txn_rollback; |
| 410 |
}; |
412 |
}; |
| 411 |
|
413 |
|
| 412 |
subtest 'object.search helper with q parameter' => sub { |
414 |
subtest 'objects.search helper with q parameter' => sub { |
| 413 |
plan tests => 4; |
415 |
plan tests => 4; |
| 414 |
|
416 |
|
| 415 |
$schema->storage->txn_begin; |
417 |
$schema->storage->txn_begin; |
|
Lines 433-439
subtest 'object.search helper with q parameter' => sub {
Link Here
|
| 433 |
$schema->storage->txn_rollback; |
435 |
$schema->storage->txn_rollback; |
| 434 |
}; |
436 |
}; |
| 435 |
|
437 |
|
| 436 |
subtest 'object.search helper with x-koha-query header' => sub { |
438 |
subtest 'objects.search helper with x-koha-query header' => sub { |
| 437 |
plan tests => 4; |
439 |
plan tests => 4; |
| 438 |
|
440 |
|
| 439 |
$schema->storage->txn_begin; |
441 |
$schema->storage->txn_begin; |
|
Lines 457-463
subtest 'object.search helper with x-koha-query header' => sub {
Link Here
|
| 457 |
$schema->storage->txn_rollback; |
459 |
$schema->storage->txn_rollback; |
| 458 |
}; |
460 |
}; |
| 459 |
|
461 |
|
| 460 |
subtest 'object.search helper with all query methods' => sub { |
462 |
subtest 'objects.search helper with all query methods' => sub { |
| 461 |
plan tests => 6; |
463 |
plan tests => 6; |
| 462 |
|
464 |
|
| 463 |
$schema->storage->txn_begin; |
465 |
$schema->storage->txn_begin; |
|
Lines 484-491
subtest 'object.search helper with all query methods' => sub {
Link Here
|
| 484 |
$schema->storage->txn_rollback; |
486 |
$schema->storage->txn_rollback; |
| 485 |
}; |
487 |
}; |
| 486 |
|
488 |
|
| 487 |
subtest 'object.search helper order by embedded columns' => sub { |
489 |
subtest 'objects.search helper order by embedded columns' => sub { |
| 488 |
|
|
|
| 489 |
plan tests => 3; |
490 |
plan tests => 3; |
| 490 |
|
491 |
|
| 491 |
$schema->storage->txn_begin; |
492 |
$schema->storage->txn_begin; |
|
Lines 618-620
subtest 'objects.search helper, search_limited() tests' => sub {
Link Here
|
| 618 |
|
619 |
|
| 619 |
$schema->storage->txn_rollback; |
620 |
$schema->storage->txn_rollback; |
| 620 |
}; |
621 |
}; |
| 621 |
- |
622 |
|
|
|
623 |
subtest 'objects.find helper with expanded authorised values' => sub { |
| 624 |
plan tests => 10; |
| 625 |
|
| 626 |
$schema->storage->txn_begin; |
| 627 |
|
| 628 |
my $t = Test::Mojo->new; |
| 629 |
|
| 630 |
Koha::AuthorisedValues->search( { category => 'Countries' } )->delete; |
| 631 |
Koha::AuthorisedValueCategories->search( { category_name => 'Countries' } ) |
| 632 |
->delete; |
| 633 |
|
| 634 |
my $cat = $builder->build_object( |
| 635 |
{ |
| 636 |
class => 'Koha::AuthorisedValueCategories', |
| 637 |
value => { category_name => 'Countries' } |
| 638 |
} |
| 639 |
); |
| 640 |
my $fr = $builder->build_object( |
| 641 |
{ |
| 642 |
class => 'Koha::AuthorisedValues', |
| 643 |
value => { |
| 644 |
authorised_value => 'FR', |
| 645 |
lib => 'France', |
| 646 |
category => $cat->category_name |
| 647 |
} |
| 648 |
} |
| 649 |
); |
| 650 |
my $us = $builder->build_object( |
| 651 |
{ |
| 652 |
class => 'Koha::AuthorisedValues', |
| 653 |
value => { |
| 654 |
authorised_value => 'US', |
| 655 |
lib => 'United States of America', |
| 656 |
category => $cat->category_name |
| 657 |
} |
| 658 |
} |
| 659 |
); |
| 660 |
my $ar = $builder->build_object( |
| 661 |
{ |
| 662 |
class => 'Koha::AuthorisedValues', |
| 663 |
value => { |
| 664 |
authorised_value => 'AR', |
| 665 |
lib => 'Argentina', |
| 666 |
category => $cat->category_name |
| 667 |
} |
| 668 |
} |
| 669 |
); |
| 670 |
|
| 671 |
my $city_class = Test::MockModule->new('Koha::City'); |
| 672 |
$city_class->mock( |
| 673 |
'_fetch_authorised_values', |
| 674 |
sub { |
| 675 |
my ($self) = @_; |
| 676 |
use Koha::AuthorisedValues; |
| 677 |
my $av = Koha::AuthorisedValues->find( |
| 678 |
{ |
| 679 |
authorised_value => $self->city_country, |
| 680 |
category => 'Countries' |
| 681 |
} |
| 682 |
); |
| 683 |
return { country => $av->unblessed }; |
| 684 |
} |
| 685 |
); |
| 686 |
|
| 687 |
my $manuel = $builder->build_object( |
| 688 |
{ |
| 689 |
class => 'Koha::Cities', |
| 690 |
value => { |
| 691 |
city_name => 'Manuel', |
| 692 |
city_country => 'AR' |
| 693 |
} |
| 694 |
} |
| 695 |
); |
| 696 |
my $manuela = $builder->build_object( |
| 697 |
{ |
| 698 |
class => 'Koha::Cities', |
| 699 |
value => { |
| 700 |
city_name => 'Manuela', |
| 701 |
city_country => 'US' |
| 702 |
} |
| 703 |
} |
| 704 |
); |
| 705 |
|
| 706 |
$t->get_ok( '/cities/' . $manuel->cityid => { 'x-koha-av-expand' => 1 } ) |
| 707 |
->status_is(200)->json_is( '/name' => 'Manuel' ) |
| 708 |
->json_has('/_authorised_values') |
| 709 |
->json_is( '/_authorised_values/country/lib' => $ar->lib ); |
| 710 |
|
| 711 |
$t->get_ok( '/cities/' . $manuela->cityid => { 'x-koha-av-expand' => 1 } ) |
| 712 |
->status_is(200)->json_is( '/name' => 'Manuela' ) |
| 713 |
->json_has('/_authorised_values') |
| 714 |
->json_is( '/_authorised_values/country/lib' => $us->lib ); |
| 715 |
|
| 716 |
$schema->storage->txn_rollback; |
| 717 |
}; |
| 718 |
|
| 719 |
subtest 'objects.search helper with expanded authorised values' => sub { |
| 720 |
|
| 721 |
plan tests => 11; |
| 722 |
|
| 723 |
my $t = Test::Mojo->new; |
| 724 |
|
| 725 |
$schema->storage->txn_begin; |
| 726 |
|
| 727 |
Koha::AuthorisedValues->search( { category => 'Countries' } )->delete; |
| 728 |
Koha::AuthorisedValueCategories->search( { category_name => 'Countries' } ) |
| 729 |
->delete; |
| 730 |
|
| 731 |
my $cat = $builder->build_object( |
| 732 |
{ |
| 733 |
class => 'Koha::AuthorisedValueCategories', |
| 734 |
value => { category_name => 'Countries' } |
| 735 |
} |
| 736 |
); |
| 737 |
my $fr = $builder->build_object( |
| 738 |
{ |
| 739 |
class => 'Koha::AuthorisedValues', |
| 740 |
value => { |
| 741 |
authorised_value => 'FR', |
| 742 |
lib => 'France', |
| 743 |
category => $cat->category_name |
| 744 |
} |
| 745 |
} |
| 746 |
); |
| 747 |
my $us = $builder->build_object( |
| 748 |
{ |
| 749 |
class => 'Koha::AuthorisedValues', |
| 750 |
value => { |
| 751 |
authorised_value => 'US', |
| 752 |
lib => 'United States of America', |
| 753 |
category => $cat->category_name |
| 754 |
} |
| 755 |
} |
| 756 |
); |
| 757 |
my $ar = $builder->build_object( |
| 758 |
{ |
| 759 |
class => 'Koha::AuthorisedValues', |
| 760 |
value => { |
| 761 |
authorised_value => 'AR', |
| 762 |
lib => 'Argentina', |
| 763 |
category => $cat->category_name |
| 764 |
} |
| 765 |
} |
| 766 |
); |
| 767 |
|
| 768 |
my $city_class = Test::MockModule->new('Koha::City'); |
| 769 |
$city_class->mock( |
| 770 |
'_fetch_authorised_values', |
| 771 |
sub { |
| 772 |
my ($self) = @_; |
| 773 |
use Koha::AuthorisedValues; |
| 774 |
my $av = Koha::AuthorisedValues->find( |
| 775 |
{ |
| 776 |
authorised_value => $self->city_country, |
| 777 |
category => 'Countries' |
| 778 |
} |
| 779 |
); |
| 780 |
return { country => $av->unblessed }; |
| 781 |
} |
| 782 |
); |
| 783 |
|
| 784 |
$builder->build_object( |
| 785 |
{ |
| 786 |
class => 'Koha::Cities', |
| 787 |
value => { |
| 788 |
city_name => 'Manuel', |
| 789 |
city_country => 'AR' |
| 790 |
} |
| 791 |
} |
| 792 |
); |
| 793 |
$builder->build_object( |
| 794 |
{ |
| 795 |
class => 'Koha::Cities', |
| 796 |
value => { |
| 797 |
city_name => 'Manuela', |
| 798 |
city_country => 'US' |
| 799 |
} |
| 800 |
} |
| 801 |
); |
| 802 |
|
| 803 |
$t->get_ok( '/cities?name=manuel&_per_page=4&_page=1&_match=starts_with' => |
| 804 |
{ 'x-koha-av-expand' => 1 } )->status_is(200)->json_has('/0') |
| 805 |
->json_has('/1')->json_hasnt('/2')->json_is( '/0/name' => 'Manuel' ) |
| 806 |
->json_has('/0/_authorised_values') |
| 807 |
->json_is( '/0/_authorised_values/country/lib' => $ar->lib ) |
| 808 |
->json_is( '/1/name' => 'Manuela' )->json_has('/1/_authorised_values') |
| 809 |
->json_is( '/1/_authorised_values/country/lib' => $us->lib ); |
| 810 |
|
| 811 |
$schema->storage->txn_rollback; |
| 812 |
}; |