3 class SiteControllerTest < ActionController::TestCase
9 Object.const_set("ID_KEY", client_applications(:oauth_web_app).key)
10 Object.const_set("POTLATCH2_KEY", client_applications(:oauth_web_app).key)
16 Object.send("remove_const", "ID_KEY")
17 Object.send("remove_const", "POTLATCH2_KEY")
21 # test all routes which lead to this controller
24 { :path => "/", :method => :get },
25 { :controller => "site", :action => "index" }
28 { :path => "/", :method => :post },
29 { :controller => "site", :action => "index" }
32 { :path => "/edit", :method => :get },
33 { :controller => "site", :action => "edit" }
36 { :controller => "site", :action => "edit", :format => "html" },
37 { :path => "/edit.html", :method => :get }
40 { :path => "/copyright", :method => :get },
41 { :controller => "site", :action => "copyright" }
44 { :path => "/copyright/locale", :method => :get },
45 { :controller => "site", :action => "copyright", :copyright_locale => "locale" }
48 { :path => "/welcome", :method => :get },
49 { :controller => "site", :action => "welcome" }
52 { :path => "/fixthemap", :method => :get },
53 { :controller => "site", :action => "fixthemap" }
56 { :path => "/export", :method => :get },
57 { :controller => "site", :action => "export" }
60 { :controller => "site", :action => "export", :format => "html" },
61 { :path => "/export.html", :method => :get }
64 { :path => "/offline", :method => :get },
65 { :controller => "site", :action => "offline" }
68 { :path => "/key", :method => :get },
69 { :controller => "site", :action => "key" }
72 { :path => "/go/shortcode", :method => :get },
73 { :controller => "site", :action => "permalink", :code => "shortcode" }
76 { :path => "/preview/formatname", :method => :post },
77 { :controller => "site", :action => "preview", :format => "formatname" }
80 { :path => "/id", :method => :get },
81 { :controller => "site", :action => "id" }
88 assert_response :success
89 assert_template "index"
92 # Test the index page redirects
93 def test_index_redirect
94 get :index, :lat => 4, :lon => 5
95 assert_redirected_to :controller => :site, :action => :index, :anchor => "map=5/4/5"
97 get :index, :lat => 4, :lon => 5, :zoom => 3
98 assert_redirected_to :controller => :site, :action => :index, :anchor => "map=3/4/5"
100 get :index, :layers => "T"
101 assert_redirected_to :controller => :site, :action => :index, :anchor => "layers=T"
103 get :index, :notes => "yes"
104 assert_redirected_to :controller => :site, :action => :index, :anchor => "layers=N"
106 get :index, :lat => 4, :lon => 5, :zoom => 3, :layers => "T"
107 assert_redirected_to :controller => :site, :action => :index, :anchor => "map=3/4/5&layers=T"
110 # Test the permalink redirect
112 get :permalink, :code => "wBz3--"
113 assert_response :redirect
114 assert_redirected_to :controller => :site, :action => :index, :anchor => "map=3/4.8779296875/3.955078125"
116 get :permalink, :code => "wBz3--", :m => ""
117 assert_response :redirect
118 assert_redirected_to :controller => :site, :action => :index, :mlat => "4.8779296875", :mlon => "3.955078125", :anchor => "map=3/4.8779296875/3.955078125"
120 get :permalink, :code => "wBz3--", :layers => "T"
121 assert_response :redirect
122 assert_redirected_to :controller => :site, :action => :index, :anchor => "map=3/4.8779296875/3.955078125&layers=T"
124 get :permalink, :code => "wBz3--", :node => 1
125 assert_response :redirect
126 assert_redirected_to :controller => :browse, :action => :node, :id => 1, :anchor => "map=3/4.8779296875/3.955078125"
128 get :permalink, :code => "wBz3--", :way => 2
129 assert_response :redirect
130 assert_redirected_to :controller => :browse, :action => :way, :id => 2, :anchor => "map=3/4.8779296875/3.955078125"
132 get :permalink, :code => "wBz3--", :relation => 3
133 assert_response :redirect
134 assert_redirected_to :controller => :browse, :action => :relation, :id => 3, :anchor => "map=3/4.8779296875/3.955078125"
136 get :permalink, :code => "wBz3--", :changeset => 4
137 assert_response :redirect
138 assert_redirected_to :controller => :browse, :action => :changeset, :id => 4, :anchor => "map=3/4.8779296875/3.955078125"
144 assert_response :success
145 assert_template "key"
146 assert_template :layout => false
149 # Test the edit page redirects when you aren't logged in
152 assert_response :redirect
153 assert_redirected_to :controller => :user, :action => :login, :referer => "/edit"
156 # Test the right editor gets used when the user hasn't set a preference
157 def test_edit_without_preference
158 get :edit, nil, :user => users(:public_user).id
159 assert_response :success
160 assert_template "edit"
161 assert_template :partial => "_#{DEFAULT_EDITOR}", :count => 1
164 # Test the right editor gets used when the user has set a preference
165 def test_edit_with_preference
166 user = users(:public_user)
167 user.preferred_editor = "id"
170 get :edit, nil, :user => user.id
171 assert_response :success
172 assert_template "edit"
173 assert_template :partial => "_id", :count => 1
175 user = users(:public_user)
176 user.preferred_editor = "potlatch2"
179 get :edit, nil, :user => user.id
180 assert_response :success
181 assert_template "edit"
182 assert_template :partial => "_potlatch2", :count => 1
184 user = users(:public_user)
185 user.preferred_editor = "potlatch"
188 get :edit, nil, :user => user.id
189 assert_response :success
190 assert_template "edit"
191 assert_template :partial => "_potlatch", :count => 1
193 user = users(:public_user)
194 user.preferred_editor = "remote"
197 get :edit, nil, :user => user.id
198 assert_response :success
199 assert_template "index"
202 # Test the right editor gets used when the URL has an override
203 def test_edit_with_override
204 get :edit, { :editor => "id" }, { :user => users(:public_user).id }
205 assert_response :success
206 assert_template "edit"
207 assert_template :partial => "_id", :count => 1
209 get :edit, { :editor => "potlatch2" }, { :user => users(:public_user).id }
210 assert_response :success
211 assert_template "edit"
212 assert_template :partial => "_potlatch2", :count => 1
214 get :edit, { :editor => "potlatch" }, { :user => users(:public_user).id }
215 assert_response :success
216 assert_template "edit"
217 assert_template :partial => "_potlatch", :count => 1
219 get :edit, { :editor => "remote" }, { :user => users(:public_user).id }
220 assert_response :success
221 assert_template "index"
224 # Test the right editor gets used when the browser is IE
225 def test_edit_with_ie
226 @request.env["HTTP_USER_AGENT"] = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/7.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E)"
228 get :edit, {}, { :user => users(:public_user).id }
229 assert_response :success
230 assert_template "edit"
231 assert_template :partial => "_potlatch2", :count => 1
233 get :edit, { :editor => "id" }, { :user => users(:public_user).id }
234 assert_response :success
235 assert_template "edit"
236 assert_template :partial => "_potlatch2", :count => 1
238 @request.env["HTTP_USER_AGENT"] = "Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko"
240 get :edit, {}, { :user => users(:public_user).id }
241 assert_response :success
242 assert_template "edit"
243 assert_template :partial => "_potlatch2", :count => 1
245 get :edit, { :editor => "id" }, { :user => users(:public_user).id }
246 assert_response :success
247 assert_template "edit"
248 assert_template :partial => "_potlatch2", :count => 1
251 # Test editing a specific node
252 def test_edit_with_node
253 user = users(:public_user)
254 node = current_nodes(:visible_node)
256 get :edit, { :node => node.id }, { :user => user.id }
257 assert_response :success
258 assert_template "edit"
259 assert_equal 1.0, assigns(:lat)
260 assert_equal 1.0, assigns(:lon)
261 assert_equal 18, assigns(:zoom)
264 # Test editing a specific way
265 def test_edit_with_way
266 user = users(:public_user)
267 way = current_ways(:visible_way)
269 get :edit, { :way => way.id }, { :user => user.id }
270 assert_response :success
271 assert_template "edit"
272 assert_equal 3.0, assigns(:lat)
273 assert_equal 3.0, assigns(:lon)
274 assert_equal 17, assigns(:zoom)
277 # Test editing a specific note
278 def test_edit_with_note
279 user = users(:public_user)
280 note = notes(:open_note)
282 get :edit, { :note => note.id }, { :user => user.id }
283 assert_response :success
284 assert_template "edit"
285 assert_equal 1.0, assigns(:lat)
286 assert_equal 1.0, assigns(:lon)
287 assert_equal 17, assigns(:zoom)
290 # Test editing a specific GPX trace
291 def test_edit_with_gpx
292 user = users(:public_user)
293 gpx = gpx_files(:public_trace_file)
295 get :edit, { :gpx => gpx.id }, { :user => user.id }
296 assert_response :success
297 assert_template "edit"
298 assert_equal 1.0, assigns(:lat)
299 assert_equal 1.0, assigns(:lon)
300 assert_equal 16, assigns(:zoom)
303 # Test the edit page redirects
304 def test_edit_redirect
305 get :edit, :lat => 4, :lon => 5
306 assert_redirected_to :controller => :site, :action => :edit, :anchor => "map=5/4/5"
308 get :edit, :lat => 4, :lon => 5, :zoom => 3
309 assert_redirected_to :controller => :site, :action => :edit, :anchor => "map=3/4/5"
311 get :edit, :lat => 4, :lon => 5, :zoom => 3, :editor => "id"
312 assert_redirected_to :controller => :site, :action => :edit, :editor => "id", :anchor => "map=3/4/5"
315 # Test the copyright page
318 assert_response :success
319 assert_template "copyright"
322 # Test the welcome page
325 assert_response :redirect
326 assert_redirected_to :controller => :user, :action => :login, :referer => "/welcome"
328 get :welcome, nil, :user => users(:public_user).id
329 assert_response :success
330 assert_template "welcome"
333 # Test the fixthemap page
336 assert_response :success
337 assert_template "fixthemap"
343 assert_response :success
344 assert_template "help"
347 # Test the about page
350 assert_response :success
351 assert_template "about"
354 # Test the export page
357 assert_response :success
358 assert_template "export"
359 assert_template :layout => "map"
362 assert_response :success
363 assert_template "export"
364 assert_template :layout => "xhr"
367 # Test the offline page
370 assert_response :success
371 assert_template "offline"
374 # Test the rich text preview
376 xhr :post, :preview, :format => "html"
377 assert_response :success
379 xhr :post, :preview, :format => "markdown"
380 assert_response :success
382 xhr :post, :preview, :format => "text"
383 assert_response :success
388 get :id, nil, :user => users(:public_user).id
389 assert_response :success
391 assert_template :layout => false