Lines 1-7
Link Here
|
1 |
#!/usr/bin/perl |
1 |
#!/usr/bin/perl |
2 |
|
2 |
|
3 |
use Modern::Perl; |
3 |
use Modern::Perl; |
4 |
use Test::More tests => 15; |
4 |
use Test::More tests => 16; |
|
|
5 |
use Test::MockModule; |
5 |
|
6 |
|
6 |
use t::lib::TestBuilder; |
7 |
use t::lib::TestBuilder; |
7 |
use t::lib::Mocks; |
8 |
use t::lib::Mocks; |
Lines 12-17
use Koha::AuthorisedValue;
Link Here
|
12 |
use Koha::AuthorisedValues; |
13 |
use Koha::AuthorisedValues; |
13 |
use Koha::AuthorisedValueCategories; |
14 |
use Koha::AuthorisedValueCategories; |
14 |
use Koha::MarcSubfieldStructures; |
15 |
use Koha::MarcSubfieldStructures; |
|
|
16 |
use utf8; |
15 |
|
17 |
|
16 |
my $schema = Koha::Database->new->schema; |
18 |
my $schema = Koha::Database->new->schema; |
17 |
$schema->storage->txn_begin; |
19 |
$schema->storage->txn_begin; |
Lines 229-232
subtest 'search_by_*_field + find_by_koha_field + get_description' => sub {
Link Here
|
229 |
}; |
231 |
}; |
230 |
}; |
232 |
}; |
231 |
|
233 |
|
|
|
234 |
subtest "localization" => sub { |
235 |
plan tests => 14; |
236 |
|
237 |
Koha::AuthorisedValues->delete; |
238 |
|
239 |
my $category = |
240 |
Koha::AuthorisedValueCategory->new( { category_name => 'av_for_t' } ); |
241 |
my $av1 = $builder->build_object( |
242 |
{ |
243 |
class => 'Koha::AuthorisedValues', |
244 |
value => { category => $category->category_name, authorised_value => 'av1' } |
245 |
} |
246 |
); # translated in es-ES and fr-FR |
247 |
my $av2 = $builder->build_object( |
248 |
{ |
249 |
class => 'Koha::AuthorisedValues', |
250 |
value => { category => $category->category_name, authorised_value => 'av2' } |
251 |
} |
252 |
); # translated in es-ES and de-DE |
253 |
my $av3 = $builder->build_object( |
254 |
{ |
255 |
class => 'Koha::AuthorisedValues', |
256 |
value => { category => $category->category_name, authorised_value => 'av3' } |
257 |
} |
258 |
); # no translation |
259 |
Koha::Localization->new( |
260 |
{ |
261 |
entity => 'authorised_values', |
262 |
code => sprintf( "%s_%s", $av1->category, $av1->authorised_value ), |
263 |
lang => 'es-ES', |
264 |
interface => 'intranet', |
265 |
translation => 'traducción 1' |
266 |
} |
267 |
)->store; |
268 |
Koha::Localization->new( |
269 |
{ |
270 |
entity => 'authorised_values', |
271 |
code => sprintf( "%s_%s", $av1->category, $av1->authorised_value ), |
272 |
lang => 'es-ES', |
273 |
interface => 'opac', |
274 |
translation => 'opac traducción 1' |
275 |
} |
276 |
)->store; |
277 |
Koha::Localization->new( |
278 |
{ |
279 |
entity => 'authorised_values', |
280 |
code => sprintf( "%s_%s", $av1->category, $av2->authorised_value ), |
281 |
lang => 'es-ES', |
282 |
interface => 'intranet', |
283 |
translation => 'traducción 2' |
284 |
} |
285 |
)->store; |
286 |
|
287 |
Koha::Localization->new( |
288 |
{ |
289 |
entity => 'authorised_values', |
290 |
code => sprintf( "%s_%s", $av1->category, $av1->authorised_value ), |
291 |
lang => 'fr-FR', |
292 |
interface => 'intranet', |
293 |
translation => 'traduction 1' |
294 |
} |
295 |
)->store; |
296 |
Koha::Localization->new( |
297 |
{ |
298 |
entity => 'authorised_values', |
299 |
code => sprintf( "%s_%s", $av2->category, $av2->authorised_value ), |
300 |
lang => 'de-DE', |
301 |
interface => 'intranet', |
302 |
translation => 'Übersetzung 2' |
303 |
} |
304 |
)->store; |
305 |
|
306 |
my $c4_languages = Test::MockModule->new('C4::Languages'); |
307 |
$c4_languages->mock('getlanguage', sub { 'es-ES' }); |
308 |
my $c4_context = Test::MockModule->new('C4::Context'); |
309 |
$c4_context->mock('interface', 'intranet'); |
310 |
|
311 |
my $avs = Koha::AuthorisedValues->search_with_localization; |
312 |
is( $avs->count, 3); |
313 |
|
314 |
my $av1_loc = $avs->search( { authorised_value => $av1->authorised_value } )->next; |
315 |
is( $av1_loc->translated_description, 'traducción 1', 'av1 has a translated description fetched from search_with_localization' ); |
316 |
|
317 |
my $av2_loc = $avs->search( { authorised_value => $av2->authorised_value } )->next; |
318 |
is( $av2_loc->translated_description, 'traducción 2', 'av2 has a translated description fetched from search_with_localization' ); |
319 |
|
320 |
my $av3_loc = $avs->search( { authorised_value => $av3->authorised_value } )->next; |
321 |
is( $av3_loc->translated_description, $av3->lib, 'av3 does not have a translated description for intranet, lib is returned' ); |
322 |
|
323 |
is( $av1_loc->opac_translated_description, 'opac traducción 1', 'opac_translated_description is not fetched from search_with localization, but accessor is available' ); |
324 |
|
325 |
is( $av2_loc->opac_translated_description, $av2->lib_opac, 'av2 does not have a translated description for opac, lib_opac is returned' ); |
326 |
|
327 |
|
328 |
$c4_context->mock('opac', 'intranet'); |
329 |
|
330 |
$avs = Koha::AuthorisedValues->search_with_localization; |
331 |
is( $avs->count, 3); |
332 |
|
333 |
$av1_loc = $avs->search( { authorised_value => $av1->authorised_value } )->next; |
334 |
is( $av1_loc->opac_translated_description, 'opac traducción 1', 'opac_translated_description is fetched from search_with_localization' ); |
335 |
|
336 |
$av2_loc = $avs->search( { authorised_value => $av2->authorised_value } )->next; |
337 |
is( $av2_loc->opac_translated_description, $av2->lib_opac, 'av2 does not have a translated description, lib_opac is returned' ); |
338 |
|
339 |
$av3_loc = $avs->search( { authorised_value => $av3->authorised_value } )->next; |
340 |
is( $av3_loc->opac_translated_description, $av3->lib_opac, 'same than av2 for av3' ); |
341 |
|
342 |
is( $av1_loc->translated_description, 'traducción 1', 'translated description for intranet is not fetched from search_with_localization but accessor is available' ); |
343 |
|
344 |
is( $av2_loc->translated_description, 'traducción 2', 'translated description for intranet is not fetched from search_with_localization but accessor is available' ); |
345 |
|
346 |
is( $av3_loc->translated_description, $av3->lib, 'av3 does not have a translated description, lib is returned' ); |
347 |
|
348 |
my $translated_descriptions = $av1->translated_descriptions; |
349 |
is_deeply( |
350 |
$translated_descriptions, |
351 |
[ |
352 |
{ lang => "es-ES", translation => "traducción 1" }, |
353 |
{ lang => "fr-FR", translation => "traduction 1" }, |
354 |
{ lang => "es-ES", translation => "opac traducción 1" } |
355 |
] |
356 |
, 'translated_descriptions return all the translations for a given av'); |
357 |
|
358 |
}; |
359 |
|
232 |
$schema->storage->txn_rollback; |
360 |
$schema->storage->txn_rollback; |
233 |
- |
|
|