1 # -*- coding: utf-8 -*-
5 class BrowseHelperTest < ActionView::TestCase
7 include ApplicationHelper
19 def test_printable_name
20 assert_dom_equal "17", printable_name(current_nodes(:redacted_node))
21 assert_dom_equal "<bdi>Test Node</bdi> (<bdi>18</bdi>)", printable_name(current_nodes(:node_with_name))
22 assert_dom_equal "<bdi>Test Node</bdi> (<bdi>18</bdi>)", printable_name(nodes(:node_with_name_current_version))
23 assert_dom_equal "18", printable_name(nodes(:node_with_name_redacted_version))
24 assert_dom_equal "<bdi>Test Node</bdi> (<bdi>18, v2</bdi>)", printable_name(nodes(:node_with_name_current_version), true)
25 assert_dom_equal "18, v1", printable_name(nodes(:node_with_name_redacted_version), true)
26 assert_dom_equal "<bdi>3.1415926</bdi> (<bdi>19</bdi>)", printable_name(current_nodes(:node_with_ref_without_name))
30 assert_dom_equal "17", printable_name(current_nodes(:redacted_node))
31 assert_dom_equal "<bdi>Nó teste</bdi> (<bdi>18</bdi>)", printable_name(current_nodes(:node_with_name))
32 assert_dom_equal "<bdi>Nó teste</bdi> (<bdi>18</bdi>)", printable_name(nodes(:node_with_name_current_version))
33 assert_dom_equal "18", printable_name(nodes(:node_with_name_redacted_version))
34 assert_dom_equal "<bdi>Nó teste</bdi> (<bdi>18, v2</bdi>)", printable_name(nodes(:node_with_name_current_version), true)
35 assert_dom_equal "18, v1", printable_name(nodes(:node_with_name_redacted_version), true)
36 assert_dom_equal "<bdi>3.1415926</bdi> (<bdi>19</bdi>)", printable_name(current_nodes(:node_with_ref_without_name))
40 assert_dom_equal "17", printable_name(current_nodes(:redacted_node))
41 assert_dom_equal "<bdi>Nó teste</bdi> (<bdi>18</bdi>)", printable_name(current_nodes(:node_with_name))
42 assert_dom_equal "<bdi>Nó teste</bdi> (<bdi>18</bdi>)", printable_name(nodes(:node_with_name_current_version))
43 assert_dom_equal "18", printable_name(nodes(:node_with_name_redacted_version))
44 assert_dom_equal "<bdi>Nó teste</bdi> (<bdi>18, v2</bdi>)", printable_name(nodes(:node_with_name_current_version), true)
45 assert_dom_equal "18, v1", printable_name(nodes(:node_with_name_redacted_version), true)
46 assert_dom_equal "<bdi>3.1415926</bdi> (<bdi>19</bdi>)", printable_name(current_nodes(:node_with_ref_without_name))
50 assert_dom_equal "17", printable_name(current_nodes(:redacted_node))
51 assert_dom_equal "<bdi>Test Node</bdi> (<bdi>18</bdi>)", printable_name(current_nodes(:node_with_name))
52 assert_dom_equal "<bdi>Test Node</bdi> (<bdi>18</bdi>)", printable_name(nodes(:node_with_name_current_version))
53 assert_dom_equal "18", printable_name(nodes(:node_with_name_redacted_version))
54 assert_dom_equal "<bdi>Test Node</bdi> (<bdi>18, v2</bdi>)", printable_name(nodes(:node_with_name_current_version), true)
55 assert_dom_equal "18, v1", printable_name(nodes(:node_with_name_redacted_version), true)
56 assert_dom_equal "<bdi>3.1415926</bdi> (<bdi>19</bdi>)", printable_name(current_nodes(:node_with_ref_without_name))
60 assert_equal "node", link_class("node", current_nodes(:visible_node))
61 assert_equal "node deleted", link_class("node", current_nodes(:invisible_node))
62 assert_equal "node deleted", link_class("node", current_nodes(:redacted_node))
63 assert_equal "node building yes shop gift tourism museum", link_class("node", current_nodes(:node_with_name))
64 assert_equal "node building yes shop gift tourism museum", link_class("node", nodes(:node_with_name_current_version))
65 assert_equal "node deleted", link_class("node", nodes(:node_with_name_redacted_version))
69 assert_equal "", link_title(current_nodes(:visible_node))
70 assert_equal "", link_title(current_nodes(:invisible_node))
71 assert_equal "", link_title(current_nodes(:redacted_node))
72 assert_equal "building=yes, shop=gift, and tourism=museum", link_title(current_nodes(:node_with_name))
73 assert_equal "building=yes, shop=gift, and tourism=museum", link_title(nodes(:node_with_name_current_version))
74 assert_equal "", link_title(nodes(:node_with_name_redacted_version))
78 html = format_key("highway")
79 assert_dom_equal "<a href=\"http://wiki.openstreetmap.org/wiki/Key:highway?uselang=en\" title=\"The wiki description page for the highway tag\">highway</a>", html
81 html = format_key("unknown")
82 assert_dom_equal "unknown", html
86 html = format_value("highway", "primary")
87 assert_dom_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
89 html = format_value("highway", "unknown")
90 assert_dom_equal "unknown", html
92 html = format_value("unknown", "unknown")
93 assert_dom_equal "unknown", html
95 html = format_value("phone", "+1234567890")
96 assert_dom_equal "<a href=\"tel:+1234567890\" title=\"Call +1234567890\">+1234567890</a>", html
98 html = format_value("wikipedia", "Test")
99 assert_dom_equal "<a title=\"The Test article on Wikipedia\" href=\"http://en.wikipedia.org/wiki/Test?uselang=en\">Test</a>", html
101 html = format_value("wikidata", "Q42")
102 assert_dom_equal "<a title=\"The Q42 item on Wikidata\" href=\"//www.wikidata.org/wiki/Q42?uselang=en\">Q42</a>", html
106 tags = icon_tags(current_nodes(:node_with_name))
107 assert_equal 3, tags.count
108 assert tags.include?(%w(building yes))
109 assert tags.include?(%w(tourism museum))
110 assert tags.include?(%w(shop gift))
112 tags = icon_tags(nodes(:node_with_name_current_version))
113 assert_equal 3, tags.count
114 assert tags.include?(%w(building yes))
115 assert tags.include?(%w(tourism museum))
116 assert tags.include?(%w(shop gift))
118 tags = icon_tags(nodes(:node_with_name_redacted_version))
119 assert_equal 3, tags.count
120 assert tags.include?(%w(building yes))
121 assert tags.include?(%w(tourism museum))
122 assert tags.include?(%w(shop gift))
126 link = wiki_link("key", "highway")
127 assert_equal "http://wiki.openstreetmap.org/wiki/Key:highway?uselang=en", link
129 link = wiki_link("tag", "highway=primary")
130 assert_equal "http://wiki.openstreetmap.org/wiki/Tag:highway=primary?uselang=en", link
134 link = wiki_link("key", "highway")
135 assert_equal "http://wiki.openstreetmap.org/wiki/DE:Key:highway?uselang=de", link
137 link = wiki_link("tag", "highway=primary")
138 assert_equal "http://wiki.openstreetmap.org/wiki/DE:Tag:highway=primary?uselang=de", link
142 link = wiki_link("key", "highway")
143 assert_equal "http://wiki.openstreetmap.org/wiki/Tr:Key:highway?uselang=tr", link
145 link = wiki_link("tag", "highway=primary")
146 assert_equal "http://wiki.openstreetmap.org/wiki/Tag:highway=primary?uselang=tr", link
149 def test_wikidata_link
150 link = wikidata_link("foo", "Test")
153 link = wikidata_link("wikidata", "http://www.wikidata.org/wiki/Q1")
156 link = wikidata_link("wikidata", "en:Q1")
159 link = wikidata_link("wikidata", "1")
162 link = wikidata_link("wikidata", "Q0123")
165 link = wikidata_link("wikidata", "Q42")
166 assert_equal "//www.wikidata.org/wiki/Q42?uselang=en", link[:url]
167 assert_equal "Q42", link[:title]
169 I18n.locale = "zh-CN"
171 link = wikidata_link("wikidata", "Q1234")
172 assert_equal "//www.wikidata.org/wiki/Q1234?uselang=zh-CN", link[:url]
173 assert_equal "Q1234", link[:title]
176 def test_wikipedia_link
177 link = wikipedia_link("wikipedia", "http://en.wikipedia.org/wiki/Full%20URL")
180 link = wikipedia_link("wikipedia", "https://en.wikipedia.org/wiki/Full%20URL")
183 link = wikipedia_link("wikipedia", "Test")
184 assert_equal "http://en.wikipedia.org/wiki/Test?uselang=en", link[:url]
185 assert_equal "Test", link[:title]
187 link = wikipedia_link("wikipedia", "de:Test")
188 assert_equal "http://de.wikipedia.org/wiki/de:Test?uselang=en", link[:url]
189 assert_equal "de:Test", link[:title]
191 link = wikipedia_link("wikipedia:fr", "de:Test")
192 assert_equal "http://fr.wikipedia.org/wiki/de:Test?uselang=en", link[:url]
193 assert_equal "de:Test", link[:title]
195 link = wikipedia_link("wikipedia", "de:Englischer Garten (München)#Japanisches Teehaus")
196 assert_equal "http://de.wikipedia.org/wiki/de:Englischer Garten (München)?uselang=en#Japanisches_Teehaus", link[:url]
197 assert_equal "de:Englischer Garten (München)#Japanisches Teehaus", link[:title]
199 link = wikipedia_link("wikipedia", "de:Alte Brücke (Heidelberg)#Brückenaffe")
200 assert_equal "http://de.wikipedia.org/wiki/de:Alte Brücke (Heidelberg)?uselang=en#Br.C3.BCckenaffe", link[:url]
201 assert_equal "de:Alte Brücke (Heidelberg)#Brückenaffe", link[:title]
203 link = wikipedia_link("wikipedia", "de:Liste der Baudenkmäler in Eichstätt#Brückenstraße 1, Ehemaliges Bauernhaus")
204 assert_equal "http://de.wikipedia.org/wiki/de:Liste der Baudenkmäler in Eichstätt?uselang=en#Br.C3.BCckenstra.C3.9Fe_1.2C_Ehemaliges_Bauernhaus", link[:url]
205 assert_equal "de:Liste der Baudenkmäler in Eichstätt#Brückenstraße 1, Ehemaliges Bauernhaus", link[:title]
207 I18n.locale = "pt-BR"
209 link = wikipedia_link("wikipedia", "zh-classical:Test#Section")
210 assert_equal "http://zh-classical.wikipedia.org/wiki/zh-classical:Test?uselang=pt-BR#Section", link[:url]
211 assert_equal "zh-classical:Test#Section", link[:title]
213 link = wikipedia_link("foo", "Test")
217 def test_telephone_link
218 link = telephone_link("foo", "Test")
221 link = telephone_link("phone", "+123")
224 link = telephone_link("phone", "123")
227 link = telephone_link("phone", "123 abcdefg")
230 link = telephone_link("phone", "+1234567890 abc")
233 link = telephone_link("phone", "+1234567890; +22334455667788")
236 link = telephone_link("phone", "1234567890")
239 link = telephone_link("phone", "+1234567890")
240 assert_equal "tel:+1234567890", link
242 link = telephone_link("phone", "+1234-567-890")
243 assert_equal "tel:+1234-567-890", link
245 link = telephone_link("phone", "+1234/567/890")
246 assert_equal "tel:+1234/567/890", link
248 link = telephone_link("phone", "+1234.567.890")
249 assert_equal "tel:+1234.567.890", link
251 link = telephone_link("phone", " +1234 567-890 ")
252 assert_equal "tel:+1234567-890", link
254 link = telephone_link("phone", "+1 234-567-890")
255 assert_equal "tel:+1234-567-890", link
257 link = telephone_link("phone", "+1 (234) 567-890")
258 assert_equal "tel:+1(234)567-890", link