X-Git-Url: https://git.openstreetmap.org/rails.git/blobdiff_plain/93da9596997444baa576e296e371065a3cb99eb3..305acfe5167dec7440448cfa02e6c1430286c742:/test/helpers/browse_tags_helper_test.rb diff --git a/test/helpers/browse_tags_helper_test.rb b/test/helpers/browse_tags_helper_test.rb index fb90eb51d..2329a7c96 100644 --- a/test/helpers/browse_tags_helper_test.rb +++ b/test/helpers/browse_tags_helper_test.rb @@ -4,14 +4,6 @@ class BrowseTagsHelperTest < ActionView::TestCase include ERB::Util include ApplicationHelper - def setup - I18n.locale = "en" - end - - def teardown - I18n.locale = "en" - end - def test_format_key html = format_key("highway") assert_dom_equal "highway", html @@ -43,7 +35,8 @@ class BrowseTagsHelperTest < ActionView::TestCase assert_dom_equal "Q42", html html = format_value("operator:wikidata", "Q12;Q98") - assert_dom_equal "Q12;Q98", html + assert_dom_equal "Q12;" \ + "Q98", html html = format_value("name:etymology:wikidata", "Q123") assert_dom_equal "Q123", html @@ -53,6 +46,15 @@ class BrowseTagsHelperTest < ActionView::TestCase html = format_value("colour", "#f00") assert_dom_equal %(#f00), html + + html = format_value("contact", "foo@example.com") + assert_dom_equal "foo@example.com", html + + html = format_value("source", "https://example.com") + assert_dom_equal "https://example.com", html + + html = format_value("source", "https://example.com;hello;https://example.net") + assert_dom_equal "https://example.com;hello;https://example.net", html end def test_wiki_link @@ -62,21 +64,21 @@ class BrowseTagsHelperTest < ActionView::TestCase link = wiki_link("tag", "highway=primary") assert_equal "https://wiki.openstreetmap.org/wiki/Tag:highway=primary?uselang=en", link - I18n.locale = "de" - - link = wiki_link("key", "highway") - assert_equal "https://wiki.openstreetmap.org/wiki/DE:Key:highway?uselang=de", link - - link = wiki_link("tag", "highway=primary") - assert_equal "https://wiki.openstreetmap.org/wiki/DE:Tag:highway=primary?uselang=de", link + I18n.with_locale "de" do + link = wiki_link("key", "highway") + assert_equal "https://wiki.openstreetmap.org/wiki/DE:Key:highway?uselang=de", link - I18n.locale = "tr" + link = wiki_link("tag", "highway=primary") + assert_equal "https://wiki.openstreetmap.org/wiki/DE:Tag:highway=primary?uselang=de", link + end - link = wiki_link("key", "highway") - assert_equal "https://wiki.openstreetmap.org/wiki/Tr:Key:highway?uselang=tr", link + I18n.with_locale "tr" do + link = wiki_link("key", "highway") + assert_equal "https://wiki.openstreetmap.org/wiki/Tr:Key:highway?uselang=tr", link - link = wiki_link("tag", "highway=primary") - assert_equal "https://wiki.openstreetmap.org/wiki/Tag:highway=primary?uselang=tr", link + link = wiki_link("tag", "highway=primary") + assert_equal "https://wiki.openstreetmap.org/wiki/Tag:highway=primary?uselang=tr", link + end end def test_wikidata_links @@ -109,12 +111,12 @@ class BrowseTagsHelperTest < ActionView::TestCase assert_equal "Q42", links[0][:title] # the language of the wikidata-page should match the current locale - I18n.locale = "zh-CN" - links = wikidata_links("wikidata", "Q1234") - assert_equal 1, links.length - assert_equal "//www.wikidata.org/entity/Q1234?uselang=zh-CN", links[0][:url] - assert_equal "Q1234", links[0][:title] - I18n.locale = "en" + I18n.with_locale "zh-CN" do + links = wikidata_links("wikidata", "Q1234") + assert_equal 1, links.length + assert_equal "//www.wikidata.org/entity/Q1234?uselang=zh-CN", links[0][:url] + assert_equal "Q1234", links[0][:title] + end ### Prefixed wikidata-tags @@ -128,16 +130,16 @@ class BrowseTagsHelperTest < ActionView::TestCase assert_equal "Q24", links[0][:title] # Another allowed key, this time with multiple values and I18n - I18n.locale = "dsb" - links = wikidata_links("brand:wikidata", "Q936;Q2013;Q1568346") - assert_equal 3, links.length - assert_equal "//www.wikidata.org/entity/Q936?uselang=dsb", links[0][:url] - assert_equal "Q936", links[0][:title] - assert_equal "//www.wikidata.org/entity/Q2013?uselang=dsb", links[1][:url] - assert_equal "Q2013", links[1][:title] - assert_equal "//www.wikidata.org/entity/Q1568346?uselang=dsb", links[2][:url] - assert_equal "Q1568346", links[2][:title] - I18n.locale = "en" + I18n.with_locale "dsb" do + links = wikidata_links("brand:wikidata", "Q936;Q2013;Q1568346") + assert_equal 3, links.length + assert_equal "//www.wikidata.org/entity/Q936?uselang=dsb", links[0][:url] + assert_equal "Q936", links[0][:title] + assert_equal "//www.wikidata.org/entity/Q2013?uselang=dsb", links[1][:url] + assert_equal "Q2013", links[1][:title] + assert_equal "//www.wikidata.org/entity/Q1568346?uselang=dsb", links[2][:url] + assert_equal "Q1568346", links[2][:title] + end # and now with whitespaces... links = wikidata_links("subject:wikidata", "Q6542248 ;\tQ180\n ;\rQ364\t\n\r ;\nQ4006") @@ -176,18 +178,18 @@ class BrowseTagsHelperTest < ActionView::TestCase assert_equal "de:Englischer Garten (München)#Japanisches Teehaus", link[:title] link = wikipedia_link("wikipedia", "de:Alte Brücke (Heidelberg)#Brückenaffe") - assert_equal "https://de.wikipedia.org/wiki/de:Alte Brücke (Heidelberg)?uselang=en#Br.C3.BCckenaffe", link[:url] + assert_equal "https://de.wikipedia.org/wiki/de:Alte Brücke (Heidelberg)?uselang=en#Br%C3%BCckenaffe", link[:url] assert_equal "de:Alte Brücke (Heidelberg)#Brückenaffe", link[:title] link = wikipedia_link("wikipedia", "de:Liste der Baudenkmäler in Eichstätt#Brückenstraße 1, Ehemaliges Bauernhaus") - assert_equal "https://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] + assert_equal "https://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] assert_equal "de:Liste der Baudenkmäler in Eichstätt#Brückenstraße 1, Ehemaliges Bauernhaus", link[:title] - I18n.locale = "pt-BR" - - link = wikipedia_link("wikipedia", "zh-classical:Test#Section") - assert_equal "https://zh-classical.wikipedia.org/wiki/zh-classical:Test?uselang=pt-BR#Section", link[:url] - assert_equal "zh-classical:Test#Section", link[:title] + I18n.with_locale "pt-BR" do + link = wikipedia_link("wikipedia", "zh-classical:Test#Section") + assert_equal "https://zh-classical.wikipedia.org/wiki/zh-classical:Test?uselang=pt-BR#Section", link[:url] + assert_equal "zh-classical:Test#Section", link[:title] + end link = wikipedia_link("foo", "Test") assert_nil link @@ -211,11 +213,11 @@ class BrowseTagsHelperTest < ActionView::TestCase assert_equal "//commons.wikimedia.org/wiki/Category:Test_Category?uselang=en", link[:url] assert_equal "Category:Test_Category", link[:title] - I18n.locale = "pt-BR" - - link = wikimedia_commons_link("wikimedia_commons", "File:Test.jpg") - assert_equal "//commons.wikimedia.org/wiki/File:Test.jpg?uselang=pt-BR", link[:url] - assert_equal "File:Test.jpg", link[:title] + I18n.with_locale "pt-BR" do + link = wikimedia_commons_link("wikimedia_commons", "File:Test.jpg") + assert_equal "//commons.wikimedia.org/wiki/File:Test.jpg?uselang=pt-BR", link[:url] + assert_equal "File:Test.jpg", link[:title] + end link = wikimedia_commons_link("foo", "Test") assert_nil link @@ -247,29 +249,23 @@ class BrowseTagsHelperTest < ActionView::TestCase assert_nil email email = email_link("email", "x@example.com") - assert_equal "x@example.com", email[:email] - assert_equal "mailto:x@example.com", email[:url] + assert_equal "x@example.com", email email = email_link("email", "other.email-with-hyphen@example.com") - assert_equal "other.email-with-hyphen@example.com", email[:email] - assert_equal "mailto:other.email-with-hyphen@example.com", email[:url] + assert_equal "other.email-with-hyphen@example.com", email email = email_link("email", "user.name+tag+sorting@example.com") - assert_equal "user.name+tag+sorting@example.com", email[:email] - assert_equal "mailto:user.name+tag+sorting@example.com", email[:url] + assert_equal "user.name+tag+sorting@example.com", email email = email_link("email", "dash-in@both-parts.com") - assert_equal "dash-in@both-parts.com", email[:email] - assert_equal "mailto:dash-in@both-parts.com", email[:url] + assert_equal "dash-in@both-parts.com", email email = email_link("email", "example@s.example") - assert_equal "example@s.example", email[:email] - assert_equal "mailto:example@s.example", email[:url] + assert_equal "example@s.example", email # Strips whitespace at ends email = email_link("email", " test@email.com ") - assert_equal "test@email.com", email[:email] - assert_equal "mailto:test@email.com", email[:url] + assert_equal "test@email.com", email end def test_telephone_links