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 => { |
438 |
category => $category->category_name, |
439 |
lib => 'AR (Argentina)', |
440 |
lib_opac => 'Argentina', |
441 |
} |
442 |
} |
443 |
); |
444 |
my $france = $builder->build_object( |
445 |
{ class => 'Koha::AuthorisedValues', |
446 |
value => { |
447 |
category => $category->category_name, |
448 |
lib => 'FR (France)', |
449 |
lib_opac => 'France', |
450 |
} |
451 |
} |
452 |
); |
453 |
|
454 |
my $city_mock = Test::MockModule->new('Koha::City'); |
455 |
$city_mock->mock( |
456 |
'api_av_mapping', |
457 |
sub { |
458 |
my ( $self, $params ) = @_; |
459 |
|
460 |
my $av = Koha::AuthorisedValues->find( |
461 |
{ |
462 |
authorised_value => $self->city_country, |
463 |
category => $category->category_name, |
464 |
} |
465 |
); |
466 |
|
467 |
return { |
468 |
city_country => { |
469 |
category => $av->category, |
470 |
str => ( $params->{public} ) ? $av->lib_opac : $av->lib, |
471 |
type => 'av', |
472 |
} |
473 |
}; |
474 |
} |
475 |
); |
476 |
$city_mock->mock( 'public_read_list', sub { return [ 'city_id', 'city_country', 'city_name', 'city_state' ] } ); |
477 |
|
478 |
my $cordoba = $builder->build_object( |
479 |
{ class => 'Koha::Cities', |
480 |
value => { city_country => $argentina->authorised_value, city_name => 'Cordoba' } |
481 |
} |
482 |
); |
483 |
my $marseille = $builder->build_object( |
484 |
{ class => 'Koha::Cities', |
485 |
value => { city_country => $france->authorised_value, city_name => 'Marseille' } |
486 |
} |
487 |
); |
488 |
|
489 |
my $mobj = $marseille->to_api( { av_expand => 1, public => 1 } ); |
490 |
my $cobj = $cordoba->to_api( { av_expand => 1, public => 0 } ); |
491 |
|
492 |
ok( exists $mobj->{_str}, '_str exists for Marseille' ); |
493 |
ok( exists $cobj->{_str}, '_str exists for Córdoba' ); |
494 |
|
495 |
is_deeply( |
496 |
$mobj->{_str}->{country}, |
497 |
{ |
498 |
category => $category->category_name, |
499 |
str => $france->lib_opac, |
500 |
type => 'av', |
501 |
}, |
502 |
'Authorised value for country expanded' |
503 |
); |
504 |
is_deeply( |
505 |
$cobj->{_str}->{country}, |
506 |
{ |
507 |
category => $category->category_name, |
508 |
str => $argentina->lib, |
509 |
type => 'av' |
510 |
}, |
511 |
'Authorised value for country expanded' |
512 |
); |
513 |
|
514 |
$schema->storage->txn_rollback; |
515 |
}; |
516 |
|
426 |
$schema->storage->txn_rollback; |
517 |
$schema->storage->txn_rollback; |
427 |
}; |
518 |
}; |
428 |
|
519 |
|
Lines 997-1040
subtest 'messages() and add_message() tests' => sub {
Link Here
|
997 |
isnt( $patron->object_messages, undef, '->messages initializes the array if required' ); |
1088 |
isnt( $patron->object_messages, undef, '->messages initializes the array if required' ); |
998 |
is( scalar @{ $patron->object_messages }, 0, '->messages returns an empty arrayref' ); |
1089 |
is( scalar @{ $patron->object_messages }, 0, '->messages returns an empty arrayref' ); |
999 |
|
1090 |
|
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; |
1091 |
$schema->storage->txn_rollback; |
1040 |
}; |
1092 |
}; |