3 class SiteControllerTest < ActionController::TestCase
9 Settings.id_key = create(:client_application).key
10 Settings.potlatch2_key = create(:client_application).key
19 Settings.potlatch2_key = nil
23 # test all routes which lead to this controller
26 { :path => "/", :method => :get },
27 { :controller => "site", :action => "index" }
30 { :path => "/", :method => :post },
31 { :controller => "site", :action => "index" }
34 { :path => "/edit", :method => :get },
35 { :controller => "site", :action => "edit" }
38 { :controller => "site", :action => "edit", :format => "html" },
39 { :path => "/edit.html", :method => :get }
42 { :path => "/copyright", :method => :get },
43 { :controller => "site", :action => "copyright" }
46 { :path => "/copyright/locale", :method => :get },
47 { :controller => "site", :action => "copyright", :copyright_locale => "locale" }
50 { :path => "/welcome", :method => :get },
51 { :controller => "site", :action => "welcome" }
54 { :path => "/fixthemap", :method => :get },
55 { :controller => "site", :action => "fixthemap" }
58 { :path => "/help", :method => :get },
59 { :controller => "site", :action => "help" }
62 { :path => "/about", :method => :get },
63 { :controller => "site", :action => "about" }
66 { :path => "/about/locale", :method => :get },
67 { :controller => "site", :action => "about", :about_locale => "locale" }
70 { :path => "/export", :method => :get },
71 { :controller => "site", :action => "export" }
74 { :controller => "site", :action => "export", :format => "html" },
75 { :path => "/export.html", :method => :get }
78 { :path => "/offline", :method => :get },
79 { :controller => "site", :action => "offline" }
82 { :path => "/key", :method => :get },
83 { :controller => "site", :action => "key" }
86 { :path => "/go/shortcode", :method => :get },
87 { :controller => "site", :action => "permalink", :code => "shortcode" }
90 { :path => "/preview/typename", :method => :post },
91 { :controller => "site", :action => "preview", :type => "typename" }
94 { :path => "/id", :method => :get },
95 { :controller => "site", :action => "id" }
102 assert_response :success
103 assert_template "index"
106 # Test the index page redirects
107 def test_index_redirect
108 get :index, :params => { :node => 123 }
109 assert_redirected_to :controller => :browse, :action => :node, :id => 123
111 get :index, :params => { :way => 123 }
112 assert_redirected_to :controller => :browse, :action => :way, :id => 123
114 get :index, :params => { :relation => 123 }
115 assert_redirected_to :controller => :browse, :action => :relation, :id => 123
117 get :index, :params => { :note => 123 }
118 assert_redirected_to :controller => :browse, :action => :note, :id => 123
120 get :index, :params => { :query => "test" }
121 assert_redirected_to :controller => :geocoder, :action => :search, :query => "test"
123 get :index, :params => { :lat => 4, :lon => 5 }
124 assert_redirected_to :controller => :site, :action => :index, :anchor => "map=5/4/5"
126 get :index, :params => { :lat => 4, :lon => 5, :zoom => 3 }
127 assert_redirected_to :controller => :site, :action => :index, :anchor => "map=3/4/5"
129 get :index, :params => { :layers => "T" }
130 assert_redirected_to :controller => :site, :action => :index, :anchor => "layers=T"
132 get :index, :params => { :notes => "yes" }
133 assert_redirected_to :controller => :site, :action => :index, :anchor => "layers=N"
135 get :index, :params => { :lat => 4, :lon => 5, :zoom => 3, :layers => "T" }
136 assert_redirected_to :controller => :site, :action => :index, :anchor => "map=3/4/5&layers=T"
139 # Test the permalink redirect
141 get :permalink, :params => { :code => "wBz3--" }
142 assert_response :redirect
143 assert_redirected_to :controller => :site, :action => :index, :anchor => "map=3/4.8779296875/3.955078125"
145 get :permalink, :params => { :code => "wBz3--", :m => "" }
146 assert_response :redirect
147 assert_redirected_to :controller => :site, :action => :index, :mlat => "4.8779296875", :mlon => "3.955078125", :anchor => "map=3/4.8779296875/3.955078125"
149 get :permalink, :params => { :code => "wBz3--", :layers => "T" }
150 assert_response :redirect
151 assert_redirected_to :controller => :site, :action => :index, :anchor => "map=3/4.8779296875/3.955078125&layers=T"
153 get :permalink, :params => { :code => "wBz3--", :node => 1 }
154 assert_response :redirect
155 assert_redirected_to :controller => :browse, :action => :node, :id => 1, :anchor => "map=3/4.8779296875/3.955078125"
157 get :permalink, :params => { :code => "wBz3--", :way => 2 }
158 assert_response :redirect
159 assert_redirected_to :controller => :browse, :action => :way, :id => 2, :anchor => "map=3/4.8779296875/3.955078125"
161 get :permalink, :params => { :code => "wBz3--", :relation => 3 }
162 assert_response :redirect
163 assert_redirected_to :controller => :browse, :action => :relation, :id => 3, :anchor => "map=3/4.8779296875/3.955078125"
165 get :permalink, :params => { :code => "wBz3--", :changeset => 4 }
166 assert_response :redirect
167 assert_redirected_to :controller => :browse, :action => :changeset, :id => 4, :anchor => "map=3/4.8779296875/3.955078125"
172 get :key, :xhr => true
173 assert_response :success
174 assert_template "key"
175 assert_template :layout => false
178 # Test the edit page redirects when you aren't logged in
181 assert_response :redirect
182 assert_redirected_to :controller => :users, :action => :login, :referer => "/edit"
185 # Test the error when trying to edit without public edits
186 def test_edit_non_public
187 get :edit, :session => { :user => create(:user, :data_public => false) }
188 assert_response :success
189 assert_template "edit"
190 assert_select "a[href='https://wiki.openstreetmap.org/wiki/Disabling_anonymous_edits']"
193 # Test the right editor gets used when the user hasn't set a preference
194 def test_edit_without_preference
195 get :edit, :session => { :user => create(:user) }
196 assert_response :success
197 assert_template "edit"
198 assert_template :partial => "_#{Settings.default_editor}", :count => 1
201 # Test the right editor gets used when the user has set a preference
202 def test_edit_with_preference
204 user.preferred_editor = "id"
207 get :edit, :session => { :user => user }
208 assert_response :success
209 assert_template "edit"
210 assert_template :partial => "_id", :count => 1
213 user.preferred_editor = "potlatch2"
216 get :edit, :session => { :user => user }
217 assert_response :success
218 assert_template "edit"
219 assert_template :partial => "_potlatch2", :count => 1
222 user.preferred_editor = "potlatch"
225 get :edit, :session => { :user => user }
226 assert_response :success
227 assert_template "edit"
228 assert_template :partial => "_potlatch", :count => 1
231 user.preferred_editor = "remote"
234 get :edit, :session => { :user => user }
235 assert_response :success
236 assert_template "index"
239 # Test the right editor gets used when the URL has an override
240 def test_edit_with_override
241 get :edit, :params => { :editor => "id" }, :session => { :user => create(:user) }
242 assert_response :success
243 assert_template "edit"
244 assert_template :partial => "_id", :count => 1
246 get :edit, :params => { :editor => "potlatch2" }, :session => { :user => create(:user) }
247 assert_response :success
248 assert_template "edit"
249 assert_template :partial => "_potlatch2", :count => 1
251 get :edit, :params => { :editor => "potlatch" }, :session => { :user => create(:user) }
252 assert_response :success
253 assert_template "edit"
254 assert_template :partial => "_potlatch", :count => 1
256 get :edit, :params => { :editor => "remote" }, :session => { :user => create(:user) }
257 assert_response :success
258 assert_template "index"
261 # Test editing a specific node
262 def test_edit_with_node
264 node = create(:node, :lat => 1.0, :lon => 1.0)
266 get :edit, :params => { :node => node.id }, :session => { :user => user }
267 assert_response :success
268 assert_template "edit"
269 assert_equal 1.0, assigns(:lat)
270 assert_equal 1.0, assigns(:lon)
271 assert_equal 18, assigns(:zoom)
274 # Test editing inaccessible nodes
275 def test_edit_with_inaccessible_nodes
277 deleted_node = create(:node, :lat => 1.0, :lon => 1.0, :visible => false)
279 get :edit, :params => { :node => 99999 }, :session => { :user => user }
280 assert_response :success
281 assert_template "edit"
282 assert_nil assigns(:lat)
283 assert_nil assigns(:lon)
284 assert_nil assigns(:zoom)
286 get :edit, :params => { :node => deleted_node.id }, :session => { :user => user }
287 assert_response :success
288 assert_template "edit"
289 assert_nil assigns(:lat)
290 assert_nil assigns(:lon)
291 assert_nil assigns(:zoom)
294 # Test editing a specific way
295 def test_edit_with_way
297 node = create(:node, :lat => 3, :lon => 3)
299 create(:way_node, :node => node, :way => way)
301 get :edit, :params => { :way => way.id }, :session => { :user => user }
302 assert_response :success
303 assert_template "edit"
304 assert_equal 3.0, assigns(:lat)
305 assert_equal 3.0, assigns(:lon)
306 assert_equal 17, assigns(:zoom)
309 # Test editing inaccessible ways
310 def test_edit_with_inaccessible_ways
312 deleted_way = create(:way, :visible => false)
314 get :edit, :params => { :way => 99999 }, :session => { :user => user }
315 assert_response :success
316 assert_template "edit"
317 assert_nil assigns(:lat)
318 assert_nil assigns(:lon)
319 assert_nil assigns(:zoom)
321 get :edit, :params => { :way => deleted_way.id }, :session => { :user => user }
322 assert_response :success
323 assert_template "edit"
324 assert_nil assigns(:lat)
325 assert_nil assigns(:lon)
326 assert_nil assigns(:zoom)
329 # Test editing a specific note
330 def test_edit_with_note
332 note = create(:note) do |n|
333 n.comments.create(:author_id => user.id)
336 get :edit, :params => { :note => note.id }, :session => { :user => user }
337 assert_response :success
338 assert_template "edit"
339 assert_equal 1.0, assigns(:lat)
340 assert_equal 1.0, assigns(:lon)
341 assert_equal 17, assigns(:zoom)
344 # Test editing inaccessible notes
345 def test_edit_with_inaccessible_notes
347 deleted_note = create(:note, :status => "hidden") do |n|
348 n.comments.create(:author_id => user.id)
351 get :edit, :params => { :note => 99999 }, :session => { :user => user }
352 assert_response :success
353 assert_template "edit"
354 assert_nil assigns(:lat)
355 assert_nil assigns(:lon)
356 assert_nil assigns(:zoom)
358 get :edit, :params => { :note => deleted_note.id }, :session => { :user => user }
359 assert_response :success
360 assert_template "edit"
361 assert_nil assigns(:lat)
362 assert_nil assigns(:lon)
363 assert_nil assigns(:zoom)
366 # Test editing a specific GPX trace
367 def test_edit_with_gpx
369 gpx = create(:trace, :latitude => 1, :longitude => 1)
371 get :edit, :params => { :gpx => gpx.id }, :session => { :user => user }
372 assert_response :success
373 assert_template "edit"
374 assert_equal 1.0, assigns(:lat)
375 assert_equal 1.0, assigns(:lon)
376 assert_equal 16, assigns(:zoom)
379 # Test editing inaccessible GPX traces
380 def test_edit_with_inaccessible_gpxes
382 deleted_gpx = create(:trace, :deleted, :latitude => 1, :longitude => 1)
383 private_gpx = create(:trace, :latitude => 1, :longitude => 1, :visibility => "private")
385 get :edit, :params => { :gpx => 99999 }, :session => { :user => user }
386 assert_response :success
387 assert_template "edit"
388 assert_nil assigns(:lat)
389 assert_nil assigns(:lon)
390 assert_nil assigns(:zoom)
392 get :edit, :params => { :gpx => deleted_gpx.id }, :session => { :user => user }
393 assert_response :success
394 assert_template "edit"
395 assert_nil assigns(:lat)
396 assert_nil assigns(:lon)
397 assert_nil assigns(:zoom)
399 get :edit, :params => { :gpx => private_gpx.id }, :session => { :user => user }
400 assert_response :success
401 assert_template "edit"
402 assert_nil assigns(:lat)
403 assert_nil assigns(:lon)
404 assert_nil assigns(:zoom)
407 # Test the edit page redirects
408 def test_edit_redirect
409 get :edit, :params => { :lat => 4, :lon => 5 }
410 assert_redirected_to :controller => :site, :action => :edit, :anchor => "map=5/4/5"
412 get :edit, :params => { :lat => 4, :lon => 5, :zoom => 3 }
413 assert_redirected_to :controller => :site, :action => :edit, :anchor => "map=3/4/5"
415 get :edit, :params => { :lat => 4, :lon => 5, :zoom => 3, :editor => "id" }
416 assert_redirected_to :controller => :site, :action => :edit, :editor => "id", :anchor => "map=3/4/5"
419 # Test the copyright page
422 assert_response :success
423 assert_template "copyright"
426 # Test the welcome page
429 assert_response :redirect
430 assert_redirected_to :controller => :users, :action => :login, :referer => "/welcome"
432 get :welcome, :session => { :user => create(:user) }
433 assert_response :success
434 assert_template "welcome"
437 # Test the fixthemap page
440 assert_response :success
441 assert_template "fixthemap"
447 assert_response :success
448 assert_template "help"
451 # Test the about page
454 assert_response :success
455 assert_template "about"
458 # Test the export page
461 assert_response :success
462 assert_template "export"
463 assert_template :layout => "map"
465 get :export, :xhr => true
466 assert_response :success
467 assert_template "export"
468 assert_template :layout => "xhr"
471 # Test the offline page
474 assert_response :success
475 assert_template "offline"
478 # Test the rich text preview
480 post :preview, :xhr => true, :params => { :type => "html" }
481 assert_response :success
483 post :preview, :xhr => true, :params => { :type => "markdown" }
484 assert_response :success
486 post :preview, :xhr => true, :params => { :type => "text" }
487 assert_response :success
492 get :id, :session => { :user => create(:user) }
493 assert_response :success
495 assert_template :layout => false