Mercurial > hg > soundsoftware-site
comparison test/functional/wiki_controller_test.rb @ 909:cbb26bc654de redmine-1.3
Update to Redmine 1.3-stable branch (Redmine SVN rev 8964)
author | Chris Cannam |
---|---|
date | Fri, 24 Feb 2012 19:09:32 +0000 |
parents | 0c939c159af4 |
children | 433d4f72a19b |
comparison
equal
deleted
inserted
replaced
908:c6c2cbd0afee | 909:cbb26bc654de |
---|---|
20 | 20 |
21 # Re-raise errors caught by the controller. | 21 # Re-raise errors caught by the controller. |
22 class WikiController; def rescue_action(e) raise e end; end | 22 class WikiController; def rescue_action(e) raise e end; end |
23 | 23 |
24 class WikiControllerTest < ActionController::TestCase | 24 class WikiControllerTest < ActionController::TestCase |
25 fixtures :projects, :users, :roles, :members, :member_roles, :enabled_modules, :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions, :attachments | 25 fixtures :projects, :users, :roles, :members, :member_roles, |
26 :enabled_modules, :wikis, :wiki_pages, :wiki_contents, | |
27 :wiki_content_versions, :attachments | |
26 | 28 |
27 def setup | 29 def setup |
28 @controller = WikiController.new | 30 @controller = WikiController.new |
29 @request = ActionController::TestRequest.new | 31 @request = ActionController::TestRequest.new |
30 @response = ActionController::TestResponse.new | 32 @response = ActionController::TestResponse.new |
40 # child_pages macro | 42 # child_pages macro |
41 assert_tag :ul, :attributes => { :class => 'pages-hierarchy' }, | 43 assert_tag :ul, :attributes => { :class => 'pages-hierarchy' }, |
42 :child => { :tag => 'li', | 44 :child => { :tag => 'li', |
43 :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Page_with_an_inline_image' }, | 45 :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Page_with_an_inline_image' }, |
44 :content => 'Page with an inline image' } } | 46 :content => 'Page with an inline image' } } |
47 end | |
48 | |
49 def test_export_link | |
50 Role.anonymous.add_permission! :export_wiki_pages | |
51 get :show, :project_id => 'ecookbook' | |
52 assert_response :success | |
53 assert_tag 'a', :attributes => {:href => '/projects/ecookbook/wiki/CookBook_documentation.txt'} | |
45 end | 54 end |
46 | 55 |
47 def test_show_page_with_name | 56 def test_show_page_with_name |
48 get :show, :project_id => 1, :id => 'Another_page' | 57 get :show, :project_id => 1, :id => 'Another_page' |
49 assert_response :success | 58 assert_response :success |
74 end | 83 end |
75 | 84 |
76 def test_show_unexistent_page_without_edit_right | 85 def test_show_unexistent_page_without_edit_right |
77 get :show, :project_id => 1, :id => 'Unexistent page' | 86 get :show, :project_id => 1, :id => 'Unexistent page' |
78 assert_response 404 | 87 assert_response 404 |
88 end | |
89 | |
90 def test_show_should_display_section_edit_links | |
91 @request.session[:user_id] = 2 | |
92 get :show, :project_id => 1, :id => 'Page with sections' | |
93 assert_no_tag 'a', :attributes => { | |
94 :href => '/projects/ecookbook/wiki/Page_with_sections/edit?section=1' | |
95 } | |
96 assert_tag 'a', :attributes => { | |
97 :href => '/projects/ecookbook/wiki/Page_with_sections/edit?section=2' | |
98 } | |
99 assert_tag 'a', :attributes => { | |
100 :href => '/projects/ecookbook/wiki/Page_with_sections/edit?section=3' | |
101 } | |
102 end | |
103 | |
104 def test_show_current_version_should_display_section_edit_links | |
105 @request.session[:user_id] = 2 | |
106 get :show, :project_id => 1, :id => 'Page with sections', :version => 3 | |
107 | |
108 assert_tag 'a', :attributes => { | |
109 :href => '/projects/ecookbook/wiki/Page_with_sections/edit?section=2' | |
110 } | |
111 end | |
112 | |
113 def test_show_old_version_should_not_display_section_edit_links | |
114 @request.session[:user_id] = 2 | |
115 get :show, :project_id => 1, :id => 'Page with sections', :version => 2 | |
116 | |
117 assert_no_tag 'a', :attributes => { | |
118 :href => '/projects/ecookbook/wiki/Page_with_sections/edit?section=2' | |
119 } | |
79 end | 120 end |
80 | 121 |
81 def test_show_unexistent_page_with_edit_right | 122 def test_show_unexistent_page_with_edit_right |
82 @request.session[:user_id] = 2 | 123 @request.session[:user_id] = 2 |
83 get :show, :project_id => 1, :id => 'Unexistent page' | 124 get :show, :project_id => 1, :id => 'Unexistent page' |
112 end | 153 end |
113 end | 154 end |
114 page = Project.find(1).wiki.find_page('New page') | 155 page = Project.find(1).wiki.find_page('New page') |
115 assert_equal 1, page.attachments.count | 156 assert_equal 1, page.attachments.count |
116 assert_equal 'testfile.txt', page.attachments.first.filename | 157 assert_equal 'testfile.txt', page.attachments.first.filename |
158 end | |
159 | |
160 def test_edit_page | |
161 @request.session[:user_id] = 2 | |
162 get :edit, :project_id => 'ecookbook', :id => 'Another_page' | |
163 | |
164 assert_response :success | |
165 assert_template 'edit' | |
166 | |
167 assert_tag 'textarea', | |
168 :attributes => { :name => 'content[text]' }, | |
169 :content => WikiPage.find_by_title('Another_page').content.text | |
170 end | |
171 | |
172 def test_edit_section | |
173 @request.session[:user_id] = 2 | |
174 get :edit, :project_id => 'ecookbook', :id => 'Page_with_sections', :section => 2 | |
175 | |
176 assert_response :success | |
177 assert_template 'edit' | |
178 | |
179 page = WikiPage.find_by_title('Page_with_sections') | |
180 section, hash = Redmine::WikiFormatting::Textile::Formatter.new(page.content.text).get_section(2) | |
181 | |
182 assert_tag 'textarea', | |
183 :attributes => { :name => 'content[text]' }, | |
184 :content => section | |
185 assert_tag 'input', | |
186 :attributes => { :name => 'section', :type => 'hidden', :value => '2' } | |
187 assert_tag 'input', | |
188 :attributes => { :name => 'section_hash', :type => 'hidden', :value => hash } | |
189 end | |
190 | |
191 def test_edit_invalid_section_should_respond_with_404 | |
192 @request.session[:user_id] = 2 | |
193 get :edit, :project_id => 'ecookbook', :id => 'Page_with_sections', :section => 10 | |
194 | |
195 assert_response 404 | |
117 end | 196 end |
118 | 197 |
119 def test_update_page | 198 def test_update_page |
120 @request.session[:user_id] = 2 | 199 @request.session[:user_id] = 2 |
121 assert_no_difference 'WikiPage.count' do | 200 assert_no_difference 'WikiPage.count' do |
196 c.reload | 275 c.reload |
197 assert_equal 'Previous text', c.text | 276 assert_equal 'Previous text', c.text |
198 assert_equal 2, c.version | 277 assert_equal 2, c.version |
199 end | 278 end |
200 | 279 |
280 def test_update_section | |
281 @request.session[:user_id] = 2 | |
282 page = WikiPage.find_by_title('Page_with_sections') | |
283 section, hash = Redmine::WikiFormatting::Textile::Formatter.new(page.content.text).get_section(2) | |
284 text = page.content.text | |
285 | |
286 assert_no_difference 'WikiPage.count' do | |
287 assert_no_difference 'WikiContent.count' do | |
288 assert_difference 'WikiContent::Version.count' do | |
289 put :update, :project_id => 1, :id => 'Page_with_sections', | |
290 :content => { | |
291 :text => "New section content", | |
292 :version => 3 | |
293 }, | |
294 :section => 2, | |
295 :section_hash => hash | |
296 end | |
297 end | |
298 end | |
299 assert_redirected_to '/projects/ecookbook/wiki/Page_with_sections' | |
300 assert_equal Redmine::WikiFormatting::Textile::Formatter.new(text).update_section(2, "New section content"), page.reload.content.text | |
301 end | |
302 | |
303 def test_update_section_should_allow_stale_page_update | |
304 @request.session[:user_id] = 2 | |
305 page = WikiPage.find_by_title('Page_with_sections') | |
306 section, hash = Redmine::WikiFormatting::Textile::Formatter.new(page.content.text).get_section(2) | |
307 text = page.content.text | |
308 | |
309 assert_no_difference 'WikiPage.count' do | |
310 assert_no_difference 'WikiContent.count' do | |
311 assert_difference 'WikiContent::Version.count' do | |
312 put :update, :project_id => 1, :id => 'Page_with_sections', | |
313 :content => { | |
314 :text => "New section content", | |
315 :version => 2 # Current version is 3 | |
316 }, | |
317 :section => 2, | |
318 :section_hash => hash | |
319 end | |
320 end | |
321 end | |
322 assert_redirected_to '/projects/ecookbook/wiki/Page_with_sections' | |
323 page.reload | |
324 assert_equal Redmine::WikiFormatting::Textile::Formatter.new(text).update_section(2, "New section content"), page.content.text | |
325 assert_equal 4, page.content.version | |
326 end | |
327 | |
328 def test_update_section_should_not_allow_stale_section_update | |
329 @request.session[:user_id] = 2 | |
330 | |
331 assert_no_difference 'WikiPage.count' do | |
332 assert_no_difference 'WikiContent.count' do | |
333 assert_no_difference 'WikiContent::Version.count' do | |
334 put :update, :project_id => 1, :id => 'Page_with_sections', | |
335 :content => { | |
336 :comments => 'My comments', | |
337 :text => "Text should not be lost", | |
338 :version => 3 | |
339 }, | |
340 :section => 2, | |
341 :section_hash => Digest::MD5.hexdigest("wrong hash") | |
342 end | |
343 end | |
344 end | |
345 assert_response :success | |
346 assert_template 'edit' | |
347 assert_tag :div, | |
348 :attributes => { :class => /error/ }, | |
349 :content => /Data has been updated by another user/ | |
350 assert_tag 'textarea', | |
351 :attributes => { :name => 'content[text]' }, | |
352 :content => /Text should not be lost/ | |
353 assert_tag 'input', | |
354 :attributes => { :name => 'content[comments]', :value => 'My comments' } | |
355 end | |
356 | |
201 def test_preview | 357 def test_preview |
202 @request.session[:user_id] = 2 | 358 @request.session[:user_id] = 2 |
203 xhr :post, :preview, :project_id => 1, :id => 'CookBook_documentation', | 359 xhr :post, :preview, :project_id => 1, :id => 'CookBook_documentation', |
204 :content => { :comments => '', | 360 :content => { :comments => '', |
205 :text => 'this is a *previewed text*', | 361 :text => 'this is a *previewed text*', |
248 | 404 |
249 def test_annotate | 405 def test_annotate |
250 get :annotate, :project_id => 1, :id => 'CookBook_documentation', :version => 2 | 406 get :annotate, :project_id => 1, :id => 'CookBook_documentation', :version => 2 |
251 assert_response :success | 407 assert_response :success |
252 assert_template 'annotate' | 408 assert_template 'annotate' |
253 | 409 |
254 # Line 1 | 410 # Line 1 |
255 assert_tag :tag => 'tr', :child => { | 411 assert_tag :tag => 'tr', :child => { |
256 :tag => 'th', :attributes => {:class => 'line-num'}, :content => '1', :sibling => { | 412 :tag => 'th', :attributes => {:class => 'line-num'}, :content => '1', :sibling => { |
257 :tag => 'td', :attributes => {:class => 'author'}, :content => /John Smith/, :sibling => { | 413 :tag => 'td', :attributes => {:class => 'author'}, :content => /John Smith/, :sibling => { |
258 :tag => 'td', :content => /h1\. CookBook documentation/ | 414 :tag => 'td', :content => /h1\. CookBook documentation/ |
259 } | 415 } |
260 } | 416 } |
261 } | 417 } |
262 | 418 |
263 # Line 5 | 419 # Line 5 |
264 assert_tag :tag => 'tr', :child => { | 420 assert_tag :tag => 'tr', :child => { |
265 :tag => 'th', :attributes => {:class => 'line-num'}, :content => '5', :sibling => { | 421 :tag => 'th', :attributes => {:class => 'line-num'}, :content => '5', :sibling => { |
266 :tag => 'td', :attributes => {:class => 'author'}, :content => /redMine Admin/, :sibling => { | 422 :tag => 'td', :attributes => {:class => 'author'}, :content => /redMine Admin/, :sibling => { |
267 :tag => 'td', :content => /Some updated \[\[documentation\]\] here/ | 423 :tag => 'td', :content => /Some updated \[\[documentation\]\] here/ |
490 assert_response :success | 646 assert_response :success |
491 assert_template 'show' | 647 assert_template 'show' |
492 assert_no_tag :tag => 'a', :attributes => { :href => '/projects/1/wiki/CookBook_documentation/edit' } | 648 assert_no_tag :tag => 'a', :attributes => { :href => '/projects/1/wiki/CookBook_documentation/edit' } |
493 end | 649 end |
494 | 650 |
651 def test_show_pdf | |
652 @request.session[:user_id] = 2 | |
653 get :show, :project_id => 1, :format => 'pdf' | |
654 assert_response :success | |
655 assert_not_nil assigns(:page) | |
656 assert_equal 'application/pdf', @response.content_type | |
657 assert_equal 'attachment; filename="CookBook_documentation.pdf"', | |
658 @response.headers['Content-Disposition'] | |
659 end | |
660 | |
661 def test_show_html | |
662 @request.session[:user_id] = 2 | |
663 get :show, :project_id => 1, :format => 'html' | |
664 assert_response :success | |
665 assert_not_nil assigns(:page) | |
666 assert_equal 'text/html', @response.content_type | |
667 assert_equal 'attachment; filename="CookBook_documentation.html"', | |
668 @response.headers['Content-Disposition'] | |
669 end | |
670 | |
671 def test_show_txt | |
672 @request.session[:user_id] = 2 | |
673 get :show, :project_id => 1, :format => 'txt' | |
674 assert_response :success | |
675 assert_not_nil assigns(:page) | |
676 assert_equal 'text/plain', @response.content_type | |
677 assert_equal 'attachment; filename="CookBook_documentation.txt"', | |
678 @response.headers['Content-Disposition'] | |
679 end | |
680 | |
495 def test_edit_unprotected_page | 681 def test_edit_unprotected_page |
496 # Non members can edit unprotected wiki pages | 682 # Non members can edit unprotected wiki pages |
497 @request.session[:user_id] = 4 | 683 @request.session[:user_id] = 4 |
498 get :edit, :project_id => 1, :id => 'Another_page' | 684 get :edit, :project_id => 1, :id => 'Another_page' |
499 assert_response :success | 685 assert_response :success |