2005-08-11 07:46:38 +02:00
|
|
|
#!/usr/bin/env ruby
|
2005-01-28 02:24:31 +01:00
|
|
|
|
2005-08-09 04:20:28 +02:00
|
|
|
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
2005-01-28 02:24:31 +01:00
|
|
|
require 'admin_controller'
|
|
|
|
|
|
|
|
# Raise errors beyond the default web-based presentation
|
|
|
|
class AdminController; def rescue_action(e) logger.error(e); raise e end; end
|
|
|
|
|
|
|
|
class AdminControllerTest < Test::Unit::TestCase
|
2005-09-11 10:05:19 +02:00
|
|
|
fixtures :webs, :pages, :revisions, :system, :wiki_references
|
2005-01-28 02:24:31 +01:00
|
|
|
|
|
|
|
def setup
|
2005-08-09 04:20:28 +02:00
|
|
|
@controller = AdminController.new
|
|
|
|
@request = ActionController::TestRequest.new
|
|
|
|
@response = ActionController::TestResponse.new
|
|
|
|
@wiki = Wiki.new
|
|
|
|
@oak = pages(:oak)
|
|
|
|
@elephant = pages(:elephant)
|
|
|
|
@web = webs(:test_wiki)
|
|
|
|
@home = @page = pages(:home_page)
|
2005-01-28 02:24:31 +01:00
|
|
|
end
|
|
|
|
|
2005-01-28 03:35:59 +01:00
|
|
|
def test_create_system_form_displayed
|
2005-08-09 04:20:28 +02:00
|
|
|
use_blank_wiki
|
2005-01-28 03:35:59 +01:00
|
|
|
process('create_system')
|
2005-08-09 04:20:28 +02:00
|
|
|
assert_response :success
|
2005-01-28 03:35:59 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_create_system_form_submitted
|
2005-08-09 04:20:28 +02:00
|
|
|
use_blank_wiki
|
|
|
|
assert !@wiki.setup?
|
2005-01-28 02:24:31 +01:00
|
|
|
|
|
|
|
process('create_system', 'password' => 'a_password', 'web_name' => 'My Wiki',
|
|
|
|
'web_address' => 'my_wiki')
|
|
|
|
|
2005-01-28 03:57:25 +01:00
|
|
|
assert_redirected_to :web => 'my_wiki', :controller => 'wiki', :action => 'new',
|
|
|
|
:id => 'HomePage'
|
2005-08-09 04:20:28 +02:00
|
|
|
assert @wiki.setup?
|
|
|
|
assert_equal 'a_password', @wiki.system[:password]
|
|
|
|
assert_equal 1, @wiki.webs.size
|
|
|
|
new_web = @wiki.webs['my_wiki']
|
2005-01-28 02:24:31 +01:00
|
|
|
assert_equal 'My Wiki', new_web.name
|
|
|
|
assert_equal 'my_wiki', new_web.address
|
|
|
|
end
|
|
|
|
|
2005-01-28 03:35:59 +01:00
|
|
|
def test_create_system_form_submitted_and_wiki_already_initialized
|
2005-08-09 04:20:28 +02:00
|
|
|
wiki_before = @wiki
|
|
|
|
old_size = @wiki.webs.size
|
|
|
|
assert @wiki.setup?
|
2005-01-28 02:24:31 +01:00
|
|
|
|
|
|
|
process 'create_system', 'password' => 'a_password', 'web_name' => 'My Wiki',
|
|
|
|
'web_address' => 'my_wiki'
|
|
|
|
|
2005-08-09 04:20:28 +02:00
|
|
|
assert_redirected_to :web => @wiki.webs.keys.first, :action => 'show', :id => 'HomePage'
|
|
|
|
assert_equal wiki_before, @wiki
|
2005-01-28 03:35:59 +01:00
|
|
|
# and no new web should be created either
|
2005-08-09 04:20:28 +02:00
|
|
|
assert_equal old_size, @wiki.webs.size
|
2007-05-08 00:46:00 +02:00
|
|
|
assert(@response.has_flash_object?(:error))
|
2005-01-28 03:35:59 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_create_system_no_form_and_wiki_already_initialized
|
|
|
|
assert @wiki.setup?
|
|
|
|
process('create_system')
|
2005-08-09 04:20:28 +02:00
|
|
|
assert_redirected_to :web => @wiki.webs.keys.first, :action => 'show', :id => 'HomePage'
|
2007-05-08 00:46:00 +02:00
|
|
|
assert(@response.has_flash_object?(:error))
|
2005-01-28 02:24:31 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def test_create_web
|
2005-08-09 04:20:28 +02:00
|
|
|
@wiki.system.update_attribute(:password, 'pswd')
|
2005-01-28 02:24:31 +01:00
|
|
|
|
|
|
|
process 'create_web', 'system_password' => 'pswd', 'name' => 'Wiki Two', 'address' => 'wiki2'
|
|
|
|
|
2005-03-26 01:15:04 +01:00
|
|
|
assert_redirected_to :web => 'wiki2', :action => 'new', :id => 'HomePage'
|
2005-01-28 02:24:31 +01:00
|
|
|
wiki2 = @wiki.webs['wiki2']
|
|
|
|
assert wiki2
|
|
|
|
assert_equal 'Wiki Two', wiki2.name
|
|
|
|
assert_equal 'wiki2', wiki2.address
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_create_web_default_password
|
2005-08-09 04:20:28 +02:00
|
|
|
@wiki.system.update_attribute(:password, nil)
|
2005-01-28 02:24:31 +01:00
|
|
|
|
|
|
|
process 'create_web', 'system_password' => 'instiki', 'name' => 'Wiki Two', 'address' => 'wiki2'
|
|
|
|
|
2005-03-26 01:15:04 +01:00
|
|
|
assert_redirected_to :web => 'wiki2', :action => 'new', :id => 'HomePage'
|
2005-01-28 02:24:31 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_create_web_failed_authentication
|
2005-08-09 04:20:28 +02:00
|
|
|
@wiki.system.update_attribute(:password, 'pswd')
|
2005-01-28 02:24:31 +01:00
|
|
|
|
|
|
|
process 'create_web', 'system_password' => 'wrong', 'name' => 'Wiki Two', 'address' => 'wiki2'
|
|
|
|
|
|
|
|
assert_redirected_to :web => nil, :action => 'index'
|
|
|
|
assert_nil @wiki.webs['wiki2']
|
|
|
|
end
|
|
|
|
|
2005-01-28 04:44:36 +01:00
|
|
|
def test_create_web_no_form_submitted
|
2005-08-09 04:20:28 +02:00
|
|
|
@wiki.system.update_attribute(:password, 'pswd')
|
2005-01-28 04:44:36 +01:00
|
|
|
process 'create_web'
|
2005-08-09 04:20:28 +02:00
|
|
|
assert_response :success
|
2005-01-28 02:24:31 +01:00
|
|
|
end
|
|
|
|
|
2005-01-28 04:44:36 +01:00
|
|
|
|
2005-02-05 14:19:20 +01:00
|
|
|
def test_edit_web_no_form
|
2005-01-28 04:44:36 +01:00
|
|
|
process 'edit_web', 'web' => 'wiki1'
|
|
|
|
# this action simply renders a form
|
2005-08-09 04:20:28 +02:00
|
|
|
assert_response :success
|
2005-01-28 02:24:31 +01:00
|
|
|
end
|
|
|
|
|
2005-02-05 14:19:20 +01:00
|
|
|
def test_edit_web_form_submitted
|
2005-08-09 04:20:28 +02:00
|
|
|
@wiki.system.update_attribute(:password, 'pswd')
|
2005-01-28 02:24:31 +01:00
|
|
|
|
2005-02-05 14:04:55 +01:00
|
|
|
process('edit_web', 'system_password' => 'pswd',
|
2005-01-28 02:24:31 +01:00
|
|
|
'web' => 'wiki1', 'address' => 'renamed_wiki1', 'name' => 'Renamed Wiki1',
|
|
|
|
'markup' => 'markdown', 'color' => 'blue', 'additional_style' => 'whatever',
|
|
|
|
'safe_mode' => 'on', 'password' => 'new_password', 'published' => 'on',
|
2005-01-30 07:18:57 +01:00
|
|
|
'brackets_only' => 'on', 'count_pages' => 'on', 'allow_uploads' => 'on',
|
|
|
|
'max_upload_size' => '300')
|
2005-01-28 02:24:31 +01:00
|
|
|
|
|
|
|
assert_redirected_to :web => 'renamed_wiki1', :action => 'show', :id => 'HomePage'
|
2005-08-09 04:20:28 +02:00
|
|
|
@web = Web.find(@web.id)
|
2005-01-28 02:24:31 +01:00
|
|
|
assert_equal 'renamed_wiki1', @web.address
|
|
|
|
assert_equal 'Renamed Wiki1', @web.name
|
|
|
|
assert_equal :markdown, @web.markup
|
|
|
|
assert_equal 'blue', @web.color
|
2005-08-09 04:20:28 +02:00
|
|
|
assert @web.safe_mode?
|
2005-01-28 02:24:31 +01:00
|
|
|
assert_equal 'new_password', @web.password
|
2005-08-09 04:20:28 +02:00
|
|
|
assert @web.published?
|
|
|
|
assert @web.brackets_only?
|
|
|
|
assert @web.count_pages?
|
|
|
|
assert @web.allow_uploads?
|
2005-01-30 07:18:57 +01:00
|
|
|
assert_equal 300, @web.max_upload_size
|
2005-01-28 02:24:31 +01:00
|
|
|
end
|
|
|
|
|
2005-02-05 14:04:55 +01:00
|
|
|
def test_edit_web_opposite_values
|
2005-08-09 04:20:28 +02:00
|
|
|
@wiki.system.update_attribute(:password, 'pswd')
|
2005-01-28 02:24:31 +01:00
|
|
|
|
2005-02-05 14:04:55 +01:00
|
|
|
process('edit_web', 'system_password' => 'pswd',
|
2005-01-28 02:24:31 +01:00
|
|
|
'web' => 'wiki1', 'address' => 'renamed_wiki1', 'name' => 'Renamed Wiki1',
|
|
|
|
'markup' => 'markdown', 'color' => 'blue', 'additional_style' => 'whatever',
|
|
|
|
'password' => 'new_password')
|
|
|
|
# safe_mode, published, brackets_only, count_pages, allow_uploads not set
|
|
|
|
# and should become false
|
|
|
|
|
|
|
|
assert_redirected_to :web => 'renamed_wiki1', :action => 'show', :id => 'HomePage'
|
2005-08-09 04:20:28 +02:00
|
|
|
@web = Web.find(@web.id)
|
|
|
|
assert !@web.safe_mode?
|
|
|
|
assert !@web.published?
|
|
|
|
assert !@web.brackets_only?
|
|
|
|
assert !@web.count_pages?
|
|
|
|
assert !@web.allow_uploads?
|
2005-01-28 02:24:31 +01:00
|
|
|
end
|
|
|
|
|
2005-02-05 14:19:20 +01:00
|
|
|
def test_edit_web_wrong_password
|
|
|
|
process('edit_web', 'system_password' => 'wrong',
|
|
|
|
'web' => 'wiki1', 'address' => 'renamed_wiki1', 'name' => 'Renamed Wiki1',
|
|
|
|
'markup' => 'markdown', 'color' => 'blue', 'additional_style' => 'whatever',
|
|
|
|
'password' => 'new_password')
|
|
|
|
|
|
|
|
#returns to the same form
|
2005-08-09 04:20:28 +02:00
|
|
|
assert_response :success
|
2005-07-20 03:50:49 +02:00
|
|
|
assert @response.has_template_object?('error')
|
2005-02-05 14:19:20 +01:00
|
|
|
end
|
|
|
|
|
2005-02-10 23:05:30 +01:00
|
|
|
def test_edit_web_rename_to_already_existing_web_name
|
2005-08-09 04:20:28 +02:00
|
|
|
@wiki.system.update_attribute(:password, 'pswd')
|
2005-02-10 23:05:30 +01:00
|
|
|
|
|
|
|
@wiki.create_web('Another', 'another')
|
|
|
|
process('edit_web', 'system_password' => 'pswd',
|
|
|
|
'web' => 'wiki1', 'address' => 'another', 'name' => 'Renamed Wiki1',
|
|
|
|
'markup' => 'markdown', 'color' => 'blue', 'additional_style' => 'whatever',
|
|
|
|
'password' => 'new_password')
|
|
|
|
|
|
|
|
#returns to the same form
|
2005-08-09 04:20:28 +02:00
|
|
|
assert_response :success
|
2005-07-20 03:50:49 +02:00
|
|
|
assert @response.has_template_object?('error')
|
2005-02-10 23:05:30 +01:00
|
|
|
end
|
|
|
|
|
2005-02-05 14:19:20 +01:00
|
|
|
def test_edit_web_empty_password
|
|
|
|
process('edit_web', 'system_password' => '',
|
|
|
|
'web' => 'wiki1', 'address' => 'renamed_wiki1', 'name' => 'Renamed Wiki1',
|
|
|
|
'markup' => 'markdown', 'color' => 'blue', 'additional_style' => 'whatever',
|
|
|
|
'password' => 'new_password')
|
|
|
|
|
|
|
|
#returns to the same form
|
2005-08-09 04:20:28 +02:00
|
|
|
assert_response :success
|
2005-07-20 03:50:49 +02:00
|
|
|
assert @response.has_template_object?('error')
|
2005-02-05 14:19:20 +01:00
|
|
|
end
|
2005-01-28 02:24:31 +01:00
|
|
|
|
2005-02-13 15:58:03 +01:00
|
|
|
|
|
|
|
def test_remove_orphaned_pages
|
2005-08-09 04:20:28 +02:00
|
|
|
@wiki.system.update_attribute(:password, 'pswd')
|
|
|
|
page_order = [@home, pages(:my_way), @oak, pages(:smart_engine), pages(:that_way)]
|
|
|
|
orphan_page_linking_to_oak = @wiki.write_page('wiki1', 'Pine',
|
2005-02-13 15:58:03 +01:00
|
|
|
"Refers to [[Oak]].\n" +
|
|
|
|
"category: trees",
|
2005-09-10 08:12:57 +02:00
|
|
|
Time.now, Author.new('TreeHugger', '127.0.0.2'), test_renderer)
|
2005-02-13 15:58:03 +01:00
|
|
|
|
|
|
|
r = process('remove_orphaned_pages', 'web' => 'wiki1', 'system_password_orphaned' => 'pswd')
|
|
|
|
|
2005-02-15 23:41:58 +01:00
|
|
|
assert_redirected_to :controller => 'wiki', :web => 'wiki1', :action => 'list'
|
2005-08-09 04:20:28 +02:00
|
|
|
@web.pages(true)
|
|
|
|
assert_equal page_order, @web.select.sort,
|
2005-02-13 15:58:03 +01:00
|
|
|
"Pages are not as expected: #{@web.select.sort.map {|p| p.name}.inspect}"
|
|
|
|
|
|
|
|
# Oak is now orphan, second pass should remove it
|
2005-02-15 23:41:58 +01:00
|
|
|
r = process('remove_orphaned_pages', 'web' => 'wiki1', 'system_password_orphaned' => 'pswd')
|
|
|
|
assert_redirected_to :controller => 'wiki', :web => 'wiki1', :action => 'list'
|
2005-08-09 04:20:28 +02:00
|
|
|
@web.pages(true)
|
|
|
|
page_order.delete(@oak)
|
|
|
|
assert_equal page_order, @web.select.sort,
|
2005-02-13 15:58:03 +01:00
|
|
|
"Pages are not as expected: #{@web.select.sort.map {|p| p.name}.inspect}"
|
|
|
|
|
|
|
|
# third pass does not destroy HomePage
|
2005-02-15 23:41:58 +01:00
|
|
|
r = process('remove_orphaned_pages', 'web' => 'wiki1', 'system_password_orphaned' => 'pswd')
|
2005-02-13 15:58:03 +01:00
|
|
|
assert_redirected_to :action => 'list'
|
2005-08-09 04:20:28 +02:00
|
|
|
@web.pages(true)
|
|
|
|
assert_equal page_order, @web.select.sort,
|
2005-02-13 15:58:03 +01:00
|
|
|
"Pages are not as expected: #{@web.select.sort.map {|p| p.name}.inspect}"
|
|
|
|
end
|
|
|
|
|
2005-05-09 05:52:43 +02:00
|
|
|
def test_remove_orphaned_pages_empty_or_wrong_password
|
|
|
|
@wiki.system[:password] = 'pswd'
|
|
|
|
|
|
|
|
process('remove_orphaned_pages', 'web' => 'wiki1')
|
|
|
|
assert_redirected_to(:controller => 'admin', :action => 'edit_web', :web => 'wiki1')
|
|
|
|
assert @response.flash[:error]
|
|
|
|
|
|
|
|
process('remove_orphaned_pages', 'web' => 'wiki1', 'system_password_orphaned' => 'wrong')
|
|
|
|
assert_redirected_to(:controller => 'admin', :action => 'edit_web', :web => 'wiki1')
|
|
|
|
assert @response.flash[:error]
|
|
|
|
end
|
2005-01-28 02:24:31 +01:00
|
|
|
end
|