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