##// END OF EJS Templates
remove trailing white-spaces from test/functional/wiki_controller_test.rb....
Toshi MARUYAMA -
r6438:78dba8073bdb
parent child
Show More
@@ -1,521 +1,521
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2011 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.expand_path('../../test_helper', __FILE__)
19 19 require 'wiki_controller'
20 20
21 21 # Re-raise errors caught by the controller.
22 22 class WikiController; def rescue_action(e) raise e end; end
23 23
24 24 class WikiControllerTest < ActionController::TestCase
25 25 fixtures :projects, :users, :roles, :members, :member_roles, :enabled_modules, :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions, :attachments
26 26
27 27 def setup
28 28 @controller = WikiController.new
29 29 @request = ActionController::TestRequest.new
30 30 @response = ActionController::TestResponse.new
31 31 User.current = nil
32 32 end
33 33
34 34 def test_show_start_page
35 35 get :show, :project_id => 'ecookbook'
36 36 assert_response :success
37 37 assert_template 'show'
38 38 assert_tag :tag => 'h1', :content => /CookBook documentation/
39 39
40 40 # child_pages macro
41 41 assert_tag :ul, :attributes => { :class => 'pages-hierarchy' },
42 42 :child => { :tag => 'li',
43 43 :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Page_with_an_inline_image' },
44 44 :content => 'Page with an inline image' } }
45 45 end
46 46
47 47 def test_show_page_with_name
48 48 get :show, :project_id => 1, :id => 'Another_page'
49 49 assert_response :success
50 50 assert_template 'show'
51 51 assert_tag :tag => 'h1', :content => /Another page/
52 52 # Included page with an inline image
53 53 assert_tag :tag => 'p', :content => /This is an inline image/
54 54 assert_tag :tag => 'img', :attributes => { :src => '/attachments/download/3',
55 55 :alt => 'This is a logo' }
56 56 end
57 57
58 58 def test_show_redirected_page
59 59 WikiRedirect.create!(:wiki_id => 1, :title => 'Old_title', :redirects_to => 'Another_page')
60 60
61 61 get :show, :project_id => 'ecookbook', :id => 'Old_title'
62 62 assert_redirected_to '/projects/ecookbook/wiki/Another_page'
63 63 end
64 64
65 65 def test_show_with_sidebar
66 66 page = Project.find(1).wiki.pages.new(:title => 'Sidebar')
67 67 page.content = WikiContent.new(:text => 'Side bar content for test_show_with_sidebar')
68 68 page.save!
69 69
70 70 get :show, :project_id => 1, :id => 'Another_page'
71 71 assert_response :success
72 72 assert_tag :tag => 'div', :attributes => {:id => 'sidebar'},
73 73 :content => /Side bar content for test_show_with_sidebar/
74 74 end
75 75
76 76 def test_show_unexistent_page_without_edit_right
77 77 get :show, :project_id => 1, :id => 'Unexistent page'
78 78 assert_response 404
79 79 end
80 80
81 81 def test_show_unexistent_page_with_edit_right
82 82 @request.session[:user_id] = 2
83 83 get :show, :project_id => 1, :id => 'Unexistent page'
84 84 assert_response :success
85 85 assert_template 'edit'
86 86 end
87 87
88 88 def test_create_page
89 89 @request.session[:user_id] = 2
90 90 put :update, :project_id => 1,
91 91 :id => 'New page',
92 92 :content => {:comments => 'Created the page',
93 93 :text => "h1. New page\n\nThis is a new page",
94 94 :version => 0}
95 95 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'New_page'
96 96 page = Project.find(1).wiki.find_page('New page')
97 97 assert !page.new_record?
98 98 assert_not_nil page.content
99 99 assert_equal 'Created the page', page.content.comments
100 100 end
101 101
102 102 def test_create_page_with_attachments
103 103 @request.session[:user_id] = 2
104 104 assert_difference 'WikiPage.count' do
105 105 assert_difference 'Attachment.count' do
106 106 put :update, :project_id => 1,
107 107 :id => 'New page',
108 108 :content => {:comments => 'Created the page',
109 109 :text => "h1. New page\n\nThis is a new page",
110 110 :version => 0},
111 111 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
112 112 end
113 113 end
114 114 page = Project.find(1).wiki.find_page('New page')
115 115 assert_equal 1, page.attachments.count
116 116 assert_equal 'testfile.txt', page.attachments.first.filename
117 117 end
118 118
119 119 def test_update_page
120 120 @request.session[:user_id] = 2
121 121 assert_no_difference 'WikiPage.count' do
122 122 assert_no_difference 'WikiContent.count' do
123 123 assert_difference 'WikiContent::Version.count' do
124 124 put :update, :project_id => 1,
125 125 :id => 'Another_page',
126 126 :content => {
127 127 :comments => "my comments",
128 128 :text => "edited",
129 129 :version => 1
130 130 }
131 131 end
132 132 end
133 133 end
134 134 assert_redirected_to '/projects/ecookbook/wiki/Another_page'
135 135
136 136 page = Wiki.find(1).pages.find_by_title('Another_page')
137 137 assert_equal "edited", page.content.text
138 138 assert_equal 2, page.content.version
139 139 assert_equal "my comments", page.content.comments
140 140 end
141 141
142 142 def test_update_page_with_failure
143 143 @request.session[:user_id] = 2
144 144 assert_no_difference 'WikiPage.count' do
145 145 assert_no_difference 'WikiContent.count' do
146 146 assert_no_difference 'WikiContent::Version.count' do
147 147 put :update, :project_id => 1,
148 148 :id => 'Another_page',
149 149 :content => {
150 150 :comments => 'a' * 300, # failure here, comment is too long
151 151 :text => 'edited',
152 152 :version => 1
153 153 }
154 154 end
155 155 end
156 156 end
157 157 assert_response :success
158 158 assert_template 'edit'
159 159
160 160 assert_error_tag :descendant => {:content => /Comment is too long/}
161 161 assert_tag :tag => 'textarea', :attributes => {:id => 'content_text'}, :content => 'edited'
162 162 assert_tag :tag => 'input', :attributes => {:id => 'content_version', :value => '1'}
163 163 end
164 164
165 165 def test_update_stale_page_should_not_raise_an_error
166 166 @request.session[:user_id] = 2
167 167 c = Wiki.find(1).find_page('Another_page').content
168 168 c.text = 'Previous text'
169 169 c.save!
170 170 assert_equal 2, c.version
171 171
172 172 assert_no_difference 'WikiPage.count' do
173 173 assert_no_difference 'WikiContent.count' do
174 174 assert_no_difference 'WikiContent::Version.count' do
175 175 put :update, :project_id => 1,
176 176 :id => 'Another_page',
177 177 :content => {
178 178 :comments => 'My comments',
179 179 :text => 'Text should not be lost',
180 180 :version => 1
181 181 }
182 182 end
183 183 end
184 184 end
185 185 assert_response :success
186 186 assert_template 'edit'
187 187 assert_tag :div,
188 188 :attributes => { :class => /error/ },
189 189 :content => /Data has been updated by another user/
190 190 assert_tag 'textarea',
191 191 :attributes => { :name => 'content[text]' },
192 192 :content => /Text should not be lost/
193 193 assert_tag 'input',
194 194 :attributes => { :name => 'content[comments]', :value => 'My comments' }
195 195
196 196 c.reload
197 197 assert_equal 'Previous text', c.text
198 198 assert_equal 2, c.version
199 199 end
200 200
201 201 def test_preview
202 202 @request.session[:user_id] = 2
203 203 xhr :post, :preview, :project_id => 1, :id => 'CookBook_documentation',
204 204 :content => { :comments => '',
205 205 :text => 'this is a *previewed text*',
206 206 :version => 3 }
207 207 assert_response :success
208 208 assert_template 'common/_preview'
209 209 assert_tag :tag => 'strong', :content => /previewed text/
210 210 end
211 211
212 212 def test_preview_new_page
213 213 @request.session[:user_id] = 2
214 214 xhr :post, :preview, :project_id => 1, :id => 'New page',
215 215 :content => { :text => 'h1. New page',
216 216 :comments => '',
217 217 :version => 0 }
218 218 assert_response :success
219 219 assert_template 'common/_preview'
220 220 assert_tag :tag => 'h1', :content => /New page/
221 221 end
222 222
223 223 def test_history
224 224 get :history, :project_id => 1, :id => 'CookBook_documentation'
225 225 assert_response :success
226 226 assert_template 'history'
227 227 assert_not_nil assigns(:versions)
228 228 assert_equal 3, assigns(:versions).size
229 229 assert_select "input[type=submit][name=commit]"
230 230 end
231 231
232 232 def test_history_with_one_version
233 233 get :history, :project_id => 1, :id => 'Another_page'
234 234 assert_response :success
235 235 assert_template 'history'
236 236 assert_not_nil assigns(:versions)
237 237 assert_equal 1, assigns(:versions).size
238 238 assert_select "input[type=submit][name=commit]", false
239 239 end
240 240
241 241 def test_diff
242 242 get :diff, :project_id => 1, :id => 'CookBook_documentation', :version => 2, :version_from => 1
243 243 assert_response :success
244 244 assert_template 'diff'
245 245 assert_tag :tag => 'span', :attributes => { :class => 'diff_in'},
246 246 :content => /updated/
247 247 end
248 248
249 249 def test_annotate
250 250 get :annotate, :project_id => 1, :id => 'CookBook_documentation', :version => 2
251 251 assert_response :success
252 252 assert_template 'annotate'
253
253
254 254 # Line 1
255 255 assert_tag :tag => 'tr', :child => {
256 256 :tag => 'th', :attributes => {:class => 'line-num'}, :content => '1', :sibling => {
257 257 :tag => 'td', :attributes => {:class => 'author'}, :content => /John Smith/, :sibling => {
258 258 :tag => 'td', :content => /h1\. CookBook documentation/
259 259 }
260 260 }
261 261 }
262
262
263 263 # Line 5
264 264 assert_tag :tag => 'tr', :child => {
265 265 :tag => 'th', :attributes => {:class => 'line-num'}, :content => '5', :sibling => {
266 266 :tag => 'td', :attributes => {:class => 'author'}, :content => /redMine Admin/, :sibling => {
267 267 :tag => 'td', :content => /Some updated \[\[documentation\]\] here/
268 268 }
269 269 }
270 270 }
271 271 end
272 272
273 273 def test_get_rename
274 274 @request.session[:user_id] = 2
275 275 get :rename, :project_id => 1, :id => 'Another_page'
276 276 assert_response :success
277 277 assert_template 'rename'
278 278 assert_tag 'option',
279 279 :attributes => {:value => ''},
280 280 :content => '',
281 281 :parent => {:tag => 'select', :attributes => {:name => 'wiki_page[parent_id]'}}
282 282 assert_no_tag 'option',
283 283 :attributes => {:selected => 'selected'},
284 284 :parent => {:tag => 'select', :attributes => {:name => 'wiki_page[parent_id]'}}
285 285 end
286 286
287 287 def test_get_rename_child_page
288 288 @request.session[:user_id] = 2
289 289 get :rename, :project_id => 1, :id => 'Child_1'
290 290 assert_response :success
291 291 assert_template 'rename'
292 292 assert_tag 'option',
293 293 :attributes => {:value => ''},
294 294 :content => '',
295 295 :parent => {:tag => 'select', :attributes => {:name => 'wiki_page[parent_id]'}}
296 296 assert_tag 'option',
297 297 :attributes => {:value => '2', :selected => 'selected'},
298 298 :content => /Another page/,
299 299 :parent => {
300 300 :tag => 'select',
301 301 :attributes => {:name => 'wiki_page[parent_id]'}
302 302 }
303 303 end
304 304
305 305 def test_rename_with_redirect
306 306 @request.session[:user_id] = 2
307 307 post :rename, :project_id => 1, :id => 'Another_page',
308 308 :wiki_page => { :title => 'Another renamed page',
309 309 :redirect_existing_links => 1 }
310 310 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_renamed_page'
311 311 wiki = Project.find(1).wiki
312 312 # Check redirects
313 313 assert_not_nil wiki.find_page('Another page')
314 314 assert_nil wiki.find_page('Another page', :with_redirect => false)
315 315 end
316 316
317 317 def test_rename_without_redirect
318 318 @request.session[:user_id] = 2
319 319 post :rename, :project_id => 1, :id => 'Another_page',
320 320 :wiki_page => { :title => 'Another renamed page',
321 321 :redirect_existing_links => "0" }
322 322 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_renamed_page'
323 323 wiki = Project.find(1).wiki
324 324 # Check that there's no redirects
325 325 assert_nil wiki.find_page('Another page')
326 326 end
327 327
328 328 def test_rename_with_parent_assignment
329 329 @request.session[:user_id] = 2
330 330 post :rename, :project_id => 1, :id => 'Another_page',
331 331 :wiki_page => { :title => 'Another page', :redirect_existing_links => "0", :parent_id => '4' }
332 332 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_page'
333 333 assert_equal WikiPage.find(4), WikiPage.find_by_title('Another_page').parent
334 334 end
335 335
336 336 def test_rename_with_parent_unassignment
337 337 @request.session[:user_id] = 2
338 338 post :rename, :project_id => 1, :id => 'Child_1',
339 339 :wiki_page => { :title => 'Child 1', :redirect_existing_links => "0", :parent_id => '' }
340 340 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Child_1'
341 341 assert_nil WikiPage.find_by_title('Child_1').parent
342 342 end
343 343
344 344 def test_destroy_child
345 345 @request.session[:user_id] = 2
346 346 delete :destroy, :project_id => 1, :id => 'Child_1'
347 347 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
348 348 end
349 349
350 350 def test_destroy_parent
351 351 @request.session[:user_id] = 2
352 352 assert_no_difference('WikiPage.count') do
353 353 delete :destroy, :project_id => 1, :id => 'Another_page'
354 354 end
355 355 assert_response :success
356 356 assert_template 'destroy'
357 357 end
358 358
359 359 def test_destroy_parent_with_nullify
360 360 @request.session[:user_id] = 2
361 361 assert_difference('WikiPage.count', -1) do
362 362 delete :destroy, :project_id => 1, :id => 'Another_page', :todo => 'nullify'
363 363 end
364 364 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
365 365 assert_nil WikiPage.find_by_id(2)
366 366 end
367 367
368 368 def test_destroy_parent_with_cascade
369 369 @request.session[:user_id] = 2
370 370 assert_difference('WikiPage.count', -3) do
371 371 delete :destroy, :project_id => 1, :id => 'Another_page', :todo => 'destroy'
372 372 end
373 373 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
374 374 assert_nil WikiPage.find_by_id(2)
375 375 assert_nil WikiPage.find_by_id(5)
376 376 end
377 377
378 378 def test_destroy_parent_with_reassign
379 379 @request.session[:user_id] = 2
380 380 assert_difference('WikiPage.count', -1) do
381 381 delete :destroy, :project_id => 1, :id => 'Another_page', :todo => 'reassign', :reassign_to_id => 1
382 382 end
383 383 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
384 384 assert_nil WikiPage.find_by_id(2)
385 385 assert_equal WikiPage.find(1), WikiPage.find_by_id(5).parent
386 386 end
387 387
388 388 def test_index
389 389 get :index, :project_id => 'ecookbook'
390 390 assert_response :success
391 391 assert_template 'index'
392 392 pages = assigns(:pages)
393 393 assert_not_nil pages
394 394 assert_equal Project.find(1).wiki.pages.size, pages.size
395 395 assert_equal pages.first.content.updated_on, pages.first.updated_on
396 396
397 397 assert_tag :ul, :attributes => { :class => 'pages-hierarchy' },
398 398 :child => { :tag => 'li', :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/CookBook_documentation' },
399 399 :content => 'CookBook documentation' },
400 400 :child => { :tag => 'ul',
401 401 :child => { :tag => 'li',
402 402 :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Page_with_an_inline_image' },
403 403 :content => 'Page with an inline image' } } } },
404 404 :child => { :tag => 'li', :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Another_page' },
405 405 :content => 'Another page' } }
406 406 end
407 407
408 408 def test_index_should_include_atom_link
409 409 get :index, :project_id => 'ecookbook'
410 410 assert_tag 'a', :attributes => { :href => '/projects/ecookbook/activity.atom?show_wiki_edits=1'}
411 411 end
412 412
413 413 context "GET :export" do
414 414 context "with an authorized user to export the wiki" do
415 415 setup do
416 416 @request.session[:user_id] = 2
417 417 get :export, :project_id => 'ecookbook'
418 418 end
419 419
420 420 should_respond_with :success
421 421 should_assign_to :pages
422 422 should_respond_with_content_type "text/html"
423 423 should "export all of the wiki pages to a single html file" do
424 424 assert_select "a[name=?]", "CookBook_documentation"
425 425 assert_select "a[name=?]", "Another_page"
426 426 assert_select "a[name=?]", "Page_with_an_inline_image"
427 427 end
428 428
429 429 end
430 430
431 431 context "with an unauthorized user" do
432 432 setup do
433 433 get :export, :project_id => 'ecookbook'
434 434
435 435 should_respond_with :redirect
436 436 should_redirect_to('wiki index') { {:action => 'show', :project_id => @project, :id => nil} }
437 437 end
438 438 end
439 439 end
440 440
441 441 context "GET :date_index" do
442 442 setup do
443 443 get :date_index, :project_id => 'ecookbook'
444 444 end
445 445
446 446 should_respond_with :success
447 447 should_assign_to :pages
448 448 should_assign_to :pages_by_date
449 449 should_render_template 'wiki/date_index'
450 450
451 451 should "include atom link" do
452 452 assert_tag 'a', :attributes => { :href => '/projects/ecookbook/activity.atom?show_wiki_edits=1'}
453 453 end
454 454 end
455 455
456 456 def test_not_found
457 457 get :show, :project_id => 999
458 458 assert_response 404
459 459 end
460 460
461 461 def test_protect_page
462 462 page = WikiPage.find_by_wiki_id_and_title(1, 'Another_page')
463 463 assert !page.protected?
464 464 @request.session[:user_id] = 2
465 465 post :protect, :project_id => 1, :id => page.title, :protected => '1'
466 466 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_page'
467 467 assert page.reload.protected?
468 468 end
469 469
470 470 def test_unprotect_page
471 471 page = WikiPage.find_by_wiki_id_and_title(1, 'CookBook_documentation')
472 472 assert page.protected?
473 473 @request.session[:user_id] = 2
474 474 post :protect, :project_id => 1, :id => page.title, :protected => '0'
475 475 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'CookBook_documentation'
476 476 assert !page.reload.protected?
477 477 end
478 478
479 479 def test_show_page_with_edit_link
480 480 @request.session[:user_id] = 2
481 481 get :show, :project_id => 1
482 482 assert_response :success
483 483 assert_template 'show'
484 484 assert_tag :tag => 'a', :attributes => { :href => '/projects/1/wiki/CookBook_documentation/edit' }
485 485 end
486 486
487 487 def test_show_page_without_edit_link
488 488 @request.session[:user_id] = 4
489 489 get :show, :project_id => 1
490 490 assert_response :success
491 491 assert_template 'show'
492 492 assert_no_tag :tag => 'a', :attributes => { :href => '/projects/1/wiki/CookBook_documentation/edit' }
493 493 end
494 494
495 495 def test_edit_unprotected_page
496 496 # Non members can edit unprotected wiki pages
497 497 @request.session[:user_id] = 4
498 498 get :edit, :project_id => 1, :id => 'Another_page'
499 499 assert_response :success
500 500 assert_template 'edit'
501 501 end
502 502
503 503 def test_edit_protected_page_by_nonmember
504 504 # Non members can't edit protected wiki pages
505 505 @request.session[:user_id] = 4
506 506 get :edit, :project_id => 1, :id => 'CookBook_documentation'
507 507 assert_response 403
508 508 end
509 509
510 510 def test_edit_protected_page_by_member
511 511 @request.session[:user_id] = 2
512 512 get :edit, :project_id => 1, :id => 'CookBook_documentation'
513 513 assert_response :success
514 514 assert_template 'edit'
515 515 end
516 516
517 517 def test_history_of_non_existing_page_should_return_404
518 518 get :history, :project_id => 1, :id => 'Unknown_page'
519 519 assert_response 404
520 520 end
521 521 end
General Comments 0
You need to be logged in to leave comments. Login now