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