wovnrb 0.2.01 → 0.2.02
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/.gitignore +3 -6
- data/README.md +116 -12
- data/lib/wovnrb/api_data.rb +59 -0
- data/lib/wovnrb/headers.rb +30 -5
- data/lib/wovnrb/html_replacers/image_replacer.rb +44 -0
- data/lib/wovnrb/html_replacers/link_replacer.rb +18 -0
- data/lib/wovnrb/html_replacers/meta_replacer.rb +20 -0
- data/lib/wovnrb/html_replacers/replacer_base.rb +17 -0
- data/lib/wovnrb/html_replacers/script_replacer.rb +39 -0
- data/lib/wovnrb/html_replacers/text_replacer.rb +19 -0
- data/lib/wovnrb/lang.rb +133 -23
- data/lib/wovnrb/services/url.rb +2 -68
- data/lib/wovnrb/services/wovn_logger.rb +45 -0
- data/lib/wovnrb/store.rb +19 -38
- data/lib/wovnrb/text_caches/cache_base.rb +52 -0
- data/lib/wovnrb/text_caches/memory_cache.rb +52 -0
- data/lib/wovnrb/version.rb +1 -1
- data/lib/wovnrb.rb +19 -224
- data/test/lib/api_data_test.rb +62 -0
- data/test/lib/headers_test.rb +1221 -1212
- data/test/lib/html_replacers/image_replacer_test.rb +86 -0
- data/test/lib/html_replacers/link_replacer_test.rb +43 -0
- data/test/lib/html_replacers/meta_replacer_test.rb +105 -0
- data/test/lib/html_replacers/replacer_base_test.rb +31 -0
- data/test/lib/html_replacers/script_replacer_test.rb +90 -0
- data/test/lib/html_replacers/text_replacer_test.rb +57 -0
- data/test/lib/lang_test.rb +446 -33
- data/test/lib/services/wovn_logger_test.rb +40 -0
- data/test/lib/store_test.rb +39 -29
- data/test/lib/text_caches/cache_base_test.rb +31 -0
- data/test/lib/text_caches/memory_cache_test.rb +91 -0
- data/test/lib/wovnrb_test.rb +39 -886
- data/test/test_helper.rb +96 -1
- data/wovnrb.gemspec +4 -0
- metadata +89 -2
data/test/lib/wovnrb_test.rb
CHANGED
@@ -2,14 +2,14 @@
|
|
2
2
|
require 'wovnrb'
|
3
3
|
require 'wovnrb/headers'
|
4
4
|
require 'minitest/autorun'
|
5
|
+
require 'webmock/minitest'
|
5
6
|
require 'pry'
|
6
7
|
|
7
8
|
class WovnrbTest < Minitest::Test
|
8
|
-
|
9
|
-
|
9
|
+
def setup
|
10
|
+
Wovnrb::Store.instance.reset
|
10
11
|
end
|
11
12
|
|
12
|
-
|
13
13
|
def test_initialize
|
14
14
|
i = Wovnrb::Interceptor.new(get_app)
|
15
15
|
refute_nil(i)
|
@@ -23,288 +23,44 @@ class WovnrbTest < Minitest::Test
|
|
23
23
|
# def test_switch_lang(body, values, url, lang=STORE.settings['default_lang'], headers)
|
24
24
|
# end
|
25
25
|
|
26
|
+
def test_api_call
|
27
|
+
settings = Wovnrb.get_settings
|
28
|
+
token = settings['user_token']
|
29
|
+
url = 'wovn.io/dashboard'
|
30
|
+
stub = stub_request(:get, "#{settings['api_url']}?token=#{token}&url=#{url}").
|
31
|
+
to_return(:body => '{"test_body": "a"}')
|
26
32
|
|
27
|
-
|
28
|
-
# end
|
29
|
-
|
30
|
-
def test_add_lang_code
|
31
|
-
i = Wovnrb::Interceptor.new(get_app)
|
32
|
-
h = Wovnrb::Headers.new(get_env('url' => 'http://favy.tips'), get_settings('url_pattern' => 'subdomain', 'url_pattern_reg' => '^(?<lang>[^.]+).'))
|
33
|
-
assert_equal("http://www.facebook.com", i.add_lang_code("http://www.facebook.com", 'subdomain', 'zh-cht', h))
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_add_lang_code_relative_slash_href_url_with_path
|
37
|
-
i = Wovnrb::Interceptor.new(get_app)
|
38
|
-
h = Wovnrb::Headers.new(get_env('url' => 'http://fr.favy.tips/topics/44'), get_settings('url_pattern' => 'subdomain', 'url_pattern_reg' => '^(?<lang>[^.]+).'))
|
39
|
-
assert_equal("http://fr.favy.tips/topics/50", i.add_lang_code("/topics/50", 'subdomain', 'fr', h))
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_add_lang_code_relative_dot_href_url_with_path
|
43
|
-
i = Wovnrb::Interceptor.new(get_app)
|
44
|
-
h = Wovnrb::Headers.new(get_env('url' => 'http://fr.favy.tips/topics/44'), get_settings('url_pattern' => 'subdomain', 'url_pattern_reg' => '^(?<lang>[^.]+).'))
|
45
|
-
assert_equal("http://fr.favy.tips/topics/44/topics/50", i.add_lang_code("./topics/50", 'subdomain', 'fr', h))
|
46
|
-
end
|
47
|
-
|
48
|
-
def test_add_lang_code_relative_two_dots_href_url_with_path
|
49
|
-
i = Wovnrb::Interceptor.new(get_app)
|
50
|
-
h = Wovnrb::Headers.new(get_env('url' => 'http://fr.favy.tips/topics/44'), get_settings('url_pattern' => 'subdomain', 'url_pattern_reg' => '^(?<lang>[^.]+).'))
|
51
|
-
assert_equal("http://fr.favy.tips/topics/50", i.add_lang_code("../topics/50", 'subdomain', 'fr', h))
|
52
|
-
end
|
53
|
-
|
54
|
-
def test_add_lang_code_trad_chinese
|
55
|
-
i = Wovnrb::Interceptor.new(get_app)
|
56
|
-
h = Wovnrb::Headers.new(get_env('url' => 'http://favy.tips'), get_settings('url_pattern' => 'subdomain', 'url_pattern_reg' => '^(?<lang>[^.]+).'))
|
57
|
-
assert_equal("http://zh-cht.favy.tips/topics/31", i.add_lang_code("http://favy.tips/topics/31", 'subdomain', 'zh-cht', h))
|
58
|
-
end
|
59
|
-
|
60
|
-
def test_add_lang_code_trad_chinese_2
|
61
|
-
i = Wovnrb::Interceptor.new(get_app)
|
62
|
-
h = Wovnrb::Headers.new(get_env('url' => 'http://zh-cht.favy.tips'), get_settings('url_pattern' => 'subdomain', 'url_pattern_reg' => '^(?<lang>[^.]+).'))
|
63
|
-
assert_equal("http://zh-cht.favy.tips/topics/31", i.add_lang_code("/topics/31", 'subdomain', 'zh-cht', h))
|
64
|
-
end
|
65
|
-
|
66
|
-
def test_add_lang_code_trad_chinese_lang_in_link_already
|
67
|
-
i = Wovnrb::Interceptor.new(get_app)
|
68
|
-
h = Wovnrb::Headers.new(get_env('url' => 'http://zh-cht.favy.tips'), get_settings('url_pattern' => 'subdomain', 'url_pattern_reg' => '^(?<lang>[^.]+).'))
|
69
|
-
assert_equal("http://zh-cht.favy.tips/topics/31", i.add_lang_code("http://zh-cht.favy.tips/topics/31", 'subdomain', 'zh-cht', h))
|
70
|
-
end
|
33
|
+
i = Wovnrb::Interceptor.new(get_app, settings)
|
71
34
|
|
72
|
-
|
73
|
-
|
74
|
-
h = Wovnrb::Headers.new(get_env('url' => 'https://zh-cht.google.com'), get_settings('url_pattern' => 'subdomain', 'url_pattern_reg' => '^(?<lang>[^.]+).'))
|
75
|
-
assert_equal("//zh-cht.google.com", i.add_lang_code("//google.com", 'subdomain', 'zh-cht', h))
|
35
|
+
i.call(Wovnrb.get_env)
|
36
|
+
assert_requested(stub, :times => 1)
|
76
37
|
end
|
77
38
|
|
78
|
-
def
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
39
|
+
def test_api_call_with_cache
|
40
|
+
settings = Wovnrb.get_settings
|
41
|
+
token = settings['user_token']
|
42
|
+
url = 'wovn.io/dashboard'
|
43
|
+
stub = stub_request(:get, "#{settings['api_url']}?token=#{token}&url=#{url}").
|
44
|
+
to_return(:body => '{"test_body": "a"}')
|
83
45
|
|
84
|
-
|
85
|
-
i = Wovnrb::Interceptor.new(get_app)
|
86
|
-
h = Wovnrb::Headers.new(get_env('url' => 'http://favy.tips'), get_settings('url_pattern' => 'subdomain', 'url_pattern_reg' => '^(?<lang>[^.]+).'))
|
87
|
-
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!", i.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!", 'subdomain', 'zh-cht', h))
|
88
|
-
end
|
46
|
+
i = Wovnrb::Interceptor.new(RackMock.new, settings)
|
89
47
|
|
90
|
-
|
91
|
-
i
|
92
|
-
|
93
|
-
assert_equal("http://zh-cht.favy.tips/topics/31", i.add_lang_code("/topics/31", 'subdomain', 'zh-cht', h))
|
48
|
+
i.call(Wovnrb.get_env)
|
49
|
+
i.call(Wovnrb.get_env)
|
50
|
+
assert_requested(stub, :times => 1)
|
94
51
|
end
|
95
52
|
|
96
|
-
def
|
97
|
-
i = Wovnrb::Interceptor.new(get_app)
|
98
|
-
h = Wovnrb::Headers.new(get_env('url' => 'http://favy.tips'), get_settings('url_pattern' => 'subdomain', 'url_pattern_reg' => '^(?<lang>[^.]+).'))
|
99
|
-
assert_equal("http://zh-cht.favy.tips/topics/31", i.add_lang_code("topics/31", 'subdomain', 'zh-cht', h))
|
100
|
-
end
|
101
|
-
|
102
|
-
def test_add_lang_code_path_explicit_page_no_slash
|
103
|
-
i = Wovnrb::Interceptor.new(get_app)
|
104
|
-
h = Wovnrb::Headers.new(get_env('url' => 'http://favy.tips'), get_settings('url_pattern' => 'subdomain', 'url_pattern_reg' => '^(?<lang>[^.]+).'))
|
105
|
-
assert_equal("http://zh-cht.favy.tips/topics/31.html", i.add_lang_code("topics/31.html", 'subdomain', 'zh-cht', h))
|
106
|
-
end
|
107
|
-
|
108
|
-
def test_add_lang_code_path_explicit_page_with_slash
|
109
|
-
i = Wovnrb::Interceptor.new(get_app)
|
110
|
-
h = Wovnrb::Headers.new(get_env('url' => 'http://favy.tips'), get_settings('url_pattern' => 'subdomain', 'url_pattern_reg' => '^(?<lang>[^.]+).'))
|
111
|
-
assert_equal("http://zh-cht.favy.tips/topics/31.html", i.add_lang_code("/topics/31.html", 'subdomain', 'zh-cht', h))
|
112
|
-
end
|
113
|
-
|
114
|
-
def test_add_lang_code_no_protocol_with_path_explicit_page
|
115
|
-
i = Wovnrb::Interceptor.new(get_app)
|
116
|
-
h = Wovnrb::Headers.new(get_env('url' => 'http://favy.tips'), get_settings('url_pattern' => 'subdomain', 'url_pattern_reg' => '^(?<lang>[^.]+).'))
|
117
|
-
assert_equal("//www.google.com/topics/31.php", i.add_lang_code("//www.google.com/topics/31.php", 'subdomain', 'zh-cht', h))
|
118
|
-
end
|
119
|
-
|
120
|
-
def test_add_lang_code_protocol_with_path_explicit_page
|
121
|
-
i = Wovnrb::Interceptor.new(get_app)
|
122
|
-
h = Wovnrb::Headers.new(get_env('url' => 'http://favy.tips'), get_settings('url_pattern' => 'subdomain', 'url_pattern_reg' => '^(?<lang>[^.]+).'))
|
123
|
-
assert_equal("http://www.google.com/topics/31.php", i.add_lang_code("http://www.google.com/topics/31.php", 'subdomain', 'zh-cht', h))
|
124
|
-
end
|
125
|
-
|
126
|
-
def test_add_lang_code_relative_path_double_period
|
127
|
-
i = Wovnrb::Interceptor.new(get_app)
|
128
|
-
h = Wovnrb::Headers.new(get_env('url' => 'http://favy.tips'), get_settings('url_pattern' => 'subdomain', 'url_pattern_reg' => '^(?<lang>[^.]+).'))
|
129
|
-
assert_equal("http://zh-cht.favy.tips/topics/31", i.add_lang_code("../topics/31", 'subdomain', 'zh-cht', h))
|
130
|
-
end
|
131
|
-
|
132
|
-
def test_add_lang_code_relative_path_single_period
|
133
|
-
i = Wovnrb::Interceptor.new(get_app)
|
134
|
-
h = Wovnrb::Headers.new(get_env('url' => 'http://favy.tips'), get_settings('url_pattern' => 'subdomain', 'url_pattern_reg' => '^(?<lang>[^.]+).'))
|
135
|
-
assert_equal("http://zh-cht.favy.tips/topics/31", i.add_lang_code("./topics/31", 'subdomain', 'zh-cht', h))
|
136
|
-
end
|
137
|
-
|
138
|
-
def test_add_lang_code_empty_href
|
139
|
-
i = Wovnrb::Interceptor.new(get_app)
|
140
|
-
h = Wovnrb::Headers.new(get_env('url' => 'http://favy.tips'), get_settings('url_pattern' => 'subdomain', 'url_pattern_reg' => '^(?<lang>[^.]+).'))
|
141
|
-
assert_equal("", i.add_lang_code("", 'subdomain', 'zh-cht', h))
|
142
|
-
end
|
143
|
-
|
144
|
-
def test_add_lang_code_hash_href
|
53
|
+
def test_switch_lang
|
145
54
|
i = Wovnrb::Interceptor.new(get_app)
|
146
|
-
h = Wovnrb::Headers.new(get_env('url' => 'http://
|
147
|
-
|
148
|
-
end
|
149
|
-
|
150
|
-
# def test_add_lang_code_nil_href
|
151
|
-
# i = Wovnrb::Interceptor.new(get_app)
|
152
|
-
# assert_equal(nil, i.add_lang_code(nil,'path', 'en', nil))
|
153
|
-
# end
|
154
|
-
# def test_add_lang_code_absolute_different_host
|
155
|
-
# i = Wovnrb::Interceptor.new(get_app)
|
156
|
-
# headers = stub
|
157
|
-
# headers.expects(:host).returns('google.com')
|
158
|
-
# assert_equal('http://yahoo.co.jp', i.add_lang_code('http://yahoo.co.jp', 'path', 'fr', headers))
|
159
|
-
# end
|
160
|
-
#
|
161
|
-
# def test_add_lang_code_absolute_subdomain_no_subdomain
|
162
|
-
# i = Wovnrb::Interceptor.new(get_app)
|
163
|
-
# headers = stub
|
164
|
-
# headers.expects(:host).returns('google.com')
|
165
|
-
# assert_equal('http://fr.google.com', i.add_lang_code('http://google.com', 'subdomain', 'fr', headers))
|
166
|
-
# end
|
167
|
-
#
|
168
|
-
# def test_add_lang_code_absolute_subdomain_with_subdomain
|
169
|
-
# i = Wovnrb::Interceptor.new(get_app)
|
170
|
-
# headers = stub
|
171
|
-
# headers.expects(:host).returns('home.google.com')
|
172
|
-
# assert_equal('http://fr.home.google.com', i.add_lang_code('http://home.google.com', 'subdomain', 'fr', headers))
|
173
|
-
# end
|
174
|
-
#
|
175
|
-
# def test_add_lang_code_absolute_query_no_query
|
176
|
-
# i = Wovnrb::Interceptor.new(get_app)
|
177
|
-
# headers = stub
|
178
|
-
# headers.expects(:host).returns('google.com')
|
179
|
-
# assert_equal('http://google.com?wovn=fr', i.add_lang_code('http://google.com', 'query', 'fr', headers))
|
180
|
-
# end
|
181
|
-
#
|
182
|
-
# def test_add_lang_code_absolute_query_with_query
|
183
|
-
# i = Wovnrb::Interceptor.new(get_app)
|
184
|
-
# headers = stub
|
185
|
-
# headers.expects(:host).returns('google.com')
|
186
|
-
# assert_equal('http://google.com?hey=yo&wovn=fr', i.add_lang_code('http://google.com?hey=yo', 'query', 'fr', headers))
|
187
|
-
# end
|
188
|
-
#
|
189
|
-
# def test_add_lang_code_absolute_path_no_pathname
|
190
|
-
# i = Wovnrb::Interceptor.new(get_app)
|
191
|
-
# headers = stub
|
192
|
-
# headers.expects(:host).returns('google.com')
|
193
|
-
# assert_equal('http://google.com/fr/', i.add_lang_code('http://google.com', 'path', 'fr', headers))
|
194
|
-
# end
|
195
|
-
#
|
196
|
-
# def test_add_lang_code_absolute_path_with_pathname
|
197
|
-
# i = Wovnrb::Interceptor.new(get_app)
|
198
|
-
# headers = stub
|
199
|
-
# headers.expects(:host).returns('google.com')
|
200
|
-
# assert_equal('http://google.com/fr/index.html', i.add_lang_code('http://google.com/index.html', 'path', 'fr', headers))
|
201
|
-
# end
|
202
|
-
#
|
203
|
-
# def test_add_lang_code_absolute_path_with_long_pathname
|
204
|
-
# i = Wovnrb::Interceptor.new(get_app)
|
205
|
-
# headers = stub
|
206
|
-
# headers.expects(:host).returns('google.com')
|
207
|
-
# assert_equal('http://google.com/fr/hello/long/path/index.html', i.add_lang_code('http://google.com/hello/long/path/index.html', 'path', 'fr', headers))
|
208
|
-
# end
|
209
|
-
#
|
210
|
-
# def test_add_lang_code_relative_subdomain_leading_slash
|
211
|
-
# i = Wovnrb::Interceptor.new(get_app)
|
212
|
-
# headers = stub
|
213
|
-
# headers.expects(:protocol).returns('http')
|
214
|
-
# headers.expects(:host).returns('google.com')
|
215
|
-
# assert_equal('http://fr.google.com/', i.add_lang_code('/', 'subdomain', 'fr', headers))
|
216
|
-
# end
|
217
|
-
#
|
218
|
-
# def test_add_lang_code_relative_subdomain_leading_slash_filename
|
219
|
-
# i = Wovnrb::Interceptor.new(get_app)
|
220
|
-
# headers = stub
|
221
|
-
# headers.expects(:protocol).returns('http')
|
222
|
-
# headers.expects(:host).returns('google.com')
|
223
|
-
# assert_equal('http://fr.google.com/index.html', i.add_lang_code('/index.html', 'subdomain', 'fr', headers))
|
224
|
-
# end
|
225
|
-
#
|
226
|
-
# def test_add_lang_code_relative_subdomain_no_leading_slash_filename
|
227
|
-
# i = Wovnrb::Interceptor.new(get_app)
|
228
|
-
# headers = stub
|
229
|
-
# headers.expects(:protocol).returns('http')
|
230
|
-
# headers.expects(:host).returns('google.com')
|
231
|
-
# headers.expects(:pathname).returns('/')
|
232
|
-
# assert_equal('http://fr.google.com/index.html', i.add_lang_code('index.html', 'subdomain', 'fr', headers))
|
233
|
-
# end
|
234
|
-
#
|
235
|
-
# def test_add_lang_code_relative_subdomain_dot_filename
|
236
|
-
# i = Wovnrb::Interceptor.new(get_app)
|
237
|
-
# headers = stub
|
238
|
-
# headers.expects(:protocol).returns('http')
|
239
|
-
# headers.expects(:host).returns('google.com')
|
240
|
-
# headers.expects(:pathname).returns('/')
|
241
|
-
# assert_equal('http://fr.google.com/./index.html', i.add_lang_code('./index.html', 'subdomain', 'fr', headers))
|
242
|
-
# end
|
243
|
-
#
|
244
|
-
# def test_add_lang_code_relative_subdomain_two_dots_filename_long_pathname
|
245
|
-
# i = Wovnrb::Interceptor.new(get_app)
|
246
|
-
# headers = stub
|
247
|
-
# headers.expects(:protocol).returns('http')
|
248
|
-
# headers.expects(:host).returns('google.com')
|
249
|
-
# headers.expects(:pathname).returns('/home/hey/index.html')
|
250
|
-
# assert_equal('http://fr.google.com/home/hey/../index.html', i.add_lang_code('../index.html', 'subdomain', 'fr', headers))
|
251
|
-
# end
|
252
|
-
#
|
253
|
-
# def test_add_lang_code_relative_query_with_no_query
|
254
|
-
# i = Wovnrb::Interceptor.new(get_app)
|
255
|
-
# headers = stub
|
256
|
-
# assert_equal('/index.html?wovn=fr', i.add_lang_code('/index.html', 'query', 'fr', headers))
|
257
|
-
# end
|
258
|
-
#
|
259
|
-
# def test_add_lang_code_relative_query_with_query
|
260
|
-
# i = Wovnrb::Interceptor.new(get_app)
|
261
|
-
# headers = stub
|
262
|
-
# assert_equal('/index.html?hey=yo&wovn=fr', i.add_lang_code('/index.html?hey=yo', 'query', 'fr', headers))
|
263
|
-
# end
|
264
|
-
#
|
265
|
-
# def test_add_lang_code_relative_path_with_leading_slash
|
266
|
-
# i = Wovnrb::Interceptor.new(get_app)
|
267
|
-
# headers = stub
|
268
|
-
# assert_equal('/fr/index.html', i.add_lang_code('/index.html', 'path', 'fr', headers))
|
269
|
-
# end
|
270
|
-
#
|
271
|
-
# def test_add_lang_code_relative_path_without_leading_slash_different_pathname
|
272
|
-
# i = Wovnrb::Interceptor.new(get_app)
|
273
|
-
# headers = stub
|
274
|
-
# headers.expects(:pathname).returns('/hello/tab.html')
|
275
|
-
# assert_equal('/fr/hello/index.html', i.add_lang_code('index.html', 'path', 'fr', headers))
|
276
|
-
# end
|
277
|
-
#
|
278
|
-
# def test_add_lang_code_relative_path_without_leading_slash_different_pathname2
|
279
|
-
# i = Wovnrb::Interceptor.new(get_app)
|
280
|
-
# headers = stub
|
281
|
-
# headers.expects(:pathname).returns('/hello/tab.html')
|
282
|
-
# assert_equal('/fr/hello/hey/index.html', i.add_lang_code('hey/index.html', 'path', 'fr', headers))
|
283
|
-
# end
|
284
|
-
def generate_body(param = "")
|
285
|
-
case param
|
286
|
-
when "ignore_parent"
|
287
|
-
body = "<html><body><h1>Mr. Belvedere Fan Club</h1>
|
288
|
-
<div wovn-ignore><p>Hello</p></div>
|
289
|
-
</body></html>"
|
290
|
-
when "ignore_everything"
|
291
|
-
body = "<html><body wovn-ignore><h1>Mr. Belvedere Fan Club</h1>
|
55
|
+
h = Wovnrb::Headers.new(Wovnrb.get_env('url' => 'http://page.com'), Wovnrb.get_settings('url_pattern' => 'subdomain', 'url_pattern_reg' => '^(?<lang>[^.]+).'))
|
56
|
+
body = "<html><body><h1>Mr. Belvedere Fan Club</h1>
|
292
57
|
<div><p>Hello</p></div>
|
293
58
|
</body></html>"
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
</head>
|
300
|
-
<body>
|
301
|
-
<h1>ベルベデアさんファンクラブ</h1>
|
302
|
-
<div wovn-ignore=\"\"><p>Hello</p></div>
|
303
|
-
</body>
|
304
|
-
</html>
|
305
|
-
"
|
306
|
-
when "translated_in_japanese"
|
307
|
-
body = "<html lang=\"ja\">
|
59
|
+
values = generate_values
|
60
|
+
url = h.url
|
61
|
+
swapped_body = i.switch_lang([body], values, url, 'ja', h)
|
62
|
+
|
63
|
+
expected_body = "<html lang=\"ja\">
|
308
64
|
<head>
|
309
65
|
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">
|
310
66
|
<script src=\"//j.wovn.io/1\" async=\"true\" data-wovnio=\"key=&backend=true&currentLang=ja&defaultLang=en&urlPattern=path&version=#{Wovnrb::VERSION}\"> </script><link rel=\"alternate\" hreflang=\"ja\" href=\"http://ja.page.com/\">
|
@@ -315,626 +71,23 @@ class WovnrbTest < Minitest::Test
|
|
315
71
|
</body>
|
316
72
|
</html>
|
317
73
|
"
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
</head>
|
324
|
-
<body wovn-ignore=\"\">
|
325
|
-
<h1>Mr. Belvedere Fan Club</h1>
|
326
|
-
<div><p>Hello</p></div>
|
327
|
-
</body>
|
328
|
-
</html>
|
329
|
-
"
|
330
|
-
when "empty"
|
331
|
-
body = "<html><body><h1>Mr.BelvedereFanClub</h1><div wovn-ignore><p>Hello</p></div></body></html>"
|
332
|
-
when "empty_single_quote"
|
333
|
-
body = "<html><body><h1>Mr.BelvedereFanClub</h1><div wovn-ignore=''><p>Hello</p></div></body></html>"
|
334
|
-
when "empty_double_quote"
|
335
|
-
body = "<html><body><h1>Mr.BelvedereFanClub</h1><div wovn-ignore=""><p>Hello</p></div></body></html>"
|
336
|
-
when "value_single_quote"
|
337
|
-
body = "<html><body><h1>Mr.BelvedereFanClub</h1><div wovn-ignore='value'><p>Hello</p></div></body></html>"
|
338
|
-
when "value_double_quote"
|
339
|
-
body = "<html><body><h1>Mr.BelvedereFanClub</h1><div wovn-ignore=\"value\"><p>Hello</p></div></body></html>"
|
340
|
-
when "empty_translated"
|
341
|
-
body = "<html lang=\"ja\">\n<head>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n<script src=\"//j.wovn.io/1\" async=\"true\" data-wovnio=\"key=&backend=true&currentLang=ja&defaultLang=en&urlPattern=path&version=#{Wovnrb::VERSION}\"> </script><link rel=\"alternate\" hreflang=\"ja\" href=\"http://ja.ignore-page.com/\">\n</head>\n<body>\n<h1>Mr.BelvedereFanClub</h1>\n<div wovn-ignore=\"\"><p>Hello</p></div>\n</body>\n</html>\n"
|
342
|
-
when "empty_single_quote_translated"
|
343
|
-
body = "<html lang=\"ja\">\n<head>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n<script src=\"//j.wovn.io/1\" async=\"true\" data-wovnio=\"key=&backend=true&currentLang=ja&defaultLang=en&urlPattern=path&version=#{Wovnrb::VERSION}\"> </script><link rel=\"alternate\" hreflang=\"ja\" href=\"http://ja.ignore-page.com/\">\n</head>\n<body>\n<h1>Mr.BelvedereFanClub</h1>\n<div wovn-ignore=\"\"><p>Hello</p></div>\n</body>\n</html>\n"
|
344
|
-
when "empty_double_quote_translated"
|
345
|
-
body = "<html lang=\"ja\">\n<head>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n<script src=\"//j.wovn.io/1\" async=\"true\" data-wovnio=\"key=&backend=true&currentLang=ja&defaultLang=en&urlPattern=path&version=#{Wovnrb::VERSION}\"> </script><link rel=\"alternate\" hreflang=\"ja\" href=\"http://ja.ignore-page.com/\">\n</head>\n<body>\n<h1>Mr.BelvedereFanClub</h1>\n<div wovn-ignore=\"\"><p>Hello</p></div>\n</body>\n</html>\n"
|
346
|
-
when "value_single_quote_translated"
|
347
|
-
body = "<html lang=\"ja\">\n<head>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n<script src=\"//j.wovn.io/1\" async=\"true\" data-wovnio=\"key=&backend=true&currentLang=ja&defaultLang=en&urlPattern=path&version=#{Wovnrb::VERSION}\"> </script><link rel=\"alternate\" hreflang=\"ja\" href=\"http://ja.ignore-page.com/\">\n</head>\n<body>\n<h1>Mr.BelvedereFanClub</h1>\n<div wovn-ignore=\"value\"><p>Hello</p></div>\n</body>\n</html>\n"
|
348
|
-
when "value_double_quote_translated"
|
349
|
-
body = "<html lang=\"ja\">\n<head>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n<script src=\"//j.wovn.io/1\" async=\"true\" data-wovnio=\"key=&backend=true&currentLang=ja&defaultLang=en&urlPattern=path&version=#{Wovnrb::VERSION}\"> </script><link rel=\"alternate\" hreflang=\"ja\" href=\"http://ja.ignore-page.com/\">\n</head>\n<body>\n<h1>Mr.BelvedereFanClub</h1>\n<div wovn-ignore=\"value\"><p>Hello</p></div>\n</body>\n</html>\n"
|
350
|
-
when "meta_img_alt_tags_translated"
|
351
|
-
body = "<html lang=\"ja\">\n<head>\n<script src=\"//j.wovn.io/1\" async=\"true\" data-wovnio=\"key=&backend=true&currentLang=ja&defaultLang=en&urlPattern=path&version=#{Wovnrb::VERSION}\"> </script><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n<meta name=\"description\" content=\"こんにちは\">\n<meta name=\"title\" content=\"こんにちは\">\n<meta property=\"og:title\" content=\"こんにちは\">\n<meta property=\"og:description\" content=\"こんにちは\">\n<meta property=\"twitter:title\" content=\"こんにちは\">\n<meta property=\"twitter:description\" content=\"こんにちは\">\n<link rel=\"alternate\" hreflang=\"ja\" href=\"http://ja.page.com/\">\n</head>\n<body>\n<h1>ベルベデアさんファンクラブ</h1>\n<div><p>こんにちは</p></div>\n<img src=\"http://example.com/photo.png\" alt=\"こんにちは\">\n</body>\n</html>\n"
|
352
|
-
when "meta_img_alt_tags"
|
353
|
-
body = "<html><head><meta name =\"description\" content=\"Hello\">\n<meta name=\"title\" content=\"Hello\">\n<meta property=\"og:title\" content=\"Hello\">\n<meta property=\"og:description\" content=\"Hello\">\n<meta property=\"twitter:title\" content=\"Hello\">\n<meta property=\"twitter:description\" content=\"Hello\"></head>
|
354
|
-
<body><h1>Mr. Belvedere Fan Club</h1>
|
355
|
-
<div><p>Hello</p></div>
|
356
|
-
<img src=\"http://example.com/photo.png\" alt=\"Hello\">
|
357
|
-
</body></html>"
|
358
|
-
else # "" case
|
359
|
-
body = "<html><body><h1>Mr. Belvedere Fan Club</h1>
|
360
|
-
<div><p>Hello</p></div>
|
361
|
-
</body></html>"
|
362
|
-
end
|
363
|
-
return [body]
|
74
|
+
assert_equal([expected_body], swapped_body)
|
75
|
+
end
|
76
|
+
|
77
|
+
def get_app
|
78
|
+
RackMock.new
|
364
79
|
end
|
365
80
|
|
366
81
|
def generate_values
|
367
82
|
values = {}
|
368
83
|
values['text_vals'] = {'Hello' => {'ja' => [{'data' => 'こんにちは'}]},
|
369
|
-
|
84
|
+
'Mr. Belvedere Fan Club' => {'ja' => [{'data' => 'ベルベデアさんファンクラブ'}]}}
|
370
85
|
return values
|
371
86
|
end
|
372
87
|
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
body = generate_body()
|
377
|
-
values = generate_values
|
378
|
-
url = h.url
|
379
|
-
swapped_body = i.switch_lang(body, values, url, 'ja', h)
|
380
|
-
assert_equal(generate_body('translated_in_japanese'), swapped_body)
|
381
|
-
end
|
382
|
-
|
383
|
-
def test_switch_lang_meta_img_alt_tags
|
384
|
-
i = Wovnrb::Interceptor.new(get_app)
|
385
|
-
h = Wovnrb::Headers.new(get_env('url' => 'http://page.com'), get_settings('url_pattern' => 'subdomain', 'url_pattern_reg' => '^(?<lang>[^.]+).'))
|
386
|
-
body = generate_body('meta_img_alt_tags')
|
387
|
-
values = generate_values
|
388
|
-
url = h.url
|
389
|
-
swapped_body = i.switch_lang(body, values, url, 'ja', h)
|
390
|
-
assert_equal(generate_body('meta_img_alt_tags_translated'), swapped_body)
|
391
|
-
end
|
392
|
-
|
393
|
-
def test_switch_lang_wovn_ignore
|
394
|
-
i = Wovnrb::Interceptor.new(get_app)
|
395
|
-
h = Wovnrb::Headers.new(get_env('url' => 'http://ignore-page.com'), get_settings('url_pattern' => 'subdomain', 'url_pattern_reg' => '^(?<lang>[^.]+).'))
|
396
|
-
body = generate_body('ignore_parent')
|
397
|
-
values = generate_values
|
398
|
-
url = h.url
|
399
|
-
swapped_body = i.switch_lang(body, values, url, 'ja', h)
|
400
|
-
assert_equal(generate_body('ignore_parent_translated_in_japanese'), swapped_body)
|
401
|
-
end
|
402
|
-
|
403
|
-
def test_switch_lang_wovn_ignore_everything
|
404
|
-
i = Wovnrb::Interceptor.new(get_app)
|
405
|
-
h = Wovnrb::Headers.new(get_env('url' => 'http://ignore-page.com'), get_settings('url_pattern' => 'subdomain', 'url_pattern_reg' => '^(?<lang>[^.]+).'))
|
406
|
-
body = generate_body('ignore_everything')
|
407
|
-
values = generate_values
|
408
|
-
url = h.url
|
409
|
-
swapped_body = i.switch_lang(body, values, url, 'ja', h)
|
410
|
-
assert_equal(generate_body('ignore_everything_translated'), swapped_body)
|
411
|
-
end
|
412
|
-
|
413
|
-
def test_switch_lang_wovn_ignore_empty
|
414
|
-
i = Wovnrb::Interceptor.new(get_app)
|
415
|
-
h = Wovnrb::Headers.new(get_env('url' => 'http://ignore-page.com'), get_settings('url_pattern' => 'subdomain', 'url_pattern_reg' => '^(?<lang>[^.]+).'))
|
416
|
-
body = generate_body('empty')
|
417
|
-
values = generate_values
|
418
|
-
url = h.url
|
419
|
-
swapped_body = i.switch_lang(body, values, url, 'ja', h)
|
420
|
-
assert_equal(generate_body('empty_translated'), swapped_body)
|
421
|
-
end
|
422
|
-
|
423
|
-
def test_switch_lang_wovn_ignore_empty_single_quote
|
424
|
-
i = Wovnrb::Interceptor.new(get_app)
|
425
|
-
h = Wovnrb::Headers.new(get_env('url' => 'http://ignore-page.com'), get_settings('url_pattern' => 'subdomain', 'url_pattern_reg' => '^(?<lang>[^.]+).'))
|
426
|
-
body = generate_body('empty_single_quote')
|
427
|
-
values = generate_values
|
428
|
-
url = h.url
|
429
|
-
swapped_body = i.switch_lang(body, values, url, 'ja', h)
|
430
|
-
assert_equal(generate_body('empty_single_quote_translated'), swapped_body)
|
431
|
-
end
|
432
|
-
|
433
|
-
def test_switch_lang_wovn_ignore_empty_double_quote
|
434
|
-
i = Wovnrb::Interceptor.new(get_app)
|
435
|
-
h = Wovnrb::Headers.new(get_env('url' => 'http://ignore-page.com'), get_settings('url_pattern' => 'subdomain', 'url_pattern_reg' => '^(?<lang>[^.]+).'))
|
436
|
-
body = generate_body('empty_double_quote')
|
437
|
-
values = generate_values
|
438
|
-
url = h.url
|
439
|
-
swapped_body = i.switch_lang(body, values, url, 'ja', h)
|
440
|
-
assert_equal(generate_body('empty_double_quote_translated'), swapped_body)
|
441
|
-
end
|
442
|
-
|
443
|
-
def test_switch_lang_wovn_ignore_value_single_quote
|
444
|
-
i = Wovnrb::Interceptor.new(get_app)
|
445
|
-
h = Wovnrb::Headers.new(get_env('url' => 'http://ignore-page.com'), get_settings('url_pattern' => 'subdomain', 'url_pattern_reg' => '^(?<lang>[^.]+).'))
|
446
|
-
body = generate_body('value_single_quote')
|
447
|
-
values = generate_values
|
448
|
-
url = h.url
|
449
|
-
swapped_body = i.switch_lang(body, values, url, 'ja', h)
|
450
|
-
assert_equal(generate_body('value_single_quote_translated'), swapped_body)
|
451
|
-
end
|
452
|
-
|
453
|
-
def test_switch_lang_wovn_ignore_value_double_quote
|
454
|
-
i = Wovnrb::Interceptor.new(get_app)
|
455
|
-
h = Wovnrb::Headers.new(get_env('url' => 'http://ignore-page.com'), get_settings('url_pattern' => 'subdomain', 'url_pattern_reg' => '^(?<lang>[^.]+).'))
|
456
|
-
body = generate_body('value_double_quote')
|
457
|
-
values = generate_values
|
458
|
-
url = h.url
|
459
|
-
swapped_body = i.switch_lang(body, values, url, 'ja', h)
|
460
|
-
assert_equal(generate_body('value_double_quote_translated'), swapped_body)
|
461
|
-
end
|
462
|
-
|
463
|
-
def test_switch_lang_add_lang_code_path_from_action_no_method
|
464
|
-
i = Wovnrb::Interceptor.new(get_app, get_settings)
|
465
|
-
h = Wovnrb::Headers.new(get_env('url' => 'https://google.com'), get_settings)
|
466
|
-
body = <<"BODY"
|
467
|
-
<html>
|
468
|
-
<head><title>Hey</title></head>
|
469
|
-
<body>
|
470
|
-
<h1>Mr. Belvedere Fan Club</h1>
|
471
|
-
<div><p>Hello</p></div>
|
472
|
-
<a href="https://google.com/hello.html">TOP</a>
|
473
|
-
<form action="/form.php">
|
474
|
-
<input type="text" name="name" value="wovn.io" />
|
475
|
-
</form>
|
476
|
-
</body>
|
477
|
-
</html>
|
478
|
-
BODY
|
479
|
-
expected = <<"EXPECTED"
|
480
|
-
<html lang=\"ja\">
|
481
|
-
<head>
|
482
|
-
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">
|
483
|
-
<script src=\"//j.wovn.io/1\" async=\"true\" data-wovnio=\"key=OHYx9&backend=true&currentLang=ja&defaultLang=en&urlPattern=path&version=0.2\"> </script><title>Hey</title>
|
484
|
-
<link rel=\"alternate\" hreflang=\"ja\" href=\"https://google.com/ja/\">
|
485
|
-
</head>
|
486
|
-
<body>
|
487
|
-
<h1>ベルベデアさんファンクラブ</h1>
|
488
|
-
<div><p>こんにちは</p></div>
|
489
|
-
<a href=\"https://google.com/ja/hello.html\">TOP</a>
|
490
|
-
<form action=\"/ja/form.php\">
|
491
|
-
<input type=\"text\" name=\"name\" value=\"wovn.io\">
|
492
|
-
</form>
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
</body>
|
497
|
-
</html>
|
498
|
-
EXPECTED
|
499
|
-
body = [body]
|
500
|
-
expected = [expected]
|
501
|
-
values = generate_values
|
502
|
-
url = h.url
|
503
|
-
swapped_body = i.switch_lang(body, values, url, 'ja', h)
|
504
|
-
assert_equal(expected, swapped_body)
|
505
|
-
end
|
506
|
-
|
507
|
-
def test_switch_lang_add_lang_code_path_from_action_get_method
|
508
|
-
i = Wovnrb::Interceptor.new(get_app, get_settings)
|
509
|
-
h = Wovnrb::Headers.new(get_env('url' => 'https://google.com'), get_settings)
|
510
|
-
body = <<"BODY"
|
511
|
-
<html>
|
512
|
-
<head><title>Hey</title></head>
|
513
|
-
<body>
|
514
|
-
<h1>Mr. Belvedere Fan Club</h1>
|
515
|
-
<div><p>Hello</p></div>
|
516
|
-
<a href="https://google.com/hello.html">TOP</a>
|
517
|
-
<form action="/form.php" method="GET">
|
518
|
-
<input type="text" name="name" value="wovn.io" />
|
519
|
-
</form>
|
520
|
-
</body>
|
521
|
-
</html>
|
522
|
-
BODY
|
523
|
-
expected = <<"EXPECTED"
|
524
|
-
<html lang=\"ja\">
|
525
|
-
<head>
|
526
|
-
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">
|
527
|
-
<script src=\"//j.wovn.io/1\" async=\"true\" data-wovnio=\"key=OHYx9&backend=true&currentLang=ja&defaultLang=en&urlPattern=path&version=0.2\"> </script><title>Hey</title>
|
528
|
-
<link rel=\"alternate\" hreflang=\"ja\" href=\"https://google.com/ja/\">
|
529
|
-
</head>
|
530
|
-
<body>
|
531
|
-
<h1>ベルベデアさんファンクラブ</h1>
|
532
|
-
<div><p>こんにちは</p></div>
|
533
|
-
<a href=\"https://google.com/ja/hello.html\">TOP</a>
|
534
|
-
<form action=\"/ja/form.php\" method="GET">
|
535
|
-
<input type=\"text\" name=\"name\" value=\"wovn.io\">
|
536
|
-
</form>
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
</body>
|
541
|
-
</html>
|
542
|
-
EXPECTED
|
543
|
-
body = [body]
|
544
|
-
expected = [expected]
|
545
|
-
values = generate_values
|
546
|
-
url = h.url
|
547
|
-
swapped_body = i.switch_lang(body, values, url, 'ja', h)
|
548
|
-
assert_equal(expected, swapped_body)
|
549
|
-
end
|
550
|
-
|
551
|
-
def test_switch_lang_add_lang_code_path_from_action_post_method
|
552
|
-
i = Wovnrb::Interceptor.new(get_app, get_settings)
|
553
|
-
h = Wovnrb::Headers.new(get_env('url' => 'https://google.com'), get_settings)
|
554
|
-
body = <<"BODY"
|
555
|
-
<html>
|
556
|
-
<head><title>Hey</title></head>
|
557
|
-
<body>
|
558
|
-
<h1>Mr. Belvedere Fan Club</h1>
|
559
|
-
<div><p>Hello</p></div>
|
560
|
-
<a href="https://google.com/hello.html">TOP</a>
|
561
|
-
<form action="/form.php" method="POST">
|
562
|
-
<input type="text" name="name" value="wovn.io" />
|
563
|
-
</form>
|
564
|
-
</body>
|
565
|
-
</html>
|
566
|
-
BODY
|
567
|
-
expected = <<"EXPECTED"
|
568
|
-
<html lang=\"ja\">
|
569
|
-
<head>
|
570
|
-
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">
|
571
|
-
<script src=\"//j.wovn.io/1\" async=\"true\" data-wovnio=\"key=OHYx9&backend=true&currentLang=ja&defaultLang=en&urlPattern=path&version=0.2\"> </script><title>Hey</title>
|
572
|
-
<link rel=\"alternate\" hreflang=\"ja\" href=\"https://google.com/ja/\">
|
573
|
-
</head>
|
574
|
-
<body>
|
575
|
-
<h1>ベルベデアさんファンクラブ</h1>
|
576
|
-
<div><p>こんにちは</p></div>
|
577
|
-
<a href=\"https://google.com/ja/hello.html\">TOP</a>
|
578
|
-
<form action=\"/ja/form.php\" method="POST">
|
579
|
-
<input type=\"text\" name=\"name\" value=\"wovn.io\">
|
580
|
-
</form>
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
</body>
|
585
|
-
</html>
|
586
|
-
EXPECTED
|
587
|
-
body = [body]
|
588
|
-
expected = [expected]
|
589
|
-
values = generate_values
|
590
|
-
url = h.url
|
591
|
-
swapped_body = i.switch_lang(body, values, url, 'ja', h)
|
592
|
-
assert_equal(expected, swapped_body)
|
593
|
-
end
|
594
|
-
|
595
|
-
def test_switch_lang_add_lang_code_subdomain_from_action_no_method
|
596
|
-
i = Wovnrb::Interceptor.new(
|
597
|
-
get_app,
|
598
|
-
get_settings('url_pattern' => 'subdomain', 'url_pattern_reg' => "^(?<lang>[^.]+)\."),
|
599
|
-
)
|
600
|
-
h = Wovnrb::Headers.new(
|
601
|
-
get_env('url' => 'https://google.com'),
|
602
|
-
get_settings('url_pattern' => 'subdomain', 'url_pattern_reg' => "^(?<lang>[^.]+)\."),
|
603
|
-
)
|
604
|
-
body = <<"BODY"
|
605
|
-
<html>
|
606
|
-
<head><title>Hey</title></head>
|
607
|
-
<body>
|
608
|
-
<h1>Mr. Belvedere Fan Club</h1>
|
609
|
-
<div><p>Hello</p></div>
|
610
|
-
<a href="https://google.com/hello.html">TOP</a>
|
611
|
-
<form action="/form.php">
|
612
|
-
<input type="text" name="name" value="wovn.io" />
|
613
|
-
</form>
|
614
|
-
</body>
|
615
|
-
</html>
|
616
|
-
BODY
|
617
|
-
expected = <<"EXPECTED"
|
618
|
-
<html lang=\"ja\">
|
619
|
-
<head>
|
620
|
-
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">
|
621
|
-
<script src=\"//j.wovn.io/1\" async=\"true\" data-wovnio=\"key=OHYx9&backend=true&currentLang=ja&defaultLang=en&urlPattern=subdomain&version=0.2\"> </script><title>Hey</title>
|
622
|
-
<link rel=\"alternate\" hreflang=\"ja\" href=\"https://ja.google.com/\">
|
623
|
-
</head>
|
624
|
-
<body>
|
625
|
-
<h1>ベルベデアさんファンクラブ</h1>
|
626
|
-
<div><p>こんにちは</p></div>
|
627
|
-
<a href=\"https://ja.google.com/hello.html\">TOP</a>
|
628
|
-
<form action=\"https://ja.google.com/form.php\">
|
629
|
-
<input type=\"text\" name=\"name\" value=\"wovn.io\">
|
630
|
-
</form>
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
</body>
|
635
|
-
</html>
|
636
|
-
EXPECTED
|
637
|
-
body = [body]
|
638
|
-
expected = [expected]
|
639
|
-
values = generate_values
|
640
|
-
url = h.url
|
641
|
-
swapped_body = i.switch_lang(body, values, url, 'ja', h)
|
642
|
-
assert_equal(expected, swapped_body)
|
643
|
-
end
|
644
|
-
|
645
|
-
def test_switch_lang_add_lang_code_subdomain_from_action_get_method
|
646
|
-
i = Wovnrb::Interceptor.new(
|
647
|
-
get_app,
|
648
|
-
get_settings('url_pattern' => 'subdomain', 'url_pattern_reg' => "^(?<lang>[^.]+)\."),
|
649
|
-
)
|
650
|
-
h = Wovnrb::Headers.new(
|
651
|
-
get_env('url' => 'https://google.com'),
|
652
|
-
get_settings('url_pattern' => 'subdomain', 'url_pattern_reg' => "^(?<lang>[^.]+)\."),
|
653
|
-
)
|
654
|
-
body = <<"BODY"
|
655
|
-
<html>
|
656
|
-
<head><title>Hey</title></head>
|
657
|
-
<body>
|
658
|
-
<h1>Mr. Belvedere Fan Club</h1>
|
659
|
-
<div><p>Hello</p></div>
|
660
|
-
<a href="https://google.com/hello.html">TOP</a>
|
661
|
-
<form action="/form.php" method="GET">
|
662
|
-
<input type="text" name="name" value="wovn.io" />
|
663
|
-
</form>
|
664
|
-
</body>
|
665
|
-
</html>
|
666
|
-
BODY
|
667
|
-
expected = <<"EXPECTED"
|
668
|
-
<html lang=\"ja\">
|
669
|
-
<head>
|
670
|
-
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">
|
671
|
-
<script src=\"//j.wovn.io/1\" async=\"true\" data-wovnio=\"key=OHYx9&backend=true&currentLang=ja&defaultLang=en&urlPattern=subdomain&version=0.2\"> </script><title>Hey</title>
|
672
|
-
<link rel=\"alternate\" hreflang=\"ja\" href=\"https://ja.google.com/\">
|
673
|
-
</head>
|
674
|
-
<body>
|
675
|
-
<h1>ベルベデアさんファンクラブ</h1>
|
676
|
-
<div><p>こんにちは</p></div>
|
677
|
-
<a href=\"https://ja.google.com/hello.html\">TOP</a>
|
678
|
-
<form action=\"https://ja.google.com/form.php\" method="GET">
|
679
|
-
<input type=\"text\" name=\"name\" value=\"wovn.io\">
|
680
|
-
</form>
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
</body>
|
685
|
-
</html>
|
686
|
-
EXPECTED
|
687
|
-
body = [body]
|
688
|
-
expected = [expected]
|
689
|
-
values = generate_values
|
690
|
-
url = h.url
|
691
|
-
swapped_body = i.switch_lang(body, values, url, 'ja', h)
|
692
|
-
assert_equal(expected, swapped_body)
|
693
|
-
end
|
694
|
-
|
695
|
-
def test_switch_lang_add_lang_code_subdomain_from_action_post_method
|
696
|
-
i = Wovnrb::Interceptor.new(
|
697
|
-
get_app,
|
698
|
-
get_settings('url_pattern' => 'subdomain', 'url_pattern_reg' => "^(?<lang>[^.]+)\."),
|
699
|
-
)
|
700
|
-
h = Wovnrb::Headers.new(
|
701
|
-
get_env('url' => 'https://google.com'),
|
702
|
-
get_settings('url_pattern' => 'subdomain', 'url_pattern_reg' => "^(?<lang>[^.]+)\."),
|
703
|
-
)
|
704
|
-
body = <<"BODY"
|
705
|
-
<html>
|
706
|
-
<head><title>Hey</title></head>
|
707
|
-
<body>
|
708
|
-
<h1>Mr. Belvedere Fan Club</h1>
|
709
|
-
<div><p>Hello</p></div>
|
710
|
-
<a href="https://google.com/hello.html">TOP</a>
|
711
|
-
<form action="/form.php" method="POST">
|
712
|
-
<input type="text" name="name" value="wovn.io" />
|
713
|
-
</form>
|
714
|
-
</body>
|
715
|
-
</html>
|
716
|
-
BODY
|
717
|
-
expected = <<"EXPECTED"
|
718
|
-
<html lang=\"ja\">
|
719
|
-
<head>
|
720
|
-
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">
|
721
|
-
<script src=\"//j.wovn.io/1\" async=\"true\" data-wovnio=\"key=OHYx9&backend=true&currentLang=ja&defaultLang=en&urlPattern=subdomain&version=0.2\"> </script><title>Hey</title>
|
722
|
-
<link rel=\"alternate\" hreflang=\"ja\" href=\"https://ja.google.com/\">
|
723
|
-
</head>
|
724
|
-
<body>
|
725
|
-
<h1>ベルベデアさんファンクラブ</h1>
|
726
|
-
<div><p>こんにちは</p></div>
|
727
|
-
<a href=\"https://ja.google.com/hello.html\">TOP</a>
|
728
|
-
<form action=\"https://ja.google.com/form.php\" method="POST">
|
729
|
-
<input type=\"text\" name=\"name\" value=\"wovn.io\">
|
730
|
-
</form>
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
</body>
|
735
|
-
</html>
|
736
|
-
EXPECTED
|
737
|
-
body = [body]
|
738
|
-
expected = [expected]
|
739
|
-
values = generate_values
|
740
|
-
url = h.url
|
741
|
-
swapped_body = i.switch_lang(body, values, url, 'ja', h)
|
742
|
-
assert_equal(expected, swapped_body)
|
743
|
-
end
|
744
|
-
|
745
|
-
def test_switch_lang_add_lang_code_query_form_action_no_method
|
746
|
-
i = Wovnrb::Interceptor.new(
|
747
|
-
get_app,
|
748
|
-
get_settings('url_pattern' => 'query', 'url_pattern_reg' => "((\\?.*&)|\\?)wovn=(?<lang>[^&]+)(&|$)"),
|
749
|
-
)
|
750
|
-
h = Wovnrb::Headers.new(
|
751
|
-
get_env('url' => 'https://google.com'),
|
752
|
-
get_settings('url_pattern' => 'query', 'url_pattern_reg' => "((\\?.*&)|\\?)wovn=(?<lang>[^&]+)(&|$)"),
|
753
|
-
)
|
754
|
-
body = <<"BODY"
|
755
|
-
<html>
|
756
|
-
<head><title>Hey</title></head>
|
757
|
-
<body>
|
758
|
-
<h1>Mr. Belvedere Fan Club</h1>
|
759
|
-
<div><p>Hello</p></div>
|
760
|
-
<a href="https://google.com/hello.html">TOP</a>
|
761
|
-
<form action="/form.php">
|
762
|
-
<input type="text" name="name" value="wovn.io" />
|
763
|
-
</form>
|
764
|
-
</body>
|
765
|
-
</html>
|
766
|
-
BODY
|
767
|
-
expected = <<"EXPECTED"
|
768
|
-
<html lang=\"ja\">
|
769
|
-
<head>
|
770
|
-
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">
|
771
|
-
<script src=\"//j.wovn.io/1\" async=\"true\" data-wovnio=\"key=OHYx9&backend=true&currentLang=ja&defaultLang=en&urlPattern=query&version=0.2\"> </script><title>Hey</title>
|
772
|
-
<link rel=\"alternate\" hreflang=\"ja\" href=\"https://google.com/?wovn=ja\">
|
773
|
-
</head>
|
774
|
-
<body>
|
775
|
-
<h1>ベルベデアさんファンクラブ</h1>
|
776
|
-
<div><p>こんにちは</p></div>
|
777
|
-
<a href=\"https://google.com/hello.html?wovn=ja\">TOP</a>
|
778
|
-
<form action=\"/form.php\">
|
779
|
-
<input type=\"hidden\" name=\"wovn\" value=\"ja\">
|
780
|
-
<input type=\"text\" name=\"name\" value=\"wovn.io\">
|
781
|
-
</form>
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
</body>
|
786
|
-
</html>
|
787
|
-
EXPECTED
|
788
|
-
body = [body]
|
789
|
-
expected = [expected]
|
790
|
-
values = generate_values
|
791
|
-
url = h.url
|
792
|
-
swapped_body = i.switch_lang(body, values, url, 'ja', h)
|
793
|
-
assert_equal(expected, swapped_body)
|
794
|
-
end
|
795
|
-
|
796
|
-
def test_switch_lang_add_lang_code_query_form_action_get_method
|
797
|
-
i = Wovnrb::Interceptor.new(
|
798
|
-
get_app,
|
799
|
-
get_settings('url_pattern' => 'query', 'url_pattern_reg' => "((\\?.*&)|\\?)wovn=(?<lang>[^&]+)(&|$)"),
|
800
|
-
)
|
801
|
-
h = Wovnrb::Headers.new(
|
802
|
-
get_env('url' => 'https://google.com'),
|
803
|
-
get_settings('url_pattern' => 'query', 'url_pattern_reg' => "((\\?.*&)|\\?)wovn=(?<lang>[^&]+)(&|$)"),
|
804
|
-
)
|
805
|
-
body = <<"BODY"
|
806
|
-
<html>
|
807
|
-
<head><title>Hey</title></head>
|
808
|
-
<body>
|
809
|
-
<h1>Mr. Belvedere Fan Club</h1>
|
810
|
-
<div><p>Hello</p></div>
|
811
|
-
<a href="https://google.com/hello.html">TOP</a>
|
812
|
-
<form action="/form.php" method="GET">
|
813
|
-
<input type="text" name="name" value="wovn.io" />
|
814
|
-
</form>
|
815
|
-
</body>
|
816
|
-
</html>
|
817
|
-
BODY
|
818
|
-
expected = <<"EXPECTED"
|
819
|
-
<html lang=\"ja\">
|
820
|
-
<head>
|
821
|
-
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">
|
822
|
-
<script src=\"//j.wovn.io/1\" async=\"true\" data-wovnio=\"key=OHYx9&backend=true&currentLang=ja&defaultLang=en&urlPattern=query&version=0.2\"> </script><title>Hey</title>
|
823
|
-
<link rel=\"alternate\" hreflang=\"ja\" href=\"https://google.com/?wovn=ja\">
|
824
|
-
</head>
|
825
|
-
<body>
|
826
|
-
<h1>ベルベデアさんファンクラブ</h1>
|
827
|
-
<div><p>こんにちは</p></div>
|
828
|
-
<a href=\"https://google.com/hello.html?wovn=ja\">TOP</a>
|
829
|
-
<form action=\"/form.php\" method="GET">
|
830
|
-
<input type=\"hidden\" name=\"wovn\" value=\"ja\">
|
831
|
-
<input type=\"text\" name=\"name\" value=\"wovn.io\">
|
832
|
-
</form>
|
833
|
-
|
834
|
-
|
835
|
-
|
836
|
-
</body>
|
837
|
-
</html>
|
838
|
-
EXPECTED
|
839
|
-
body = [body]
|
840
|
-
expected = [expected]
|
841
|
-
values = generate_values
|
842
|
-
url = h.url
|
843
|
-
swapped_body = i.switch_lang(body, values, url, 'ja', h)
|
844
|
-
assert_equal(expected, swapped_body)
|
845
|
-
end
|
846
|
-
|
847
|
-
def test_switch_lang_add_lang_code_query_form_action_post_method
|
848
|
-
i = Wovnrb::Interceptor.new(
|
849
|
-
get_app,
|
850
|
-
get_settings('url_pattern' => 'query', 'url_pattern_reg' => "((\\?.*&)|\\?)wovn=(?<lang>[^&]+)(&|$)"),
|
851
|
-
)
|
852
|
-
h = Wovnrb::Headers.new(
|
853
|
-
get_env('url' => 'https://google.com'),
|
854
|
-
get_settings('url_pattern' => 'query', 'url_pattern_reg' => "((\\?.*&)|\\?)wovn=(?<lang>[^&]+)(&|$)"),
|
855
|
-
)
|
856
|
-
body = <<"BODY"
|
857
|
-
<html>
|
858
|
-
<head><title>Hey</title></head>
|
859
|
-
<body>
|
860
|
-
<h1>Mr. Belvedere Fan Club</h1>
|
861
|
-
<div><p>Hello</p></div>
|
862
|
-
<a href="https://google.com/hello.html">TOP</a>
|
863
|
-
<form action="/form.php" method="POST">
|
864
|
-
<input type="text" name="name" value="wovn.io" />
|
865
|
-
</form>
|
866
|
-
</body>
|
867
|
-
</html>
|
868
|
-
BODY
|
869
|
-
expected = <<"EXPECTED"
|
870
|
-
<html lang=\"ja\">
|
871
|
-
<head>
|
872
|
-
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">
|
873
|
-
<script src=\"//j.wovn.io/1\" async=\"true\" data-wovnio=\"key=OHYx9&backend=true&currentLang=ja&defaultLang=en&urlPattern=query&version=0.2\"> </script><title>Hey</title>
|
874
|
-
<link rel=\"alternate\" hreflang=\"ja\" href=\"https://google.com/?wovn=ja\">
|
875
|
-
</head>
|
876
|
-
<body>
|
877
|
-
<h1>ベルベデアさんファンクラブ</h1>
|
878
|
-
<div><p>こんにちは</p></div>
|
879
|
-
<a href=\"https://google.com/hello.html?wovn=ja\">TOP</a>
|
880
|
-
<form action=\"/form.php?wovn=ja\" method="POST">
|
881
|
-
<input type=\"text\" name=\"name\" value=\"wovn.io\">
|
882
|
-
</form>
|
883
|
-
|
884
|
-
|
885
|
-
|
886
|
-
</body>
|
887
|
-
</html>
|
888
|
-
EXPECTED
|
889
|
-
body = [body]
|
890
|
-
expected = [expected]
|
891
|
-
values = generate_values
|
892
|
-
url = h.url
|
893
|
-
swapped_body = i.switch_lang(body, values, url, 'ja', h)
|
894
|
-
assert_equal(expected, swapped_body)
|
895
|
-
end
|
896
|
-
|
897
|
-
def get_settings(options={})
|
898
|
-
settings = {}
|
899
|
-
settings['user_token'] = 'OHYx9'
|
900
|
-
settings['url_pattern'] = 'path'
|
901
|
-
settings['url_pattern_reg'] = "/(?<lang>[^/.?]+)"
|
902
|
-
settings['query'] = []
|
903
|
-
settings['api_url'] = 'http://localhost/v0/values'
|
904
|
-
settings['default_lang'] = 'en'
|
905
|
-
settings['supported_langs'] = []
|
906
|
-
settings['secret_key'] = ''
|
907
|
-
return settings.merge(options)
|
908
|
-
end
|
909
|
-
|
910
|
-
def get_env(options={})
|
911
|
-
env = {}
|
912
|
-
env['rack.url_scheme'] = 'http'
|
913
|
-
env['HTTP_HOST'] = 'wovn.io'
|
914
|
-
env['REQUEST_URI'] = '/dashboard?param=val&hey=you'
|
915
|
-
env['SERVER_NAME'] = 'wovn.io'
|
916
|
-
env['HTTP_COOKIE'] = "olfsk=olfsk021093478426337242; hblid=KB8AAMzxzu2DSxnB4X7BJ26rBGVeF0yJ; optimizelyEndUserId=oeu1426233718869r0.5398541854228824; __zlcmid=UFeZqrVo6Mv3Yl; wovn_selected_lang=en; optimizelySegments=%7B%7D; optimizelyBuckets=%7B%7D; _equalizer_session=eDFwM3M2QUZJZFhoby9JZlArckcvSUJwNFRINXhUeUxtNnltQXZhV0tqdGhZQjJMZ01URnZTK05ydFVWYmM3U0dtMVN0M0Z0UnNDVG8vdUNDTUtPc21jY0FHREgrZ05CUnBTb0hyUlkvYlBWQVhQR3RZdnhjMWsrRW5rOVp1Z3V3bkgyd3NpSlRZQWU1dlZvNmM1THp6aUZVeE83Y1pWWENRNTBUVFIrV05WeTdDMlFlem1tUzdxaEtndFZBd2dtUjU2ak5EUmJPa3RWWmMyT1pSVWdMTm8zOVZhUWhHdGQ3L1c5bm91RmNSdFRrcC90Tml4N2t3ZWlBaDRya2lLT1I0S0J2TURhUWl6Uk5rOTQ4Y1MwM3VKYnlLMUYraEt5clhRdFd1eGdEWXdZd3pFbWQvdE9vQndhdDVQbXNLcHBURm9CbnZKenU2YnNXRFdqRVl0MVV3bmRyYjhvMDExcGtUVU9tK1lqUGswM3p6M05tbVRnTjE3TUl5cEdpTTZ4a2gray8xK0FvTC9wUDVka1JSeE5GM1prZmRjWDdyVzRhWW5uS2Mxc1BxOEVVTTZFS3N5bTlVN2p5eE5YSjNZWGI2UHd3Vzc0bDM5QjIwL0l5Mm85NmQyWFAwdVQ3ZzJYYk1QOHY2NVJpY2c9LS1KNU96eHVycVJxSDJMbEc4Rm9KVXpBPT0%3D--17e47555d692fb9cde20ef78a09a5eabbf805bb3; mp_a0452663eb7abb7dfa9c94007ebb0090_mixpanel=%7B%22distinct_id%22%3A%20%2253ed9ffa4a65662e37000000%22%2C%22%24initial_referrer%22%3A%20%22http%3A%2F%2Fp.dev-wovn.io%3A8080%2Fhttp%3A%2F%2Fdev-wovn.io%3A3000%22%2C%22%24initial_referring_domain%22%3A%20%22p.dev-wovn.io%3A8080%22%2C%22__mps%22%3A%20%7B%7D%2C%22__mpso%22%3A%20%7B%7D%2C%22__mpa%22%3A%20%7B%7D%2C%22__mpu%22%3A%20%7B%7D%2C%22__mpap%22%3A%20%5B%5D%7D"
|
917
|
-
env['HTTP_ACCEPT_LANGUAGE'] = 'ja,en-US;q=0.8,en;q=0.6'
|
918
|
-
env['QUERY_STRING'] = 'param=val&hey=you'
|
919
|
-
env['ORIGINAL_FULLPATH'] = '/dashboard?param=val&hey=you'
|
920
|
-
#env['HTTP_REFERER'] =
|
921
|
-
env['REQUEST_PATH'] = '/dashboard'
|
922
|
-
env['PATH_INFO'] = '/dashboard'
|
923
|
-
|
924
|
-
if options['url']
|
925
|
-
url = URI.parse(options['url'])
|
926
|
-
env['rack.url_scheme'] = url.scheme
|
927
|
-
env['HTTP_HOST'] = url.host
|
928
|
-
if (url.scheme == 'http' && url.port != 80) || (url.scheme == 'https' && url.port != 443)
|
929
|
-
env['HTTP_HOST'] += ":#{url.port}"
|
930
|
-
end
|
931
|
-
env['SERVER_NAME'] = url.host
|
932
|
-
env['REQUEST_URI'] = url.request_uri
|
933
|
-
env['ORIGINAL_FULLPATH'] = url.request_uri
|
934
|
-
env['QUERY_STRING'] = url.query
|
935
|
-
env['REQUEST_PATH'] = url.path
|
936
|
-
env['PATH_INFO'] = url.path
|
88
|
+
class RackMock
|
89
|
+
def call(env)
|
90
|
+
[200, {'Content-Type' => 'text/html'}, ['']]
|
937
91
|
end
|
938
|
-
return env.merge(options)
|
939
92
|
end
|
940
93
|
end
|