##// END OF EJS Templates
3.3-stable: fix test failure (#23700)...
Toshi MARUYAMA -
r15411:ceeca4a88d80
parent child
Show More
@@ -1,1031 +1,1031
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2016 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
20 20 class WikiControllerTest < ActionController::TestCase
21 21 fixtures :projects, :users, :email_addresses, :roles, :members, :member_roles,
22 22 :enabled_modules, :wikis, :wiki_pages, :wiki_contents,
23 23 :wiki_content_versions, :attachments,
24 24 :issues, :issue_statuses, :trackers
25 25
26 26 def setup
27 27 User.current = nil
28 28 end
29 29
30 30 def test_show_start_page
31 31 get :show, :project_id => 'ecookbook'
32 32 assert_response :success
33 33 assert_template 'show'
34 34 assert_select 'h1', :text => /CookBook documentation/
35 35
36 36 # child_pages macro
37 37 assert_select 'ul.pages-hierarchy>li>a[href=?]', '/projects/ecookbook/wiki/Page_with_an_inline_image',
38 38 :text => 'Page with an inline image'
39 39 end
40 40
41 41 def test_export_link
42 42 Role.anonymous.add_permission! :export_wiki_pages
43 43 get :show, :project_id => 'ecookbook'
44 44 assert_response :success
45 45 assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation.txt'
46 46 end
47 47
48 48 def test_show_page_with_name
49 49 get :show, :project_id => 1, :id => 'Another_page'
50 50 assert_response :success
51 51 assert_template 'show'
52 52 assert_select 'h1', :text => /Another page/
53 53 # Included page with an inline image
54 54 assert_select 'p', :text => /This is an inline image/
55 55 assert_select 'img[src=?][alt=?]', '/attachments/download/3/logo.gif', 'This is a logo'
56 56 end
57 57
58 58 def test_show_old_version
59 59 with_settings :default_language => 'en' do
60 60 get :show, :project_id => 'ecookbook', :id => 'CookBook_documentation', :version => '2'
61 61 end
62 62 assert_response :success
63 63 assert_template 'show'
64 64
65 65 assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation/1', :text => /Previous/
66 66 assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation/2/diff', :text => /diff/
67 67 assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation/3', :text => /Next/
68 68 assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation', :text => /Current version/
69 69 end
70 70
71 71 def test_show_old_version_with_attachments
72 72 page = WikiPage.find(4)
73 73 assert page.attachments.any?
74 74 content = page.content
75 75 content.text = "update"
76 76 content.save!
77 77
78 78 get :show, :project_id => 'ecookbook', :id => page.title, :version => '1'
79 79 assert_kind_of WikiContent::Version, assigns(:content)
80 80 assert_response :success
81 81 assert_template 'show'
82 82 end
83 83
84 84 def test_show_old_version_without_permission_should_be_denied
85 85 Role.anonymous.remove_permission! :view_wiki_edits
86 86
87 87 get :show, :project_id => 'ecookbook', :id => 'CookBook_documentation', :version => '2'
88 88 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fprojects%2Fecookbook%2Fwiki%2FCookBook_documentation%2F2'
89 89 end
90 90
91 91 def test_show_first_version
92 92 with_settings :default_language => 'en' do
93 93 get :show, :project_id => 'ecookbook', :id => 'CookBook_documentation', :version => '1'
94 94 end
95 95 assert_response :success
96 96 assert_template 'show'
97 97
98 98 assert_select 'a', :text => /Previous/, :count => 0
99 99 assert_select 'a', :text => /diff/, :count => 0
100 100 assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation/2', :text => /Next/
101 101 assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation', :text => /Current version/
102 102 end
103 103
104 104 def test_show_redirected_page
105 105 WikiRedirect.create!(:wiki_id => 1, :title => 'Old_title', :redirects_to => 'Another_page')
106 106
107 107 get :show, :project_id => 'ecookbook', :id => 'Old_title'
108 108 assert_redirected_to '/projects/ecookbook/wiki/Another_page'
109 109 end
110 110
111 111 def test_show_with_sidebar
112 112 page = Project.find(1).wiki.pages.new(:title => 'Sidebar')
113 113 page.content = WikiContent.new(:text => 'Side bar content for test_show_with_sidebar')
114 114 page.save!
115 115
116 116 get :show, :project_id => 1, :id => 'Another_page'
117 117 assert_response :success
118 118 assert_select 'div#sidebar', :text => /Side bar content for test_show_with_sidebar/
119 119 end
120 120
121 121 def test_show_should_display_section_edit_links
122 122 @request.session[:user_id] = 2
123 123 get :show, :project_id => 1, :id => 'Page with sections'
124 124
125 125 assert_select 'a[href=?]', '/projects/ecookbook/wiki/Page_with_sections/edit?section=1', 0
126 126 assert_select 'a[href=?]', '/projects/ecookbook/wiki/Page_with_sections/edit?section=2'
127 127 assert_select 'a[href=?]', '/projects/ecookbook/wiki/Page_with_sections/edit?section=3'
128 128 end
129 129
130 130 def test_show_current_version_should_display_section_edit_links
131 131 @request.session[:user_id] = 2
132 132 get :show, :project_id => 1, :id => 'Page with sections', :version => 3
133 133
134 134 assert_select 'a[href=?]', '/projects/ecookbook/wiki/Page_with_sections/edit?section=2'
135 135 end
136 136
137 137 def test_show_old_version_should_not_display_section_edit_links
138 138 @request.session[:user_id] = 2
139 139 get :show, :project_id => 1, :id => 'Page with sections', :version => 2
140 140
141 141 assert_select 'a[href=?]', '/projects/ecookbook/wiki/Page_with_sections/edit?section=2', 0
142 142 end
143 143
144 144 def test_show_unexistent_page_without_edit_right
145 145 get :show, :project_id => 1, :id => 'Unexistent page'
146 146 assert_response 404
147 147 end
148 148
149 149 def test_show_unexistent_page_with_edit_right
150 150 @request.session[:user_id] = 2
151 151 get :show, :project_id => 1, :id => 'Unexistent page'
152 152 assert_response :success
153 153 assert_template 'edit'
154 154 end
155 155
156 156 def test_show_specific_version_of_an_unexistent_page_without_edit_right
157 157 get :show, :project_id => 1, :id => 'Unexistent page', :version => 1
158 158 assert_response 404
159 159 end
160 160
161 161 def test_show_unexistent_page_with_parent_should_preselect_parent
162 162 @request.session[:user_id] = 2
163 163 get :show, :project_id => 1, :id => 'Unexistent page', :parent => 'Another_page'
164 164 assert_response :success
165 165 assert_template 'edit'
166 166 assert_select 'select[name=?] option[value="2"][selected=selected]', 'wiki_page[parent_id]'
167 167 end
168 168
169 169 def test_show_should_not_show_history_without_permission
170 170 Role.anonymous.remove_permission! :view_wiki_edits
171 171 get :show, :project_id => 1, :id => 'Page with sections', :version => 2
172 172
173 173 assert_response 302
174 174 end
175 175
176 176 def test_show_page_without_content_should_display_the_edit_form
177 177 @request.session[:user_id] = 2
178 178 WikiPage.create!(:title => 'NoContent', :wiki => Project.find(1).wiki)
179 179
180 180 get :show, :project_id => 1, :id => 'NoContent'
181 181 assert_response :success
182 182 assert_template 'edit'
183 183 assert_select 'textarea[name=?]', 'content[text]'
184 184 end
185 185
186 186 def test_get_new
187 187 @request.session[:user_id] = 2
188 188
189 189 get :new, :project_id => 'ecookbook'
190 190 assert_response :success
191 191 assert_template 'new'
192 192 end
193 193
194 194 def test_get_new_xhr
195 195 @request.session[:user_id] = 2
196 196
197 197 xhr :get, :new, :project_id => 'ecookbook'
198 198 assert_response :success
199 199 assert_template 'new'
200 200 end
201 201
202 202 def test_post_new_with_valid_title_should_redirect_to_edit
203 203 @request.session[:user_id] = 2
204 204
205 205 post :new, :project_id => 'ecookbook', :title => 'New Page'
206 206 assert_redirected_to '/projects/ecookbook/wiki/New_Page'
207 207 end
208 208
209 209 def test_post_new_xhr_with_valid_title_should_redirect_to_edit
210 210 @request.session[:user_id] = 2
211 211
212 212 xhr :post, :new, :project_id => 'ecookbook', :title => 'New Page'
213 213 assert_response :success
214 214 assert_equal 'window.location = "/projects/ecookbook/wiki/New_Page"', response.body
215 215 end
216 216
217 217 def test_post_new_with_invalid_title_should_display_errors
218 218 @request.session[:user_id] = 2
219 219
220 220 post :new, :project_id => 'ecookbook', :title => 'Another page'
221 221 assert_response :success
222 222 assert_template 'new'
223 223 assert_select_error 'Title has already been taken'
224 224 end
225 225
226 226 def test_post_new_with_protected_title_should_display_errors
227 227 Role.find(1).remove_permission!(:protect_wiki_pages)
228 228 @request.session[:user_id] = 2
229 229
230 post :new, :params => {:project_id => 'ecookbook', :title => 'Sidebar'}
230 post :new, :project_id => 'ecookbook', :title => 'Sidebar'
231 231 assert_response :success
232 232 assert_select_error /Title/
233 233 end
234 234
235 235 def test_post_new_xhr_with_invalid_title_should_display_errors
236 236 @request.session[:user_id] = 2
237 237
238 238 xhr :post, :new, :project_id => 'ecookbook', :title => 'Another page'
239 239 assert_response :success
240 240 assert_template 'new'
241 241 assert_include 'Title has already been taken', response.body
242 242 end
243 243
244 244 def test_create_page
245 245 @request.session[:user_id] = 2
246 246 assert_difference 'WikiPage.count' do
247 247 assert_difference 'WikiContent.count' do
248 248 put :update, :project_id => 1,
249 249 :id => 'New page',
250 250 :content => {:comments => 'Created the page',
251 251 :text => "h1. New page\n\nThis is a new page",
252 252 :version => 0}
253 253 end
254 254 end
255 255 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'New_page'
256 256 page = Project.find(1).wiki.find_page('New page')
257 257 assert !page.new_record?
258 258 assert_not_nil page.content
259 259 assert_nil page.parent
260 260 assert_equal 'Created the page', page.content.comments
261 261 end
262 262
263 263 def test_create_page_with_attachments
264 264 @request.session[:user_id] = 2
265 265 assert_difference 'WikiPage.count' do
266 266 assert_difference 'Attachment.count' do
267 267 put :update, :project_id => 1,
268 268 :id => 'New page',
269 269 :content => {:comments => 'Created the page',
270 270 :text => "h1. New page\n\nThis is a new page",
271 271 :version => 0},
272 272 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
273 273 end
274 274 end
275 275 page = Project.find(1).wiki.find_page('New page')
276 276 assert_equal 1, page.attachments.count
277 277 assert_equal 'testfile.txt', page.attachments.first.filename
278 278 end
279 279
280 280 def test_create_page_with_parent
281 281 @request.session[:user_id] = 2
282 282 assert_difference 'WikiPage.count' do
283 283 put :update, :project_id => 1, :id => 'New page',
284 284 :content => {:text => "h1. New page\n\nThis is a new page", :version => 0},
285 285 :wiki_page => {:parent_id => 2}
286 286 end
287 287 page = Project.find(1).wiki.find_page('New page')
288 288 assert_equal WikiPage.find(2), page.parent
289 289 end
290 290
291 291 def test_edit_page
292 292 @request.session[:user_id] = 2
293 293 get :edit, :project_id => 'ecookbook', :id => 'Another_page'
294 294
295 295 assert_response :success
296 296 assert_template 'edit'
297 297
298 298 assert_select 'textarea[name=?]', 'content[text]',
299 299 :text => WikiPage.find_by_title('Another_page').content.text
300 300 end
301 301
302 302 def test_edit_section
303 303 @request.session[:user_id] = 2
304 304 get :edit, :project_id => 'ecookbook', :id => 'Page_with_sections', :section => 2
305 305
306 306 assert_response :success
307 307 assert_template 'edit'
308 308
309 309 page = WikiPage.find_by_title('Page_with_sections')
310 310 section, hash = Redmine::WikiFormatting::Textile::Formatter.new(page.content.text).get_section(2)
311 311
312 312 assert_select 'textarea[name=?]', 'content[text]', :text => section
313 313 assert_select 'input[name=section][type=hidden][value="2"]'
314 314 assert_select 'input[name=section_hash][type=hidden][value=?]', hash
315 315 end
316 316
317 317 def test_edit_invalid_section_should_respond_with_404
318 318 @request.session[:user_id] = 2
319 319 get :edit, :project_id => 'ecookbook', :id => 'Page_with_sections', :section => 10
320 320
321 321 assert_response 404
322 322 end
323 323
324 324 def test_update_page
325 325 @request.session[:user_id] = 2
326 326 assert_no_difference 'WikiPage.count' do
327 327 assert_no_difference 'WikiContent.count' do
328 328 assert_difference 'WikiContent::Version.count' do
329 329 put :update, :project_id => 1,
330 330 :id => 'Another_page',
331 331 :content => {
332 332 :comments => "my comments",
333 333 :text => "edited",
334 334 :version => 1
335 335 }
336 336 end
337 337 end
338 338 end
339 339 assert_redirected_to '/projects/ecookbook/wiki/Another_page'
340 340
341 341 page = Wiki.find(1).pages.find_by_title('Another_page')
342 342 assert_equal "edited", page.content.text
343 343 assert_equal 2, page.content.version
344 344 assert_equal "my comments", page.content.comments
345 345 end
346 346
347 347 def test_update_page_with_parent
348 348 @request.session[:user_id] = 2
349 349 assert_no_difference 'WikiPage.count' do
350 350 assert_no_difference 'WikiContent.count' do
351 351 assert_difference 'WikiContent::Version.count' do
352 352 put :update, :project_id => 1,
353 353 :id => 'Another_page',
354 354 :content => {
355 355 :comments => "my comments",
356 356 :text => "edited",
357 357 :version => 1
358 358 },
359 359 :wiki_page => {:parent_id => '1'}
360 360 end
361 361 end
362 362 end
363 363 assert_redirected_to '/projects/ecookbook/wiki/Another_page'
364 364
365 365 page = Wiki.find(1).pages.find_by_title('Another_page')
366 366 assert_equal "edited", page.content.text
367 367 assert_equal 2, page.content.version
368 368 assert_equal "my comments", page.content.comments
369 369 assert_equal WikiPage.find(1), page.parent
370 370 end
371 371
372 372 def test_update_page_with_failure
373 373 @request.session[:user_id] = 2
374 374 assert_no_difference 'WikiPage.count' do
375 375 assert_no_difference 'WikiContent.count' do
376 376 assert_no_difference 'WikiContent::Version.count' do
377 377 put :update, :project_id => 1,
378 378 :id => 'Another_page',
379 379 :content => {
380 380 :comments => 'a' * 1300, # failure here, comment is too long
381 381 :text => 'edited'
382 382 },
383 383 :wiki_page => {
384 384 :parent_id => ""
385 385 }
386 386 end
387 387 end
388 388 end
389 389 assert_response :success
390 390 assert_template 'edit'
391 391
392 392 assert_select_error /Comment is too long/
393 393 assert_select 'textarea#content_text', :text => "edited"
394 394 assert_select 'input#content_version[value="1"]'
395 395 end
396 396
397 397 def test_update_page_with_parent_change_only_should_not_create_content_version
398 398 @request.session[:user_id] = 2
399 399 assert_no_difference 'WikiPage.count' do
400 400 assert_no_difference 'WikiContent.count' do
401 401 assert_no_difference 'WikiContent::Version.count' do
402 402 put :update, :project_id => 1,
403 403 :id => 'Another_page',
404 404 :content => {
405 405 :comments => '',
406 406 :text => Wiki.find(1).find_page('Another_page').content.text,
407 407 :version => 1
408 408 },
409 409 :wiki_page => {:parent_id => '1'}
410 410 end
411 411 end
412 412 end
413 413 page = Wiki.find(1).pages.find_by_title('Another_page')
414 414 assert_equal 1, page.content.version
415 415 assert_equal WikiPage.find(1), page.parent
416 416 end
417 417
418 418 def test_update_page_with_attachments_only_should_not_create_content_version
419 419 @request.session[:user_id] = 2
420 420 assert_no_difference 'WikiPage.count' do
421 421 assert_no_difference 'WikiContent.count' do
422 422 assert_no_difference 'WikiContent::Version.count' do
423 423 assert_difference 'Attachment.count' do
424 424 put :update, :project_id => 1,
425 425 :id => 'Another_page',
426 426 :content => {
427 427 :comments => '',
428 428 :text => Wiki.find(1).find_page('Another_page').content.text,
429 429 :version => 1
430 430 },
431 431 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
432 432 end
433 433 end
434 434 end
435 435 end
436 436 page = Wiki.find(1).pages.find_by_title('Another_page')
437 437 assert_equal 1, page.content.version
438 438 end
439 439
440 440 def test_update_stale_page_should_not_raise_an_error
441 441 @request.session[:user_id] = 2
442 442 c = Wiki.find(1).find_page('Another_page').content
443 443 c.text = 'Previous text'
444 444 c.save!
445 445 assert_equal 2, c.version
446 446
447 447 assert_no_difference 'WikiPage.count' do
448 448 assert_no_difference 'WikiContent.count' do
449 449 assert_no_difference 'WikiContent::Version.count' do
450 450 put :update, :project_id => 1,
451 451 :id => 'Another_page',
452 452 :content => {
453 453 :comments => 'My comments',
454 454 :text => 'Text should not be lost',
455 455 :version => 1
456 456 }
457 457 end
458 458 end
459 459 end
460 460 assert_response :success
461 461 assert_template 'edit'
462 462 assert_select 'div.error', :text => /Data has been updated by another user/
463 463 assert_select 'textarea[name=?]', 'content[text]', :text => /Text should not be lost/
464 464 assert_select 'input[name=?][value=?]', 'content[comments]', 'My comments'
465 465
466 466 c.reload
467 467 assert_equal 'Previous text', c.text
468 468 assert_equal 2, c.version
469 469 end
470 470
471 471 def test_update_page_without_content_should_create_content
472 472 @request.session[:user_id] = 2
473 473 page = WikiPage.create!(:title => 'NoContent', :wiki => Project.find(1).wiki)
474 474
475 475 assert_no_difference 'WikiPage.count' do
476 476 assert_difference 'WikiContent.count' do
477 477 put :update, :project_id => 1, :id => 'NoContent', :content => {:text => 'Some content'}
478 478 assert_response 302
479 479 end
480 480 end
481 481 assert_equal 'Some content', page.reload.content.text
482 482 end
483 483
484 484 def test_update_section
485 485 @request.session[:user_id] = 2
486 486 page = WikiPage.find_by_title('Page_with_sections')
487 487 section, hash = Redmine::WikiFormatting::Textile::Formatter.new(page.content.text).get_section(2)
488 488 text = page.content.text
489 489
490 490 assert_no_difference 'WikiPage.count' do
491 491 assert_no_difference 'WikiContent.count' do
492 492 assert_difference 'WikiContent::Version.count' do
493 493 put :update, :project_id => 1, :id => 'Page_with_sections',
494 494 :content => {
495 495 :text => "New section content",
496 496 :version => 3
497 497 },
498 498 :section => 2,
499 499 :section_hash => hash
500 500 end
501 501 end
502 502 end
503 503 assert_redirected_to '/projects/ecookbook/wiki/Page_with_sections#section-2'
504 504 assert_equal Redmine::WikiFormatting::Textile::Formatter.new(text).update_section(2, "New section content"), page.reload.content.text
505 505 end
506 506
507 507 def test_update_section_should_allow_stale_page_update
508 508 @request.session[:user_id] = 2
509 509 page = WikiPage.find_by_title('Page_with_sections')
510 510 section, hash = Redmine::WikiFormatting::Textile::Formatter.new(page.content.text).get_section(2)
511 511 text = page.content.text
512 512
513 513 assert_no_difference 'WikiPage.count' do
514 514 assert_no_difference 'WikiContent.count' do
515 515 assert_difference 'WikiContent::Version.count' do
516 516 put :update, :project_id => 1, :id => 'Page_with_sections',
517 517 :content => {
518 518 :text => "New section content",
519 519 :version => 2 # Current version is 3
520 520 },
521 521 :section => 2,
522 522 :section_hash => hash
523 523 end
524 524 end
525 525 end
526 526 assert_redirected_to '/projects/ecookbook/wiki/Page_with_sections#section-2'
527 527 page.reload
528 528 assert_equal Redmine::WikiFormatting::Textile::Formatter.new(text).update_section(2, "New section content"), page.content.text
529 529 assert_equal 4, page.content.version
530 530 end
531 531
532 532 def test_update_section_should_not_allow_stale_section_update
533 533 @request.session[:user_id] = 2
534 534
535 535 assert_no_difference 'WikiPage.count' do
536 536 assert_no_difference 'WikiContent.count' do
537 537 assert_no_difference 'WikiContent::Version.count' do
538 538 put :update, :project_id => 1, :id => 'Page_with_sections',
539 539 :content => {
540 540 :comments => 'My comments',
541 541 :text => "Text should not be lost",
542 542 :version => 3
543 543 },
544 544 :section => 2,
545 545 :section_hash => Digest::MD5.hexdigest("wrong hash")
546 546 end
547 547 end
548 548 end
549 549 assert_response :success
550 550 assert_template 'edit'
551 551 assert_select 'div.error', :text => /Data has been updated by another user/
552 552 assert_select 'textarea[name=?]', 'content[text]', :text => /Text should not be lost/
553 553 assert_select 'input[name=?][value=?]', 'content[comments]', 'My comments'
554 554 end
555 555
556 556 def test_preview
557 557 @request.session[:user_id] = 2
558 558 xhr :post, :preview, :project_id => 1, :id => 'CookBook_documentation',
559 559 :content => { :comments => '',
560 560 :text => 'this is a *previewed text*',
561 561 :version => 3 }
562 562 assert_response :success
563 563 assert_template 'common/_preview'
564 564 assert_select 'strong', :text => /previewed text/
565 565 end
566 566
567 567 def test_preview_new_page
568 568 @request.session[:user_id] = 2
569 569 xhr :post, :preview, :project_id => 1, :id => 'New page',
570 570 :content => { :text => 'h1. New page',
571 571 :comments => '',
572 572 :version => 0 }
573 573 assert_response :success
574 574 assert_template 'common/_preview'
575 575 assert_select 'h1', :text => /New page/
576 576 end
577 577
578 578 def test_history
579 579 @request.session[:user_id] = 2
580 580 get :history, :project_id => 'ecookbook', :id => 'CookBook_documentation'
581 581 assert_response :success
582 582 assert_template 'history'
583 583 assert_not_nil assigns(:versions)
584 584 assert_equal 3, assigns(:versions).size
585 585
586 586 assert_select "input[type=submit][name=commit]"
587 587 assert_select 'td' do
588 588 assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation/2', :text => '2'
589 589 assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation/2/annotate', :text => 'Annotate'
590 590 assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation/2', :text => 'Delete'
591 591 end
592 592 end
593 593
594 594 def test_history_with_one_version
595 595 @request.session[:user_id] = 2
596 596 get :history, :project_id => 'ecookbook', :id => 'Another_page'
597 597 assert_response :success
598 598 assert_template 'history'
599 599 assert_not_nil assigns(:versions)
600 600 assert_equal 1, assigns(:versions).size
601 601 assert_select "input[type=submit][name=commit]", false
602 602 assert_select 'td' do
603 603 assert_select 'a[href=?]', '/projects/ecookbook/wiki/Another_page/1', :text => '1'
604 604 assert_select 'a[href=?]', '/projects/ecookbook/wiki/Another_page/1/annotate', :text => 'Annotate'
605 605 assert_select 'a[href=?]', '/projects/ecookbook/wiki/Another_page/1', :text => 'Delete', :count => 0
606 606 end
607 607 end
608 608
609 609 def test_diff
610 610 content = WikiPage.find(1).content
611 611 assert_difference 'WikiContent::Version.count', 2 do
612 612 content.text = "Line removed\nThis is a sample text for testing diffs"
613 613 content.save!
614 614 content.text = "This is a sample text for testing diffs\nLine added"
615 615 content.save!
616 616 end
617 617
618 618 get :diff, :project_id => 1, :id => 'CookBook_documentation', :version => content.version, :version_from => (content.version - 1)
619 619 assert_response :success
620 620 assert_template 'diff'
621 621 assert_select 'span.diff_out', :text => 'Line removed'
622 622 assert_select 'span.diff_in', :text => 'Line added'
623 623 end
624 624
625 625 def test_diff_with_invalid_version_should_respond_with_404
626 626 get :diff, :project_id => 1, :id => 'CookBook_documentation', :version => '99'
627 627 assert_response 404
628 628 end
629 629
630 630 def test_diff_with_invalid_version_from_should_respond_with_404
631 631 get :diff, :project_id => 1, :id => 'CookBook_documentation', :version => '99', :version_from => '98'
632 632 assert_response 404
633 633 end
634 634
635 635 def test_annotate
636 636 get :annotate, :project_id => 1, :id => 'CookBook_documentation', :version => 2
637 637 assert_response :success
638 638 assert_template 'annotate'
639 639
640 640 # Line 1
641 641 assert_select 'table.annotate tr:nth-child(1)' do
642 642 assert_select 'th.line-num', :text => '1'
643 643 assert_select 'td.author', :text => /John Smith/
644 644 assert_select 'td', :text => /h1\. CookBook documentation/
645 645 end
646 646
647 647 # Line 5
648 648 assert_select 'table.annotate tr:nth-child(5)' do
649 649 assert_select 'th.line-num', :text => '5'
650 650 assert_select 'td.author', :text => /Redmine Admin/
651 651 assert_select 'td', :text => /Some updated \[\[documentation\]\] here/
652 652 end
653 653 end
654 654
655 655 def test_annotate_with_invalid_version_should_respond_with_404
656 656 get :annotate, :project_id => 1, :id => 'CookBook_documentation', :version => '99'
657 657 assert_response 404
658 658 end
659 659
660 660 def test_get_rename
661 661 @request.session[:user_id] = 2
662 662 get :rename, :project_id => 1, :id => 'Another_page'
663 663 assert_response :success
664 664 assert_template 'rename'
665 665
666 666 assert_select 'select[name=?]', 'wiki_page[parent_id]' do
667 667 assert_select 'option[value=""]', :text => ''
668 668 assert_select 'option[selected=selected]', 0
669 669 end
670 670 end
671 671
672 672 def test_get_rename_child_page
673 673 @request.session[:user_id] = 2
674 674 get :rename, :project_id => 1, :id => 'Child_1'
675 675 assert_response :success
676 676 assert_template 'rename'
677 677
678 678 assert_select 'select[name=?]', 'wiki_page[parent_id]' do
679 679 assert_select 'option[value=""]', :text => ''
680 680 assert_select 'option[value="2"][selected=selected]', :text => /Another page/
681 681 end
682 682 end
683 683
684 684 def test_rename_with_redirect
685 685 @request.session[:user_id] = 2
686 686 post :rename, :project_id => 1, :id => 'Another_page',
687 687 :wiki_page => { :title => 'Another renamed page',
688 688 :redirect_existing_links => 1 }
689 689 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_renamed_page'
690 690 wiki = Project.find(1).wiki
691 691 # Check redirects
692 692 assert_not_nil wiki.find_page('Another page')
693 693 assert_nil wiki.find_page('Another page', :with_redirect => false)
694 694 end
695 695
696 696 def test_rename_without_redirect
697 697 @request.session[:user_id] = 2
698 698 post :rename, :project_id => 1, :id => 'Another_page',
699 699 :wiki_page => { :title => 'Another renamed page',
700 700 :redirect_existing_links => "0" }
701 701 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_renamed_page'
702 702 wiki = Project.find(1).wiki
703 703 # Check that there's no redirects
704 704 assert_nil wiki.find_page('Another page')
705 705 end
706 706
707 707 def test_rename_with_parent_assignment
708 708 @request.session[:user_id] = 2
709 709 post :rename, :project_id => 1, :id => 'Another_page',
710 710 :wiki_page => { :title => 'Another page', :redirect_existing_links => "0", :parent_id => '4' }
711 711 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_page'
712 712 assert_equal WikiPage.find(4), WikiPage.find_by_title('Another_page').parent
713 713 end
714 714
715 715 def test_rename_with_parent_unassignment
716 716 @request.session[:user_id] = 2
717 717 post :rename, :project_id => 1, :id => 'Child_1',
718 718 :wiki_page => { :title => 'Child 1', :redirect_existing_links => "0", :parent_id => '' }
719 719 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Child_1'
720 720 assert_nil WikiPage.find_by_title('Child_1').parent
721 721 end
722 722
723 723 def test_get_rename_should_show_target_projects_list
724 724 @request.session[:user_id] = 2
725 725 project = Project.find(5)
726 726 project.enable_module! :wiki
727 727
728 728 get :rename, :project_id => 1, :id => 'Another_page'
729 729 assert_response :success
730 730 assert_template 'rename'
731 731
732 732 assert_select 'select[name=?]', 'wiki_page[wiki_id]' do
733 733 assert_select 'option', 2
734 734 assert_select 'option[value=?][selected=selected]', '1', :text => /eCookbook/
735 735 assert_select 'option[value=?]', project.wiki.id.to_s, :text => /#{project.name}/
736 736 end
737 737 end
738 738
739 739 def test_rename_with_move
740 740 @request.session[:user_id] = 2
741 741 project = Project.find(5)
742 742 project.enable_module! :wiki
743 743
744 744 post :rename, :project_id => 1, :id => 'Another_page',
745 745 :wiki_page => {
746 746 :wiki_id => project.wiki.id.to_s,
747 747 :title => 'Another renamed page',
748 748 :redirect_existing_links => 1
749 749 }
750 750 assert_redirected_to '/projects/private-child/wiki/Another_renamed_page'
751 751
752 752 page = WikiPage.find(2)
753 753 assert_equal project.wiki.id, page.wiki_id
754 754 end
755 755
756 756 def test_destroy_a_page_without_children_should_not_ask_confirmation
757 757 @request.session[:user_id] = 2
758 758 delete :destroy, :project_id => 1, :id => 'Child_2'
759 759 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
760 760 end
761 761
762 762 def test_destroy_parent_should_ask_confirmation
763 763 @request.session[:user_id] = 2
764 764 assert_no_difference('WikiPage.count') do
765 765 delete :destroy, :project_id => 1, :id => 'Another_page'
766 766 end
767 767 assert_response :success
768 768 assert_template 'destroy'
769 769 assert_select 'form' do
770 770 assert_select 'input[name=todo][value=nullify]'
771 771 assert_select 'input[name=todo][value=destroy]'
772 772 assert_select 'input[name=todo][value=reassign]'
773 773 end
774 774 end
775 775
776 776 def test_destroy_parent_with_nullify_should_delete_parent_only
777 777 @request.session[:user_id] = 2
778 778 assert_difference('WikiPage.count', -1) do
779 779 delete :destroy, :project_id => 1, :id => 'Another_page', :todo => 'nullify'
780 780 end
781 781 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
782 782 assert_nil WikiPage.find_by_id(2)
783 783 end
784 784
785 785 def test_destroy_parent_with_cascade_should_delete_descendants
786 786 @request.session[:user_id] = 2
787 787 assert_difference('WikiPage.count', -4) do
788 788 delete :destroy, :project_id => 1, :id => 'Another_page', :todo => 'destroy'
789 789 end
790 790 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
791 791 assert_nil WikiPage.find_by_id(2)
792 792 assert_nil WikiPage.find_by_id(5)
793 793 end
794 794
795 795 def test_destroy_parent_with_reassign
796 796 @request.session[:user_id] = 2
797 797 assert_difference('WikiPage.count', -1) do
798 798 delete :destroy, :project_id => 1, :id => 'Another_page', :todo => 'reassign', :reassign_to_id => 1
799 799 end
800 800 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
801 801 assert_nil WikiPage.find_by_id(2)
802 802 assert_equal WikiPage.find(1), WikiPage.find_by_id(5).parent
803 803 end
804 804
805 805 def test_destroy_version
806 806 @request.session[:user_id] = 2
807 807 assert_difference 'WikiContent::Version.count', -1 do
808 808 assert_no_difference 'WikiContent.count' do
809 809 assert_no_difference 'WikiPage.count' do
810 810 delete :destroy_version, :project_id => 'ecookbook', :id => 'CookBook_documentation', :version => 2
811 811 assert_redirected_to '/projects/ecookbook/wiki/CookBook_documentation/history'
812 812 end
813 813 end
814 814 end
815 815 end
816 816
817 817 def test_destroy_invalid_version_should_respond_with_404
818 818 @request.session[:user_id] = 2
819 819 assert_no_difference 'WikiContent::Version.count' do
820 820 assert_no_difference 'WikiContent.count' do
821 821 assert_no_difference 'WikiPage.count' do
822 822 delete :destroy_version, :project_id => 'ecookbook', :id => 'CookBook_documentation', :version => 99
823 823 end
824 824 end
825 825 end
826 826 assert_response 404
827 827 end
828 828
829 829 def test_index
830 830 get :index, :project_id => 'ecookbook'
831 831 assert_response :success
832 832 assert_template 'index'
833 833 pages = assigns(:pages)
834 834 assert_not_nil pages
835 835 assert_equal Project.find(1).wiki.pages.size, pages.size
836 836 assert_equal pages.first.content.updated_on, pages.first.updated_on
837 837
838 838 assert_select 'ul.pages-hierarchy' do
839 839 assert_select 'li' do
840 840 assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation', :text => 'CookBook documentation'
841 841 assert_select 'ul li a[href=?]', '/projects/ecookbook/wiki/Page_with_an_inline_image', :text => 'Page with an inline image'
842 842 end
843 843 assert_select 'li a[href=?]', '/projects/ecookbook/wiki/Another_page', :text => 'Another page'
844 844 end
845 845 end
846 846
847 847 def test_index_should_include_atom_link
848 848 get :index, :project_id => 'ecookbook'
849 849 assert_select 'a[href=?]', '/projects/ecookbook/activity.atom?show_wiki_edits=1'
850 850 end
851 851
852 852 def test_export_to_html
853 853 @request.session[:user_id] = 2
854 854 get :export, :project_id => 'ecookbook'
855 855
856 856 assert_response :success
857 857 assert_not_nil assigns(:pages)
858 858 assert assigns(:pages).any?
859 859 assert_equal "text/html", @response.content_type
860 860
861 861 assert_select "a[name=?]", "CookBook_documentation"
862 862 assert_select "a[name=?]", "Another_page"
863 863 assert_select "a[name=?]", "Page_with_an_inline_image"
864 864 end
865 865
866 866 def test_export_to_pdf
867 867 @request.session[:user_id] = 2
868 868 get :export, :project_id => 'ecookbook', :format => 'pdf'
869 869
870 870 assert_response :success
871 871 assert_not_nil assigns(:pages)
872 872 assert assigns(:pages).any?
873 873 assert_equal 'application/pdf', @response.content_type
874 874 assert_equal 'attachment; filename="ecookbook.pdf"', @response.headers['Content-Disposition']
875 875 assert @response.body.starts_with?('%PDF')
876 876 end
877 877
878 878 def test_export_without_permission_should_be_denied
879 879 @request.session[:user_id] = 2
880 880 Role.find_by_name('Manager').remove_permission! :export_wiki_pages
881 881 get :export, :project_id => 'ecookbook'
882 882
883 883 assert_response 403
884 884 end
885 885
886 886 def test_date_index
887 887 get :date_index, :project_id => 'ecookbook'
888 888
889 889 assert_response :success
890 890 assert_template 'date_index'
891 891 assert_not_nil assigns(:pages)
892 892 assert_not_nil assigns(:pages_by_date)
893 893
894 894 assert_select 'a[href=?]', '/projects/ecookbook/activity.atom?show_wiki_edits=1'
895 895 end
896 896
897 897 def test_not_found
898 898 get :show, :project_id => 999
899 899 assert_response 404
900 900 end
901 901
902 902 def test_protect_page
903 903 page = WikiPage.find_by_wiki_id_and_title(1, 'Another_page')
904 904 assert !page.protected?
905 905 @request.session[:user_id] = 2
906 906 post :protect, :project_id => 1, :id => page.title, :protected => '1'
907 907 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_page'
908 908 assert page.reload.protected?
909 909 end
910 910
911 911 def test_unprotect_page
912 912 page = WikiPage.find_by_wiki_id_and_title(1, 'CookBook_documentation')
913 913 assert page.protected?
914 914 @request.session[:user_id] = 2
915 915 post :protect, :project_id => 1, :id => page.title, :protected => '0'
916 916 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'CookBook_documentation'
917 917 assert !page.reload.protected?
918 918 end
919 919
920 920 def test_show_page_with_edit_link
921 921 @request.session[:user_id] = 2
922 922 get :show, :project_id => 1
923 923 assert_response :success
924 924 assert_template 'show'
925 925 assert_select 'a[href=?]', '/projects/1/wiki/CookBook_documentation/edit'
926 926 end
927 927
928 928 def test_show_page_without_edit_link
929 929 @request.session[:user_id] = 4
930 930 get :show, :project_id => 1
931 931 assert_response :success
932 932 assert_template 'show'
933 933 assert_select 'a[href=?]', '/projects/1/wiki/CookBook_documentation/edit', 0
934 934 end
935 935
936 936 def test_show_pdf
937 937 @request.session[:user_id] = 2
938 938 get :show, :project_id => 1, :format => 'pdf'
939 939 assert_response :success
940 940 assert_not_nil assigns(:page)
941 941 assert_equal 'application/pdf', @response.content_type
942 942 assert_equal 'attachment; filename="CookBook_documentation.pdf"',
943 943 @response.headers['Content-Disposition']
944 944 end
945 945
946 946 def test_show_html
947 947 @request.session[:user_id] = 2
948 948 get :show, :project_id => 1, :format => 'html'
949 949 assert_response :success
950 950 assert_not_nil assigns(:page)
951 951 assert_equal 'text/html', @response.content_type
952 952 assert_equal 'attachment; filename="CookBook_documentation.html"',
953 953 @response.headers['Content-Disposition']
954 954 assert_select 'h1', :text => /CookBook documentation/
955 955 end
956 956
957 957 def test_show_versioned_html
958 958 @request.session[:user_id] = 2
959 959 get :show, :project_id => 1, :format => 'html', :version => 2
960 960 assert_response :success
961 961 assert_not_nil assigns(:content)
962 962 assert_equal 2, assigns(:content).version
963 963 assert_equal 'text/html', @response.content_type
964 964 assert_equal 'attachment; filename="CookBook_documentation.html"',
965 965 @response.headers['Content-Disposition']
966 966 assert_select 'h1', :text => /CookBook documentation/
967 967 end
968 968
969 969 def test_show_txt
970 970 @request.session[:user_id] = 2
971 971 get :show, :project_id => 1, :format => 'txt'
972 972 assert_response :success
973 973 assert_not_nil assigns(:page)
974 974 assert_equal 'text/plain', @response.content_type
975 975 assert_equal 'attachment; filename="CookBook_documentation.txt"',
976 976 @response.headers['Content-Disposition']
977 977 assert_include 'h1. CookBook documentation', @response.body
978 978 end
979 979
980 980 def test_show_versioned_txt
981 981 @request.session[:user_id] = 2
982 982 get :show, :project_id => 1, :format => 'txt', :version => 2
983 983 assert_response :success
984 984 assert_not_nil assigns(:content)
985 985 assert_equal 2, assigns(:content).version
986 986 assert_equal 'text/plain', @response.content_type
987 987 assert_equal 'attachment; filename="CookBook_documentation.txt"',
988 988 @response.headers['Content-Disposition']
989 989 assert_include 'h1. CookBook documentation', @response.body
990 990 end
991 991
992 992 def test_edit_unprotected_page
993 993 # Non members can edit unprotected wiki pages
994 994 @request.session[:user_id] = 4
995 995 get :edit, :project_id => 1, :id => 'Another_page'
996 996 assert_response :success
997 997 assert_template 'edit'
998 998 end
999 999
1000 1000 def test_edit_protected_page_by_nonmember
1001 1001 # Non members cannot edit protected wiki pages
1002 1002 @request.session[:user_id] = 4
1003 1003 get :edit, :project_id => 1, :id => 'CookBook_documentation'
1004 1004 assert_response 403
1005 1005 end
1006 1006
1007 1007 def test_edit_protected_page_by_member
1008 1008 @request.session[:user_id] = 2
1009 1009 get :edit, :project_id => 1, :id => 'CookBook_documentation'
1010 1010 assert_response :success
1011 1011 assert_template 'edit'
1012 1012 end
1013 1013
1014 1014 def test_history_of_non_existing_page_should_return_404
1015 1015 get :history, :project_id => 1, :id => 'Unknown_page'
1016 1016 assert_response 404
1017 1017 end
1018 1018
1019 1019 def test_add_attachment
1020 1020 @request.session[:user_id] = 2
1021 1021 assert_difference 'Attachment.count' do
1022 1022 post :add_attachment, :project_id => 1, :id => 'CookBook_documentation',
1023 1023 :attachments => {
1024 1024 '1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'),
1025 1025 'description' => 'test file'}
1026 1026 }
1027 1027 end
1028 1028 attachment = Attachment.order('id DESC').first
1029 1029 assert_equal Wiki.find(1).find_page('CookBook_documentation'), attachment.container
1030 1030 end
1031 1031 end
General Comments 0
You need to be logged in to leave comments. Login now