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 => "/export", :method => :get },
53 { :controller => "site", :action => "export" }
56 { :controller => "site", :action => "export", :format => "html" },
57 { :path => "/export.html", :method => :get }
60 { :path => "/offline", :method => :get },
61 { :controller => "site", :action => "offline" }
64 { :path => "/key", :method => :get },
65 { :controller => "site", :action => "key" }
68 { :path => "/go/shortcode", :method => :get },
69 { :controller => "site", :action => "permalink", :code => "shortcode" }
72 { :path => "/preview/formatname", :method => :post },
73 { :controller => "site", :action => "preview", :format => "formatname" }
76 { :path => "/id", :method => :get },
77 { :controller => "site", :action => "id" }
84 assert_response :success
85 assert_template 'index'
88 # Test the index page redirects
89 def test_index_redirect
90 get :index, :lat => 4, :lon => 5
91 assert_redirected_to :controller => :site, :action => :index, :anchor => 'map=5/4/5'
93 get :index, :lat => 4, :lon => 5, :zoom => 3
94 assert_redirected_to :controller => :site, :action => :index, :anchor => 'map=3/4/5'
96 get :index, :layers => 'T'
97 assert_redirected_to :controller => :site, :action => :index, :anchor => 'layers=T'
99 get :index, :notes => 'yes'
100 assert_redirected_to :controller => :site, :action => :index, :anchor => 'layers=N'
102 get :index, :lat => 4, :lon => 5, :zoom => 3, :layers => 'T'
103 assert_redirected_to :controller => :site, :action => :index, :anchor => 'map=3/4/5&layers=T'
106 # Test the permalink redirect
108 get :permalink, :code => 'wBz3--'
109 assert_response :redirect
110 assert_redirected_to :controller => :site, :action => :index, :anchor => 'map=3/4.8779296875/3.955078125'
116 assert_response :success
117 assert_template "key"
118 assert_template :layout => false
121 # Test the edit page redirects when you aren't logged in
124 assert_response :redirect
125 assert_redirected_to :controller => :user, :action => :login, :referer => "/edit"
128 # Test the right editor gets used when the user hasn't set a preference
129 def test_edit_without_preference
130 get :edit, nil, { :user => users(:public_user).id }
131 assert_response :success
132 assert_template "edit"
133 assert_template :partial => "_#{DEFAULT_EDITOR}", :count => 1
136 # Test the right editor gets used when the user has set a preference
137 def test_edit_with_preference
138 user = users(:public_user)
139 user.preferred_editor = "id"
142 get :edit, nil, { :user => user.id }
143 assert_response :success
144 assert_template "edit"
145 assert_template :partial => "_id", :count => 1
147 user = users(:public_user)
148 user.preferred_editor = "potlatch2"
151 get :edit, nil, { :user => user.id }
152 assert_response :success
153 assert_template "edit"
154 assert_template :partial => "_potlatch2", :count => 1
156 user = users(:public_user)
157 user.preferred_editor = "potlatch"
160 get :edit, nil, { :user => user.id }
161 assert_response :success
162 assert_template "edit"
163 assert_template :partial => "_potlatch", :count => 1
165 user = users(:public_user)
166 user.preferred_editor = "remote"
169 get :edit, nil, { :user => user.id }
170 assert_response :success
171 assert_template "index"
174 # Test editing a specific node
175 def test_edit_with_node
176 user = users(:public_user)
177 node = current_nodes(:visible_node)
179 get :edit, { :node => node.id }, { :user => user.id }
180 assert_response :success
181 assert_template "edit"
182 assert_equal 1.0, assigns(:lat)
183 assert_equal 1.0, assigns(:lon)
184 assert_equal 18, assigns(:zoom)
187 # Test editing a specific way
188 def test_edit_with_way
189 user = users(:public_user)
190 way = current_ways(:visible_way)
192 get :edit, { :way => way.id }, { :user => user.id }
193 assert_response :success
194 assert_template "edit"
195 assert_equal 3.0, assigns(:lat)
196 assert_equal 3.0, assigns(:lon)
197 assert_equal 17, assigns(:zoom)
200 # Test editing a specific note
201 def test_edit_with_note
202 user = users(:public_user)
203 note = notes(:open_note)
205 get :edit, { :note => note.id }, { :user => user.id }
206 assert_response :success
207 assert_template "edit"
208 assert_equal 1.0, assigns(:lat)
209 assert_equal 1.0, assigns(:lon)
210 assert_equal 17, assigns(:zoom)
213 # Test editing a specific GPX trace
214 def test_edit_with_gpx
215 user = users(:public_user)
216 gpx = gpx_files(:public_trace_file)
218 get :edit, { :gpx => gpx.id }, { :user => user.id }
219 assert_response :success
220 assert_template "edit"
221 assert_equal 1.0, assigns(:lat)
222 assert_equal 1.0, assigns(:lon)
223 assert_equal 16, assigns(:zoom)
226 # Test the edit page redirects
227 def test_edit_redirect
228 get :edit, :lat => 4, :lon => 5
229 assert_redirected_to :controller => :site, :action => :edit, :anchor => 'map=5/4/5'
231 get :edit, :lat => 4, :lon => 5, :zoom => 3
232 assert_redirected_to :controller => :site, :action => :edit, :anchor => 'map=3/4/5'
234 get :edit, :lat => 4, :lon => 5, :zoom => 3, :editor => 'id'
235 assert_redirected_to :controller => :site, :action => :edit, :editor => 'id', :anchor => 'map=3/4/5'
238 # Test the copyright page
241 assert_response :success
242 assert_template "copyright"
245 # Test the welcome page
248 assert_response :redirect
249 assert_redirected_to :controller => :user, :action => :login, :referer => "/welcome"
251 get :welcome, nil, { :user => users(:public_user).id }
252 assert_response :success
253 assert_template "welcome"
259 assert_response :success
260 assert_template "help"
263 # Test the about page
266 assert_response :success
267 assert_template "about"
270 # Test the export page
273 assert_response :success
274 assert_template "export"
275 assert_template :layout => "map"
278 assert_response :success
279 assert_template "export"
280 assert_template :layout => "xhr"
283 # Test the offline page
286 assert_response :success
287 assert_template "offline"
290 # Test the rich text preview
292 xhr :post, :preview, :format => "html"
293 assert_response :success
295 xhr :post, :preview, :format => "markdown"
296 assert_response :success
298 xhr :post, :preview, :format => "text"
299 assert_response :success
304 get :id, nil, { :user => users(:public_user).id }
305 assert_response :success
307 assert_template :layout => false