1 require File.dirname(__FILE__) + '/../test_helper'
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'
120 assert_response :success
121 assert_template "key"
122 assert_template :layout => false
125 # Test the edit page redirects when you aren't logged in
128 assert_response :redirect
129 assert_redirected_to :controller => :user, :action => :login, :referer => "/edit"
132 # Test the right editor gets used when the user hasn't set a preference
133 def test_edit_without_preference
134 get :edit, nil, { :user => users(:public_user).id }
135 assert_response :success
136 assert_template "edit"
137 assert_template :partial => "_#{DEFAULT_EDITOR}", :count => 1
140 # Test the right editor gets used when the user has set a preference
141 def test_edit_with_preference
142 user = users(:public_user)
143 user.preferred_editor = "id"
146 get :edit, nil, { :user => user.id }
147 assert_response :success
148 assert_template "edit"
149 assert_template :partial => "_id", :count => 1
151 user = users(:public_user)
152 user.preferred_editor = "potlatch2"
155 get :edit, nil, { :user => user.id }
156 assert_response :success
157 assert_template "edit"
158 assert_template :partial => "_potlatch2", :count => 1
160 user = users(:public_user)
161 user.preferred_editor = "potlatch"
164 get :edit, nil, { :user => user.id }
165 assert_response :success
166 assert_template "edit"
167 assert_template :partial => "_potlatch", :count => 1
169 user = users(:public_user)
170 user.preferred_editor = "remote"
173 get :edit, nil, { :user => user.id }
174 assert_response :success
175 assert_template "index"
178 # Test editing a specific node
179 def test_edit_with_node
180 user = users(:public_user)
181 node = current_nodes(:visible_node)
183 get :edit, { :node => node.id }, { :user => user.id }
184 assert_response :success
185 assert_template "edit"
186 assert_equal 1.0, assigns(:lat)
187 assert_equal 1.0, assigns(:lon)
188 assert_equal 18, assigns(:zoom)
191 # Test editing a specific way
192 def test_edit_with_way
193 user = users(:public_user)
194 way = current_ways(:visible_way)
196 get :edit, { :way => way.id }, { :user => user.id }
197 assert_response :success
198 assert_template "edit"
199 assert_equal 3.0, assigns(:lat)
200 assert_equal 3.0, assigns(:lon)
201 assert_equal 17, assigns(:zoom)
204 # Test editing a specific note
205 def test_edit_with_note
206 user = users(:public_user)
207 note = notes(:open_note)
209 get :edit, { :note => note.id }, { :user => user.id }
210 assert_response :success
211 assert_template "edit"
212 assert_equal 1.0, assigns(:lat)
213 assert_equal 1.0, assigns(:lon)
214 assert_equal 17, assigns(:zoom)
217 # Test editing a specific GPX trace
218 def test_edit_with_gpx
219 user = users(:public_user)
220 gpx = gpx_files(:public_trace_file)
222 get :edit, { :gpx => gpx.id }, { :user => user.id }
223 assert_response :success
224 assert_template "edit"
225 assert_equal 1.0, assigns(:lat)
226 assert_equal 1.0, assigns(:lon)
227 assert_equal 16, assigns(:zoom)
230 # Test the edit page redirects
231 def test_edit_redirect
232 get :edit, :lat => 4, :lon => 5
233 assert_redirected_to :controller => :site, :action => :edit, :anchor => 'map=5/4/5'
235 get :edit, :lat => 4, :lon => 5, :zoom => 3
236 assert_redirected_to :controller => :site, :action => :edit, :anchor => 'map=3/4/5'
238 get :edit, :lat => 4, :lon => 5, :zoom => 3, :editor => 'id'
239 assert_redirected_to :controller => :site, :action => :edit, :editor => 'id', :anchor => 'map=3/4/5'
242 # Test the copyright page
245 assert_response :success
246 assert_template "copyright"
249 # Test the welcome page
252 assert_response :redirect
253 assert_redirected_to :controller => :user, :action => :login, :referer => "/welcome"
255 get :welcome, nil, { :user => users(:public_user).id }
256 assert_response :success
257 assert_template "welcome"
260 # Test the fixthemap page
263 assert_response :success
264 assert_template "fixthemap"
270 assert_response :success
271 assert_template "help"
274 # Test the about page
277 assert_response :success
278 assert_template "about"
281 # Test the export page
284 assert_response :success
285 assert_template "export"
286 assert_template :layout => "map"
289 assert_response :success
290 assert_template "export"
291 assert_template :layout => "xhr"
294 # Test the offline page
297 assert_response :success
298 assert_template "offline"
301 # Test the rich text preview
303 xhr :post, :preview, :format => "html"
304 assert_response :success
306 xhr :post, :preview, :format => "markdown"
307 assert_response :success
309 xhr :post, :preview, :format => "text"
310 assert_response :success
315 get :id, nil, { :user => users(:public_user).id }
316 assert_response :success
318 assert_template :layout => false