comparison test/functional/wiki_controller_test.rb @ 1526:404aa68d4227

Merge from live branch
author Chris Cannam
date Thu, 11 Sep 2014 12:46:20 +0100
parents dffacf8a6908
children
comparison
equal deleted inserted replaced
1493:a5f2bdf3b486 1526:404aa68d4227
1 # Redmine - project management software 1 # Redmine - project management software
2 # Copyright (C) 2006-2012 Jean-Philippe Lang 2 # Copyright (C) 2006-2014 Jean-Philippe Lang
3 # 3 #
4 # This program is free software; you can redistribute it and/or 4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License 5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2 6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version. 7 # of the License, or (at your option) any later version.
14 # You should have received a copy of the GNU General Public License 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 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. 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 require File.expand_path('../../test_helper', __FILE__) 18 require File.expand_path('../../test_helper', __FILE__)
19 require 'wiki_controller'
20
21 # Re-raise errors caught by the controller.
22 class WikiController; def rescue_action(e) raise e end; end
23 19
24 class WikiControllerTest < ActionController::TestCase 20 class WikiControllerTest < ActionController::TestCase
25 fixtures :projects, :users, :roles, :members, :member_roles, 21 fixtures :projects, :users, :roles, :members, :member_roles,
26 :enabled_modules, :wikis, :wiki_pages, :wiki_contents, 22 :enabled_modules, :wikis, :wiki_pages, :wiki_contents,
27 :wiki_content_versions, :attachments 23 :wiki_content_versions, :attachments
28 24
29 def setup 25 def setup
30 @controller = WikiController.new
31 @request = ActionController::TestRequest.new
32 @response = ActionController::TestResponse.new
33 User.current = nil 26 User.current = nil
34 end 27 end
35 28
36 def test_show_start_page 29 def test_show_start_page
37 get :show, :project_id => 'ecookbook' 30 get :show, :project_id => 'ecookbook'
58 assert_response :success 51 assert_response :success
59 assert_template 'show' 52 assert_template 'show'
60 assert_tag :tag => 'h1', :content => /Another page/ 53 assert_tag :tag => 'h1', :content => /Another page/
61 # Included page with an inline image 54 # Included page with an inline image
62 assert_tag :tag => 'p', :content => /This is an inline image/ 55 assert_tag :tag => 'p', :content => /This is an inline image/
63 assert_tag :tag => 'img', :attributes => { :src => '/attachments/download/3', 56 assert_tag :tag => 'img', :attributes => { :src => '/attachments/download/3/logo.gif',
64 :alt => 'This is a logo' } 57 :alt => 'This is a logo' }
65 end 58 end
66 59
67 def test_show_old_version 60 def test_show_old_version
68 get :show, :project_id => 'ecookbook', :id => 'CookBook_documentation', :version => '2' 61 get :show, :project_id => 'ecookbook', :id => 'CookBook_documentation', :version => '2'
166 get :show, :project_id => 1, :id => 'Unexistent page' 159 get :show, :project_id => 1, :id => 'Unexistent page'
167 assert_response :success 160 assert_response :success
168 assert_template 'edit' 161 assert_template 'edit'
169 end 162 end
170 163
164 def test_show_specific_version_of_an_unexistent_page_without_edit_right
165 get :show, :project_id => 1, :id => 'Unexistent page', :version => 1
166 assert_response 404
167 end
168
171 def test_show_unexistent_page_with_parent_should_preselect_parent 169 def test_show_unexistent_page_with_parent_should_preselect_parent
172 @request.session[:user_id] = 2 170 @request.session[:user_id] = 2
173 get :show, :project_id => 1, :id => 'Unexistent page', :parent => 'Another_page' 171 get :show, :project_id => 1, :id => 'Unexistent page', :parent => 'Another_page'
174 assert_response :success 172 assert_response :success
175 assert_template 'edit' 173 assert_template 'edit'
180 def test_show_should_not_show_history_without_permission 178 def test_show_should_not_show_history_without_permission
181 Role.anonymous.remove_permission! :view_wiki_edits 179 Role.anonymous.remove_permission! :view_wiki_edits
182 get :show, :project_id => 1, :id => 'Page with sections', :version => 2 180 get :show, :project_id => 1, :id => 'Page with sections', :version => 2
183 181
184 assert_response 302 182 assert_response 302
183 end
184
185 def test_show_page_without_content_should_display_the_edit_form
186 @request.session[:user_id] = 2
187 WikiPage.create!(:title => 'NoContent', :wiki => Project.find(1).wiki)
188
189 get :show, :project_id => 1, :id => 'NoContent'
190 assert_response :success
191 assert_template 'edit'
192 assert_select 'textarea[name=?]', 'content[text]'
185 end 193 end
186 194
187 def test_create_page 195 def test_create_page
188 @request.session[:user_id] = 2 196 @request.session[:user_id] = 2
189 assert_difference 'WikiPage.count' do 197 assert_difference 'WikiPage.count' do
417 c.reload 425 c.reload
418 assert_equal 'Previous text', c.text 426 assert_equal 'Previous text', c.text
419 assert_equal 2, c.version 427 assert_equal 2, c.version
420 end 428 end
421 429
430 def test_update_page_without_content_should_create_content
431 @request.session[:user_id] = 2
432 page = WikiPage.create!(:title => 'NoContent', :wiki => Project.find(1).wiki)
433
434 assert_no_difference 'WikiPage.count' do
435 assert_difference 'WikiContent.count' do
436 put :update, :project_id => 1, :id => 'NoContent', :content => {:text => 'Some content'}
437 assert_response 302
438 end
439 end
440 assert_equal 'Some content', page.reload.content.text
441 end
442
422 def test_update_section 443 def test_update_section
423 @request.session[:user_id] = 2 444 @request.session[:user_id] = 2
424 page = WikiPage.find_by_title('Page_with_sections') 445 page = WikiPage.find_by_title('Page_with_sections')
425 section, hash = Redmine::WikiFormatting::Textile::Formatter.new(page.content.text).get_section(2) 446 section, hash = Redmine::WikiFormatting::Textile::Formatter.new(page.content.text).get_section(2)
426 text = page.content.text 447 text = page.content.text
436 :section => 2, 457 :section => 2,
437 :section_hash => hash 458 :section_hash => hash
438 end 459 end
439 end 460 end
440 end 461 end
441 assert_redirected_to '/projects/ecookbook/wiki/Page_with_sections' 462 assert_redirected_to '/projects/ecookbook/wiki/Page_with_sections#section-2'
442 assert_equal Redmine::WikiFormatting::Textile::Formatter.new(text).update_section(2, "New section content"), page.reload.content.text 463 assert_equal Redmine::WikiFormatting::Textile::Formatter.new(text).update_section(2, "New section content"), page.reload.content.text
443 end 464 end
444 465
445 def test_update_section_should_allow_stale_page_update 466 def test_update_section_should_allow_stale_page_update
446 @request.session[:user_id] = 2 467 @request.session[:user_id] = 2
459 :section => 2, 480 :section => 2,
460 :section_hash => hash 481 :section_hash => hash
461 end 482 end
462 end 483 end
463 end 484 end
464 assert_redirected_to '/projects/ecookbook/wiki/Page_with_sections' 485 assert_redirected_to '/projects/ecookbook/wiki/Page_with_sections#section-2'
465 page.reload 486 page.reload
466 assert_equal Redmine::WikiFormatting::Textile::Formatter.new(text).update_section(2, "New section content"), page.content.text 487 assert_equal Redmine::WikiFormatting::Textile::Formatter.new(text).update_section(2, "New section content"), page.content.text
467 assert_equal 4, page.content.version 488 assert_equal 4, page.content.version
468 end 489 end
469 490
590 } 611 }
591 612
592 # Line 5 613 # Line 5
593 assert_tag :tag => 'tr', :child => { 614 assert_tag :tag => 'tr', :child => {
594 :tag => 'th', :attributes => {:class => 'line-num'}, :content => '5', :sibling => { 615 :tag => 'th', :attributes => {:class => 'line-num'}, :content => '5', :sibling => {
595 :tag => 'td', :attributes => {:class => 'author'}, :content => /redMine Admin/, :sibling => { 616 :tag => 'td', :attributes => {:class => 'author'}, :content => /Redmine Admin/, :sibling => {
596 :tag => 'td', :content => /Some updated \[\[documentation\]\] here/ 617 :tag => 'td', :content => /Some updated \[\[documentation\]\] here/
597 } 618 }
598 } 619 }
599 } 620 }
600 end 621 end
930 951
931 def test_add_attachment 952 def test_add_attachment
932 @request.session[:user_id] = 2 953 @request.session[:user_id] = 2
933 assert_difference 'Attachment.count' do 954 assert_difference 'Attachment.count' do
934 post :add_attachment, :project_id => 1, :id => 'CookBook_documentation', 955 post :add_attachment, :project_id => 1, :id => 'CookBook_documentation',
935 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}} 956 :attachments => {
936 end 957 '1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'),
937 attachment = Attachment.first(:order => 'id DESC') 958 'description' => 'test file'}
959 }
960 end
961 attachment = Attachment.order('id DESC').first
938 assert_equal Wiki.find(1).find_page('CookBook_documentation'), attachment.container 962 assert_equal Wiki.find(1).find_page('CookBook_documentation'), attachment.container
939 end 963 end
940 end 964 end