wovnrb 3.7.2 → 3.9.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,75 @@
1
+ require 'test_helper'
2
+ require 'wovnrb/custom_domain/custom_domain_langs'
3
+ require 'wovnrb/custom_domain/custom_domain_lang_url_handler'
4
+
5
+ module Wovnrb
6
+ class CustomDomainLangUrlHandlerTest < WovnMiniTest
7
+ def setup
8
+ custom_domain_langs_setting = {
9
+ 'fr' => { 'url' => 'foo.com/' },
10
+ 'ja' => { 'url' => 'foo.com/path' },
11
+ 'zh-CHS' => { 'url' => 'foo.com/dir/path' },
12
+ 'en' => { 'url' => 'english.foo.com/' },
13
+ 'zh-Hant-HK' => { 'url' => 'zh-hant-hk.foo.com/zh' },
14
+ 'pt' => { 'url' => '17797-trial2.foo.com/' }
15
+ }
16
+ @custom_domain_langs = CustomDomainLangs.new(custom_domain_langs_setting)
17
+ end
18
+
19
+ def test_add_custom_domain_lang_to_absolute_url
20
+ # apply to original lang
21
+ assert_equal('foo.com', CustomDomainLangUrlHandler.add_custom_domain_lang_to_absolute_url('foo.com', 'fr', @custom_domain_langs))
22
+ assert_equal('foo.com/path', CustomDomainLangUrlHandler.add_custom_domain_lang_to_absolute_url('foo.com', 'ja', @custom_domain_langs))
23
+ assert_equal('foo.com/dir/path', CustomDomainLangUrlHandler.add_custom_domain_lang_to_absolute_url('foo.com', 'zh-CHS', @custom_domain_langs))
24
+ assert_equal('english.foo.com', CustomDomainLangUrlHandler.add_custom_domain_lang_to_absolute_url('foo.com', 'en', @custom_domain_langs))
25
+ assert_equal('zh-hant-hk.foo.com/zh', CustomDomainLangUrlHandler.add_custom_domain_lang_to_absolute_url('foo.com', 'zh-Hant-HK', @custom_domain_langs))
26
+
27
+ # apply to target lang
28
+ assert_equal('foo.com', CustomDomainLangUrlHandler.add_custom_domain_lang_to_absolute_url('zh-hant-hk.foo.com/zh', 'fr', @custom_domain_langs))
29
+ assert_equal('foo.com/path', CustomDomainLangUrlHandler.add_custom_domain_lang_to_absolute_url('zh-hant-hk.foo.com/zh', 'ja', @custom_domain_langs))
30
+ assert_equal('foo.com/dir/path', CustomDomainLangUrlHandler.add_custom_domain_lang_to_absolute_url('zh-hant-hk.foo.com/zh', 'zh-CHS', @custom_domain_langs))
31
+ assert_equal('english.foo.com', CustomDomainLangUrlHandler.add_custom_domain_lang_to_absolute_url('zh-hant-hk.foo.com/zh', 'en', @custom_domain_langs))
32
+ assert_equal('zh-hant-hk.foo.com/zh', CustomDomainLangUrlHandler.add_custom_domain_lang_to_absolute_url('zh-hant-hk.foo.com/zh', 'zh-Hant-HK', @custom_domain_langs))
33
+
34
+ assert_equal('zh-hant-hk.foo.com/zh', CustomDomainLangUrlHandler.add_custom_domain_lang_to_absolute_url('foo.com/path', 'zh-Hant-HK', @custom_domain_langs))
35
+ assert_equal('zh-hant-hk.foo.com/zh/', CustomDomainLangUrlHandler.add_custom_domain_lang_to_absolute_url('foo.com/path/', 'zh-Hant-HK', @custom_domain_langs))
36
+ assert_equal('zh-hant-hk.foo.com/zh/index.html', CustomDomainLangUrlHandler.add_custom_domain_lang_to_absolute_url('foo.com/path/index.html', 'zh-Hant-HK', @custom_domain_langs))
37
+ assert_equal('zh-hant-hk.foo.com/zh/path2/index.html', CustomDomainLangUrlHandler.add_custom_domain_lang_to_absolute_url('foo.com/path/path2/index.html', 'zh-Hant-HK', @custom_domain_langs))
38
+ assert_equal('zh-hant-hk.foo.com/zh/path2/index.html?test=1', CustomDomainLangUrlHandler.add_custom_domain_lang_to_absolute_url('foo.com/path/path2/index.html?test=1', 'zh-Hant-HK', @custom_domain_langs))
39
+ assert_equal('zh-hant-hk.foo.com/zh/path2/index.html#hash', CustomDomainLangUrlHandler.add_custom_domain_lang_to_absolute_url('foo.com/path/path2/index.html#hash', 'zh-Hant-HK', @custom_domain_langs))
40
+ end
41
+
42
+ def test_change_to_new_custom_domain_lang
43
+ fr = @custom_domain_langs.custom_domain_lang_by_lang('fr')
44
+ ja = @custom_domain_langs.custom_domain_lang_by_lang('ja')
45
+ zh_chs = @custom_domain_langs.custom_domain_lang_by_lang('zh-CHS')
46
+ en = @custom_domain_langs.custom_domain_lang_by_lang('en')
47
+ zh_hant_hk = @custom_domain_langs.custom_domain_lang_by_lang('zh-Hant-HK')
48
+ pt = @custom_domain_langs.custom_domain_lang_by_lang('pt')
49
+
50
+ assert_equal('foo.com', CustomDomainLangUrlHandler.change_to_new_custom_domain_lang('foo.com', fr, fr))
51
+ assert_equal('foo.com/path', CustomDomainLangUrlHandler.change_to_new_custom_domain_lang('foo.com', fr, ja))
52
+ assert_equal('foo.com/dir/path', CustomDomainLangUrlHandler.change_to_new_custom_domain_lang('foo.com', fr, zh_chs))
53
+ assert_equal('english.foo.com', CustomDomainLangUrlHandler.change_to_new_custom_domain_lang('foo.com', fr, en))
54
+ assert_equal('zh-hant-hk.foo.com/zh', CustomDomainLangUrlHandler.change_to_new_custom_domain_lang('foo.com', fr, zh_hant_hk))
55
+
56
+ assert_equal('foo.com', CustomDomainLangUrlHandler.change_to_new_custom_domain_lang('zh-hant-hk.foo.com/zh', zh_hant_hk, fr))
57
+ assert_equal('foo.com/path', CustomDomainLangUrlHandler.change_to_new_custom_domain_lang('zh-hant-hk.foo.com/zh', zh_hant_hk, ja))
58
+ assert_equal('foo.com/dir/path', CustomDomainLangUrlHandler.change_to_new_custom_domain_lang('zh-hant-hk.foo.com/zh', zh_hant_hk, zh_chs))
59
+ assert_equal('english.foo.com', CustomDomainLangUrlHandler.change_to_new_custom_domain_lang('zh-hant-hk.foo.com/zh', zh_hant_hk, en))
60
+ assert_equal('zh-hant-hk.foo.com/zh', CustomDomainLangUrlHandler.change_to_new_custom_domain_lang('zh-hant-hk.foo.com/zh', zh_hant_hk, zh_hant_hk))
61
+
62
+ assert_equal('foo.com/path', CustomDomainLangUrlHandler.change_to_new_custom_domain_lang('zh-hant-hk.foo.com/zh', zh_hant_hk, ja))
63
+ assert_equal('foo.com/path/', CustomDomainLangUrlHandler.change_to_new_custom_domain_lang('zh-hant-hk.foo.com/zh/', zh_hant_hk, ja))
64
+ assert_equal('foo.com/path/index.html', CustomDomainLangUrlHandler.change_to_new_custom_domain_lang('zh-hant-hk.foo.com/zh/index.html', zh_hant_hk, ja))
65
+ assert_equal('foo.com/path/path', CustomDomainLangUrlHandler.change_to_new_custom_domain_lang('zh-hant-hk.foo.com/zh/path', zh_hant_hk, ja))
66
+ assert_equal('foo.com/path/path/index.html', CustomDomainLangUrlHandler.change_to_new_custom_domain_lang('zh-hant-hk.foo.com/zh/path/index.html', zh_hant_hk, ja))
67
+ assert_equal('foo.com/path/path/index.html?test=1', CustomDomainLangUrlHandler.change_to_new_custom_domain_lang('zh-hant-hk.foo.com/zh/path/index.html?test=1', zh_hant_hk, ja))
68
+ assert_equal('foo.com/path/path/index.html#hash', CustomDomainLangUrlHandler.change_to_new_custom_domain_lang('zh-hant-hk.foo.com/zh/path/index.html#hash', zh_hant_hk, ja))
69
+
70
+ assert_equal('zh-hant-hk.foo.com/zhtrap', CustomDomainLangUrlHandler.change_to_new_custom_domain_lang('zh-hant-hk.foo.com/zhtrap', zh_hant_hk, ja))
71
+ assert_equal('english.foo.com/zhtrap', CustomDomainLangUrlHandler.change_to_new_custom_domain_lang('17797-trial2.foo.com/zhtrap', pt, en))
72
+ assert_equal('17797-trial2.foo.com/zhtrap', CustomDomainLangUrlHandler.change_to_new_custom_domain_lang('17797-trial2.foo.com/zhtrap', pt, pt))
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,82 @@
1
+ require 'test_helper'
2
+ require 'wovnrb/custom_domain/custom_domain_langs'
3
+
4
+ module Wovnrb
5
+ class CustomDomainLangsTest < WovnMiniTest
6
+ def setup
7
+ custom_domain_langs_setting = {
8
+ 'fr' => { 'url' => 'foo.com/' },
9
+ 'ja' => { 'url' => 'foo.com/path', 'source' => 'japan.foo.com/' },
10
+ 'zh-CHS' => { 'url' => 'foo.com/dir/path' },
11
+ 'en' => { 'url' => 'english.foo.com/', 'source' => 'global.foo.com/' }
12
+ }
13
+ @custom_domain_langs = CustomDomainLangs.new(custom_domain_langs_setting)
14
+ end
15
+
16
+ def test_get_custom_domain_lang_by_lang
17
+ assert_nil(@custom_domain_langs.custom_domain_lang_by_lang('unknown'))
18
+
19
+ assert_equal('fr', lang_for(@custom_domain_langs.custom_domain_lang_by_lang('fr')))
20
+ assert_equal('ja', lang_for(@custom_domain_langs.custom_domain_lang_by_lang('ja')))
21
+ assert_equal('zh-CHS', lang_for(@custom_domain_langs.custom_domain_lang_by_lang('zh-CHS')))
22
+ assert_equal('en', lang_for(@custom_domain_langs.custom_domain_lang_by_lang('en')))
23
+ end
24
+
25
+ def test_get_custom_domain_lang_by_url
26
+ assert_nil(@custom_domain_langs.custom_domain_lang_by_url('http://otherdomain.com'))
27
+ assert_nil(@custom_domain_langs.custom_domain_lang_by_url('http://otherdomain.com/path/test.html'))
28
+ assert_nil(@custom_domain_langs.custom_domain_lang_by_url('http://otherdomain.com/dir/path/test.html'))
29
+
30
+ assert_equal('fr', lang_for(@custom_domain_langs.custom_domain_lang_by_url('http://foo.com')))
31
+ assert_equal('fr', lang_for(@custom_domain_langs.custom_domain_lang_by_url('http://foo.com/')))
32
+ assert_equal('fr', lang_for(@custom_domain_langs.custom_domain_lang_by_url('http://foo.com/test.html')))
33
+
34
+ assert_equal('ja', lang_for(@custom_domain_langs.custom_domain_lang_by_url('http://foo.com/path')))
35
+ assert_equal('ja', lang_for(@custom_domain_langs.custom_domain_lang_by_url('http://foo.com/path/')))
36
+ assert_equal('ja', lang_for(@custom_domain_langs.custom_domain_lang_by_url('http://foo.com/path/dir')))
37
+ assert_equal('ja', lang_for(@custom_domain_langs.custom_domain_lang_by_url('http://foo.com/path/test.html')))
38
+
39
+ assert_equal('zh-CHS', lang_for(@custom_domain_langs.custom_domain_lang_by_url('http://foo.com/dir/path')))
40
+ assert_equal('zh-CHS', lang_for(@custom_domain_langs.custom_domain_lang_by_url('http://foo.com/dir/path/')))
41
+ assert_equal('zh-CHS', lang_for(@custom_domain_langs.custom_domain_lang_by_url('http://foo.com/dir/path/dir')))
42
+ assert_equal('zh-CHS', lang_for(@custom_domain_langs.custom_domain_lang_by_url('http://foo.com/dir/path/test.html')))
43
+
44
+ assert_equal('en', lang_for(@custom_domain_langs.custom_domain_lang_by_url('http://english.foo.com/dir/path')))
45
+ assert_equal('en', lang_for(@custom_domain_langs.custom_domain_lang_by_url('http://english.foo.com/dir/path/')))
46
+ assert_equal('en', lang_for(@custom_domain_langs.custom_domain_lang_by_url('http://english.foo.com/dir/path/test.html')))
47
+ end
48
+
49
+ def test_get_custom_domain_lang_by_url_with_nested_paths
50
+ custom_domain_langs_setting = {
51
+ 'ja' => { 'url' => 'foo.com/path' },
52
+ 'en' => { 'url' => 'foo.com/path/en' },
53
+ 'fr' => { 'url' => 'foo.com/path/fr' }
54
+ }
55
+ custom_domain_langs = CustomDomainLangs.new(custom_domain_langs_setting)
56
+ assert_equal('ja', lang_for(custom_domain_langs.custom_domain_lang_by_url('http://foo.com/path')))
57
+ assert_equal('en', lang_for(custom_domain_langs.custom_domain_lang_by_url('http://foo.com/path/en')))
58
+ assert_equal('fr', lang_for(custom_domain_langs.custom_domain_lang_by_url('http://foo.com/path/fr')))
59
+ end
60
+
61
+ def test_to_html_swapper_hash
62
+ expected = {
63
+ 'foo.com' => 'fr',
64
+ 'foo.com/path' => 'ja',
65
+ 'foo.com/dir/path' => 'zh-CHS',
66
+ 'english.foo.com' => 'en'
67
+ }
68
+
69
+ assert(hash_equals(expected, @custom_domain_langs.to_html_swapper_hash))
70
+ end
71
+
72
+ private
73
+
74
+ def lang_for(custom_domain_lang)
75
+ custom_domain_lang.lang
76
+ end
77
+
78
+ def hash_equals(orig_hash, test_hash)
79
+ (orig_hash <=> test_hash) == 0
80
+ end
81
+ end
82
+ end