summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2008-05-04 15:05:38 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2008-05-04 15:05:38 +0000
commit04766697357b29521515e7c71ae5139e04dd5ba2 (patch)
treee51f4c5770517801ee3772dfaf3d5bfb93b00a24 /test
parent556df99456bf579057213157eb593c6a0dea0676 (diff)
downloadredmine-04766697357b29521515e7c71ae5139e04dd5ba2.tar.gz
redmine-04766697357b29521515e7c71ae5139e04dd5ba2.zip
Wiki page protection (#851, patch #1146 by Mateo Murphy with slight changes).
New permission added: protect wiki pages. Once a page is protected, it can be edited/renamed/deleted only by users who have this permission. git-svn-id: http://redmine.rubyforge.org/svn/trunk@1415 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'test')
-rw-r--r--test/fixtures/roles.yml2
-rw-r--r--test/fixtures/wiki_pages.yml4
-rw-r--r--test/functional/wiki_controller_test.rb56
3 files changed, 62 insertions, 0 deletions
diff --git a/test/fixtures/roles.yml b/test/fixtures/roles.yml
index 1ede6fca9..e7b142268 100644
--- a/test/fixtures/roles.yml
+++ b/test/fixtures/roles.yml
@@ -29,6 +29,7 @@ roles_001:
- :manage_documents
- :view_wiki_pages
- :edit_wiki_pages
+ - :protect_wiki_pages
- :delete_wiki_pages
- :rename_wiki_pages
- :add_messages
@@ -69,6 +70,7 @@ roles_002:
- :manage_documents
- :view_wiki_pages
- :edit_wiki_pages
+ - :protect_wiki_pages
- :delete_wiki_pages
- :add_messages
- :manage_boards
diff --git a/test/fixtures/wiki_pages.yml b/test/fixtures/wiki_pages.yml
index f89832e44..ef7242430 100644
--- a/test/fixtures/wiki_pages.yml
+++ b/test/fixtures/wiki_pages.yml
@@ -4,19 +4,23 @@ wiki_pages_001:
title: CookBook_documentation
id: 1
wiki_id: 1
+ protected: true
wiki_pages_002:
created_on: 2007-03-08 00:18:07 +01:00
title: Another_page
id: 2
wiki_id: 1
+ protected: false
wiki_pages_003:
created_on: 2007-03-08 00:18:07 +01:00
title: Start_page
id: 3
wiki_id: 2
+ protected: false
wiki_pages_004:
created_on: 2007-03-08 00:18:07 +01:00
title: Page_with_an_inline_image
id: 4
wiki_id: 1
+ protected: false
\ No newline at end of file
diff --git a/test/functional/wiki_controller_test.rb b/test/functional/wiki_controller_test.rb
index bf31e6614..8688c2e03 100644
--- a/test/functional/wiki_controller_test.rb
+++ b/test/functional/wiki_controller_test.rb
@@ -160,4 +160,60 @@ class WikiControllerTest < Test::Unit::TestCase
get :index, :id => 999
assert_response 404
end
+
+ def test_protect_page
+ page = WikiPage.find_by_wiki_id_and_title(1, 'Another_page')
+ assert !page.protected?
+ @request.session[:user_id] = 2
+ post :protect, :id => 1, :page => page.title, :protected => '1'
+ assert_redirected_to 'wiki/ecookbook/Another_page'
+ assert page.reload.protected?
+ end
+
+ def test_unprotect_page
+ page = WikiPage.find_by_wiki_id_and_title(1, 'CookBook_documentation')
+ assert page.protected?
+ @request.session[:user_id] = 2
+ post :protect, :id => 1, :page => page.title, :protected => '0'
+ assert_redirected_to 'wiki/ecookbook'
+ assert !page.reload.protected?
+ end
+
+ def test_show_page_with_edit_link
+ @request.session[:user_id] = 2
+ get :index, :id => 1
+ assert_response :success
+ assert_template 'show'
+ assert_tag :tag => 'a', :attributes => { :href => '/wiki/1/CookBook_documentation/edit' }
+ end
+
+ def test_show_page_without_edit_link
+ @request.session[:user_id] = 4
+ get :index, :id => 1
+ assert_response :success
+ assert_template 'show'
+ assert_no_tag :tag => 'a', :attributes => { :href => '/wiki/1/CookBook_documentation/edit' }
+ end
+
+ def test_edit_unprotected_page
+ # Non members can edit unprotected wiki pages
+ @request.session[:user_id] = 4
+ get :edit, :id => 1, :page => 'Another_page'
+ assert_response :success
+ assert_template 'edit'
+ end
+
+ def test_edit_protected_page_by_nonmember
+ # Non members can't edit protected wiki pages
+ @request.session[:user_id] = 4
+ get :edit, :id => 1, :page => 'CookBook_documentation'
+ assert_response 403
+ end
+
+ def test_edit_protected_page_by_member
+ @request.session[:user_id] = 2
+ get :edit, :id => 1, :page => 'CookBook_documentation'
+ assert_response :success
+ assert_template 'edit'
+ end
end