wovnrb 3.10.1 → 3.10.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,149 +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 = '<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
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
@@ -856,7 +856,7 @@ module Wovnrb
856
856
  url_lang_switcher = UrlLanguageSwitcher.new(store)
857
857
 
858
858
  keys = Wovnrb::Lang::LANG.keys
859
- assert_equal(77, keys.size)
859
+ assert(!keys.empty?)
860
860
 
861
861
  keys.each do |key|
862
862
  uri_without_custom_lang_param = "wovn.io/?wovn=#{key}"
@@ -877,7 +877,7 @@ module Wovnrb
877
877
  url_lang_switcher = UrlLanguageSwitcher.new(store)
878
878
 
879
879
  keys = Wovnrb::Lang::LANG.keys
880
- assert_equal(77, keys.size)
880
+ assert(!keys.empty?)
881
881
 
882
882
  uri_without_scheme = url_lang_switcher.remove_lang_from_uri_component('wovn.io', nil)
883
883
  assert_equal('wovn.io', uri_without_scheme)
@@ -904,7 +904,7 @@ module Wovnrb
904
904
  url_lang_switcher = UrlLanguageSwitcher.new(store)
905
905
 
906
906
  keys = Wovnrb::Lang::LANG.keys
907
- assert_equal(77, keys.size)
907
+ assert(!keys.empty?)
908
908
 
909
909
  keys.each do |key|
910
910
  uri_without_scheme = url_lang_switcher.remove_lang_from_uri_component("#{key.downcase}.wovn.io/", key)
@@ -920,7 +920,7 @@ module Wovnrb
920
920
  store = Wovnrb.get_store(settings)
921
921
  url_lang_switcher = UrlLanguageSwitcher.new(store)
922
922
  keys = Wovnrb::Lang::LANG.keys
923
- assert_equal(77, keys.size)
923
+ assert(!keys.empty?)
924
924
 
925
925
  uri_without_scheme = url_lang_switcher.remove_lang_from_uri_component('wovn.io', nil)
926
926
  assert_equal('wovn.io', uri_without_scheme)
@@ -958,7 +958,7 @@ module Wovnrb
958
958
  sut = UrlLanguageSwitcher.new(store)
959
959
 
960
960
  keys = Wovnrb::Lang::LANG.keys
961
- assert_equal(77, keys.size)
961
+ assert(!keys.empty?)
962
962
 
963
963
  keys.each do |key|
964
964
  assert_equal('/', sut.remove_lang_from_uri_component("/#{key}", key))
@@ -978,7 +978,7 @@ module Wovnrb
978
978
  url_lang_switcher = UrlLanguageSwitcher.new(store)
979
979
 
980
980
  keys = Wovnrb::Lang::LANG.keys
981
- assert_equal(77, keys.size)
981
+ assert(!keys.empty?)
982
982
 
983
983
  uri_without_scheme = url_lang_switcher.remove_lang_from_uri_component('wovn.io', nil)
984
984
  assert_equal('wovn.io', uri_without_scheme)