include ERB::Util
include ApplicationHelper
- def setup
- I18n.locale = "en"
- end
-
- def teardown
- I18n.locale = "en"
- end
-
def test_printable_name
node = create(:node, :with_history, :version => 2)
node_v1 = node.old_nodes.find_by(:version => 1)
assert_dom_equal "#{node.id}, v1", printable_name(node_v1, :version => true)
assert_dom_equal "<bdi>3.1415926</bdi> (<bdi>#{node_with_ref_without_name.id}</bdi>)", printable_name(node_with_ref_without_name)
- I18n.locale = "pt"
-
- assert_dom_equal deleted_node.id.to_s, printable_name(deleted_node)
- assert_dom_equal "<bdi>Nó teste</bdi> (<bdi>#{node.id}</bdi>)", printable_name(node)
- assert_dom_equal "<bdi>Nó teste</bdi> (<bdi>#{node.id}</bdi>)", printable_name(node_v2)
- assert_dom_equal node.id.to_s, printable_name(node_v1)
- assert_dom_equal "<bdi>Nó teste</bdi> (<bdi>#{node.id}, v2</bdi>)", printable_name(node_v2, :version => true)
- assert_dom_equal "#{node.id}, v1", printable_name(node_v1, :version => true)
- assert_dom_equal "<bdi>3.1415926</bdi> (<bdi>#{node_with_ref_without_name.id}</bdi>)", printable_name(node_with_ref_without_name)
-
- I18n.locale = "pt-BR"
-
- assert_dom_equal deleted_node.id.to_s, printable_name(deleted_node)
- assert_dom_equal "<bdi>Nó teste</bdi> (<bdi>#{node.id}</bdi>)", printable_name(node)
- assert_dom_equal "<bdi>Nó teste</bdi> (<bdi>#{node.id}</bdi>)", printable_name(node_v2)
- assert_dom_equal node.id.to_s, printable_name(node_v1)
- assert_dom_equal "<bdi>Nó teste</bdi> (<bdi>#{node.id}, v2</bdi>)", printable_name(node_v2, :version => true)
- assert_dom_equal "#{node.id}, v1", printable_name(node_v1, :version => true)
- assert_dom_equal "<bdi>3.1415926</bdi> (<bdi>#{node_with_ref_without_name.id}</bdi>)", printable_name(node_with_ref_without_name)
+ I18n.with_locale "pt" do
+ assert_dom_equal deleted_node.id.to_s, printable_name(deleted_node)
+ assert_dom_equal "<bdi>Nó teste</bdi> (<bdi>#{node.id}</bdi>)", printable_name(node)
+ assert_dom_equal "<bdi>Nó teste</bdi> (<bdi>#{node.id}</bdi>)", printable_name(node_v2)
+ assert_dom_equal node.id.to_s, printable_name(node_v1)
+ assert_dom_equal "<bdi>Nó teste</bdi> (<bdi>#{node.id}, v2</bdi>)", printable_name(node_v2, :version => true)
+ assert_dom_equal "#{node.id}, v1", printable_name(node_v1, :version => true)
+ assert_dom_equal "<bdi>3.1415926</bdi> (<bdi>#{node_with_ref_without_name.id}</bdi>)", printable_name(node_with_ref_without_name)
+ end
- I18n.locale = "de"
+ I18n.with_locale "pt-BR" do
+ assert_dom_equal deleted_node.id.to_s, printable_name(deleted_node)
+ assert_dom_equal "<bdi>Nó teste</bdi> (<bdi>#{node.id}</bdi>)", printable_name(node)
+ assert_dom_equal "<bdi>Nó teste</bdi> (<bdi>#{node.id}</bdi>)", printable_name(node_v2)
+ assert_dom_equal node.id.to_s, printable_name(node_v1)
+ assert_dom_equal "<bdi>Nó teste</bdi> (<bdi>#{node.id}, v2</bdi>)", printable_name(node_v2, :version => true)
+ assert_dom_equal "#{node.id}, v1", printable_name(node_v1, :version => true)
+ assert_dom_equal "<bdi>3.1415926</bdi> (<bdi>#{node_with_ref_without_name.id}</bdi>)", printable_name(node_with_ref_without_name)
+ end
- assert_dom_equal deleted_node.id.to_s, printable_name(deleted_node)
- assert_dom_equal "<bdi>Test Node</bdi> (<bdi>#{node.id}</bdi>)", printable_name(node)
- assert_dom_equal "<bdi>Test Node</bdi> (<bdi>#{node.id}</bdi>)", printable_name(node_v2)
- assert_dom_equal node.id.to_s, printable_name(node_v1)
- assert_dom_equal "<bdi>Test Node</bdi> (<bdi>#{node.id}, v2</bdi>)", printable_name(node_v2, :version => true)
- assert_dom_equal "#{node.id}, v1", printable_name(node_v1, :version => true)
- assert_dom_equal "<bdi>3.1415926</bdi> (<bdi>#{node_with_ref_without_name.id}</bdi>)", printable_name(node_with_ref_without_name)
+ I18n.with_locale "de" do
+ assert_dom_equal deleted_node.id.to_s, printable_name(deleted_node)
+ assert_dom_equal "<bdi>Test Node</bdi> (<bdi>#{node.id}</bdi>)", printable_name(node)
+ assert_dom_equal "<bdi>Test Node</bdi> (<bdi>#{node.id}</bdi>)", printable_name(node_v2)
+ assert_dom_equal node.id.to_s, printable_name(node_v1)
+ assert_dom_equal "<bdi>Test Node</bdi> (<bdi>#{node.id}, v2</bdi>)", printable_name(node_v2, :version => true)
+ assert_dom_equal "#{node.id}, v1", printable_name(node_v1, :version => true)
+ assert_dom_equal "<bdi>3.1415926</bdi> (<bdi>#{node_with_ref_without_name.id}</bdi>)", printable_name(node_with_ref_without_name)
+ end
end
def test_link_class
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 "<a href=\"https://wiki.openstreetmap.org/wiki/Key:highway?uselang=en\" title=\"The wiki description page for the highway tag\">highway</a>", html
link = wiki_link("tag", "highway=primary")
assert_equal "https://wiki.openstreetmap.org/wiki/Tag:highway=primary?uselang=en", link
- I18n.locale = "de"
+ I18n.with_locale "de" do
+ link = wiki_link("key", "highway")
+ assert_equal "https://wiki.openstreetmap.org/wiki/DE:Key:highway?uselang=de", link
- 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
+ link = wiki_link("tag", "highway=primary")
+ assert_equal "https://wiki.openstreetmap.org/wiki/DE:Tag:highway=primary?uselang=de", link
+ end
- I18n.locale = "tr"
+ 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("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
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
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")
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
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