Lines 17-23
Link Here
|
17 |
|
17 |
|
18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
19 |
|
19 |
|
20 |
use Test::More tests => 22; |
20 |
use Test::More tests => 21; |
21 |
use Test::Exception; |
21 |
use Test::Exception; |
22 |
use Test::Warn; |
22 |
use Test::Warn; |
23 |
use DateTime; |
23 |
use DateTime; |
Lines 226-232
subtest 'TO_JSON tests' => sub {
Link Here
|
226 |
|
226 |
|
227 |
subtest "to_api() tests" => sub { |
227 |
subtest "to_api() tests" => sub { |
228 |
|
228 |
|
229 |
plan tests => 29; |
229 |
plan tests => 30; |
230 |
|
230 |
|
231 |
$schema->storage->txn_begin; |
231 |
$schema->storage->txn_begin; |
232 |
|
232 |
|
Lines 423-428
subtest "to_api() tests" => sub {
Link Here
|
423 |
} |
423 |
} |
424 |
}; |
424 |
}; |
425 |
|
425 |
|
|
|
426 |
subtest 'Authorised values expansion' => sub { |
427 |
|
428 |
plan tests => 4; |
429 |
|
430 |
$schema->storage->txn_begin; |
431 |
|
432 |
# new category |
433 |
my $category = $builder->build_object({ class => 'Koha::AuthorisedValueCategories' }); |
434 |
# add two countries |
435 |
my $argentina = $builder->build_object( |
436 |
{ class => 'Koha::AuthorisedValues', |
437 |
value => { category => $category->category_name, lib => 'AR (Argentina)', lib_opac => 'Argentina' } |
438 |
} |
439 |
); |
440 |
my $france = $builder->build_object( |
441 |
{ class => 'Koha::AuthorisedValues', |
442 |
value => { category => $category->category_name, lib => 'FR (France)', lib_opac => 'France' } |
443 |
} |
444 |
); |
445 |
|
446 |
my $city_mock = Test::MockModule->new('Koha::City'); |
447 |
$city_mock->mock( |
448 |
'api_av_mapping', |
449 |
sub { |
450 |
my ( $self, $params ) = @_; |
451 |
|
452 |
my $av = Koha::AuthorisedValues->find( |
453 |
{ |
454 |
authorised_value => $self->city_country, |
455 |
category => $category->category_name, |
456 |
} |
457 |
); |
458 |
|
459 |
return { |
460 |
city_country => { |
461 |
category => $av->category, |
462 |
description => ($params->{public}) ? $av->lib_opac : $av->lib, |
463 |
} |
464 |
}; |
465 |
} |
466 |
); |
467 |
$city_mock->mock( 'public_read_list', sub { return [ 'city_id', 'city_country', 'city_name', 'city_state' ] } ); |
468 |
|
469 |
my $cordoba = $builder->build_object( |
470 |
{ class => 'Koha::Cities', |
471 |
value => { city_country => $argentina->authorised_value, city_name => 'Cordoba' } |
472 |
} |
473 |
); |
474 |
my $marseille = $builder->build_object( |
475 |
{ class => 'Koha::Cities', |
476 |
value => { city_country => $france->authorised_value, city_name => 'Marseille' } |
477 |
} |
478 |
); |
479 |
|
480 |
my $mobj = $marseille->to_api( { av_expand => 1, public => 1 } ); |
481 |
my $cobj = $cordoba->to_api( { av_expand => 1, public => 0 } ); |
482 |
|
483 |
ok( exists $mobj->{_authorised_values}, '_authorised_values exists for Marseille' ); |
484 |
ok( exists $cobj->{_authorised_values}, '_authorised_values exists for Córdoba' ); |
485 |
|
486 |
is_deeply( |
487 |
$mobj->{_authorised_values}->{country}, |
488 |
{ category => $category->category_name, description => $france->lib_opac }, |
489 |
'Authorised value for country expanded' |
490 |
); |
491 |
is_deeply( |
492 |
$cobj->{_authorised_values}->{country}, |
493 |
{ category => $category->category_name, description => $argentina->lib }, |
494 |
'Authorised value for country expanded' |
495 |
); |
496 |
|
497 |
$schema->storage->txn_rollback; |
498 |
}; |
499 |
|
426 |
$schema->storage->txn_rollback; |
500 |
$schema->storage->txn_rollback; |
427 |
}; |
501 |
}; |
428 |
|
502 |
|
Lines 997-1040
subtest 'messages() and add_message() tests' => sub {
Link Here
|
997 |
isnt( $patron->object_messages, undef, '->messages initializes the array if required' ); |
1071 |
isnt( $patron->object_messages, undef, '->messages initializes the array if required' ); |
998 |
is( scalar @{ $patron->object_messages }, 0, '->messages returns an empty arrayref' ); |
1072 |
is( scalar @{ $patron->object_messages }, 0, '->messages returns an empty arrayref' ); |
999 |
|
1073 |
|
1000 |
$schema->storage->txn_rollback; |
|
|
1001 |
}; |
1002 |
|
1003 |
subtest 'Authorised values expansion' => sub { |
1004 |
plan tests => 4; |
1005 |
|
1006 |
$schema->storage->txn_begin; |
1007 |
|
1008 |
Koha::AuthorisedValues->search({category => 'Countries'})->delete; |
1009 |
Koha::AuthorisedValueCategories->search({category_name =>'Countries'})->delete; |
1010 |
|
1011 |
my $cat = $builder->build_object({ class => 'Koha::AuthorisedValueCategories', value => {category_name =>'Countries'} }); |
1012 |
my $fr = $builder->build_object({ class => 'Koha::AuthorisedValues', value => {authorised_value => 'FR', lib=>'France', category=>$cat->category_name} }); |
1013 |
my $us = $builder->build_object({ class => 'Koha::AuthorisedValues', value => {authorised_value => 'US', lib=>'United States of America', category=>$cat->category_name} }); |
1014 |
my $ar = $builder->build_object({ class => 'Koha::AuthorisedValues', value => {authorised_value => 'AR', lib=>'Argentina', category=>$cat->category_name} }); |
1015 |
|
1016 |
my $city_class = Test::MockModule->new('Koha::City'); |
1017 |
$city_class->mock( '_fetch_authorised_values', |
1018 |
sub { |
1019 |
my ($self) = @_; |
1020 |
use Koha::AuthorisedValues; |
1021 |
my $av = Koha::AuthorisedValues->find({authorised_value => $self->city_country, category => 'Countries'}); |
1022 |
return {country => $av->unblessed}; |
1023 |
} |
1024 |
); |
1025 |
|
1026 |
my $marseille = $builder->build_object({ class => 'Koha::Cities', value => {city_country => 'FR', city_name => 'Marseille'} }); |
1027 |
my $cordoba = $builder->build_object({ class => 'Koha::Cities', value => {city_country => 'AR', city_name => 'Córdoba'} }); |
1028 |
|
1029 |
my $mobj = $marseille->to_api({av_expand => 1}); |
1030 |
my $cobj = $cordoba->to_api({av_expand => 1}); |
1031 |
|
1032 |
isnt($mobj->{_authorised_values}, undef, '_authorised_values exists for Marseille'); |
1033 |
isnt($cobj->{_authorised_values}, undef, '_authorised_values exists for Córdoba'); |
1034 |
|
1035 |
is($mobj->{_authorised_values}->{country}->{lib}, $fr->lib, 'Authorised value for country expanded'); |
1036 |
is($cobj->{_authorised_values}->{country}->{lib}, $ar->lib, 'Authorised value for country expanded'); |
1037 |
|
1038 |
|
1039 |
$schema->storage->txn_rollback; |
1074 |
$schema->storage->txn_rollback; |
1040 |
}; |
1075 |
}; |