wovnrb 3.5.0 → 3.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.en.md +30 -13
- data/build.sh +7 -0
- data/docker/nginx/Dockerfile +18 -0
- data/docker/nginx/README.md +13 -0
- data/docker/nginx/build.sh +8 -0
- data/docker/nginx/scripts/configure_sshd.sh +25 -0
- data/docker/nginx/scripts/startup.sh +10 -0
- data/docker/nginx/wovnrb.conf +19 -0
- data/docker/rails/Dockerfile +9 -0
- data/docker/rails/Dockerfile.ECS +17 -0
- data/docker/rails/TestSite/Gemfile +0 -2
- data/docker/rails/TestSite/app/controllers/custom_response_controller.rb +1 -1
- data/docker/rails/TestSite/config/environments/development.rb +2 -0
- data/docker/rails/TestSite/config/environments/production.rb +2 -0
- data/docker/rails/TestSite/config/environments/test.rb +2 -0
- data/docker/rails/TestSite/public/index.html +1 -1
- data/docker/rails/TestSite/start.sh +2 -11
- data/docker/rails/TestSite/start_rails.sh +9 -0
- data/docker/rails/TestSite/yarn.lock +3 -3
- data/docker/scripts/jenkins/build.sh +45 -0
- data/docker/scripts/jenkins/tag_and_push_image.sh +30 -0
- data/docker/scripts/jenkins/taskdef.json +104 -0
- data/docker/scripts/jenkins/taskdef.json.bak +99 -0
- data/lib/wovnrb/api_translator.rb +6 -1
- data/lib/wovnrb/headers.rb +19 -2
- data/lib/wovnrb/services/html_converter.rb +17 -1
- data/lib/wovnrb/services/url.rb +136 -0
- data/lib/wovnrb/store.rb +8 -2
- data/lib/wovnrb/url_language_switcher.rb +124 -0
- data/lib/wovnrb/version.rb +1 -1
- data/lib/wovnrb.rb +3 -1
- data/test/lib/api_translator_test.rb +44 -0
- data/test/lib/services/html_converter_test.rb +210 -37
- data/test/lib/services/url_test.rb +308 -0
- data/test/lib/url_language_switcher_test.rb +798 -0
- data/test/lib/wovnrb_test.rb +2 -1
- data/test/test_helper.rb +4 -1
- metadata +22 -3
@@ -0,0 +1,798 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Wovnrb
|
4
|
+
class UrlLanguageSwitcherTest < WovnMiniTest
|
5
|
+
def test_add_lang_code
|
6
|
+
lang_code = 'zh-cht'
|
7
|
+
store_options = { 'url_pattern' => 'subdomain' }
|
8
|
+
|
9
|
+
store, headers = store_headers_factory(store_options, 'http://favy.tips')
|
10
|
+
url_lang_switcher = Wovnrb::UrlLanguageSwitcher.new(store)
|
11
|
+
|
12
|
+
res = url_lang_switcher.add_lang_code('http://www.facebook.com', lang_code, headers)
|
13
|
+
|
14
|
+
assert_equal('http://www.facebook.com', res)
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_add_lang_code_relative_slash_href_url_with_path
|
18
|
+
lang_code = 'fr'
|
19
|
+
|
20
|
+
store_options = { 'url_pattern' => 'subdomain' }
|
21
|
+
|
22
|
+
store, headers = store_headers_factory(store_options, 'http://favy.tips/topics/44')
|
23
|
+
url_lang_switcher = Wovnrb::UrlLanguageSwitcher.new(store)
|
24
|
+
|
25
|
+
res = url_lang_switcher.add_lang_code('/topics/50', lang_code, headers)
|
26
|
+
|
27
|
+
assert_equal('http://fr.favy.tips/topics/50', res)
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_add_lang_code_relative_dot_href_url_with_path
|
31
|
+
lang_code = 'fr'
|
32
|
+
|
33
|
+
store_options = { 'url_pattern' => 'subdomain' }
|
34
|
+
|
35
|
+
store, headers = store_headers_factory(store_options, 'http://favy.tips/topics/44')
|
36
|
+
url_lang_switcher = Wovnrb::UrlLanguageSwitcher.new(store)
|
37
|
+
|
38
|
+
res = url_lang_switcher.add_lang_code('./topics/50', lang_code, headers)
|
39
|
+
|
40
|
+
assert_equal('http://fr.favy.tips/topics/topics/50', res)
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_add_lang_code_relative_two_dots_href_url_with_path
|
44
|
+
lang_code = 'fr'
|
45
|
+
|
46
|
+
store_options = { 'url_pattern' => 'subdomain' }
|
47
|
+
|
48
|
+
store, headers = store_headers_factory(store_options, 'http://favy.tips/topics/44')
|
49
|
+
url_lang_switcher = Wovnrb::UrlLanguageSwitcher.new(store)
|
50
|
+
|
51
|
+
res = url_lang_switcher.add_lang_code('../topics/50', lang_code, headers)
|
52
|
+
|
53
|
+
assert_equal('http://fr.favy.tips/topics/50', res)
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_add_lang_code_trad_chinese
|
57
|
+
lang_code = 'zh-cht'
|
58
|
+
|
59
|
+
store_options = { 'url_pattern' => 'subdomain' }
|
60
|
+
|
61
|
+
store, headers = store_headers_factory(store_options, 'http://favy.tips')
|
62
|
+
url_lang_switcher = Wovnrb::UrlLanguageSwitcher.new(store)
|
63
|
+
|
64
|
+
res = url_lang_switcher.add_lang_code('http://favy.tips/topics/31', lang_code, headers)
|
65
|
+
|
66
|
+
assert_equal('http://zh-cht.favy.tips/topics/31', res)
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_add_lang_code_trad_chinese_two
|
70
|
+
lang_code = 'zh-cht'
|
71
|
+
|
72
|
+
store_options = { 'url_pattern' => 'subdomain' }
|
73
|
+
|
74
|
+
store, headers = store_headers_factory(store_options, 'http://favy.tips')
|
75
|
+
url_lang_switcher = Wovnrb::UrlLanguageSwitcher.new(store)
|
76
|
+
|
77
|
+
res = url_lang_switcher.add_lang_code('/topics/31', lang_code, headers)
|
78
|
+
|
79
|
+
assert_equal('http://zh-cht.favy.tips/topics/31', res)
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_add_lang_code_trad_chinese_lang_in_link_already
|
83
|
+
lang_code = 'zh-cht'
|
84
|
+
|
85
|
+
store_options = { 'url_pattern' => 'subdomain' }
|
86
|
+
|
87
|
+
store, headers = store_headers_factory(store_options, 'http://favy.tips')
|
88
|
+
url_lang_switcher = Wovnrb::UrlLanguageSwitcher.new(store)
|
89
|
+
|
90
|
+
res = url_lang_switcher.add_lang_code('http://zh-cht.favy.tips/topics/31', lang_code, headers)
|
91
|
+
|
92
|
+
assert_equal('http://zh-cht.favy.tips/topics/31', res)
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_add_lang_code_no_protocol
|
96
|
+
lang_code = 'zh-cht'
|
97
|
+
|
98
|
+
store_options = { 'url_pattern' => 'subdomain' }
|
99
|
+
|
100
|
+
store, headers = store_headers_factory(store_options, 'https://google.com')
|
101
|
+
url_lang_switcher = Wovnrb::UrlLanguageSwitcher.new(store)
|
102
|
+
|
103
|
+
res = url_lang_switcher.add_lang_code('//google.com', lang_code, headers)
|
104
|
+
|
105
|
+
assert_equal('//zh-cht.google.com', res)
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_add_lang_code_no_protocol_two
|
109
|
+
lang_code = 'zh-cht'
|
110
|
+
|
111
|
+
store_options = { 'url_pattern' => 'subdomain' }
|
112
|
+
|
113
|
+
store, headers = store_headers_factory(store_options, 'https://favy.tips')
|
114
|
+
url_lang_switcher = Wovnrb::UrlLanguageSwitcher.new(store)
|
115
|
+
|
116
|
+
res = url_lang_switcher.add_lang_code('//google.com', lang_code, headers)
|
117
|
+
|
118
|
+
assert_equal('//google.com', res)
|
119
|
+
end
|
120
|
+
|
121
|
+
def test_add_lang_code_invalid_url
|
122
|
+
lang_code = 'zh-cht'
|
123
|
+
store_options = { 'url_pattern' => 'subdomain' }
|
124
|
+
|
125
|
+
store, headers = store_headers_factory(store_options, 'https://favy.tips')
|
126
|
+
url_lang_switcher = Wovnrb::UrlLanguageSwitcher.new(store)
|
127
|
+
|
128
|
+
res = url_lang_switcher.add_lang_code('http://www.facebook.com/sharer.php?u=http://favy.tips/topics/50&amp;t=Gourmet Tofu World: Vegetarian-Friendly Japanese Food is Here!', lang_code, headers)
|
129
|
+
|
130
|
+
assert_equal('http://www.facebook.com/sharer.php?u=http://favy.tips/topics/50&amp;t=Gourmet Tofu World: Vegetarian-Friendly Japanese Food is Here!', res)
|
131
|
+
end
|
132
|
+
|
133
|
+
def test_add_lang_code_path_only_with_slash
|
134
|
+
lang_code = 'zh-cht'
|
135
|
+
|
136
|
+
store_options = { 'url_pattern' => 'subdomain' }
|
137
|
+
|
138
|
+
store, headers = store_headers_factory(store_options, 'http://favy.tips')
|
139
|
+
url_lang_switcher = Wovnrb::UrlLanguageSwitcher.new(store)
|
140
|
+
|
141
|
+
res = url_lang_switcher.add_lang_code('/topics/31', lang_code, headers)
|
142
|
+
|
143
|
+
assert_equal('http://zh-cht.favy.tips/topics/31', res)
|
144
|
+
end
|
145
|
+
|
146
|
+
def test_add_lang_code_path_only_no_slash
|
147
|
+
lang_code = 'zh-cht'
|
148
|
+
store_options = { 'url_pattern' => 'subdomain' }
|
149
|
+
|
150
|
+
store, headers = store_headers_factory(store_options, 'http://favy.tips')
|
151
|
+
url_lang_switcher = Wovnrb::UrlLanguageSwitcher.new(store)
|
152
|
+
|
153
|
+
res = url_lang_switcher.add_lang_code('topics/31', lang_code, headers)
|
154
|
+
|
155
|
+
assert_equal('http://zh-cht.favy.tips/topics/31', res)
|
156
|
+
end
|
157
|
+
|
158
|
+
def test_add_lang_code_path_explicit_page_no_slash
|
159
|
+
lang_code = 'zh-cht'
|
160
|
+
|
161
|
+
store_options = { 'url_pattern' => 'subdomain' }
|
162
|
+
|
163
|
+
store, headers = store_headers_factory(store_options, 'http://favy.tips')
|
164
|
+
url_lang_switcher = Wovnrb::UrlLanguageSwitcher.new(store)
|
165
|
+
|
166
|
+
res = url_lang_switcher.add_lang_code('topics/31.html', lang_code, headers)
|
167
|
+
|
168
|
+
assert_equal('http://zh-cht.favy.tips/topics/31.html', res)
|
169
|
+
end
|
170
|
+
|
171
|
+
def test_add_lang_code_path_explicit_page_with_slash
|
172
|
+
lang_code = 'zh-cht'
|
173
|
+
|
174
|
+
store_options = { 'url_pattern' => 'subdomain' }
|
175
|
+
|
176
|
+
store, headers = store_headers_factory(store_options, 'http://favy.tips')
|
177
|
+
url_lang_switcher = Wovnrb::UrlLanguageSwitcher.new(store)
|
178
|
+
|
179
|
+
res = url_lang_switcher.add_lang_code('/topics/31.html', lang_code, headers)
|
180
|
+
|
181
|
+
assert_equal('http://zh-cht.favy.tips/topics/31.html', res)
|
182
|
+
end
|
183
|
+
|
184
|
+
def test_add_lang_code_no_protocol_with_path_explicit_page
|
185
|
+
lang_code = 'zh-cht'
|
186
|
+
|
187
|
+
store_options = { 'url_pattern' => 'subdomain' }
|
188
|
+
|
189
|
+
store, headers = store_headers_factory(store_options, 'http://favy.tips')
|
190
|
+
url_lang_switcher = Wovnrb::UrlLanguageSwitcher.new(store)
|
191
|
+
|
192
|
+
res = url_lang_switcher.add_lang_code('//www.google.com/topics/31.php', lang_code, headers)
|
193
|
+
|
194
|
+
assert_equal('//www.google.com/topics/31.php', res)
|
195
|
+
end
|
196
|
+
|
197
|
+
def test_add_lang_code_protocol_with_path_explicit_page
|
198
|
+
lang_code = 'zh-cht'
|
199
|
+
|
200
|
+
store_options = { 'url_pattern' => 'subdomain' }
|
201
|
+
|
202
|
+
store, headers = store_headers_factory(store_options, 'http://favy.tips')
|
203
|
+
url_lang_switcher = Wovnrb::UrlLanguageSwitcher.new(store)
|
204
|
+
|
205
|
+
res = url_lang_switcher.add_lang_code('http://www.google.com/topics/31.php', lang_code, headers)
|
206
|
+
|
207
|
+
assert_equal('http://www.google.com/topics/31.php', res)
|
208
|
+
end
|
209
|
+
|
210
|
+
def test_add_lang_code_relative_path_double_period
|
211
|
+
lang_code = 'zh-cht'
|
212
|
+
|
213
|
+
store_options = { 'url_pattern' => 'subdomain' }
|
214
|
+
|
215
|
+
store, headers = store_headers_factory(store_options, 'http://favy.tips')
|
216
|
+
url_lang_switcher = Wovnrb::UrlLanguageSwitcher.new(store)
|
217
|
+
|
218
|
+
res = url_lang_switcher.add_lang_code('../topics/31', lang_code, headers)
|
219
|
+
|
220
|
+
assert_equal('http://zh-cht.favy.tips/topics/31', res)
|
221
|
+
end
|
222
|
+
|
223
|
+
def test_add_lang_code_relative_path_single_period
|
224
|
+
lang_code = 'zh-cht'
|
225
|
+
|
226
|
+
store_options = { 'url_pattern' => 'subdomain' }
|
227
|
+
|
228
|
+
store, headers = store_headers_factory(store_options, 'http://favy.tips')
|
229
|
+
url_lang_switcher = Wovnrb::UrlLanguageSwitcher.new(store)
|
230
|
+
|
231
|
+
res = url_lang_switcher.add_lang_code('./topics/31', lang_code, headers)
|
232
|
+
|
233
|
+
assert_equal('http://zh-cht.favy.tips/topics/31', res)
|
234
|
+
end
|
235
|
+
|
236
|
+
def test_add_lang_code_empty_href
|
237
|
+
lang_code = 'zh-cht'
|
238
|
+
|
239
|
+
store_options = { 'url_pattern' => 'subdomain' }
|
240
|
+
|
241
|
+
store, headers = store_headers_factory(store_options, 'http://favy.tips')
|
242
|
+
url_lang_switcher = Wovnrb::UrlLanguageSwitcher.new(store)
|
243
|
+
|
244
|
+
res = url_lang_switcher.add_lang_code('', lang_code, headers)
|
245
|
+
|
246
|
+
assert_equal('', res)
|
247
|
+
end
|
248
|
+
|
249
|
+
def test_add_lang_code_hash_href
|
250
|
+
lang_code = 'zh-cht'
|
251
|
+
|
252
|
+
store_options = { 'url_pattern' => 'subdomain' }
|
253
|
+
|
254
|
+
store, headers = store_headers_factory(store_options, 'http://favy.tips')
|
255
|
+
url_lang_switcher = Wovnrb::UrlLanguageSwitcher.new(store)
|
256
|
+
|
257
|
+
res = url_lang_switcher.add_lang_code('#', lang_code, headers)
|
258
|
+
|
259
|
+
assert_equal('#', res)
|
260
|
+
end
|
261
|
+
|
262
|
+
def test_add_lang_code_nil_href
|
263
|
+
lang_code = 'en'
|
264
|
+
store_options = { 'url_pattern' => 'subdomain' }
|
265
|
+
|
266
|
+
store, headers = store_headers_factory(store_options, 'http://favy.tips')
|
267
|
+
url_lang_switcher = Wovnrb::UrlLanguageSwitcher.new(store)
|
268
|
+
|
269
|
+
res = url_lang_switcher.add_lang_code(nil, lang_code, headers)
|
270
|
+
|
271
|
+
assert_nil(res)
|
272
|
+
end
|
273
|
+
|
274
|
+
def test_add_lang_code_absolute_different_host
|
275
|
+
lang_code = 'fr'
|
276
|
+
store_options = { 'url_pattern' => 'subdomain' }
|
277
|
+
|
278
|
+
store, headers = store_headers_factory(store_options, 'http://google.com')
|
279
|
+
url_lang_switcher = Wovnrb::UrlLanguageSwitcher.new(store)
|
280
|
+
|
281
|
+
res = url_lang_switcher.add_lang_code('http://yahoo.co.jp', lang_code, headers)
|
282
|
+
|
283
|
+
assert_equal('http://yahoo.co.jp', res)
|
284
|
+
end
|
285
|
+
|
286
|
+
def test_add_lang_code_absolute_subdomain_no_subdomain
|
287
|
+
lang_code = 'fr'
|
288
|
+
store_options = { 'url_pattern' => 'subdomain' }
|
289
|
+
|
290
|
+
store, headers = store_headers_factory(store_options, 'http://google.com')
|
291
|
+
url_lang_switcher = Wovnrb::UrlLanguageSwitcher.new(store)
|
292
|
+
|
293
|
+
res = url_lang_switcher.add_lang_code('http://google.com', lang_code, headers)
|
294
|
+
|
295
|
+
assert_equal('http://fr.google.com', res)
|
296
|
+
end
|
297
|
+
|
298
|
+
def test_add_lang_code_absolute_subdomain_with_subdomain
|
299
|
+
lang_code = 'fr'
|
300
|
+
|
301
|
+
store_options = { 'url_pattern' => 'subdomain' }
|
302
|
+
|
303
|
+
store, headers = store_headers_factory(store_options, 'http://home.google.com')
|
304
|
+
url_lang_switcher = Wovnrb::UrlLanguageSwitcher.new(store)
|
305
|
+
|
306
|
+
res = url_lang_switcher.add_lang_code('http://home.google.com', lang_code, headers)
|
307
|
+
|
308
|
+
assert_equal('http://fr.home.google.com', res)
|
309
|
+
end
|
310
|
+
|
311
|
+
def test_add_lang_code_absolute_query_no_query
|
312
|
+
lang_code = 'fr'
|
313
|
+
|
314
|
+
store_options = { 'url_pattern' => 'query' }
|
315
|
+
|
316
|
+
store, headers = store_headers_factory(store_options, 'http://google.com')
|
317
|
+
url_lang_switcher = Wovnrb::UrlLanguageSwitcher.new(store)
|
318
|
+
|
319
|
+
res = url_lang_switcher.add_lang_code('http://google.com', lang_code, headers)
|
320
|
+
|
321
|
+
assert_equal('http://google.com?wovn=fr', res)
|
322
|
+
end
|
323
|
+
|
324
|
+
def test_add_lang_code_absolute_query_with_query
|
325
|
+
lang_code = 'fr'
|
326
|
+
|
327
|
+
store_options = { 'url_pattern' => 'query' }
|
328
|
+
|
329
|
+
store, headers = store_headers_factory(store_options, 'http://google.com')
|
330
|
+
url_lang_switcher = Wovnrb::UrlLanguageSwitcher.new(store)
|
331
|
+
|
332
|
+
res = url_lang_switcher.add_lang_code('http://google.com?hey=yo', lang_code, headers)
|
333
|
+
|
334
|
+
assert_equal('http://google.com?hey=yo&wovn=fr', res)
|
335
|
+
end
|
336
|
+
|
337
|
+
def test_add_lang_code_absolute_query_with_hash
|
338
|
+
lang_code = 'fr'
|
339
|
+
|
340
|
+
store_options = { 'url_pattern' => 'query' }
|
341
|
+
|
342
|
+
store, headers = store_headers_factory(store_options, 'http://google.com')
|
343
|
+
url_lang_switcher = Wovnrb::UrlLanguageSwitcher.new(store)
|
344
|
+
|
345
|
+
res = url_lang_switcher.add_lang_code('http://google.com#test', lang_code, headers)
|
346
|
+
|
347
|
+
assert_equal('http://google.com?wovn=fr#test', res)
|
348
|
+
end
|
349
|
+
|
350
|
+
def test_add_lang_code_absolute_query_and_lang_param_name_with_no_query
|
351
|
+
lang_code = 'fr'
|
352
|
+
|
353
|
+
store_options = { 'url_pattern' => 'query', 'lang_param_name' => 'test_param' }
|
354
|
+
|
355
|
+
store, headers = store_headers_factory(store_options, 'http://google.com')
|
356
|
+
url_lang_switcher = Wovnrb::UrlLanguageSwitcher.new(store)
|
357
|
+
|
358
|
+
res = url_lang_switcher.add_lang_code('http://google.com', lang_code, headers)
|
359
|
+
|
360
|
+
assert_equal('http://google.com?test_param=fr', res)
|
361
|
+
end
|
362
|
+
|
363
|
+
def test_add_lang_code_absolute_query_and_lang_param_name_with_query
|
364
|
+
lang_code = 'fr'
|
365
|
+
|
366
|
+
store_options = { 'url_pattern' => 'query', 'lang_param_name' => 'test_param' }
|
367
|
+
|
368
|
+
store, headers = store_headers_factory(store_options, 'http://google.com')
|
369
|
+
url_lang_switcher = Wovnrb::UrlLanguageSwitcher.new(store)
|
370
|
+
|
371
|
+
res = url_lang_switcher.add_lang_code('http://google.com?hey=yo', lang_code, headers)
|
372
|
+
|
373
|
+
assert_equal('http://google.com?hey=yo&test_param=fr', res)
|
374
|
+
end
|
375
|
+
|
376
|
+
def test_add_lang_code_absolute_query_and_lang_param_name_with_hash
|
377
|
+
lang_code = 'fr'
|
378
|
+
|
379
|
+
store_options = { 'url_pattern' => 'query', 'lang_param_name' => 'test_param' }
|
380
|
+
|
381
|
+
store, headers = store_headers_factory(store_options, 'http://google.com')
|
382
|
+
url_lang_switcher = Wovnrb::UrlLanguageSwitcher.new(store)
|
383
|
+
|
384
|
+
res = url_lang_switcher.add_lang_code('http://google.com#test', lang_code, headers)
|
385
|
+
|
386
|
+
assert_equal('http://google.com?test_param=fr#test', res)
|
387
|
+
end
|
388
|
+
|
389
|
+
def test_add_lang_code_absolute_path_no_pathname
|
390
|
+
lang_code = 'fr'
|
391
|
+
|
392
|
+
store_options = { 'url_pattern' => 'path' }
|
393
|
+
|
394
|
+
store, headers = store_headers_factory(store_options, 'http://google.com')
|
395
|
+
url_lang_switcher = Wovnrb::UrlLanguageSwitcher.new(store)
|
396
|
+
|
397
|
+
res = url_lang_switcher.add_lang_code('http://google.com', lang_code, headers)
|
398
|
+
|
399
|
+
assert_equal('http://google.com/fr', res)
|
400
|
+
end
|
401
|
+
|
402
|
+
def test_add_lang_code__requested_with_deep_path
|
403
|
+
lang_code = 'fr'
|
404
|
+
|
405
|
+
store_options = { 'url_pattern' => 'path' }
|
406
|
+
|
407
|
+
store, headers = store_headers_factory(store_options, 'http://google.com/dir1/dir2')
|
408
|
+
url_lang_switcher = Wovnrb::UrlLanguageSwitcher.new(store)
|
409
|
+
|
410
|
+
assert_equal('http://google.com/fr', url_lang_switcher.add_lang_code('http://google.com', lang_code, headers))
|
411
|
+
assert_equal('/fr/', url_lang_switcher.add_lang_code('/', lang_code, headers))
|
412
|
+
assert_equal('', url_lang_switcher.add_lang_code('', lang_code, headers))
|
413
|
+
end
|
414
|
+
|
415
|
+
def test_add_lang_code_absolute_path_with_pathname
|
416
|
+
lang_code = 'fr'
|
417
|
+
|
418
|
+
store_options = { 'url_pattern' => 'path' }
|
419
|
+
|
420
|
+
store, headers = store_headers_factory(store_options, 'http://google.com')
|
421
|
+
url_lang_switcher = Wovnrb::UrlLanguageSwitcher.new(store)
|
422
|
+
|
423
|
+
res = url_lang_switcher.add_lang_code('http://google.com/index.html', lang_code, headers)
|
424
|
+
|
425
|
+
assert_equal('http://google.com/fr/index.html', res)
|
426
|
+
end
|
427
|
+
|
428
|
+
def test_add_lang_code_absolute_path_with_pathname_hash_is_preserved
|
429
|
+
lang_code = 'fr'
|
430
|
+
|
431
|
+
store_options = { 'url_pattern' => 'path' }
|
432
|
+
|
433
|
+
store, headers = store_headers_factory(store_options, 'http://google.com')
|
434
|
+
url_lang_switcher = Wovnrb::UrlLanguageSwitcher.new(store)
|
435
|
+
|
436
|
+
res = url_lang_switcher.add_lang_code('http://google.com/index.html?foo=bar#hash', lang_code, headers)
|
437
|
+
|
438
|
+
assert_equal('http://google.com/fr/index.html?foo=bar#hash', res)
|
439
|
+
end
|
440
|
+
|
441
|
+
def test_add_lang_code_absolute_path_with_long_pathname
|
442
|
+
lang_code = 'fr'
|
443
|
+
|
444
|
+
store_options = { 'url_pattern' => 'path' }
|
445
|
+
|
446
|
+
store, headers = store_headers_factory(store_options, 'http://google.com')
|
447
|
+
url_lang_switcher = Wovnrb::UrlLanguageSwitcher.new(store)
|
448
|
+
|
449
|
+
res = url_lang_switcher.add_lang_code('http://google.com/hello/long/path/index.html', lang_code, headers)
|
450
|
+
|
451
|
+
assert_equal('http://google.com/fr/hello/long/path/index.html', res)
|
452
|
+
end
|
453
|
+
|
454
|
+
def test_add_lang_code_relative_subdomain_leading_slash
|
455
|
+
lang_code = 'fr'
|
456
|
+
|
457
|
+
store_options = { 'url_pattern' => 'subdomain' }
|
458
|
+
|
459
|
+
store, headers = store_headers_factory(store_options, 'http://google.com')
|
460
|
+
url_lang_switcher = Wovnrb::UrlLanguageSwitcher.new(store)
|
461
|
+
|
462
|
+
res = url_lang_switcher.add_lang_code('/', lang_code, headers)
|
463
|
+
|
464
|
+
assert_equal('http://fr.google.com/', res)
|
465
|
+
end
|
466
|
+
|
467
|
+
def test_add_lang_code_relative_subdomain_leading_slash_filename
|
468
|
+
lang_code = 'fr'
|
469
|
+
|
470
|
+
store_options = { 'url_pattern' => 'subdomain' }
|
471
|
+
|
472
|
+
store, headers = store_headers_factory(store_options, 'http://google.com')
|
473
|
+
url_lang_switcher = Wovnrb::UrlLanguageSwitcher.new(store)
|
474
|
+
|
475
|
+
res = url_lang_switcher.add_lang_code('/index.html', lang_code, headers)
|
476
|
+
|
477
|
+
assert_equal('http://fr.google.com/index.html', res)
|
478
|
+
end
|
479
|
+
|
480
|
+
def test_add_lang_code_relative_subdomain_no_leading_slash_filename
|
481
|
+
lang_code = 'fr'
|
482
|
+
|
483
|
+
store_options = { 'url_pattern' => 'subdomain' }
|
484
|
+
|
485
|
+
store, headers = store_headers_factory(store_options, 'http://google.com')
|
486
|
+
url_lang_switcher = Wovnrb::UrlLanguageSwitcher.new(store)
|
487
|
+
|
488
|
+
res = url_lang_switcher.add_lang_code('index.html', lang_code, headers)
|
489
|
+
|
490
|
+
assert_equal('http://fr.google.com/index.html', res)
|
491
|
+
end
|
492
|
+
|
493
|
+
def test_add_lang_code_relative_query_with_no_query
|
494
|
+
lang_code = 'fr'
|
495
|
+
|
496
|
+
store_options = { 'url_pattern' => 'query' }
|
497
|
+
|
498
|
+
store, headers = store_headers_factory(store_options, 'http://google.com')
|
499
|
+
url_lang_switcher = Wovnrb::UrlLanguageSwitcher.new(store)
|
500
|
+
|
501
|
+
res = url_lang_switcher.add_lang_code('/index.html', lang_code, headers)
|
502
|
+
|
503
|
+
assert_equal('/index.html?wovn=fr', res)
|
504
|
+
end
|
505
|
+
|
506
|
+
def test_add_lang_code_relative_query_with_query
|
507
|
+
lang_code = 'fr'
|
508
|
+
|
509
|
+
store_options = { 'url_pattern' => 'query' }
|
510
|
+
|
511
|
+
store, headers = store_headers_factory(store_options, 'http://google.com')
|
512
|
+
url_lang_switcher = Wovnrb::UrlLanguageSwitcher.new(store)
|
513
|
+
|
514
|
+
res = url_lang_switcher.add_lang_code('/index.html?hey=yo', lang_code, headers)
|
515
|
+
|
516
|
+
assert_equal('/index.html?hey=yo&wovn=fr', res)
|
517
|
+
end
|
518
|
+
|
519
|
+
def test_add_lang_code_relative_query_with_hash
|
520
|
+
lang_code = 'fr'
|
521
|
+
|
522
|
+
store_options = { 'url_pattern' => 'query' }
|
523
|
+
|
524
|
+
store, headers = store_headers_factory(store_options, 'http://google.com')
|
525
|
+
url_lang_switcher = Wovnrb::UrlLanguageSwitcher.new(store)
|
526
|
+
|
527
|
+
res = url_lang_switcher.add_lang_code('/index.html?hey=yo', lang_code, headers)
|
528
|
+
|
529
|
+
assert_equal('/index.html?hey=yo&wovn=fr', res)
|
530
|
+
end
|
531
|
+
|
532
|
+
def test_add_lang_code_relative_query_and_lang_param_name_with_no_query
|
533
|
+
lang_code = 'fr'
|
534
|
+
|
535
|
+
store_options = { 'url_pattern' => 'query', 'lang_param_name' => 'test_param' }
|
536
|
+
|
537
|
+
store, headers = store_headers_factory(store_options, 'http://google.com')
|
538
|
+
url_lang_switcher = Wovnrb::UrlLanguageSwitcher.new(store)
|
539
|
+
|
540
|
+
res = url_lang_switcher.add_lang_code('/index.html', lang_code, headers)
|
541
|
+
|
542
|
+
assert_equal('/index.html?test_param=fr', res)
|
543
|
+
end
|
544
|
+
|
545
|
+
def test_add_lang_code_relative_query_and_lang_param_name_with_query
|
546
|
+
lang_code = 'fr'
|
547
|
+
|
548
|
+
store_options = { 'url_pattern' => 'query', 'lang_param_name' => 'test_param' }
|
549
|
+
|
550
|
+
store, headers = store_headers_factory(store_options, 'http://google.com')
|
551
|
+
url_lang_switcher = Wovnrb::UrlLanguageSwitcher.new(store)
|
552
|
+
|
553
|
+
res = url_lang_switcher.add_lang_code('/index.html?hey=yo', lang_code, headers)
|
554
|
+
|
555
|
+
assert_equal('/index.html?hey=yo&test_param=fr', res)
|
556
|
+
end
|
557
|
+
|
558
|
+
def test_add_lang_code_relative_query_and_lang_param_name_with_hash
|
559
|
+
lang_code = 'fr'
|
560
|
+
|
561
|
+
store_options = { 'url_pattern' => 'query', 'lang_param_name' => 'test_param' }
|
562
|
+
|
563
|
+
store, headers = store_headers_factory(store_options, 'http://google.com')
|
564
|
+
url_lang_switcher = Wovnrb::UrlLanguageSwitcher.new(store)
|
565
|
+
|
566
|
+
res = url_lang_switcher.add_lang_code('/index.html?hey=yo#hey', lang_code, headers)
|
567
|
+
|
568
|
+
assert_equal('/index.html?hey=yo&test_param=fr#hey', res)
|
569
|
+
end
|
570
|
+
|
571
|
+
def test_add_lang_code_relative_path_with_leading_slash
|
572
|
+
lang_code = 'fr'
|
573
|
+
|
574
|
+
store_options = { 'url_pattern' => 'path' }
|
575
|
+
|
576
|
+
store, headers = store_headers_factory(store_options, 'http://google.com')
|
577
|
+
url_lang_switcher = Wovnrb::UrlLanguageSwitcher.new(store)
|
578
|
+
|
579
|
+
res = url_lang_switcher.add_lang_code('/index.html', lang_code, headers)
|
580
|
+
|
581
|
+
assert_equal('/fr/index.html', res)
|
582
|
+
end
|
583
|
+
|
584
|
+
def test_add_lang_code_relative_path_without_leading_slash_different_pathname
|
585
|
+
lang_code = 'fr'
|
586
|
+
|
587
|
+
store_options = { 'url_pattern' => 'path' }
|
588
|
+
|
589
|
+
store, headers = store_headers_factory(store_options, 'http://google.com/hello/tab.html')
|
590
|
+
url_lang_switcher = Wovnrb::UrlLanguageSwitcher.new(store)
|
591
|
+
|
592
|
+
res = url_lang_switcher.add_lang_code('index.html', lang_code, headers)
|
593
|
+
|
594
|
+
assert_equal('/fr/hello/index.html', res)
|
595
|
+
end
|
596
|
+
|
597
|
+
def test_add_lang_code_relative_path_without_leading_slash_and_dot_dot
|
598
|
+
lang_code = 'fr'
|
599
|
+
|
600
|
+
store_options = { 'url_pattern' => 'path' }
|
601
|
+
|
602
|
+
store, headers = store_headers_factory(store_options, 'https://pre.avex.jp/wovn_aaa/news/')
|
603
|
+
url_lang_switcher = Wovnrb::UrlLanguageSwitcher.new(store)
|
604
|
+
|
605
|
+
res = url_lang_switcher.add_lang_code('../news/', lang_code, headers)
|
606
|
+
|
607
|
+
assert_equal("/#{lang_code}/wovn_aaa/news/", res)
|
608
|
+
end
|
609
|
+
|
610
|
+
def test_add_lang_code_relative_path_without_leading_slash_different_pathname2
|
611
|
+
lang_code = 'fr'
|
612
|
+
|
613
|
+
store_options = { 'url_pattern' => 'path' }
|
614
|
+
|
615
|
+
store, headers = store_headers_factory(store_options, 'http://google.com/hello/tab.html')
|
616
|
+
url_lang_switcher = Wovnrb::UrlLanguageSwitcher.new(store)
|
617
|
+
|
618
|
+
res = url_lang_switcher.add_lang_code('hey/index.html', lang_code, headers)
|
619
|
+
|
620
|
+
assert_equal('/fr/hello/hey/index.html', res)
|
621
|
+
end
|
622
|
+
|
623
|
+
def test_add_lang_code_relative_path_at_root
|
624
|
+
lang_code = 'fr'
|
625
|
+
|
626
|
+
store_options = { 'url_pattern' => 'path' }
|
627
|
+
|
628
|
+
store, headers = store_headers_factory(store_options, 'http://google.com/')
|
629
|
+
url_lang_switcher = Wovnrb::UrlLanguageSwitcher.new(store)
|
630
|
+
|
631
|
+
res = url_lang_switcher.add_lang_code('index.html', lang_code, headers)
|
632
|
+
|
633
|
+
assert_equal('/fr/index.html', res)
|
634
|
+
end
|
635
|
+
|
636
|
+
def test_add_lang_code__jp_domain__path_pattern__absolute_path
|
637
|
+
lang_code = 'ja'
|
638
|
+
|
639
|
+
store_options = { 'url_pattern' => 'path' }
|
640
|
+
|
641
|
+
store, headers = store_headers_factory(store_options, 'http://favy.co.jp')
|
642
|
+
url_lang_switcher = Wovnrb::UrlLanguageSwitcher.new(store)
|
643
|
+
|
644
|
+
res = url_lang_switcher.add_lang_code('/page', lang_code, headers)
|
645
|
+
|
646
|
+
assert_equal('/ja/page', res)
|
647
|
+
end
|
648
|
+
|
649
|
+
def test_add_lang_code__jp_domain__path_pattern__absolute_path_with_query
|
650
|
+
lang_code = 'ja'
|
651
|
+
|
652
|
+
store_options = { 'url_pattern' => 'path' }
|
653
|
+
|
654
|
+
store, headers = store_headers_factory(store_options, 'http://favy.co.jp')
|
655
|
+
url_lang_switcher = Wovnrb::UrlLanguageSwitcher.new(store)
|
656
|
+
|
657
|
+
res = url_lang_switcher.add_lang_code('/page?user=tom', lang_code, headers)
|
658
|
+
|
659
|
+
assert_equal('/ja/page?user=tom', res)
|
660
|
+
end
|
661
|
+
|
662
|
+
def test_add_lang_code__jp_domain__path_pattern__absolute_path_with_query__top_page
|
663
|
+
lang_code = 'ja'
|
664
|
+
|
665
|
+
store_options = { 'url_pattern' => 'path' }
|
666
|
+
|
667
|
+
store, headers = store_headers_factory(store_options, 'http://favy.co.jp')
|
668
|
+
url_lang_switcher = Wovnrb::UrlLanguageSwitcher.new(store)
|
669
|
+
|
670
|
+
res = url_lang_switcher.add_lang_code('/?user=tom', lang_code, headers)
|
671
|
+
|
672
|
+
assert_equal('/ja/?user=tom', res)
|
673
|
+
end
|
674
|
+
|
675
|
+
def test_add_lang_code__jp_domain__path_pattern__absolute_path_with_hash__top_page
|
676
|
+
lang_code = 'ja'
|
677
|
+
|
678
|
+
store_options = { 'url_pattern' => 'path' }
|
679
|
+
|
680
|
+
store, headers = store_headers_factory(store_options, 'http://favy.co.jp')
|
681
|
+
url_lang_switcher = Wovnrb::UrlLanguageSwitcher.new(store)
|
682
|
+
|
683
|
+
res = url_lang_switcher.add_lang_code('/#top', lang_code, headers)
|
684
|
+
|
685
|
+
assert_equal('/ja/#top', res)
|
686
|
+
end
|
687
|
+
|
688
|
+
def test_add_lang_code__jp_domain__path_pattern__absolute_url
|
689
|
+
lang_code = 'ja'
|
690
|
+
|
691
|
+
store_options = { 'url_pattern' => 'path' }
|
692
|
+
|
693
|
+
store, headers = store_headers_factory(store_options, 'http://favy.co.jp')
|
694
|
+
url_lang_switcher = Wovnrb::UrlLanguageSwitcher.new(store)
|
695
|
+
|
696
|
+
res = url_lang_switcher.add_lang_code('http://favy.co.jp/page', lang_code, headers)
|
697
|
+
|
698
|
+
assert_equal('http://favy.co.jp/ja/page', res)
|
699
|
+
end
|
700
|
+
|
701
|
+
def test_add_lang_code__jp_domain__path_pattern__absolute_url_with_query
|
702
|
+
lang_code = 'ja'
|
703
|
+
|
704
|
+
store_options = { 'url_pattern' => 'path' }
|
705
|
+
|
706
|
+
store, headers = store_headers_factory(store_options, 'http://favy.co.jp')
|
707
|
+
url_lang_switcher = Wovnrb::UrlLanguageSwitcher.new(store)
|
708
|
+
|
709
|
+
res = url_lang_switcher.add_lang_code('http://favy.co.jp?user=tom', lang_code, headers)
|
710
|
+
|
711
|
+
assert_equal('http://favy.co.jp/ja?user=tom', res)
|
712
|
+
end
|
713
|
+
|
714
|
+
def test_add_lang_code__jp_domain__path_pattern__absolute_url_with_trailing_slash_and_query
|
715
|
+
lang_code = 'ja'
|
716
|
+
|
717
|
+
store_options = { 'url_pattern' => 'path' }
|
718
|
+
|
719
|
+
store, headers = store_headers_factory(store_options, 'http://favy.co.jp')
|
720
|
+
url_lang_switcher = Wovnrb::UrlLanguageSwitcher.new(store)
|
721
|
+
|
722
|
+
res = url_lang_switcher.add_lang_code('http://favy.co.jp/?user=tom', lang_code, headers)
|
723
|
+
|
724
|
+
assert_equal('http://favy.co.jp/ja/?user=tom', res)
|
725
|
+
end
|
726
|
+
|
727
|
+
def test_add_lang_code__jp_domain__path_pattern__absolute_url_with_hash
|
728
|
+
lang_code = 'ja'
|
729
|
+
|
730
|
+
store_options = { 'url_pattern' => 'path' }
|
731
|
+
|
732
|
+
store, headers = store_headers_factory(store_options, 'http://favy.co.jp')
|
733
|
+
url_lang_switcher = Wovnrb::UrlLanguageSwitcher.new(store)
|
734
|
+
|
735
|
+
res = url_lang_switcher.add_lang_code('http://favy.co.jp#top', lang_code, headers)
|
736
|
+
|
737
|
+
assert_equal('http://favy.co.jp/ja#top', res)
|
738
|
+
end
|
739
|
+
|
740
|
+
def test_add_lang_code__absolute_url_with_default_lang_alias__replaces_lang_code
|
741
|
+
lang_aliases = {
|
742
|
+
'en' => 'en'
|
743
|
+
}
|
744
|
+
|
745
|
+
store_options = { 'url_pattern' => 'path', 'custom_lang_aliases' => lang_aliases }
|
746
|
+
|
747
|
+
store, headers = store_headers_factory(store_options, 'http://www.example.com/th/')
|
748
|
+
url_lang_switcher = Wovnrb::UrlLanguageSwitcher.new(store)
|
749
|
+
|
750
|
+
href_no_trailing_slash = 'http://www.example.com/en'
|
751
|
+
href_trailing_slash = 'http://www.example.com/en/'
|
752
|
+
|
753
|
+
assert_equal('http://www.example.com/th', url_lang_switcher.add_lang_code(href_no_trailing_slash, 'th', headers))
|
754
|
+
assert_equal('http://www.example.com/th/', url_lang_switcher.add_lang_code(href_trailing_slash, 'th', headers))
|
755
|
+
end
|
756
|
+
|
757
|
+
def test_add_lang_code__absolute_path_with_default_lang_alias__replaces_lang_code
|
758
|
+
lang_aliases = {
|
759
|
+
'en' => 'en'
|
760
|
+
}
|
761
|
+
|
762
|
+
store_options = { 'url_pattern' => 'path', 'custom_lang_aliases' => lang_aliases }
|
763
|
+
|
764
|
+
store, headers = store_headers_factory(store_options, 'http://www.example.com/th/')
|
765
|
+
url_lang_switcher = Wovnrb::UrlLanguageSwitcher.new(store)
|
766
|
+
|
767
|
+
href_no_trailing_slash = '/en'
|
768
|
+
href_trailing_slash = '/en/'
|
769
|
+
|
770
|
+
assert_equal('/th', url_lang_switcher.add_lang_code(href_no_trailing_slash, 'th', headers))
|
771
|
+
assert_equal('/th/', url_lang_switcher.add_lang_code(href_trailing_slash, 'th', headers))
|
772
|
+
end
|
773
|
+
|
774
|
+
def store_headers_factory(setting_opts = {}, url = 'http://my-site.com')
|
775
|
+
settings = default_store_settings.merge(setting_opts)
|
776
|
+
store = Wovnrb::Store.instance
|
777
|
+
store.update_settings(settings)
|
778
|
+
|
779
|
+
headers = Wovnrb::Headers.new(
|
780
|
+
Wovnrb.get_env('url' => url),
|
781
|
+
store.settings
|
782
|
+
)
|
783
|
+
|
784
|
+
[store, headers]
|
785
|
+
end
|
786
|
+
|
787
|
+
def default_store_settings
|
788
|
+
{
|
789
|
+
'project_token' => '123456',
|
790
|
+
'custom_lang_aliases' => {},
|
791
|
+
'default_lang' => 'en',
|
792
|
+
'url_pattern' => 'query',
|
793
|
+
'url_pattern_reg' => '((\?.*&)|\?)wovn=(?<lang>[^&]+)(&|)',
|
794
|
+
'supported_langs' => %w[en fr ja vi]
|
795
|
+
}
|
796
|
+
end
|
797
|
+
end
|
798
|
+
end
|