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, :node => 123
95 assert_redirected_to :controller => :browse, :action => :node, :id => 123
97 get :index, :way => 123
98 assert_redirected_to :controller => :browse, :action => :way, :id => 123
100 get :index, :relation => 123
101 assert_redirected_to :controller => :browse, :action => :relation, :id => 123
103 get :index, :note => 123
104 assert_redirected_to :controller => :browse, :action => :note, :id => 123
106 get :index, :query => "test"
107 assert_redirected_to :controller => :geocoder, :action => :search, :query => "test"
109 get :index, :lat => 4, :lon => 5
110 assert_redirected_to :controller => :site, :action => :index, :anchor => "map=5/4/5"
112 get :index, :lat => 4, :lon => 5, :zoom => 3
113 assert_redirected_to :controller => :site, :action => :index, :anchor => "map=3/4/5"
115 get :index, :layers => "T"
116 assert_redirected_to :controller => :site, :action => :index, :anchor => "layers=T"
118 get :index, :notes => "yes"
119 assert_redirected_to :controller => :site, :action => :index, :anchor => "layers=N"
121 get :index, :lat => 4, :lon => 5, :zoom => 3, :layers => "T"
122 assert_redirected_to :controller => :site, :action => :index, :anchor => "map=3/4/5&layers=T"
125 # Test the permalink redirect
127 get :permalink, :code => "wBz3--"
128 assert_response :redirect
129 assert_redirected_to :controller => :site, :action => :index, :anchor => "map=3/4.8779296875/3.955078125"
131 get :permalink, :code => "wBz3--", :m => ""
132 assert_response :redirect
133 assert_redirected_to :controller => :site, :action => :index, :mlat => "4.8779296875", :mlon => "3.955078125", :anchor => "map=3/4.8779296875/3.955078125"
135 get :permalink, :code => "wBz3--", :layers => "T"
136 assert_response :redirect
137 assert_redirected_to :controller => :site, :action => :index, :anchor => "map=3/4.8779296875/3.955078125&layers=T"
139 get :permalink, :code => "wBz3--", :node => 1
140 assert_response :redirect
141 assert_redirected_to :controller => :browse, :action => :node, :id => 1, :anchor => "map=3/4.8779296875/3.955078125"
143 get :permalink, :code => "wBz3--", :way => 2
144 assert_response :redirect
145 assert_redirected_to :controller => :browse, :action => :way, :id => 2, :anchor => "map=3/4.8779296875/3.955078125"
147 get :permalink, :code => "wBz3--", :relation => 3
148 assert_response :redirect
149 assert_redirected_to :controller => :browse, :action => :relation, :id => 3, :anchor => "map=3/4.8779296875/3.955078125"
151 get :permalink, :code => "wBz3--", :changeset => 4
152 assert_response :redirect
153 assert_redirected_to :controller => :browse, :action => :changeset, :id => 4, :anchor => "map=3/4.8779296875/3.955078125"
159 assert_response :success
160 assert_template "key"
161 assert_template :layout => false
164 # Test the edit page redirects when you aren't logged in
167 assert_response :redirect
168 assert_redirected_to :controller => :user, :action => :login, :referer => "/edit"
171 # Test the right editor gets used when the user hasn't set a preference
172 def test_edit_without_preference
173 get :edit, nil, :user => users(:public_user).id
174 assert_response :success
175 assert_template "edit"
176 assert_template :partial => "_#{DEFAULT_EDITOR}", :count => 1
179 # Test the right editor gets used when the user has set a preference
180 def test_edit_with_preference
181 user = users(:public_user)
182 user.preferred_editor = "id"
185 get :edit, nil, :user => user.id
186 assert_response :success
187 assert_template "edit"
188 assert_template :partial => "_id", :count => 1
190 user = users(:public_user)
191 user.preferred_editor = "potlatch2"
194 get :edit, nil, :user => user.id
195 assert_response :success
196 assert_template "edit"
197 assert_template :partial => "_potlatch2", :count => 1
199 user = users(:public_user)
200 user.preferred_editor = "potlatch"
203 get :edit, nil, :user => user.id
204 assert_response :success
205 assert_template "edit"
206 assert_template :partial => "_potlatch", :count => 1
208 user = users(:public_user)
209 user.preferred_editor = "remote"
212 get :edit, nil, :user => user.id
213 assert_response :success
214 assert_template "index"
217 # Test the right editor gets used when the URL has an override
218 def test_edit_with_override
219 get :edit, { :editor => "id" }, { :user => users(:public_user).id }
220 assert_response :success
221 assert_template "edit"
222 assert_template :partial => "_id", :count => 1
224 get :edit, { :editor => "potlatch2" }, { :user => users(:public_user).id }
225 assert_response :success
226 assert_template "edit"
227 assert_template :partial => "_potlatch2", :count => 1
229 get :edit, { :editor => "potlatch" }, { :user => users(:public_user).id }
230 assert_response :success
231 assert_template "edit"
232 assert_template :partial => "_potlatch", :count => 1
234 get :edit, { :editor => "remote" }, { :user => users(:public_user).id }
235 assert_response :success
236 assert_template "index"
239 # Test the right editor gets used when the browser is IE
240 def test_edit_with_ie
241 @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)"
243 get :edit, {}, { :user => users(:public_user).id }
244 assert_response :success
245 assert_template "edit"
246 assert_template :partial => "_potlatch2", :count => 1
248 get :edit, { :editor => "id" }, { :user => users(:public_user).id }
249 assert_response :success
250 assert_template "edit"
251 assert_template :partial => "_potlatch2", :count => 1
253 @request.env["HTTP_USER_AGENT"] = "Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko"
255 get :edit, {}, { :user => users(:public_user).id }
256 assert_response :success
257 assert_template "edit"
258 assert_template :partial => "_potlatch2", :count => 1
260 get :edit, { :editor => "id" }, { :user => users(:public_user).id }
261 assert_response :success
262 assert_template "edit"
263 assert_template :partial => "_potlatch2", :count => 1
266 # Test editing a specific node
267 def test_edit_with_node
268 user = users(:public_user)
269 node = current_nodes(:visible_node)
271 get :edit, { :node => node.id }, { :user => user.id }
272 assert_response :success
273 assert_template "edit"
274 assert_equal 1.0, assigns(:lat)
275 assert_equal 1.0, assigns(:lon)
276 assert_equal 18, assigns(:zoom)
279 # Test editing a specific way
280 def test_edit_with_way
281 user = users(:public_user)
282 way = current_ways(:visible_way)
284 get :edit, { :way => way.id }, { :user => user.id }
285 assert_response :success
286 assert_template "edit"
287 assert_equal 3.0, assigns(:lat)
288 assert_equal 3.0, assigns(:lon)
289 assert_equal 17, assigns(:zoom)
292 # Test editing a specific note
293 def test_edit_with_note
294 user = users(:public_user)
295 note = notes(:open_note)
297 get :edit, { :note => note.id }, { :user => user.id }
298 assert_response :success
299 assert_template "edit"
300 assert_equal 1.0, assigns(:lat)
301 assert_equal 1.0, assigns(:lon)
302 assert_equal 17, assigns(:zoom)
305 # Test editing a specific GPX trace
306 def test_edit_with_gpx
307 user = users(:public_user)
308 gpx = gpx_files(:public_trace_file)
310 get :edit, { :gpx => gpx.id }, { :user => user.id }
311 assert_response :success
312 assert_template "edit"
313 assert_equal 1.0, assigns(:lat)
314 assert_equal 1.0, assigns(:lon)
315 assert_equal 16, assigns(:zoom)
318 # Test the edit page redirects
319 def test_edit_redirect
320 get :edit, :lat => 4, :lon => 5
321 assert_redirected_to :controller => :site, :action => :edit, :anchor => "map=5/4/5"
323 get :edit, :lat => 4, :lon => 5, :zoom => 3
324 assert_redirected_to :controller => :site, :action => :edit, :anchor => "map=3/4/5"
326 get :edit, :lat => 4, :lon => 5, :zoom => 3, :editor => "id"
327 assert_redirected_to :controller => :site, :action => :edit, :editor => "id", :anchor => "map=3/4/5"
330 # Test the copyright page
333 assert_response :success
334 assert_template "copyright"
337 # Test the welcome page
340 assert_response :redirect
341 assert_redirected_to :controller => :user, :action => :login, :referer => "/welcome"
343 get :welcome, nil, :user => users(:public_user).id
344 assert_response :success
345 assert_template "welcome"
348 # Test the fixthemap page
351 assert_response :success
352 assert_template "fixthemap"
358 assert_response :success
359 assert_template "help"
362 # Test the about page
365 assert_response :success
366 assert_template "about"
369 # Test the export page
372 assert_response :success
373 assert_template "export"
374 assert_template :layout => "map"
377 assert_response :success
378 assert_template "export"
379 assert_template :layout => "xhr"
382 # Test the offline page
385 assert_response :success
386 assert_template "offline"
389 # Test the rich text preview
391 xhr :post, :preview, :format => "html"
392 assert_response :success
394 xhr :post, :preview, :format => "markdown"
395 assert_response :success
397 xhr :post, :preview, :format => "text"
398 assert_response :success
403 get :id, nil, :user => users(:public_user).id
404 assert_response :success
406 assert_template :layout => false