diff options
Diffstat (limited to 't/roles/translatable.t')
-rw-r--r-- | t/roles/translatable.t | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/t/roles/translatable.t b/t/roles/translatable.t new file mode 100644 index 000000000..71e39c360 --- /dev/null +++ b/t/roles/translatable.t @@ -0,0 +1,71 @@ +use FixMyStreet::TestMech; +my $mech = FixMyStreet::TestMech->new; + +my $body = FixMyStreet::DB->resultset("Body")->create({ name => 'Dunkirk' }); +my $contact = $mech->create_contact_ok( + body => $body, + email => 'potholes@dunkirk', + category => 'Potholes' +); + +FixMyStreet::DB->resultset("Translation")->create({ + lang => "fr", + tbl => "body", + object_id => $body->id, + col => "name", + msgstr => "Dunkerque", +}); + +FixMyStreet::DB->resultset("Translation")->create({ + lang => "de", + tbl => "contact", + object_id => $contact->id, + col => "category", + msgstr => "Schlaglöcher", +}); + +FixMyStreet::DB->resultset("Translation")->create({ + lang => "nb", + tbl => "contact", + object_id => $contact->id, + col => "category", + msgstr => "Hull i veien", +}); + +my ($problem) = $mech->create_problems_for_body(1, $body->id, "Title", { + whensent => \'current_timestamp', + category => 'Potholes', +}); + +is $body->name, "Dunkirk"; +is $contact->category_display, "Potholes"; +is $problem->category_display, "Potholes"; + +FixMyStreet::DB->schema->lang("fr"); +is $body->name, "Dunkerque"; +is $contact->category_display, "Potholes"; +is $problem->category_display, "Potholes"; + +FixMyStreet::DB->schema->lang("de"); +is $body->name, "Dunkirk"; +is $contact->category_display, "Schlaglöcher"; +is $problem->category_display, "Schlaglöcher"; + +is $contact->translation_for('category', 'de')->msgstr, "Schlaglöcher"; +is $body->translation_for('name', 'fr')->msgstr, "Dunkerque"; + +ok $body->add_translation_for('name', 'es', 'Dunkerque'); + +FixMyStreet::DB->schema->lang("es"); +is $body->name, "Dunkerque"; + +is $body->translation_for('name')->count, 2; + +FixMyStreet::override_config { + ALLOWED_COBRANDS => [ 'fiksgatami' ], +}, sub { + $mech->get_ok($problem->url); + $mech->content_contains('Hull i veien'); +}; + +done_testing; |