]> git.openstreetmap.org Git - rails.git/blob - test/helpers/browse_helper_test.rb
Update to rails 4.1.4
[rails.git] / test / helpers / browse_helper_test.rb
1 # -*- coding: utf-8 -*-
2
3 require 'test_helper'
4
5 class BrowseHelperTest < ActionView::TestCase
6   include ERB::Util
7   include ApplicationHelper
8
9   api_fixtures
10
11   def setup
12     I18n.locale = "en"
13   end
14
15   def teardown
16     I18n.locale = "en"
17   end
18
19   def test_printable_name
20     assert_equal "17", printable_name(current_nodes(:redacted_node))
21     assert_equal "<bdi>Test Node</bdi> (<bdi>18</bdi>)", printable_name(current_nodes(:node_with_name))
22     assert_equal "<bdi>Test Node</bdi> (<bdi>18</bdi>)", printable_name(nodes(:node_with_name_current_version))
23     assert_equal "18", printable_name(nodes(:node_with_name_redacted_version))
24     assert_equal "<bdi>Test Node</bdi> (<bdi>18, v2</bdi>)", printable_name(nodes(:node_with_name_current_version), true)
25     assert_equal "18, v1", printable_name(nodes(:node_with_name_redacted_version), true)
26
27     I18n.locale = "ru"
28
29     assert_equal "17", printable_name(current_nodes(:redacted_node))
30     assert_equal "<bdi>проверки узла</bdi> (<bdi>18</bdi>)", printable_name(current_nodes(:node_with_name))
31     assert_equal "<bdi>проверки узла</bdi> (<bdi>18</bdi>)", printable_name(nodes(:node_with_name_current_version))
32     assert_equal "18", printable_name(nodes(:node_with_name_redacted_version))
33     assert_equal "<bdi>проверки узла</bdi> (<bdi>18, v2</bdi>)", printable_name(nodes(:node_with_name_current_version), true)
34     assert_equal "18, v1", printable_name(nodes(:node_with_name_redacted_version), true)
35
36     I18n.locale = "ru-RU"
37
38     assert_equal "17", printable_name(current_nodes(:redacted_node))
39     assert_equal "<bdi>проверки узла</bdi> (<bdi>18</bdi>)", printable_name(current_nodes(:node_with_name))
40     assert_equal "<bdi>проверки узла</bdi> (<bdi>18</bdi>)", printable_name(nodes(:node_with_name_current_version))
41     assert_equal "18", printable_name(nodes(:node_with_name_redacted_version))
42     assert_equal "<bdi>проверки узла</bdi> (<bdi>18, v2</bdi>)", printable_name(nodes(:node_with_name_current_version), true)
43     assert_equal "18, v1", printable_name(nodes(:node_with_name_redacted_version), true)
44
45     I18n.locale = "de"
46
47     assert_equal "17", printable_name(current_nodes(:redacted_node))
48     assert_equal "<bdi>Test Node</bdi> (<bdi>18</bdi>)", printable_name(current_nodes(:node_with_name))
49     assert_equal "<bdi>Test Node</bdi> (<bdi>18</bdi>)", printable_name(nodes(:node_with_name_current_version))
50     assert_equal "18", printable_name(nodes(:node_with_name_redacted_version))
51     assert_equal "<bdi>Test Node</bdi> (<bdi>18, v2</bdi>)", printable_name(nodes(:node_with_name_current_version), true)
52     assert_equal "18, v1", printable_name(nodes(:node_with_name_redacted_version), true)
53   end
54
55   def test_link_class
56     assert_equal "node", link_class("node", current_nodes(:visible_node))
57     assert_equal "node deleted", link_class("node", current_nodes(:invisible_node))
58     assert_equal "node deleted", link_class("node", current_nodes(:redacted_node))
59     assert_equal "node building yes shop gift tourism museum", link_class("node", current_nodes(:node_with_name))
60     assert_equal "node building yes shop gift tourism museum", link_class("node", nodes(:node_with_name_current_version))
61     assert_equal "node deleted", link_class("node", nodes(:node_with_name_redacted_version))
62   end
63
64   def test_link_title
65     assert_equal "", link_title(current_nodes(:visible_node))
66     assert_equal "", link_title(current_nodes(:invisible_node))
67     assert_equal "", link_title(current_nodes(:redacted_node))
68     assert_equal "building=yes, shop=gift, and tourism=museum", link_title(current_nodes(:node_with_name))
69     assert_equal "building=yes, shop=gift, and tourism=museum", link_title(nodes(:node_with_name_current_version))
70     assert_equal "", link_title(nodes(:node_with_name_redacted_version))
71   end
72
73   def test_format_key
74     html = format_key("highway")
75     assert_equal "<a href=\"http://wiki.openstreetmap.org/wiki/Key:highway?uselang=en\" title=\"The wiki description page for the highway tag\">highway</a>", html
76
77     html = format_key("unknown")
78     assert_equal "unknown", html
79   end
80
81   def test_format_value
82     html = format_value("highway", "primary")
83     assert_equal "<a href=\"http://wiki.openstreetmap.org/wiki/Tag:highway=primary?uselang=en\" title=\"The wiki description page for the highway=primary tag\">primary</a>", html
84
85     html = format_value("highway", "unknown")
86     assert_equal "unknown", html
87
88     html = format_value("unknown", "unknown")
89     assert_equal "unknown", html
90
91     html = format_value("phone", "+1234567890")
92     assert_equal "<a href=\"tel:+1234567890\" title=\"Call +1234567890\">+1234567890</a>", html
93   end
94
95   def test_icon_tags
96     tags = icon_tags(current_nodes(:node_with_name))
97     assert_equal 3, tags.count
98     assert tags.include?(["building", "yes"])
99     assert tags.include?(["tourism", "museum"])
100     assert tags.include?(["shop", "gift"])
101
102     tags = icon_tags(nodes(:node_with_name_current_version))
103     assert_equal 3, tags.count
104     assert tags.include?(["building", "yes"])
105     assert tags.include?(["tourism", "museum"])
106     assert tags.include?(["shop", "gift"])
107
108     tags = icon_tags(nodes(:node_with_name_redacted_version))
109     assert_equal 3, tags.count
110     assert tags.include?(["building", "yes"])
111     assert tags.include?(["tourism", "museum"])
112     assert tags.include?(["shop", "gift"])
113   end
114
115   def test_wiki_link
116     link = wiki_link("key", "highway")
117     assert_equal "http://wiki.openstreetmap.org/wiki/Key:highway?uselang=en", link
118
119     link = wiki_link("tag", "highway=primary")
120     assert_equal "http://wiki.openstreetmap.org/wiki/Tag:highway=primary?uselang=en", link
121
122     I18n.locale = "de"
123
124     link = wiki_link("key", "highway")
125     assert_equal "http://wiki.openstreetmap.org/wiki/DE:Key:highway?uselang=de", link
126
127     link = wiki_link("tag", "highway=primary")
128     assert_equal "http://wiki.openstreetmap.org/wiki/DE:Tag:highway=primary?uselang=de", link
129
130     I18n.locale = "tr"
131
132     link = wiki_link("key", "highway")
133     assert_equal "http://wiki.openstreetmap.org/wiki/Tr:Key:highway?uselang=tr", link
134
135     link = wiki_link("tag", "highway=primary")
136     assert_equal "http://wiki.openstreetmap.org/wiki/Tag:highway=primary?uselang=tr", link
137   end
138
139   def test_wikipedia_link
140     link = wikipedia_link("wikipedia", "http://en.wikipedia.org/wiki/Full%20URL")
141     assert_nil link
142
143     link = wikipedia_link("wikipedia", "https://en.wikipedia.org/wiki/Full%20URL")
144     assert_nil link
145
146     link = wikipedia_link("wikipedia", "Test")
147     assert_equal "http://en.wikipedia.org/wiki/Test?uselang=en", link[:url]
148     assert_equal "Test", link[:title]
149
150     link = wikipedia_link("wikipedia", "de:Test")
151     assert_equal "http://de.wikipedia.org/wiki/de:Test?uselang=en", link[:url]
152     assert_equal "de:Test", link[:title]
153
154     link = wikipedia_link("wikipedia:fr", "de:Test")
155     assert_equal "http://fr.wikipedia.org/wiki/de:Test?uselang=en", link[:url]
156     assert_equal "de:Test", link[:title]
157
158     I18n.locale = "pt-BR"
159
160     link = wikipedia_link("wikipedia", "zh-classical:Test#Section")
161     assert_equal "http://zh-classical.wikipedia.org/wiki/zh-classical:Test?uselang=pt-BR#Section", link[:url]
162     assert_equal "zh-classical:Test#Section", link[:title]
163
164     link = wikipedia_link("foo", "Test")
165     assert_nil link
166   end
167
168   def test_telephone_link
169     link = telephone_link("foo", "Test")
170     assert_nil link
171
172     link = telephone_link("phone", "+123")
173     assert_nil link
174
175     link = telephone_link("phone", "123")
176     assert_nil link
177
178     link = telephone_link("phone", "123 abcdefg")
179     assert_nil link
180
181     link = telephone_link("phone", "+1234567890 abc")
182     assert_nil link
183
184     link = telephone_link("phone", "+1234567890; +22334455667788")
185     assert_nil link
186
187     link = telephone_link("phone", "1234567890")
188     assert_nil link
189
190     link = telephone_link("phone", "+1234567890")
191     assert_equal "tel:+1234567890", link
192
193     link = telephone_link("phone", "+1234-567-890")
194     assert_equal "tel:+1234-567-890", link
195
196     link = telephone_link("phone", "+1234/567/890")
197     assert_equal "tel:+1234/567/890", link
198
199     link = telephone_link("phone", "+1234.567.890")
200     assert_equal "tel:+1234.567.890", link
201
202     link = telephone_link("phone", "   +1234 567-890    ")
203     assert_equal "tel:+1234567-890", link
204
205     link = telephone_link("phone", "+1 234-567-890")
206     assert_equal "tel:+1234-567-890", link
207
208     link = telephone_link("phone", "+1 (234) 567-890")
209     assert_equal "tel:+1(234)567-890", link
210   end
211 end