comparison test/functional/wiki_controller_test.rb @ 1464:261b3d9a4903 redmine-2.4

Update to Redmine 2.4 branch rev 12663
author Chris Cannam
date Tue, 14 Jan 2014 14:37:42 +0000
parents 3e4c3460b6ca
children e248c7af89ec
comparison
equal deleted inserted replaced
1296:038ba2d95de8 1464:261b3d9a4903
1 # Redmine - project management software 1 # Redmine - project management software
2 # Copyright (C) 2006-2012 Jean-Philippe Lang 2 # Copyright (C) 2006-2013 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'
180 def test_show_should_not_show_history_without_permission 173 def test_show_should_not_show_history_without_permission
181 Role.anonymous.remove_permission! :view_wiki_edits 174 Role.anonymous.remove_permission! :view_wiki_edits
182 get :show, :project_id => 1, :id => 'Page with sections', :version => 2 175 get :show, :project_id => 1, :id => 'Page with sections', :version => 2
183 176
184 assert_response 302 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]'
185 end 188 end
186 189
187 def test_create_page 190 def test_create_page
188 @request.session[:user_id] = 2 191 @request.session[:user_id] = 2
189 assert_difference 'WikiPage.count' do 192 assert_difference 'WikiPage.count' do
417 c.reload 420 c.reload
418 assert_equal 'Previous text', c.text 421 assert_equal 'Previous text', c.text
419 assert_equal 2, c.version 422 assert_equal 2, c.version
420 end 423 end
421 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
422 def test_update_section 438 def test_update_section
423 @request.session[:user_id] = 2 439 @request.session[:user_id] = 2
424 page = WikiPage.find_by_title('Page_with_sections') 440 page = WikiPage.find_by_title('Page_with_sections')
425 section, hash = Redmine::WikiFormatting::Textile::Formatter.new(page.content.text).get_section(2) 441 section, hash = Redmine::WikiFormatting::Textile::Formatter.new(page.content.text).get_section(2)
426 text = page.content.text 442 text = page.content.text
436 :section => 2, 452 :section => 2,
437 :section_hash => hash 453 :section_hash => hash
438 end 454 end
439 end 455 end
440 end 456 end
441 assert_redirected_to '/projects/ecookbook/wiki/Page_with_sections' 457 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 458 assert_equal Redmine::WikiFormatting::Textile::Formatter.new(text).update_section(2, "New section content"), page.reload.content.text
443 end 459 end
444 460
445 def test_update_section_should_allow_stale_page_update 461 def test_update_section_should_allow_stale_page_update
446 @request.session[:user_id] = 2 462 @request.session[:user_id] = 2
459 :section => 2, 475 :section => 2,
460 :section_hash => hash 476 :section_hash => hash
461 end 477 end
462 end 478 end
463 end 479 end
464 assert_redirected_to '/projects/ecookbook/wiki/Page_with_sections' 480 assert_redirected_to '/projects/ecookbook/wiki/Page_with_sections#section-2'
465 page.reload 481 page.reload
466 assert_equal Redmine::WikiFormatting::Textile::Formatter.new(text).update_section(2, "New section content"), page.content.text 482 assert_equal Redmine::WikiFormatting::Textile::Formatter.new(text).update_section(2, "New section content"), page.content.text
467 assert_equal 4, page.content.version 483 assert_equal 4, page.content.version
468 end 484 end
469 485
590 } 606 }
591 607
592 # Line 5 608 # Line 5
593 assert_tag :tag => 'tr', :child => { 609 assert_tag :tag => 'tr', :child => {
594 :tag => 'th', :attributes => {:class => 'line-num'}, :content => '5', :sibling => { 610 :tag => 'th', :attributes => {:class => 'line-num'}, :content => '5', :sibling => {
595 :tag => 'td', :attributes => {:class => 'author'}, :content => /redMine Admin/, :sibling => { 611 :tag => 'td', :attributes => {:class => 'author'}, :content => /Redmine Admin/, :sibling => {
596 :tag => 'td', :content => /Some updated \[\[documentation\]\] here/ 612 :tag => 'td', :content => /Some updated \[\[documentation\]\] here/
597 } 613 }
598 } 614 }
599 } 615 }
600 end 616 end