View | Details | Raw Unified | Return to bug 26635
Collapse All | Expand All

(-)a/t/db_dependent/Koha/Object.t (-2 / +42 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 20;
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 33-38 use Koha::DateUtils qw( dt_from_string ); Link Here
33
use Koha::Libraries;
33
use Koha::Libraries;
34
use Koha::Patrons;
34
use Koha::Patrons;
35
use Koha::ApiKeys;
35
use Koha::ApiKeys;
36
use Koha::AuthorisedValueCategories;
37
use Koha::AuthorisedValues;
36
38
37
use JSON;
39
use JSON;
38
use Scalar::Util qw( isvstring );
40
use Scalar::Util qw( isvstring );
Lines 867-869 subtest 'set_or_blank' => sub { Link Here
867
869
868
    $schema->storage->txn_rollback;
870
    $schema->storage->txn_rollback;
869
};
871
};
870
- 
872
873
subtest 'Authorised values expansion' => sub {
874
    plan tests => 4;
875
876
    $schema->storage->txn_begin;
877
878
    Koha::AuthorisedValues->search({category => 'Countries'})->delete;
879
    Koha::AuthorisedValueCategories->search({category_name =>'Countries'})->delete;
880
881
    my $cat = $builder->build_object({ class => 'Koha::AuthorisedValueCategories', value => {category_name =>'Countries'} });
882
    my $fr = $builder->build_object({ class => 'Koha::AuthorisedValues', value => {authorised_value => 'FR', lib=>'France', category=>$cat->category_name} });
883
    my $us = $builder->build_object({ class => 'Koha::AuthorisedValues', value => {authorised_value => 'US', lib=>'United States of America', category=>$cat->category_name} });
884
    my $ar = $builder->build_object({ class => 'Koha::AuthorisedValues', value => {authorised_value => 'AR', lib=>'Argentina', category=>$cat->category_name} });
885
886
    my $city_class = Test::MockModule->new('Koha::City');
887
    $city_class->mock( '_fetch_authorised_values',
888
        sub {
889
            my ($self) = @_;
890
            use Koha::AuthorisedValues;
891
            my $av = Koha::AuthorisedValues->find({authorised_value => $self->city_country, category => 'Countries'});
892
            return {country => $av->unblessed};
893
        }
894
    );
895
896
    my $marseille = $builder->build_object({ class => 'Koha::Cities', value => {city_country => 'FR', city_name => 'Marseille'} });
897
    my $cordoba = $builder->build_object({ class => 'Koha::Cities', value => {city_country => 'AR', city_name => 'Córdoba'} });
898
899
    my $mobj = $marseille->to_api({av_expand => 1});
900
    my $cobj = $cordoba->to_api({av_expand => 1});
901
902
    isnt($mobj->{_authorised_values}, undef, '_authorised_values exists for Marseille');
903
    isnt($cobj->{_authorised_values}, undef, '_authorised_values exists for Córdoba');
904
905
    is($mobj->{_authorised_values}->{country}->{lib}, $fr->lib, 'Authorised value for country expanded');
906
    is($cobj->{_authorised_values}->{country}->{lib}, $ar->lib, 'Authorised value for country expanded');
907
908
909
    $schema->storage->txn_rollback;
910
};

Return to bug 26635