]> git.openstreetmap.org Git - rails.git/blob - test/helpers/browse_helper_test.rb
Try harder to find a name in the right language
[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 test_printable_name
16     assert_equal "17", printable_name(current_nodes(:redacted_node))
17     assert_equal "<bdi>Test Node</bdi> (<bdi>18</bdi>)", printable_name(current_nodes(:node_with_name))
18     assert_equal "<bdi>Test Node</bdi> (<bdi>18</bdi>)", printable_name(nodes(:node_with_name_current_version))
19     assert_equal "18", printable_name(nodes(:node_with_name_redacted_version))
20     assert_equal "<bdi>Test Node</bdi> (<bdi>18, v2</bdi>)", printable_name(nodes(:node_with_name_current_version), true)
21     assert_equal "18, v1", printable_name(nodes(:node_with_name_redacted_version), true)
22
23     I18n.locale = "ru"
24
25     assert_equal "17", printable_name(current_nodes(:redacted_node))
26     assert_equal "<bdi>проверки узла</bdi> (<bdi>18</bdi>)", printable_name(current_nodes(:node_with_name))
27     assert_equal "<bdi>проверки узла</bdi> (<bdi>18</bdi>)", printable_name(nodes(:node_with_name_current_version))
28     assert_equal "18", printable_name(nodes(:node_with_name_redacted_version))
29     assert_equal "<bdi>проверки узла</bdi> (<bdi>18, v2</bdi>)", printable_name(nodes(:node_with_name_current_version), true)
30     assert_equal "18, v1", printable_name(nodes(:node_with_name_redacted_version), true)
31
32     I18n.locale = "ru-RU"
33
34     assert_equal "17", printable_name(current_nodes(:redacted_node))
35     assert_equal "<bdi>проверки узла</bdi> (<bdi>18</bdi>)", printable_name(current_nodes(:node_with_name))
36     assert_equal "<bdi>проверки узла</bdi> (<bdi>18</bdi>)", printable_name(nodes(:node_with_name_current_version))
37     assert_equal "18", printable_name(nodes(:node_with_name_redacted_version))
38     assert_equal "<bdi>проверки узла</bdi> (<bdi>18, v2</bdi>)", printable_name(nodes(:node_with_name_current_version), true)
39     assert_equal "18, v1", printable_name(nodes(:node_with_name_redacted_version), true)
40
41     I18n.locale = "de"
42
43     assert_equal "17", printable_name(current_nodes(:redacted_node))
44     assert_equal "<bdi>Test Node</bdi> (<bdi>18</bdi>)", printable_name(current_nodes(:node_with_name))
45     assert_equal "<bdi>Test Node</bdi> (<bdi>18</bdi>)", printable_name(nodes(:node_with_name_current_version))
46     assert_equal "18", printable_name(nodes(:node_with_name_redacted_version))
47     assert_equal "<bdi>Test Node</bdi> (<bdi>18, v2</bdi>)", printable_name(nodes(:node_with_name_current_version), true)
48     assert_equal "18, v1", printable_name(nodes(:node_with_name_redacted_version), true)
49   end
50
51   def test_link_class
52     assert_equal "node", link_class("node", current_nodes(:visible_node))
53     assert_equal "node deleted", link_class("node", current_nodes(:invisible_node))
54     assert_equal "node deleted", link_class("node", current_nodes(:redacted_node))
55     assert_equal "node building yes shop gift tourism museum", link_class("node", current_nodes(:node_with_name))
56     assert_equal "node building yes shop gift tourism museum", link_class("node", nodes(:node_with_name_current_version))
57     assert_equal "node deleted", link_class("node", nodes(:node_with_name_redacted_version))
58   end
59
60   def test_link_title
61     assert_equal "", link_title(current_nodes(:visible_node))
62     assert_equal "", link_title(current_nodes(:invisible_node))
63     assert_equal "", link_title(current_nodes(:redacted_node))
64     assert_equal "building=yes, shop=gift, and tourism=museum", link_title(current_nodes(:node_with_name))
65     assert_equal "building=yes, shop=gift, and tourism=museum", link_title(nodes(:node_with_name_current_version))
66     assert_equal "", link_title(nodes(:node_with_name_redacted_version))
67   end
68
69   def test_format_key
70     html = format_key("highway")
71     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
72
73     html = format_key("unknown")
74     assert_equal "unknown", html
75   end
76
77   def test_format_value
78     html = format_value("highway", "primary")
79     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
80
81     html = format_value("highway", "unknown")
82     assert_equal "unknown", html
83
84     html = format_value("unknown", "unknown")
85     assert_equal "unknown", html
86   end
87
88   def test_icon_tags
89     tags = icon_tags(current_nodes(:node_with_name))
90     assert_equal 3, tags.count
91     assert tags.include?(["building", "yes"])
92     assert tags.include?(["tourism", "museum"])
93     assert tags.include?(["shop", "gift"])
94
95     tags = icon_tags(nodes(:node_with_name_current_version))
96     assert_equal 3, tags.count
97     assert tags.include?(["building", "yes"])
98     assert tags.include?(["tourism", "museum"])
99     assert tags.include?(["shop", "gift"])
100
101     tags = icon_tags(nodes(:node_with_name_redacted_version))
102     assert_equal 3, tags.count
103     assert tags.include?(["building", "yes"])
104     assert tags.include?(["tourism", "museum"])
105     assert tags.include?(["shop", "gift"])
106   end
107
108   def test_wiki_link
109     link = wiki_link("key", "highway")
110     assert_equal "http://wiki.openstreetmap.org/wiki/Key:highway?uselang=en", link
111
112     link = wiki_link("tag", "highway=primary")
113     assert_equal "http://wiki.openstreetmap.org/wiki/Tag:highway=primary?uselang=en", link
114
115     I18n.locale = "de"
116
117     link = wiki_link("key", "highway")
118     assert_equal "http://wiki.openstreetmap.org/wiki/DE:Key:highway?uselang=de", link
119
120     link = wiki_link("tag", "highway=primary")
121     assert_equal "http://wiki.openstreetmap.org/wiki/DE:Tag:highway=primary?uselang=de", link
122
123     I18n.locale = "tr"
124
125     link = wiki_link("key", "highway")
126     assert_equal "http://wiki.openstreetmap.org/wiki/Tr:Key:highway?uselang=tr", link
127
128     link = wiki_link("tag", "highway=primary")
129     assert_equal "http://wiki.openstreetmap.org/wiki/Tag:highway=primary?uselang=tr", link
130   end
131
132   def test_wikipedia_link
133     link = wikipedia_link("wikipedia", "http://en.wikipedia.org/wiki/Full%20URL")
134     assert_nil link
135
136     link = wikipedia_link("wikipedia", "https://en.wikipedia.org/wiki/Full%20URL")
137     assert_nil link
138
139     link = wikipedia_link("wikipedia", "Test")
140     assert_equal "http://en.wikipedia.org/wiki/Test?uselang=en", link[:url]
141     assert_equal "Test", link[:title]
142
143     link = wikipedia_link("wikipedia", "de:Test")
144     assert_equal "http://de.wikipedia.org/wiki/de:Test?uselang=en", link[:url]
145     assert_equal "de:Test", link[:title]
146
147     link = wikipedia_link("wikipedia:fr", "de:Test")
148     assert_equal "http://fr.wikipedia.org/wiki/de:Test?uselang=en", link[:url]
149     assert_equal "de:Test", link[:title]
150
151     I18n.locale = "pt-BR"
152
153     link = wikipedia_link("wikipedia", "zh-classical:Test#Section")
154     assert_equal "http://zh-classical.wikipedia.org/wiki/zh-classical:Test?uselang=pt-BR#Section", link[:url]
155     assert_equal "zh-classical:Test#Section", link[:title]
156
157     link = wikipedia_link("foo", "Test")
158     assert_nil link
159   end
160 end