]> git.openstreetmap.org Git - rails.git/blobdiff - test/helpers/browse_helper_test.rb
Merge branch 'rails41'
[rails.git] / test / helpers / browse_helper_test.rb
index 8306749409cfcf642a19257b0c4ea025480c5420..d3ed3a8267c702eb6c9c31ed0d6838fc5a2ff8ee 100644 (file)
@@ -12,6 +12,10 @@ class BrowseHelperTest < ActionView::TestCase
     I18n.locale = "en"
   end
 
+  def teardown
+    I18n.locale = "en"
+  end
+
   def test_printable_name
     assert_equal "17", printable_name(current_nodes(:redacted_node))
     assert_equal "<bdi>Test Node</bdi> (<bdi>18</bdi>)", printable_name(current_nodes(:node_with_name))
@@ -83,6 +87,9 @@ class BrowseHelperTest < ActionView::TestCase
 
     html = format_value("unknown", "unknown")
     assert_equal "unknown", html
+
+    html = format_value("phone", "+1234567890")
+    assert_equal "<a href=\"tel:+1234567890\" title=\"Call +1234567890\">+1234567890</a>", html
   end
 
   def test_icon_tags
@@ -129,6 +136,33 @@ class BrowseHelperTest < ActionView::TestCase
     assert_equal "http://wiki.openstreetmap.org/wiki/Tag:highway=primary?uselang=tr", link
   end
 
+  def test_wikidata_link
+    link = wikidata_link("foo", "Test")
+    assert_nil link
+
+    link = wikidata_link("wikidata", "http://www.wikidata.org/wiki/Q1")
+    assert_nil link
+
+    link = wikidata_link("wikidata", "en:Q1")
+    assert_nil link
+
+    link = wikidata_link("wikidata", "1")
+    assert_nil link
+
+    link = wikidata_link("wikidata", "Q0123")
+    assert_nil link
+
+    link = wikidata_link("wikidata", "Q42")
+    assert_equal "//www.wikidata.org/wiki/Q42?uselang=en", link[:url]
+    assert_equal "Q42", link[:title]
+
+    I18n.locale = "zh-CN"
+
+    link = wikidata_link("wikidata", "Q1234")
+    assert_equal "//www.wikidata.org/wiki/Q1234?uselang=zh-CN", link[:url]
+    assert_equal "Q1234", link[:title]
+  end
+
   def test_wikipedia_link
     link = wikipedia_link("wikipedia", "http://en.wikipedia.org/wiki/Full%20URL")
     assert_nil link
@@ -157,4 +191,48 @@ class BrowseHelperTest < ActionView::TestCase
     link = wikipedia_link("foo", "Test")
     assert_nil link
   end
+
+  def test_telephone_link
+    link = telephone_link("foo", "Test")
+    assert_nil link
+
+    link = telephone_link("phone", "+123")
+    assert_nil link
+
+    link = telephone_link("phone", "123")
+    assert_nil link
+
+    link = telephone_link("phone", "123 abcdefg")
+    assert_nil link
+
+    link = telephone_link("phone", "+1234567890 abc")
+    assert_nil link
+
+    link = telephone_link("phone", "+1234567890; +22334455667788")
+    assert_nil link
+
+    link = telephone_link("phone", "1234567890")
+    assert_nil link
+
+    link = telephone_link("phone", "+1234567890")
+    assert_equal "tel:+1234567890", link
+
+    link = telephone_link("phone", "+1234-567-890")
+    assert_equal "tel:+1234-567-890", link
+
+    link = telephone_link("phone", "+1234/567/890")
+    assert_equal "tel:+1234/567/890", link
+
+    link = telephone_link("phone", "+1234.567.890")
+    assert_equal "tel:+1234.567.890", link
+
+    link = telephone_link("phone", "   +1234 567-890   ")
+    assert_equal "tel:+1234567-890", link
+
+    link = telephone_link("phone", "+1 234-567-890")
+    assert_equal "tel:+1234-567-890", link
+
+    link = telephone_link("phone", "+1 (234) 567-890")
+    assert_equal "tel:+1(234)567-890", link
+  end
 end