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