-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path02_base.t
168 lines (146 loc) · 5.94 KB
/
02_base.t
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#!perl
use strict;
use warnings;
use Test::Most tests=>87+1;
use Test::NoWarnings;
use lib qw(t/);
use testlib;
use utf8;
my $mech = init();
$mech->{catalyst_debug} = 1;
# Test 1 - set current locale
{
my $response = request($mech,'/base/test1');
is($response->{default_locale},'de_AT','Default locale');
is($response->{locale},'de_CH','Current locale');
}
# Test 2 - get locale
{
$mech->add_header( 'user-agent' => "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; fr; rv:1.9.2) Gecko/20100115 Firefox/3.6" );
my $response = request($mech,'/base/test2');
is($response->{session},'de_CH','Session locale');
is($response->{user},undef,'User locale');
is($response->{browser},'fr','Browser language');
}
# Test 3a - get locale again
{
$mech->add_header( 'user-agent' => "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; fr; rv:1.9.2) Gecko/20100115 Firefox/3.6" );
my $response = request($mech,'/base/test3');
is($response->{datetime}{locale},'German Austria','DateTime locale');
is($response->{datetime}{timezone},'Europe/Vienna','DateTime timezone');
is($response->{locale},'de_AT','Locale');
is($response->{locale_from_c},'de_AT','Locale from $c');
is($response->{request}{browser_language},'fr','Browser language');
like($response->{number_format},qr/^\+\+EUR\s+27,03$/,'Browser language');
}
# Test 3b - get with strange user-agent
{
$mech->add_header( 'user-agent' => "hidden-agent" );
my $response = request($mech,'/base/test3');
is($response->{request}{browser_territory},undef,'Browser territory');
is($response->{request}{browser_language},undef,'Browser language');
}
# Test 4a - maketext inheritance
{
my $response = request($mech,'/base/test4/de_AT');
is($response->{locale},'de_AT','Locale');
is($response->{translation}{1},'string1 de_AT','String 1 for de_AT ok');
is($response->{translation}{4},'string4 de_AT 4 hasen','String 4 for de_AT ok');
is($response->{translation}{5},'string5 de','String 5 for de_AT ok');
is($response->{translation}{6},'string6','String 6 for de_AT ok');
}
# Test 4b - maketext inheritance
{
my $response = request($mech,'/base/test4/de_CH');
is($response->{locale},'de_CH','Locale');
is($response->{translation}{1},'string1 de','String 1 for de_CH ok');
is($response->{translation}{4},'string4 de 4 hasen','String 4 for de_CH ok');
is($response->{translation}{5},'string5 de','String 5 for de_CH ok');
is($response->{translation}{6},'string6','String 6 for de_CH ok');
}
# Test 4c - maketext inheritance
{
my $response = request($mech,'/base/test4/fr_CH');
is($response->{locale},'fr_CH','Locale');
is($response->{translation}{1},'string1 fr_CH','String 1 for fr_CH ok');
is($response->{translation}{4},'string4 fr_CH 4 lapins','String 4 for fr_CH ok');
is($response->{translation}{5},'string5','String 5 for fr_CH ok');
is($response->{translation}{6},'string6','String 6 for fr_CH ok');
}
# Test 4d - maketext inheritance
{
my $response = request($mech,'/base/test4/fr');
is($response->{locale},'fr','Locale');
is($response->{translation}{1},'string1','String 1 for fr ok');
is($response->{translation}{4},'string4','String 4 for fr ok');
is($response->{translation}{5},'string5','String 5 for fr ok');
is($response->{translation}{6},'string6','String 6 for fr ok');
}
# Test 4e - invalid locale
{
my $response = request($mech,'/base/test4/xx');
is($response->{locale},'de_AT','Locale');
}
# Test 5 - locale set
{
my $response = request($mech,'/base/test5');
cmp_deeply($response,{
'de_AT' => {
'timezone' => 'Europe/Vienna'
},
'de_CH' => {
'timezone' => 'Europe/Zurich'
},
'de_DE' => {
'timezone' => 'Europe/Berlin'
},
'fr_CH' => {
'timezone' => 'Europe/Zurich'
},
'fr' => {
'timezone' => 'floating',
}
},'Multiple locales ok');
}
# Test 5 - locale set
{
my $response = request($mech,'/base/test8');
is($response->{sort_collate},'Afghanistan,Ägypten,Albanien,Algerien,Andorra,Äquatorialguinea,Äthiopien,Bahamas,Zypern');
is($response->{sort_perl},'Afghanistan,Albanien,Algerien,Andorra,Bahamas,Zypern,Ägypten,Äquatorialguinea,Äthiopien');
}
# Test 6a - data localize inheritance
{
my $response = request($mech,'/base/test9/de_AT');
is($response->{locale},'de_AT','Locale');
is($response->{translation}{1},'string1 de_AT','String 1 for de_AT ok');
is($response->{translation}{4},'string4 de_AT 4 hasen','String 4 for de_AT ok');
is($response->{translation}{5},'string5 de','String 5 for de_AT ok');
is($response->{translation}{6},'string6','String 6 for de_AT ok');
}
# Test 6b - data localize inheritance
{
my $response = request($mech,'/base/test9/de_CH');
is($response->{locale},'de_CH','Locale');
is($response->{translation}{1},'string1 de','String 1 for de_CH ok');
is($response->{translation}{4},'string4 de 4 hasen','String 4 for de_CH ok');
is($response->{translation}{5},'string5 de','String 5 for de_CH ok');
is($response->{translation}{6},'string6','String 6 for de_CH ok');
}
# Test 6c - data localize inheritance
{
my $response = request($mech,'/base/test9/fr_CH');
is($response->{locale},'fr_CH','Locale');
is($response->{translation}{1},'string1 fr_CH','String 1 for fr_CH ok');
is($response->{translation}{4},'string4 fr_CH 4 lapins','String 4 for fr_CH ok');
is($response->{translation}{5},'string5','String 5 for fr_CH ok');
is($response->{translation}{6},'string6','String 6 for fr_CH ok');
}
# Test 6d - data localize inheritance
{
my $response = request($mech,'/base/test9/fr');
is($response->{locale},'fr','Locale');
is($response->{translation}{1},'string1','String 1 for fr ok');
is($response->{translation}{4},'string4','String 4 for fr ok');
is($response->{translation}{5},'string5','String 5 for fr ok');
is($response->{translation}{6},'string6','String 6 for fr ok');
}