Added some functional tests (wiki).

git-svn-id: http://redmine.rubyforge.org/svn/trunk@999 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2007-12-15 11:57:06 +00:00
parent 27d6334afa
commit 361c50c1f4
6 changed files with 191 additions and 3 deletions

View File

@ -39,7 +39,6 @@ roles_005:
- :view_time_entries
- :view_documents
- :view_wiki_pages
- :edit_wiki_pages
- :view_files
- :browse_repository
- :view_changesets
@ -75,6 +74,7 @@ roles_001:
- :view_wiki_pages
- :edit_wiki_pages
- :delete_wiki_pages
- :rename_wiki_pages
- :add_messages
- :edit_messages
- :delete_messages

View File

@ -37,4 +37,16 @@ wiki_content_versions_003:
data: |-
h1. CookBook documentation
Some updated [[documentation]] here...
wiki_content_versions_004:
data: |-
h1. Another page
This is a link to a ticket: #2
updated_on: 2007-03-08 00:18:07 +01:00
page_id: 2
wiki_content_id: 2
id: 4
version: 1
author_id: 1
comments:

View File

@ -10,3 +10,15 @@ wiki_contents_001:
version: 3
author_id: 1
comments: Gzip compression activated
wiki_contents_002:
text: |-
h1. Another page
This is a link to a ticket: #2
updated_on: 2007-03-08 00:18:07 +01:00
page_id: 2
id: 2
version: 1
author_id: 1
comments:

View File

@ -4,3 +4,9 @@ wiki_pages_001:
title: CookBook_documentation
id: 1
wiki_id: 1
wiki_pages_002:
created_on: 2007-03-08 00:18:07 +01:00
title: Another_page
id: 2
wiki_id: 1

View File

@ -0,0 +1,145 @@
# redMine - project management software
# Copyright (C) 2006-2007 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
require File.dirname(__FILE__) + '/../test_helper'
require 'wiki_controller'
# Re-raise errors caught by the controller.
class WikiController; def rescue_action(e) raise e end; end
class WikiControllerTest < Test::Unit::TestCase
fixtures :projects, :users, :roles, :members, :enabled_modules, :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions
def setup
@controller = WikiController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
User.current = nil
end
def test_show_start_page
get :index, :id => 1
assert_response :success
assert_template 'show'
assert_tag :tag => 'h1', :content => /CookBook documentation/
end
def test_show_page_with_name
get :index, :id => 1, :page => 'Another_page'
assert_response :success
assert_template 'show'
assert_tag :tag => 'h1', :content => /Another page/
end
def test_show_unexistent_page_without_edit_right
get :index, :id => 1, :page => 'Unexistent page'
assert_response 404
end
def test_show_unexistent_page_with_edit_right
@request.session[:user_id] = 2
get :index, :id => 1, :page => 'Unexistent page'
assert_response :success
assert_template 'edit'
end
def test_create_page
@request.session[:user_id] = 2
post :edit, :id => 1,
:page => 'New page',
:content => {:comments => 'Created the page',
:text => "h1. New page\n\nThis is a new page",
:version => 0}
assert_redirected_to 'wiki/1/New_page'
page = Project.find(1).wiki.find_page('New page')
assert !page.new_record?
assert_not_nil page.content
assert_equal 'Created the page', page.content.comments
end
def test_preview
@request.session[:user_id] = 2
xhr :post, :preview, :id => 1, :page => 'CookBook_documentation',
:content => { :comments => '',
:text => 'this is a *previewed text*',
:version => 3 }
assert_response :success
assert_template 'common/_preview'
assert_tag :tag => 'strong', :content => /previewed text/
end
def test_history
get :history, :id => 1, :page => 'CookBook_documentation'
assert_response :success
assert_template 'history'
assert_not_nil assigns(:versions)
assert_equal 3, assigns(:versions).size
end
def test_diff
get :diff, :id => 1, :page => 'CookBook_documentation', :version => 2, :version_from => 1
assert_response :success
assert_template 'diff'
assert_tag :tag => 'span', :attributes => { :class => 'diff_in'},
:content => /updated/
end
def test_rename_with_redirect
@request.session[:user_id] = 2
post :rename, :id => 1, :page => 'Another_page',
:wiki_page => { :title => 'Another renamed page',
:redirect_existing_links => 1 }
assert_redirected_to 'wiki/1/Another_renamed_page'
wiki = Project.find(1).wiki
# Check redirects
assert_not_nil wiki.find_page('Another page')
assert_nil wiki.find_page('Another page', :with_redirect => false)
end
def test_rename_without_redirect
@request.session[:user_id] = 2
post :rename, :id => 1, :page => 'Another_page',
:wiki_page => { :title => 'Another renamed page',
:redirect_existing_links => "0" }
assert_redirected_to 'wiki/1/Another_renamed_page'
wiki = Project.find(1).wiki
# Check that there's no redirects
assert_nil wiki.find_page('Another page')
end
def test_destroy
@request.session[:user_id] = 2
post :destroy, :id => 1, :page => 'CookBook_documentation'
assert_redirected_to 'wiki/1/Page_index/special'
end
def test_page_index
get :special, :id => 1, :page => 'Page_index'
assert_response :success
assert_template 'special_page_index'
pages = assigns(:pages)
assert_not_nil pages
assert_equal 2, pages.size
assert_tag :tag => 'a', :attributes => { :href => '/wiki/1/CookBook_documentation' },
:content => /CookBook documentation/
end
def test_not_found
get :index, :id => 999
assert_response 404
end
end

View File

@ -31,7 +31,7 @@ class WikisControllerTest < Test::Unit::TestCase
User.current = nil
end
def test_create_wiki
def test_create
@request.session[:user_id] = 1
assert_nil Project.find(3).wiki
post :edit, :id => 3, :wiki => { :start_page => 'Start page' }
@ -40,4 +40,17 @@ class WikisControllerTest < Test::Unit::TestCase
assert_not_nil wiki
assert_equal 'Start page', wiki.start_page
end
def test_destroy
@request.session[:user_id] = 1
post :destroy, :id => 1, :confirm => 1
assert_redirected_to 'projects/settings/1'
assert_nil Project.find(1).wiki
end
def test_not_found
@request.session[:user_id] = 1
post :destroy, :id => 999, :confirm => 1
assert_response 404
end
end