|
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 348-354
subtest 'objects.search helper, embed' => sub {
Link Here
|
| 348 |
$schema->storage->txn_rollback; |
350 |
$schema->storage->txn_rollback; |
| 349 |
}; |
351 |
}; |
| 350 |
|
352 |
|
| 351 |
subtest 'object.search helper with query parameter' => sub { |
353 |
subtest 'objects.search helper with query parameter' => sub { |
| 352 |
plan tests => 4; |
354 |
plan tests => 4; |
| 353 |
|
355 |
|
| 354 |
$schema->storage->txn_begin; |
356 |
$schema->storage->txn_begin; |
|
Lines 372-378
subtest 'object.search helper with query parameter' => sub {
Link Here
|
| 372 |
$schema->storage->txn_rollback; |
374 |
$schema->storage->txn_rollback; |
| 373 |
}; |
375 |
}; |
| 374 |
|
376 |
|
| 375 |
subtest 'object.search helper with q parameter' => sub { |
377 |
subtest 'objects.search helper with q parameter' => sub { |
| 376 |
plan tests => 4; |
378 |
plan tests => 4; |
| 377 |
|
379 |
|
| 378 |
$schema->storage->txn_begin; |
380 |
$schema->storage->txn_begin; |
|
Lines 396-402
subtest 'object.search helper with q parameter' => sub {
Link Here
|
| 396 |
$schema->storage->txn_rollback; |
398 |
$schema->storage->txn_rollback; |
| 397 |
}; |
399 |
}; |
| 398 |
|
400 |
|
| 399 |
subtest 'object.search helper with x-koha-query header' => sub { |
401 |
subtest 'objects.search helper with x-koha-query header' => sub { |
| 400 |
plan tests => 4; |
402 |
plan tests => 4; |
| 401 |
|
403 |
|
| 402 |
$schema->storage->txn_begin; |
404 |
$schema->storage->txn_begin; |
|
Lines 420-426
subtest 'object.search helper with x-koha-query header' => sub {
Link Here
|
| 420 |
$schema->storage->txn_rollback; |
422 |
$schema->storage->txn_rollback; |
| 421 |
}; |
423 |
}; |
| 422 |
|
424 |
|
| 423 |
subtest 'object.search helper with all query methods' => sub { |
425 |
subtest 'objects.search helper with all query methods' => sub { |
| 424 |
plan tests => 6; |
426 |
plan tests => 6; |
| 425 |
|
427 |
|
| 426 |
$schema->storage->txn_begin; |
428 |
$schema->storage->txn_begin; |
|
Lines 447-454
subtest 'object.search helper with all query methods' => sub {
Link Here
|
| 447 |
$schema->storage->txn_rollback; |
449 |
$schema->storage->txn_rollback; |
| 448 |
}; |
450 |
}; |
| 449 |
|
451 |
|
| 450 |
subtest 'object.search helper order by embedded columns' => sub { |
452 |
subtest 'objects.search helper order by embedded columns' => sub { |
| 451 |
|
|
|
| 452 |
plan tests => 3; |
453 |
plan tests => 3; |
| 453 |
|
454 |
|
| 454 |
$schema->storage->txn_begin; |
455 |
$schema->storage->txn_begin; |
|
Lines 512-514
subtest 'objects.find helper, embed' => sub {
Link Here
|
| 512 |
|
513 |
|
| 513 |
$schema->storage->txn_rollback; |
514 |
$schema->storage->txn_rollback; |
| 514 |
}; |
515 |
}; |
| 515 |
- |
516 |
|
|
|
517 |
subtest 'objects.find helper with expanded authorised values' => sub { |
| 518 |
plan tests => 10; |
| 519 |
|
| 520 |
$schema->storage->txn_begin; |
| 521 |
|
| 522 |
my $t = Test::Mojo->new; |
| 523 |
|
| 524 |
Koha::AuthorisedValues->search( { category => 'Countries' } )->delete; |
| 525 |
Koha::AuthorisedValueCategories->search( { category_name => 'Countries' } ) |
| 526 |
->delete; |
| 527 |
|
| 528 |
my $cat = $builder->build_object( |
| 529 |
{ |
| 530 |
class => 'Koha::AuthorisedValueCategories', |
| 531 |
value => { category_name => 'Countries' } |
| 532 |
} |
| 533 |
); |
| 534 |
my $fr = $builder->build_object( |
| 535 |
{ |
| 536 |
class => 'Koha::AuthorisedValues', |
| 537 |
value => { |
| 538 |
authorised_value => 'FR', |
| 539 |
lib => 'France', |
| 540 |
category => $cat->category_name |
| 541 |
} |
| 542 |
} |
| 543 |
); |
| 544 |
my $us = $builder->build_object( |
| 545 |
{ |
| 546 |
class => 'Koha::AuthorisedValues', |
| 547 |
value => { |
| 548 |
authorised_value => 'US', |
| 549 |
lib => 'United States of America', |
| 550 |
category => $cat->category_name |
| 551 |
} |
| 552 |
} |
| 553 |
); |
| 554 |
my $ar = $builder->build_object( |
| 555 |
{ |
| 556 |
class => 'Koha::AuthorisedValues', |
| 557 |
value => { |
| 558 |
authorised_value => 'AR', |
| 559 |
lib => 'Argentina', |
| 560 |
category => $cat->category_name |
| 561 |
} |
| 562 |
} |
| 563 |
); |
| 564 |
|
| 565 |
my $city_class = Test::MockModule->new('Koha::City'); |
| 566 |
$city_class->mock( |
| 567 |
'_fetch_authorised_values', |
| 568 |
sub { |
| 569 |
my ($self) = @_; |
| 570 |
use Koha::AuthorisedValues; |
| 571 |
my $av = Koha::AuthorisedValues->find( |
| 572 |
{ |
| 573 |
authorised_value => $self->city_country, |
| 574 |
category => 'Countries' |
| 575 |
} |
| 576 |
); |
| 577 |
return { country => $av->unblessed }; |
| 578 |
} |
| 579 |
); |
| 580 |
|
| 581 |
my $manuel = $builder->build_object( |
| 582 |
{ |
| 583 |
class => 'Koha::Cities', |
| 584 |
value => { |
| 585 |
city_name => 'Manuel', |
| 586 |
city_country => 'AR' |
| 587 |
} |
| 588 |
} |
| 589 |
); |
| 590 |
my $manuela = $builder->build_object( |
| 591 |
{ |
| 592 |
class => 'Koha::Cities', |
| 593 |
value => { |
| 594 |
city_name => 'Manuela', |
| 595 |
city_country => 'US' |
| 596 |
} |
| 597 |
} |
| 598 |
); |
| 599 |
|
| 600 |
$t->get_ok( '/cities/' . $manuel->cityid => { 'x-koha-av-expand' => 1 } ) |
| 601 |
->status_is(200)->json_is( '/name' => 'Manuel' ) |
| 602 |
->json_has('/_authorised_values') |
| 603 |
->json_is( '/_authorised_values/country/lib' => $ar->lib ); |
| 604 |
|
| 605 |
$t->get_ok( '/cities/' . $manuela->cityid => { 'x-koha-av-expand' => 1 } ) |
| 606 |
->status_is(200)->json_is( '/name' => 'Manuela' ) |
| 607 |
->json_has('/_authorised_values') |
| 608 |
->json_is( '/_authorised_values/country/lib' => $us->lib ); |
| 609 |
|
| 610 |
$schema->storage->txn_rollback; |
| 611 |
}; |
| 612 |
|
| 613 |
subtest 'objects.search helper with expanded authorised values' => sub { |
| 614 |
|
| 615 |
plan tests => 11; |
| 616 |
|
| 617 |
my $t = Test::Mojo->new; |
| 618 |
|
| 619 |
$schema->storage->txn_begin; |
| 620 |
|
| 621 |
Koha::AuthorisedValues->search( { category => 'Countries' } )->delete; |
| 622 |
Koha::AuthorisedValueCategories->search( { category_name => 'Countries' } ) |
| 623 |
->delete; |
| 624 |
|
| 625 |
my $cat = $builder->build_object( |
| 626 |
{ |
| 627 |
class => 'Koha::AuthorisedValueCategories', |
| 628 |
value => { category_name => 'Countries' } |
| 629 |
} |
| 630 |
); |
| 631 |
my $fr = $builder->build_object( |
| 632 |
{ |
| 633 |
class => 'Koha::AuthorisedValues', |
| 634 |
value => { |
| 635 |
authorised_value => 'FR', |
| 636 |
lib => 'France', |
| 637 |
category => $cat->category_name |
| 638 |
} |
| 639 |
} |
| 640 |
); |
| 641 |
my $us = $builder->build_object( |
| 642 |
{ |
| 643 |
class => 'Koha::AuthorisedValues', |
| 644 |
value => { |
| 645 |
authorised_value => 'US', |
| 646 |
lib => 'United States of America', |
| 647 |
category => $cat->category_name |
| 648 |
} |
| 649 |
} |
| 650 |
); |
| 651 |
my $ar = $builder->build_object( |
| 652 |
{ |
| 653 |
class => 'Koha::AuthorisedValues', |
| 654 |
value => { |
| 655 |
authorised_value => 'AR', |
| 656 |
lib => 'Argentina', |
| 657 |
category => $cat->category_name |
| 658 |
} |
| 659 |
} |
| 660 |
); |
| 661 |
|
| 662 |
my $city_class = Test::MockModule->new('Koha::City'); |
| 663 |
$city_class->mock( |
| 664 |
'_fetch_authorised_values', |
| 665 |
sub { |
| 666 |
my ($self) = @_; |
| 667 |
use Koha::AuthorisedValues; |
| 668 |
my $av = Koha::AuthorisedValues->find( |
| 669 |
{ |
| 670 |
authorised_value => $self->city_country, |
| 671 |
category => 'Countries' |
| 672 |
} |
| 673 |
); |
| 674 |
return { country => $av->unblessed }; |
| 675 |
} |
| 676 |
); |
| 677 |
|
| 678 |
$builder->build_object( |
| 679 |
{ |
| 680 |
class => 'Koha::Cities', |
| 681 |
value => { |
| 682 |
city_name => 'Manuel', |
| 683 |
city_country => 'AR' |
| 684 |
} |
| 685 |
} |
| 686 |
); |
| 687 |
$builder->build_object( |
| 688 |
{ |
| 689 |
class => 'Koha::Cities', |
| 690 |
value => { |
| 691 |
city_name => 'Manuela', |
| 692 |
city_country => 'US' |
| 693 |
} |
| 694 |
} |
| 695 |
); |
| 696 |
|
| 697 |
$t->get_ok( '/cities?name=manuel&_per_page=4&_page=1&_match=starts_with' => |
| 698 |
{ 'x-koha-av-expand' => 1 } )->status_is(200)->json_has('/0') |
| 699 |
->json_has('/1')->json_hasnt('/2')->json_is( '/0/name' => 'Manuel' ) |
| 700 |
->json_has('/0/_authorised_values') |
| 701 |
->json_is( '/0/_authorised_values/country/lib' => $ar->lib ) |
| 702 |
->json_is( '/1/name' => 'Manuela' )->json_has('/1/_authorised_values') |
| 703 |
->json_is( '/1/_authorised_values/country/lib' => $us->lib ); |
| 704 |
|
| 705 |
$schema->storage->txn_rollback; |
| 706 |
}; |