+ subtest 'Authorised values expansion' => sub {
+
+ plan tests => 4;
+
+ $schema->storage->txn_begin;
+
+ # new category
+ my $category = $builder->build_object({ class => 'Koha::AuthorisedValueCategories' });
+ # add two countries
+ my $argentina = $builder->build_object(
+ { class => 'Koha::AuthorisedValues',
+ value => {
+ category => $category->category_name,
+ lib => 'AR (Argentina)',
+ lib_opac => 'Argentina',
+ }
+ }
+ );
+ my $france = $builder->build_object(
+ { class => 'Koha::AuthorisedValues',
+ value => {
+ category => $category->category_name,
+ lib => 'FR (France)',
+ lib_opac => 'France',
+ }
+ }
+ );
+
+ my $city_mock = Test::MockModule->new('Koha::City');
+ $city_mock->mock(
+ 'api_av_mapping',
+ sub {
+ my ( $self, $params ) = @_;
+
+ my $av = Koha::AuthorisedValues->find(
+ {
+ authorised_value => $self->city_country,
+ category => $category->category_name,
+ }
+ );
+
+ return {
+ city_country => {
+ category => $av->category,
+ str => ( $params->{public} ) ? $av->lib_opac : $av->lib,
+ type => 'av',
+ }
+ };
+ }
+ );
+ $city_mock->mock( 'public_read_list', sub { return [ 'city_id', 'city_country', 'city_name', 'city_state' ] } );
+
+ my $cordoba = $builder->build_object(
+ { class => 'Koha::Cities',
+ value => { city_country => $argentina->authorised_value, city_name => 'Cordoba' }
+ }
+ );
+ my $marseille = $builder->build_object(
+ { class => 'Koha::Cities',
+ value => { city_country => $france->authorised_value, city_name => 'Marseille' }
+ }
+ );
+
+ my $mobj = $marseille->to_api( { av_expand => 1, public => 1 } );
+ my $cobj = $cordoba->to_api( { av_expand => 1, public => 0 } );
+
+ ok( exists $mobj->{_str}, '_str exists for Marseille' );
+ ok( exists $cobj->{_str}, '_str exists for Córdoba' );
+
+ is_deeply(
+ $mobj->{_str}->{country},
+ {
+ category => $category->category_name,
+ str => $france->lib_opac,
+ type => 'av',
+ },
+ 'Authorised value for country expanded'
+ );
+ is_deeply(
+ $cobj->{_str}->{country},
+ {
+ category => $category->category_name,
+ str => $argentina->lib,
+ type => 'av'
+ },
+ 'Authorised value for country expanded'
+ );
+
+ $schema->storage->txn_rollback;
+ };
+