wovnrb 3.8.0 → 3.10.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,151 +1,149 @@
1
- require 'test_helper'
2
-
3
- module Wovnrb
4
- class HtmlReplaceMarkerTest < WovnMiniTest
5
- def test_add_comment_value
6
- marker = HtmlReplaceMarker.new
7
- assert_equal('<!-- __wovn-backend-ignored-key-0 -->', marker.add_comment_value('hello'))
8
- end
9
-
10
- def test_add_comment_value_multiple_times
11
- marker = HtmlReplaceMarker.new
12
- assert_equal('<!-- __wovn-backend-ignored-key-0 -->', marker.add_comment_value('hello'))
13
- assert_equal('<!-- __wovn-backend-ignored-key-1 -->', marker.add_comment_value('hello'))
14
- assert_equal('<!-- __wovn-backend-ignored-key-2 -->', marker.add_comment_value('hello'))
15
- assert_equal('<!-- __wovn-backend-ignored-key-3 -->', marker.add_comment_value('hello'))
16
- end
17
-
18
- def test_add_same_comment_value_multiple_times
19
- marker = HtmlReplaceMarker.new
20
-
21
- 25.times do |i|
22
- assert_equal("<!-- __wovn-backend-ignored-key-#{i} -->", marker.add_comment_value('hello'))
23
- end
24
- end
25
-
26
- def test_add_same_value_multiple_times
27
- marker = HtmlReplaceMarker.new
28
-
29
- 25.times do |i|
30
- assert_equal("__wovn-backend-ignored-key-#{i}", marker.add_value('hello'))
31
- end
32
- end
33
-
34
- def test_mixed_add_comment_value_and_add_value
35
- marker = HtmlReplaceMarker.new
36
-
37
- assert_equal('<!-- __wovn-backend-ignored-key-0 -->', marker.add_comment_value('hello'))
38
- assert_equal('__wovn-backend-ignored-key-1', marker.add_value('hello'))
39
- assert_equal('<!-- __wovn-backend-ignored-key-2 -->', marker.add_comment_value('hello'))
40
- assert_equal('__wovn-backend-ignored-key-3', marker.add_value('hello'))
41
- assert_equal('<!-- __wovn-backend-ignored-key-4 -->', marker.add_comment_value('hello'))
42
- assert_equal('__wovn-backend-ignored-key-5', marker.add_value('hello'))
43
- assert_equal('<!-- __wovn-backend-ignored-key-6 -->', marker.add_comment_value('hello'))
44
- assert_equal('__wovn-backend-ignored-key-7', marker.add_value('hello'))
45
- end
46
-
47
- def test_revert
48
- marker = HtmlReplaceMarker.new
49
- original_html = '<html><body>hello<a> replacement </a>world </body></html>'
50
- key = marker.add_comment_value('hello')
51
- new_html = original_html.sub('hello', key)
52
- assert_equal("<html><body>#{key}<a> replacement </a>world </body></html>", new_html)
53
- assert_equal(original_html, marker.revert(new_html))
54
- end
55
-
56
- def test_revert_input_value
57
- marker = HtmlReplaceMarker.new
58
- original_html = '<html><body><input type="hidden" value="please-revert"></body></html>'
59
- key = marker.add_value('please-revert')
60
- new_html = original_html.sub('please-revert', key)
61
- assert_equal("<html><body><input type=\"hidden\" value=\"#{key}\"></body></html>", new_html)
62
- assert_equal(original_html, marker.revert(new_html))
63
- end
64
-
65
- def test_revert_input_empty_value
66
- marker = HtmlReplaceMarker.new
67
- original_html = '<html><body><input type="hidden" value=""></body></html>'
68
- key = marker.add_value('')
69
- new_html = original_html.sub('value=""', "value=\"#{key}\"")
70
- assert_equal("<html><body><input type=\"hidden\" value=\"#{key}\"></body></html>", new_html)
71
- assert_equal(original_html, marker.revert(new_html))
72
- end
73
-
74
- def test_revert_multiple_input
75
- marker = HtmlReplaceMarker.new
76
- original_html = [
77
- '<html><body>',
78
- '<input type="hidden" value="please_revert1"></body></html>',
79
- '<input type="hidden" value="please_revert2"></body></html>',
80
- '<input type="hidden" value=""></body></html>'
81
- ].join
82
- new_html = [
83
- '<html><body>',
84
- "<input type=\"hidden\" value=\"#{marker.add_value('please_revert1')}\"></body></html>",
85
- "<input type=\"hidden\" value=\"#{marker.add_value('please_revert2')}\"></body></html>",
86
- "<input type=\"hidden\" value=\"#{marker.add_value('')}\">",
87
- '</body></html>'
88
- ].join
89
- assert_equal(original_html, marker.revert(new_html))
90
- end
91
-
92
- def test_revert_multiple_values
93
- marker = HtmlReplaceMarker.new
94
- original_html = '<html><body>hello<a> replacement </a>world </body></html>'
95
- key1 = marker.add_comment_value('hello')
96
- key2 = marker.add_comment_value('replacement')
97
- key3 = marker.add_comment_value('world')
98
- new_html = original_html.sub('hello', key1)
99
- new_html = new_html.sub('replacement', key2).sub('world', key3)
100
- assert_equal("<html><body>#{key1}<a> #{key2} </a>#{key3} </body></html>", new_html)
101
- assert_equal(original_html, marker.revert(new_html))
102
- end
103
-
104
- def test_revert_multiple_similar_values
105
- marker = HtmlReplaceMarker.new
106
- original_html = '<html><body>'
107
- 25.times { |i| original_html += "<a>hello_#{i}</a>" }
108
- original_html += '</body></html>'
109
-
110
- new_html = original_html
111
- keys = []
112
- 25.times do |i|
113
- key = marker.add_comment_value("hello_#{i}")
114
- keys << key
115
- new_html = new_html.sub("hello_#{i}", key)
116
- end
117
-
118
- assert_equal(false, new_html.include?('hello'))
119
- assert_equal(original_html, marker.revert(new_html))
120
- end
121
-
122
- def test_revert_same_value
123
- marker = HtmlReplaceMarker.new
124
- original_html = '<html><body>hello<a>hello</a>hello</body></html>'
125
- key1 = marker.add_comment_value('hello')
126
- key2 = marker.add_comment_value('hello')
127
- key3 = marker.add_comment_value('hello')
128
- new_html = "<html><body>#{key1}<a>#{key2}</a>#{key3}</body></html>"
129
- assert_equal(original_html, marker.revert(new_html))
130
- end
131
-
132
- def test_revert_mixed_values
133
- marker = HtmlReplaceMarker.new
134
- original_html = [
135
- '<html><body>',
136
- '<span>hello</span>',
137
- '<input type="hidden" value="please_revert">',
138
- '</body></html>'
139
- ].join
140
- key1 = marker.add_comment_value('hello')
141
- key2 = marker.add_value('please_revert')
142
- new_html = [
143
- '<html><body>',
144
- "<span>#{key1}</span>",
145
- "<input type=\"hidden\" value=\"#{key2}\">",
146
- '</body></html>'
147
- ].join
148
- assert_equal(original_html, marker.revert(new_html))
149
- end
150
- end
151
- end
1
+ require 'test_helper'
2
+
3
+ module Wovnrb
4
+ class HtmlReplaceMarkerTest < WovnMiniTest
5
+ def test_add_comment_value
6
+ marker = HtmlReplaceMarker.new
7
+ assert_equal('<!-- __wovn-backend-ignored-key-0 -->', marker.add_comment_value('hello'))
8
+ end
9
+
10
+ def test_add_comment_value_multiple_times
11
+ marker = HtmlReplaceMarker.new
12
+ assert_equal('<!-- __wovn-backend-ignored-key-0 -->', marker.add_comment_value('hello'))
13
+ assert_equal('<!-- __wovn-backend-ignored-key-1 -->', marker.add_comment_value('hello'))
14
+ assert_equal('<!-- __wovn-backend-ignored-key-2 -->', marker.add_comment_value('hello'))
15
+ assert_equal('<!-- __wovn-backend-ignored-key-3 -->', marker.add_comment_value('hello'))
16
+ end
17
+
18
+ def test_add_same_comment_value_multiple_times
19
+ marker = HtmlReplaceMarker.new
20
+
21
+ 25.times do |i|
22
+ assert_equal("<!-- __wovn-backend-ignored-key-#{i} -->", marker.add_comment_value('hello'))
23
+ end
24
+ end
25
+
26
+ def test_add_same_value_multiple_times
27
+ marker = HtmlReplaceMarker.new
28
+
29
+ 25.times do |i|
30
+ assert_equal("__wovn-backend-ignored-key-#{i}", marker.add_value('hello'))
31
+ end
32
+ end
33
+
34
+ def test_mixed_add_comment_value_and_add_value
35
+ marker = HtmlReplaceMarker.new
36
+
37
+ assert_equal('<!-- __wovn-backend-ignored-key-0 -->', marker.add_comment_value('hello'))
38
+ assert_equal('__wovn-backend-ignored-key-1', marker.add_value('hello'))
39
+ assert_equal('<!-- __wovn-backend-ignored-key-2 -->', marker.add_comment_value('hello'))
40
+ assert_equal('__wovn-backend-ignored-key-3', marker.add_value('hello'))
41
+ assert_equal('<!-- __wovn-backend-ignored-key-4 -->', marker.add_comment_value('hello'))
42
+ assert_equal('__wovn-backend-ignored-key-5', marker.add_value('hello'))
43
+ assert_equal('<!-- __wovn-backend-ignored-key-6 -->', marker.add_comment_value('hello'))
44
+ assert_equal('__wovn-backend-ignored-key-7', marker.add_value('hello'))
45
+ end
46
+
47
+ def test_revert
48
+ marker = HtmlReplaceMarker.new
49
+ original_html = '<html><body>hello<a> replacement </a>world </body></html>'
50
+ key = marker.add_comment_value('hello')
51
+ new_html = original_html.sub('hello', key)
52
+ assert_equal("<html><body>#{key}<a> replacement </a>world </body></html>", new_html)
53
+ assert_equal(original_html, marker.revert(new_html))
54
+ end
55
+
56
+ def test_revert_input_value
57
+ marker = HtmlReplaceMarker.new
58
+ original_html = '<html><body><input type="hidden" value="please-revert"></body></html>'
59
+ key = marker.add_value('please-revert')
60
+ new_html = original_html.sub('please-revert', key)
61
+ assert_equal("<html><body><input type=\"hidden\" value=\"#{key}\"></body></html>", new_html)
62
+ assert_equal(original_html, marker.revert(new_html))
63
+ end
64
+
65
+ def test_revert_input_empty_value
66
+ marker = HtmlReplaceMarker.new
67
+ original_html = '<html><body><input type="hidden" value=""></body></html>'
68
+ key = marker.add_value('')
69
+ new_html = original_html.sub('value=""', "value=\"#{key}\"")
70
+ assert_equal("<html><body><input type=\"hidden\" value=\"#{key}\"></body></html>", new_html)
71
+ assert_equal(original_html, marker.revert(new_html))
72
+ end
73
+
74
+ def test_revert_multiple_input
75
+ marker = HtmlReplaceMarker.new
76
+ original_html = '<html><body>'
77
+ new_html = '<html><body>'
78
+
79
+ 50.times do |i|
80
+ original_html += "<input type=\"hidden\" value=\"#{i}\"></body></html>"
81
+ new_html += "<input type=\"hidden\" value=\"#{marker.add_value(i.to_s)}\"></body></html>"
82
+ end
83
+
84
+ original_html += '</body></html>'
85
+ new_html += '</body></html>'
86
+
87
+ assert_equal(original_html, marker.revert(new_html))
88
+ end
89
+
90
+ def test_revert_multiple_values
91
+ marker = HtmlReplaceMarker.new
92
+ original_html = '<html><body>hello<a> replacement </a>world </body></html>'
93
+ key1 = marker.add_comment_value('hello')
94
+ key2 = marker.add_comment_value('replacement')
95
+ key3 = marker.add_comment_value('world')
96
+ new_html = original_html.sub('hello', key1)
97
+ new_html = new_html.sub('replacement', key2).sub('world', key3)
98
+ assert_equal("<html><body>#{key1}<a> #{key2} </a>#{key3} </body></html>", new_html)
99
+ assert_equal(original_html, marker.revert(new_html))
100
+ end
101
+
102
+ def test_revert_multiple_similar_values
103
+ marker = HtmlReplaceMarker.new
104
+ original_html = '<html><body>'
105
+ 25.times { |i| original_html += "<a>hello_#{i}</a>" }
106
+ original_html += '</body></html>'
107
+
108
+ new_html = original_html
109
+ keys = []
110
+ 25.times do |i|
111
+ key = marker.add_comment_value("hello_#{i}")
112
+ keys << key
113
+ new_html = new_html.sub("hello_#{i}", key)
114
+ end
115
+
116
+ assert_equal(false, new_html.include?('hello'))
117
+ assert_equal(original_html, marker.revert(new_html))
118
+ end
119
+
120
+ def test_revert_same_value
121
+ marker = HtmlReplaceMarker.new
122
+ original_html = '<html><body>hello<a>hello</a>hello</body></html>'
123
+ key1 = marker.add_comment_value('hello')
124
+ key2 = marker.add_comment_value('hello')
125
+ key3 = marker.add_comment_value('hello')
126
+ new_html = "<html><body>#{key1}<a>#{key2}</a>#{key3}</body></html>"
127
+ assert_equal(original_html, marker.revert(new_html))
128
+ end
129
+
130
+ def test_revert_mixed_values
131
+ marker = HtmlReplaceMarker.new
132
+ original_html = [
133
+ '<html><body>',
134
+ '<span>hello</span>',
135
+ '<input type="hidden" value="please_revert">',
136
+ '</body></html>'
137
+ ].join
138
+ key1 = marker.add_comment_value('hello')
139
+ key2 = marker.add_value('please_revert')
140
+ new_html = [
141
+ '<html><body>',
142
+ "<span>#{key1}</span>",
143
+ "<input type=\"hidden\" value=\"#{key2}\">",
144
+ '</body></html>'
145
+ ].join
146
+ assert_equal(original_html, marker.revert(new_html))
147
+ end
148
+ end
149
+ end
@@ -771,6 +771,85 @@ module Wovnrb
771
771
  assert_equal('/th/', url_lang_switcher.add_lang_code(href_trailing_slash, 'th', headers))
772
772
  end
773
773
 
774
+ def test_add_lang_code_with_custom_domain_langs
775
+ custom_domain_langs = {
776
+ 'en' => { 'url' => 'my-site.com' },
777
+ 'en-US' => { 'url' => 'en-us.my-site.com' },
778
+ 'ja' => { 'url' => 'my-site.com/ja' },
779
+ 'zh-CHS' => { 'url' => 'my-site.com/zh/chs' },
780
+ 'zh-Hant-HK' => { 'url' => 'zh-hant-hk.com/zh' }
781
+ }
782
+ test_cases = [
783
+ # no_lang_url, lang_code, expected_url
784
+ # absolute URL
785
+ ['https://my-site.com', 'en', 'https://my-site.com'],
786
+ ['https://my-site.com', 'ja', 'https://my-site.com/ja'],
787
+ ['https://my-site.com/index.php', 'ja', 'https://my-site.com/ja/index.php'],
788
+ ['https://my-site.com/a/b/', 'ja', 'https://my-site.com/ja/a/b/'],
789
+ ['https://my-site.com/a/b/index.php', 'ja', 'https://my-site.com/ja/a/b/index.php'],
790
+ ['https://my-site.com/index.php', 'en-US', 'https://en-us.my-site.com/index.php'],
791
+ ['https://my-site.com/index.php', 'zh-CHS', 'https://my-site.com/zh/chs/index.php'],
792
+ ['https://my-site.com/index.php', 'zh-Hant-HK', 'https://zh-hant-hk.com/zh/index.php'],
793
+ ['https://my-site.com/index.php?a=1&b=2', 'zh-Hant-HK', 'https://zh-hant-hk.com/zh/index.php?a=1&b=2'],
794
+ ['https://my-site.com/index.php#hash', 'zh-Hant-HK', 'https://zh-hant-hk.com/zh/index.php#hash'],
795
+ ['https://my-site.com/index.php?a=1&b=2#hash', 'zh-Hant-HK', 'https://zh-hant-hk.com/zh/index.php?a=1&b=2#hash'],
796
+
797
+ # absolute path
798
+ ['/', 'en', 'http://my-site.com/'],
799
+ ['/', 'ja', 'http://my-site.com/ja/'],
800
+ ['/index.php', 'ja', 'http://my-site.com/ja/index.php'],
801
+ ['/a/b/', 'ja', 'http://my-site.com/ja/a/b/'],
802
+ ['/a/b/index.php', 'ja', 'http://my-site.com/ja/a/b/index.php'],
803
+ ['/index.php', 'en-US', 'http://en-us.my-site.com/index.php'],
804
+ ['/index.php', 'zh-CHS', 'http://my-site.com/zh/chs/index.php'],
805
+ ['/index.php', 'zh-Hant-HK', 'http://zh-hant-hk.com/zh/index.php'],
806
+ ['/index.php?a=1&b=2', 'zh-Hant-HK', 'http://zh-hant-hk.com/zh/index.php?a=1&b=2'],
807
+ ['/index.php#hash', 'zh-Hant-HK', 'http://zh-hant-hk.com/zh/index.php#hash'],
808
+ ['/index.php?a=1&b=2#hash', 'zh-Hant-HK', 'http://zh-hant-hk.com/zh/index.php?a=1&b=2#hash'],
809
+
810
+ # relative path
811
+ ['index.php', 'ja', 'http://my-site.com/ja/req_uri/index.php'],
812
+ ['a/b/', 'ja', 'http://my-site.com/ja/req_uri/a/b/'],
813
+ ['a/b/index.php', 'ja', 'http://my-site.com/ja/req_uri/a/b/index.php'],
814
+ ['index.php', 'en-US', 'http://en-us.my-site.com/req_uri/index.php'],
815
+ ['index.php', 'zh-CHS', 'http://my-site.com/zh/chs/req_uri/index.php'],
816
+ ['index.php', 'zh-Hant-HK', 'http://zh-hant-hk.com/zh/req_uri/index.php'],
817
+ ['index.php?a=1&b=2', 'zh-Hant-HK', 'http://zh-hant-hk.com/zh/req_uri/index.php?a=1&b=2'],
818
+ ['index.php#hash', 'zh-Hant-HK', 'http://zh-hant-hk.com/zh/req_uri/index.php#hash'],
819
+ ['index.php?a=1&b=2#hash', 'zh-Hant-HK', 'http://zh-hant-hk.com/zh/req_uri/index.php?a=1&b=2#hash'],
820
+ ['?a=1&b=2', 'zh-Hant-HK', 'http://zh-hant-hk.com/zh/req_uri/?a=1&b=2'],
821
+
822
+ # anchor links should not be changed
823
+ ['#hash', 'zh-Hant-HK', '#hash']
824
+ ]
825
+
826
+ settings = {
827
+ 'project_token' => 'T0k3N',
828
+ 'default_lang' => 'en',
829
+ 'supported_langs' => ['en'],
830
+ 'url_pattern' => 'custom_domain',
831
+ 'custom_domain_langs' => custom_domain_langs
832
+ }
833
+ additional_env = {
834
+ 'HTTP_HOST' => 'my-site.com',
835
+ 'REQUEST_URI' => '/req_uri/'
836
+ }
837
+
838
+ test_cases.each do |test_case|
839
+ target_uri, lang, expected_uri = test_case
840
+ store = Wovnrb::Store.instance
841
+ store.update_settings(settings)
842
+ url_lang_switcher = UrlLanguageSwitcher.new(store)
843
+ headers = Wovnrb::Headers.new(
844
+ Wovnrb.get_env(additional_env),
845
+ store.settings,
846
+ url_lang_switcher
847
+ )
848
+
849
+ assert_equal(expected_uri, url_lang_switcher.add_lang_code(target_uri, lang, headers))
850
+ end
851
+ end
852
+
774
853
  def test_remove_lang_query_with_lang_param_name
775
854
  settings = Wovnrb.get_settings('url_pattern' => 'query', 'lang_param_name' => 'lang')
776
855
  store = Wovnrb.get_store(settings)
@@ -920,6 +999,75 @@ module Wovnrb
920
999
  assert_equal('https://wovn.io/', uri_with_scheme)
921
1000
  end
922
1001
 
1002
+ def test_remove_lang_custom_domain
1003
+ custom_domain_langs = {
1004
+ 'en' => { 'url' => 'my-site.com' },
1005
+ 'en-US' => { 'url' => 'en-us.my-site.com' },
1006
+ 'ja' => { 'url' => 'my-site.com/ja' },
1007
+ 'zh-CHS' => { 'url' => 'my-site.com/zh/chs' },
1008
+ 'zh-Hant-HK' => { 'url' => 'zh-hant-hk.com/zh' }
1009
+ }
1010
+ test_cases = [
1011
+ # target_uri, lang, expected_uri, env
1012
+ # absolute URL
1013
+ ['https://my-site.com', 'en', 'https://my-site.com', {}],
1014
+ ['https://my-site.com/ja', 'ja', 'https://my-site.com', { 'REQUEST_URI' => '/ja' }],
1015
+ ['https://my-site.com/ja/index.php', 'ja', 'https://my-site.com/index.php', { 'REQUEST_URI' => '/ja/index.php' }],
1016
+ ['https://my-site.com/ja/a/b/', 'ja', 'https://my-site.com/a/b/', { 'REQUEST_URI' => '/ja/a/b/' }],
1017
+ ['https://my-site.com/ja/a/b/index.php', 'ja', 'https://my-site.com/a/b/index.php', { 'REQUEST_URI' => '/ja/a/b/index.php' }],
1018
+ ['https://en-us.my-site.com/index.php', 'en-US', 'https://my-site.com/index.php', { 'HTTP_HOST' => 'en-us.my-site.com', 'SERVER_NAME' => 'en-us.my-site.com', 'REQUEST_URI' => '/index.php' }],
1019
+ ['https://my-site.com/zh/chs/index.php', 'zh-CHS', 'https://my-site.com/index.php', { 'REQUEST_URI' => '/zh/chs/index.php' }],
1020
+ ['https://zh-hant-hk.com/zh/index.php', 'zh-Hant-HK', 'https://my-site.com/index.php', { 'HTTP_HOST' => 'zh-hant-hk.com', 'SERVER_NAME' => 'zh-hant-hk.com', 'REQUEST_URI' => '/zh/index.php' }],
1021
+ ['https://zh-hant-hk.com/zh/index.php?a=1&b=2', 'zh-Hant-HK', 'https://my-site.com/index.php?a=1&b=2', { 'HTTP_HOST' => 'zh-hant-hk.com', 'SERVER_NAME' => 'zh-hant-hk.com', 'REQUEST_URI' => '/zh/index.php' }],
1022
+ ['https://zh-hant-hk.com/zh/index.php#hash', 'zh-Hant-HK', 'https://my-site.com/index.php#hash', { 'HTTP_HOST' => 'zh-hant-hk.com', 'SERVER_NAME' => 'zh-hant-hk.com', 'REQUEST_URI' => '/zh/index.php' }],
1023
+ ['https://zh-hant-hk.com/zh/index.php?a=1&b=2#hash', 'zh-Hant-HK', 'https://my-site.com/index.php?a=1&b=2#hash', { 'HTTP_HOST' => 'zh-hant-hk.com', 'SERVER_NAME' => 'zh-hant-hk.com', 'REQUEST_URI' => '/zh/index.php' }],
1024
+
1025
+ # absolute path
1026
+ ['/', 'en', '/', {}],
1027
+ ['/ja/', 'ja', '/', { 'REQUEST_URI' => '/ja' }],
1028
+ ['/ja/index.php', 'ja', '/index.php', { 'REQUEST_URI' => '/ja/index.php' }],
1029
+ ['/ja/a/b/', 'ja', '/a/b/', { 'REQUEST_URI' => '/ja/a/b/' }],
1030
+ ['/ja/a/b/index.php', 'ja', '/a/b/index.php', { 'REQUEST_URI' => '/ja/a/b/index.php' }],
1031
+ ['/index.php', 'en-US', '/index.php', { 'HTTP_HOST' => 'en-us.my-site.com', 'SERVER_NAME' => 'en-us.my-site.com', 'REQUEST_URI' => '/index.php' }],
1032
+ ['/zh/chs/index.php', 'zh-CHS', '/index.php', { 'REQUEST_URI' => '/zh/chs/index.php' }],
1033
+ ['/zh/index.php', 'zh-Hant-HK', '/index.php', { 'HTTP_HOST' => 'zh-hant-hk.com', 'SERVER_NAME' => 'zh-hant-hk.com', 'REQUEST_URI' => '/zh/index.php' }],
1034
+ ['/zh/index.php?a=1&b=2', 'zh-Hant-HK', '/index.php?a=1&b=2', { 'HTTP_HOST' => 'zh-hant-hk.com', 'SERVER_NAME' => 'zh-hant-hk.com', 'REQUEST_URI' => '/zh/index.php' }],
1035
+ ['/zh/index.php#hash', 'zh-Hant-HK', '/index.php#hash', { 'HTTP_HOST' => 'zh-hant-hk.com', 'SERVER_NAME' => 'zh-hant-hk.com', 'REQUEST_URI' => '/zh/index.php' }],
1036
+ ['/zh/index.php?a=1&b=2#hash', 'zh-Hant-HK', '/index.php?a=1&b=2#hash', { 'HTTP_HOST' => 'zh-hant-hk.com', 'SERVER_NAME' => 'zh-hant-hk.com', 'REQUEST_URI' => '/zh/index.php' }],
1037
+
1038
+ # other patterns should not be changed
1039
+ ['?a=1&b=2', 'en-US', '?a=1&b=2', { 'HTTP_HOST' => 'en-us.my-site.com', 'SERVER_NAME' => 'en-us.my-site.com', 'REQUEST_URI' => '/' }],
1040
+ ['#hash', 'en-US', '#hash', { 'HTTP_HOST' => 'en-us.my-site.com', 'SERVER_NAME' => 'en-us.my-site.com', 'REQUEST_URI' => '/' }]
1041
+ ]
1042
+
1043
+ settings = {
1044
+ 'project_token' => 'T0k3N',
1045
+ 'default_lang' => 'en',
1046
+ 'supported_langs' => %w[en en-US ja zh-CHS zh-Hant-HK],
1047
+ 'url_pattern' => 'custom_domain',
1048
+ 'custom_domain_langs' => custom_domain_langs
1049
+ }
1050
+ base_env = {
1051
+ 'HTTP_HOST' => 'my-site.com',
1052
+ 'REQUEST_URI' => '/req_uri/'
1053
+ }
1054
+
1055
+ test_cases.each do |test_case|
1056
+ target_uri, lang, expected_uri, env = test_case
1057
+ additional_env = base_env.merge(env)
1058
+ store = Wovnrb::Store.instance
1059
+ store.update_settings(settings)
1060
+ url_lang_switcher = UrlLanguageSwitcher.new(store)
1061
+ headers = Wovnrb::Headers.new(
1062
+ Wovnrb.get_env(additional_env),
1063
+ store.settings,
1064
+ url_lang_switcher
1065
+ )
1066
+
1067
+ assert_equal(expected_uri, url_lang_switcher.remove_lang_from_uri_component(target_uri, lang, headers))
1068
+ end
1069
+ end
1070
+
923
1071
  def store_headers_factory(setting_opts = {}, url = 'http://my-site.com')
924
1072
  settings = default_store_settings.merge(setting_opts)
925
1073
  store = Wovnrb::Store.instance