Bugzilla – Attachment 126322 Details for
Bug 29245
Fix the parameters of getTranslatedLanguages
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 29245: Extend tests for getTranslatedLanguages
Bug-29245-Extend-tests-for-getTranslatedLanguages.patch (text/plain), 4.29 KB, created by
Marcel de Rooy
on 2021-10-15 12:00:50 UTC
(
hide
)
Description:
Bug 29245: Extend tests for getTranslatedLanguages
Filename:
MIME Type:
Creator:
Marcel de Rooy
Created:
2021-10-15 12:00:50 UTC
Size:
4.29 KB
patch
obsolete
>From 42910ef8acd3fe82f2f826946537310a2b5d6cd1 Mon Sep 17 00:00:00 2001 >From: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >Date: Fri, 15 Oct 2021 10:04:46 +0000 >Subject: [PATCH] Bug 29245: Extend tests for getTranslatedLanguages >Content-Type: text/plain; charset=utf-8 > >Test plan: >Run test again. > >Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >--- > t/db_dependent/Languages.t | 49 +++++++++++++++++++++++++++++++------- > 1 file changed, 41 insertions(+), 8 deletions(-) > >diff --git a/t/db_dependent/Languages.t b/t/db_dependent/Languages.t >index f87c45795b..217eaa564e 100755 >--- a/t/db_dependent/Languages.t >+++ b/t/db_dependent/Languages.t >@@ -21,17 +21,21 @@ use Modern::Perl; > use List::Util qw(first); > use Test::More tests => 5; > use Test::Warn; >+use Test::MockModule; > > use t::lib::Mocks; > use Koha::Database; >+use Koha::Caches; > > BEGIN { > use_ok('C4::Languages', qw( accept_language getAllLanguages getLanguages getTranslatedLanguages get_rfc4646_from_iso639 )); > } > >-my $schema = Koha::Database->new->schema; >+our $schema = Koha::Database->new->schema; > $schema->storage->txn_begin; >-my $dbh = C4::Context->dbh; >+our $dbh = C4::Context->dbh; >+our $lang_module = Test::MockModule->new( 'C4::Languages' ); >+our $cache = Koha::Caches->get_instance; > > subtest 'get_themes, get_language_dirs' => sub { > plan tests => 4; >@@ -66,24 +70,53 @@ subtest 'getAllLanguages' => sub { > }; > > subtest 'getTranslatedLanguages' => sub { >- plan tests => 4; >+ plan tests => 9; >+ >+ # Obvious assumptions >+ t::lib::Mocks::mock_preference( 'opacthemes', 'bootstrap' ); >+ t::lib::Mocks::mock_preference( 'template', 'prog' ); > > my $translatedlanguages1; >- warnings_are { $translatedlanguages1 = C4::Languages::getTranslatedLanguages( 'opac', 'prog' ) } >+ $cache->clear_from_cache( "languages_opac_bootstrap" ); >+ warnings_are { $translatedlanguages1 = C4::Languages::getTranslatedLanguages( 'opac', 'bootstrap' ) } > [], > 'no warnings for calling getTranslatedLanguages'; >- > my @currentcheck1 = map { $_->{current} } @$translatedlanguages1; > my $onlyzeros = first { $_ != 0 } @currentcheck1; >- ok(! $onlyzeros, "Everything was zeros."); >+ is( $onlyzeros, undef, "No language was marked as current"); > > my $translatedlanguages2; >- warnings_are { $translatedlanguages2 = C4::Languages::getTranslatedLanguages( 'opac', 'prog', 'en' ) } >+ $cache->clear_from_cache( "languages_opac_bootstrap" ); >+ warnings_are { $translatedlanguages2 = C4::Languages::getTranslatedLanguages( 'opac', 'bootstrap', 'en' ) } > [], > 'no warnings for calling getTranslatedLanguages'; > my @currentcheck2 = map { $_->{current} } @$translatedlanguages2; > $onlyzeros = first { $_ != 0 } @currentcheck2; >- ok($onlyzeros, "There is a $onlyzeros"); >+ is( $onlyzeros, 1, "en is marked as current now" ); >+ >+ # mock opac languages, test leaving out opac/bootstrap >+ my @language_dirs; >+ $lang_module->mock( '_get_language_dirs', sub { return @language_dirs; } ); >+ t::lib::Mocks::mock_preference( 'OPACLanguages', 'ita,eng,nl-NL' ); >+ @language_dirs = ( 'eng', 'ita', 'nl-NL' ); >+ $translatedlanguages1 = C4::Languages::getTranslatedLanguages(); >+ is( @$translatedlanguages1, 1, 'Only one language since we didnt clear the cache' ); >+ $cache->clear_from_cache( "languages_opac_bootstrap" ); >+ $translatedlanguages1 = C4::Languages::getTranslatedLanguages(); >+ is( @$translatedlanguages1, 3, 'Check if we get back three languages now' ); >+ >+ # mock intranet languages >+ @language_dirs = ( 'eng', 'fr-CA', 'fr-FR', 'fr-NL', 'zh-NL' ); >+ $cache->clear_from_cache( "languages_intranet_prog" ); >+ t::lib::Mocks::mock_preference( 'language', 'zh,fr-NL,fr-CA,eng,fr-FR,de-DE' ); # de-DE missing >+ # TODO Should getTranslatedLanguages sort? >+ $translatedlanguages1 = [ sort >+ { $a->{language} cmp $b->{language} } >+ @{ C4::Languages::getTranslatedLanguages( 'intranet' ) }]; # forgot prog >+ is( @$translatedlanguages1, 3, 'Three intranet languages' ); >+ is( @{$translatedlanguages1->[1]->{sublanguages_loop}}, 3, 'Three french variants' ); >+ is( $translatedlanguages1->[2]->{language}, 'zh', 'Found zh too' ); >+ $lang_module->unmock( '_get_language_dirs' ); > }; > > subtest 'Language descriptions, Language_subtag_registry, RFC4646 to ISO639' => sub { >-- >2.20.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 29245
:
126312
|
126313
|
126314
|
126315
|
126322
|
126345
|
126346
|
126347
|
126348