aboutsummaryrefslogtreecommitdiffstats
path: root/t/roles/translatable.t
blob: 9f8c67394eefa6f340d5895305164cce0b6facca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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";

# Multiple LANGUAGES so translation code is called
FixMyStreet::override_config {
    LANGUAGES => [ 'en-gb,English,en_GB', 'de,German,de_DE' ]
}, sub {
    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 {
    LANGUAGES => [ 'en-gb,English,en_GB', 'nb,Norwegian,nb_NO' ],
    ALLOWED_COBRANDS => [ 'fiksgatami' ],
}, sub {
    $mech->get_ok($problem->url);
    $mech->content_contains('Hull i veien');
};

subtest 'Check display_name override' => sub {
    $contact->set_extra_metadata( display_name => 'Override name' );
    $contact->update;
    is $contact->category_display, "Override name";
    is $problem->category_display, "Override name";
};

done_testing;