diff options
Diffstat (limited to 't/app')
-rw-r--r-- | t/app/model/state.t | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/t/app/model/state.t b/t/app/model/state.t index 1653e36e2..35f3d4fb3 100644 --- a/t/app/model/state.t +++ b/t/app/model/state.t @@ -1,5 +1,5 @@ use FixMyStreet::Test; -use Test::More; +use FixMyStreet::Cobrand; my $rs = FixMyStreet::DB->resultset('State'); my $trans_rs = FixMyStreet::DB->resultset('Translation'); @@ -14,6 +14,9 @@ for ( $trans_rs->create({ tbl => 'state', col => 'name', object_id => $obj->id, lang => $lang, msgstr => "$lang $_->{label}" }); } +$trans_rs->create({ tbl => 'state', col => 'name', object_id => -1, lang => 'en-gb', msgstr => "Open Eng trans" }); + +$rs->clear; my $states = $rs->states; my %states = map { $_->label => $_ } @$states; @@ -25,6 +28,8 @@ subtest 'Open/closed database data is as expected' => sub { is @$closed, 5; }; +# No language set at this point + is $rs->display('investigating'), 'Investigating'; is $rs->display('bad'), 'bad'; is $rs->display('confirmed'), 'Open'; @@ -41,6 +46,9 @@ subtest 'default name is untranslated' => sub { }; subtest 'msgstr gets translated if available when the language changes' => sub { + FixMyStreet::DB->schema->lang('en-gb'); + is $states{confirmed}->name, 'Open'; + is $states{confirmed}->msgstr, 'Open Eng trans'; FixMyStreet::DB->schema->lang('de'); is $states{'in progress'}->name, 'In progress'; is $states{'in progress'}->msgstr, 'de in progress'; @@ -50,8 +58,6 @@ subtest 'msgstr gets translated if available when the language changes' => sub { is $states{'unable to fix'}->msgstr, 'No further action'; }; -$rs->clear; - is_deeply [ sort FixMyStreet::DB::Result::Problem->open_states ], ['action scheduled', 'confirmed', 'in progress', 'investigating', 'planned'], 'open states okay'; is_deeply [ sort FixMyStreet::DB::Result::Problem->closed_states ], @@ -59,4 +65,19 @@ is_deeply [ sort FixMyStreet::DB::Result::Problem->closed_states ], is_deeply [ sort FixMyStreet::DB::Result::Problem->fixed_states ], ['fixed', 'fixed - council', 'fixed - user'], 'fixed states okay'; +FixMyStreet::override_config { + LANGUAGES => [ 'en-gb,English,en_GB', 'nb,Norwegian,nb_NO' ], +}, sub { + subtest 'translation of open works both ways (file/db)' => sub { + # Note at this point the states have been cached + my $cobrand = FixMyStreet::Cobrand->get_class_for_moniker('default')->new; + my $lang = $cobrand->set_lang_and_domain('nb', 1, FixMyStreet->path_to('locale')->stringify); + is $lang, 'nb'; + is $rs->display('confirmed'), "Ă…pen"; + $lang = $cobrand->set_lang_and_domain('en-gb', 1, FixMyStreet->path_to('locale')->stringify); + is $lang, 'en-gb'; + is $rs->display('confirmed'), "Open Eng trans"; + }; +}; + done_testing(); |