Checkout of Instiki Trunk 1/21/2007.
This commit is contained in:
commit
69b62b6f33
1138 changed files with 139586 additions and 0 deletions
BIN
test/fixtures/exported_markup.zip
vendored
Normal file
BIN
test/fixtures/exported_markup.zip
vendored
Normal file
Binary file not shown.
55
test/fixtures/pages.yml
vendored
Normal file
55
test/fixtures/pages.yml
vendored
Normal file
|
@ -0,0 +1,55 @@
|
|||
home_page:
|
||||
id: 1
|
||||
created_at: <%= Time.local(2004, 4, 4, 16, 50).to_formatted_s(:db) %>
|
||||
updated_at: <%= Time.local(2004, 4, 4, 16, 50).to_formatted_s(:db) %>
|
||||
web_id: 1
|
||||
name: HomePage
|
||||
|
||||
my_way:
|
||||
id: 2
|
||||
created_at: <%= 9.days.ago.to_formatted_s(:db) %>
|
||||
updated_at: <%= 9.days.ago.to_formatted_s(:db) %>
|
||||
web_id: 1
|
||||
name: MyWay
|
||||
|
||||
smart_engine:
|
||||
id: 3
|
||||
created_at: <%= 8.days.ago.to_formatted_s(:db) %>
|
||||
updated_at: <%= 8.days.ago.to_formatted_s(:db) %>
|
||||
web_id: 1
|
||||
name: SmartEngine
|
||||
|
||||
that_way:
|
||||
id: 4
|
||||
created_at: <%= 7.days.ago.to_formatted_s(:db) %>
|
||||
updated_at: <%= 7.days.ago.to_formatted_s(:db) %>
|
||||
web_id: 1
|
||||
name: ThatWay
|
||||
|
||||
no_wiki_word:
|
||||
id: 5
|
||||
created_at: <%= 6.days.ago.to_formatted_s(:db) %>
|
||||
updated_at: <%= 6.days.ago.to_formatted_s(:db) %>
|
||||
web_id: 1
|
||||
name: NoWikiWord
|
||||
|
||||
first_page:
|
||||
id: 6
|
||||
created_at: <%= Time.local(2004, 4, 4, 16, 55).to_formatted_s(:db) %>
|
||||
updated_at: <%= Time.local(2004, 4, 4, 16, 55).to_formatted_s(:db) %>
|
||||
web_id: 1
|
||||
name: FirstPage
|
||||
|
||||
oak:
|
||||
id: 7
|
||||
created_at: <%= 5.days.ago.to_formatted_s(:db) %>
|
||||
updated_at: <%= 5.days.ago.to_formatted_s(:db) %>
|
||||
web_id: 1
|
||||
name: Oak
|
||||
|
||||
elephant:
|
||||
id: 8
|
||||
created_at: <%= 10.minutes.ago.to_formatted_s(:db) %>
|
||||
updated_at: <%= 10.minutes.ago.to_formatted_s(:db) %>
|
||||
web_id: 1
|
||||
name: Elephant
|
BIN
test/fixtures/rails.gif
vendored
Executable file
BIN
test/fixtures/rails.gif
vendored
Executable file
Binary file not shown.
After Width: | Height: | Size: 8.3 KiB |
83
test/fixtures/revisions.yml
vendored
Normal file
83
test/fixtures/revisions.yml
vendored
Normal file
|
@ -0,0 +1,83 @@
|
|||
home_page_first_revision:
|
||||
id: 1
|
||||
created_at: <%= Time.local(2004, 4, 4, 15, 50).to_formatted_s(:db) %>
|
||||
updated_at: <%= Time.local(2004, 4, 4, 15, 50).to_formatted_s(:db) %>
|
||||
revised_at: <%= Time.local(2004, 4, 4, 15, 50).to_formatted_s(:db) %>
|
||||
page_id: 1
|
||||
content: First revision of the HomePage end
|
||||
author: AnAuthor
|
||||
ip: 127.0.0.1
|
||||
|
||||
my_way_first_revision:
|
||||
id: 2
|
||||
created_at: <%= 9.days.ago.to_formatted_s(:db) %>
|
||||
updated_at: <%= 9.days.ago.to_formatted_s(:db) %>
|
||||
revised_at: <%= 9.days.ago.to_formatted_s(:db) %>
|
||||
page_id: 2
|
||||
content: MyWay
|
||||
author: Me
|
||||
|
||||
smart_engine_first_revision:
|
||||
id: 3
|
||||
created_at: <%= 8.days.ago.to_formatted_s(:db) %>
|
||||
updated_at: <%= 8.days.ago.to_formatted_s(:db) %>
|
||||
revised_at: <%= 8.days.ago.to_formatted_s(:db) %>
|
||||
page_id: 3
|
||||
content: SmartEngine
|
||||
author: Me
|
||||
|
||||
that_way_first_revision:
|
||||
id: 4
|
||||
created_at: <%= 7.days.ago.to_formatted_s(:db) %>
|
||||
updated_at: <%= 7.days.ago.to_formatted_s(:db) %>
|
||||
revised_at: <%= 7.days.ago.to_formatted_s(:db) %>
|
||||
page_id: 4
|
||||
content: ThatWay
|
||||
author: Me
|
||||
|
||||
no_wiki_word_first_revision:
|
||||
id: 5
|
||||
created_at: <%= 6.days.ago.to_formatted_s(:db) %>
|
||||
updated_at: <%= 6.days.ago.to_formatted_s(:db) %>
|
||||
revised_at: <%= 6.days.ago.to_formatted_s(:db) %>
|
||||
page_id: 5
|
||||
content: hey you
|
||||
author: Me
|
||||
|
||||
home_page_second_revision:
|
||||
id: 6
|
||||
created_at: <%= Time.local(2004, 4, 4, 16, 50).to_formatted_s(:db) %>
|
||||
updated_at: <%= Time.local(2004, 4, 4, 16, 50).to_formatted_s(:db) %>
|
||||
revised_at: <%= Time.local(2004, 4, 4, 16, 50).to_formatted_s(:db) %>
|
||||
page_id: 1
|
||||
content: HisWay would be MyWay in kinda ThatWay in HisWay though MyWay \OverThere -- see SmartEngine in that SmartEngineGUI
|
||||
author: DavidHeinemeierHansson
|
||||
|
||||
first_page_first_revision:
|
||||
id: 7
|
||||
created_at: <%= Time.local(2004, 4, 4, 16, 55).to_formatted_s(:db) %>
|
||||
updated_at: <%= Time.local(2004, 4, 4, 16, 55).to_formatted_s(:db) %>
|
||||
revised_at: <%= Time.local(2004, 4, 4, 16, 55).to_formatted_s(:db) %>
|
||||
page_id: 6
|
||||
content: HisWay would be MyWay in kinda ThatWay in HisWay though MyWay \\OverThere -- see SmartEngine in that SmartEngineGUI
|
||||
author: DavidHeinemeierHansson
|
||||
|
||||
oak_first_revision:
|
||||
id: 8
|
||||
created_at: <%= 5.days.ago.to_formatted_s(:db) %>
|
||||
updated_at: <%= 5.days.ago.to_formatted_s(:db) %>
|
||||
revised_at: <%= 5.days.ago.to_formatted_s(:db) %>
|
||||
page_id: 7
|
||||
content: "All about oak.\ncategory: trees"
|
||||
author: TreeHugger
|
||||
ip: 127.0.0.2
|
||||
|
||||
elephant_first_revision:
|
||||
id: 9
|
||||
created_at: <%= 10.minutes.ago.to_formatted_s(:db) %>
|
||||
updated_at: <%= 10.minutes.ago.to_formatted_s(:db) %>
|
||||
revised_at: <%= 10.minutes.ago.to_formatted_s(:db) %>
|
||||
page_id: 8
|
||||
content: "All about elephants.\ncategory: animals"
|
||||
author: Guest
|
||||
ip: 127.0.0.2
|
2
test/fixtures/system.yml
vendored
Normal file
2
test/fixtures/system.yml
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
system:
|
||||
password: test_password
|
15
test/fixtures/webs.yml
vendored
Normal file
15
test/fixtures/webs.yml
vendored
Normal file
|
@ -0,0 +1,15 @@
|
|||
test_wiki:
|
||||
id: 1
|
||||
created_at: 2004-08-01
|
||||
updated_at: 2005-08-01
|
||||
name: wiki1
|
||||
address: wiki1
|
||||
markup: textile
|
||||
|
||||
instiki:
|
||||
id: 2
|
||||
created_at: 2004-08-01
|
||||
updated_at: 2005-08-01
|
||||
name: Instiki
|
||||
address: instiki
|
||||
markup: textile
|
112
test/fixtures/wiki_references.yml
vendored
Normal file
112
test/fixtures/wiki_references.yml
vendored
Normal file
|
@ -0,0 +1,112 @@
|
|||
my_way_1:
|
||||
id: 1
|
||||
page_id: 2
|
||||
referenced_name: MyWay
|
||||
link_type: L
|
||||
created_at: <%= Time.now.to_formatted_s(:db) %>
|
||||
updated_at: <%= Time.now.to_formatted_s(:db) %>
|
||||
|
||||
smart_engine_1:
|
||||
id: 2
|
||||
page_id: 3
|
||||
referenced_name: SmartEngine
|
||||
link_type: L
|
||||
created_at: <%= Time.now.to_formatted_s(:db) %>
|
||||
updated_at: <%= Time.now.to_formatted_s(:db) %>
|
||||
|
||||
that_way_1:
|
||||
id: 3
|
||||
page_id: 4
|
||||
referenced_name: ThatWay
|
||||
link_type: L
|
||||
created_at: <%= Time.now.to_formatted_s(:db) %>
|
||||
updated_at: <%= Time.now.to_formatted_s(:db) %>
|
||||
|
||||
home_page_1:
|
||||
id: 4
|
||||
page_id: 1
|
||||
referenced_name: HisWay
|
||||
link_type: W
|
||||
created_at: <%= Time.now.to_formatted_s(:db) %>
|
||||
updated_at: <%= Time.now.to_formatted_s(:db) %>
|
||||
|
||||
home_page_2:
|
||||
id: 5
|
||||
page_id: 1
|
||||
referenced_name: MyWay
|
||||
link_type: L
|
||||
created_at: <%= Time.now.to_formatted_s(:db) %>
|
||||
updated_at: <%= Time.now.to_formatted_s(:db) %>
|
||||
|
||||
home_page_3:
|
||||
id: 6
|
||||
page_id: 1
|
||||
referenced_name: ThatWay
|
||||
link_type: L
|
||||
created_at: <%= Time.now.to_formatted_s(:db) %>
|
||||
updated_at: <%= Time.now.to_formatted_s(:db) %>
|
||||
|
||||
home_page_4:
|
||||
id: 7
|
||||
page_id: 1
|
||||
referenced_name: SmartEngine
|
||||
link_type: L
|
||||
created_at: <%= Time.now.to_formatted_s(:db) %>
|
||||
updated_at: <%= Time.now.to_formatted_s(:db) %>
|
||||
|
||||
first_page_1:
|
||||
id: 8
|
||||
page_id: 6
|
||||
referenced_name: HisWay
|
||||
link_type: W
|
||||
created_at: <%= Time.now.to_formatted_s(:db) %>
|
||||
updated_at: <%= Time.now.to_formatted_s(:db) %>
|
||||
|
||||
first_page_2:
|
||||
id: 9
|
||||
page_id: 6
|
||||
referenced_name: MyWay
|
||||
link_type: L
|
||||
created_at: <%= Time.now.to_formatted_s(:db) %>
|
||||
updated_at: <%= Time.now.to_formatted_s(:db) %>
|
||||
|
||||
first_page_3:
|
||||
id: 10
|
||||
page_id: 6
|
||||
referenced_name: ThatWay
|
||||
link_type: L
|
||||
created_at: <%= Time.now.to_formatted_s(:db) %>
|
||||
updated_at: <%= Time.now.to_formatted_s(:db) %>
|
||||
|
||||
first_page_4:
|
||||
id: 11
|
||||
page_id: 6
|
||||
referenced_name: OverThere
|
||||
link_type: W
|
||||
created_at: <%= Time.now.to_formatted_s(:db) %>
|
||||
updated_at: <%= Time.now.to_formatted_s(:db) %>
|
||||
|
||||
first_page_5:
|
||||
id: 12
|
||||
page_id: 6
|
||||
referenced_name: SmartEngine
|
||||
link_type: L
|
||||
created_at: <%= Time.now.to_formatted_s(:db) %>
|
||||
updated_at: <%= Time.now.to_formatted_s(:db) %>
|
||||
|
||||
oak_1:
|
||||
id: 13
|
||||
page_id: 7
|
||||
referenced_name: trees
|
||||
link_type: C
|
||||
created_at: <%= Time.now.to_formatted_s(:db) %>
|
||||
updated_at: <%= Time.now.to_formatted_s(:db) %>
|
||||
|
||||
elephant_1:
|
||||
id: 14
|
||||
page_id: 8
|
||||
referenced_name: animals
|
||||
link_type: C
|
||||
created_at: <%= Time.now.to_formatted_s(:db) %>
|
||||
updated_at: <%= Time.now.to_formatted_s(:db) %>
|
||||
|
234
test/functional/admin_controller_test.rb
Normal file
234
test/functional/admin_controller_test.rb
Normal file
|
@ -0,0 +1,234 @@
|
|||
#!/usr/bin/env ruby
|
||||
|
||||
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
||||
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
|
||||
fixtures :webs, :pages, :revisions, :system, :wiki_references
|
||||
|
||||
def setup
|
||||
@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)
|
||||
end
|
||||
|
||||
def test_create_system_form_displayed
|
||||
use_blank_wiki
|
||||
process('create_system')
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
def test_create_system_form_submitted
|
||||
use_blank_wiki
|
||||
assert !@wiki.setup?
|
||||
|
||||
process('create_system', 'password' => 'a_password', 'web_name' => 'My Wiki',
|
||||
'web_address' => 'my_wiki')
|
||||
|
||||
assert_redirected_to :web => 'my_wiki', :controller => 'wiki', :action => 'new',
|
||||
:id => 'HomePage'
|
||||
assert @wiki.setup?
|
||||
assert_equal 'a_password', @wiki.system[:password]
|
||||
assert_equal 1, @wiki.webs.size
|
||||
new_web = @wiki.webs['my_wiki']
|
||||
assert_equal 'My Wiki', new_web.name
|
||||
assert_equal 'my_wiki', new_web.address
|
||||
end
|
||||
|
||||
def test_create_system_form_submitted_and_wiki_already_initialized
|
||||
wiki_before = @wiki
|
||||
old_size = @wiki.webs.size
|
||||
assert @wiki.setup?
|
||||
|
||||
process 'create_system', 'password' => 'a_password', 'web_name' => 'My Wiki',
|
||||
'web_address' => 'my_wiki'
|
||||
|
||||
assert_redirected_to :web => @wiki.webs.keys.first, :action => 'show', :id => 'HomePage'
|
||||
assert_equal wiki_before, @wiki
|
||||
# and no new web should be created either
|
||||
assert_equal old_size, @wiki.webs.size
|
||||
assert_flash_has :error
|
||||
end
|
||||
|
||||
def test_create_system_no_form_and_wiki_already_initialized
|
||||
assert @wiki.setup?
|
||||
process('create_system')
|
||||
assert_redirected_to :web => @wiki.webs.keys.first, :action => 'show', :id => 'HomePage'
|
||||
assert_flash_has :error
|
||||
end
|
||||
|
||||
|
||||
def test_create_web
|
||||
@wiki.system.update_attribute(:password, 'pswd')
|
||||
|
||||
process 'create_web', 'system_password' => 'pswd', 'name' => 'Wiki Two', 'address' => 'wiki2'
|
||||
|
||||
assert_redirected_to :web => 'wiki2', :action => 'new', :id => 'HomePage'
|
||||
wiki2 = @wiki.webs['wiki2']
|
||||
assert wiki2
|
||||
assert_equal 'Wiki Two', wiki2.name
|
||||
assert_equal 'wiki2', wiki2.address
|
||||
end
|
||||
|
||||
def test_create_web_default_password
|
||||
@wiki.system.update_attribute(:password, nil)
|
||||
|
||||
process 'create_web', 'system_password' => 'instiki', 'name' => 'Wiki Two', 'address' => 'wiki2'
|
||||
|
||||
assert_redirected_to :web => 'wiki2', :action => 'new', :id => 'HomePage'
|
||||
end
|
||||
|
||||
def test_create_web_failed_authentication
|
||||
@wiki.system.update_attribute(:password, 'pswd')
|
||||
|
||||
process 'create_web', 'system_password' => 'wrong', 'name' => 'Wiki Two', 'address' => 'wiki2'
|
||||
|
||||
assert_redirected_to :web => nil, :action => 'index'
|
||||
assert_nil @wiki.webs['wiki2']
|
||||
end
|
||||
|
||||
def test_create_web_no_form_submitted
|
||||
@wiki.system.update_attribute(:password, 'pswd')
|
||||
process 'create_web'
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
|
||||
def test_edit_web_no_form
|
||||
process 'edit_web', 'web' => 'wiki1'
|
||||
# this action simply renders a form
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
def test_edit_web_form_submitted
|
||||
@wiki.system.update_attribute(:password, 'pswd')
|
||||
|
||||
process('edit_web', 'system_password' => 'pswd',
|
||||
'web' => 'wiki1', 'address' => 'renamed_wiki1', 'name' => 'Renamed Wiki1',
|
||||
'markup' => 'markdown', 'color' => 'blue', 'additional_style' => 'whatever',
|
||||
'safe_mode' => 'on', 'password' => 'new_password', 'published' => 'on',
|
||||
'brackets_only' => 'on', 'count_pages' => 'on', 'allow_uploads' => 'on',
|
||||
'max_upload_size' => '300')
|
||||
|
||||
assert_redirected_to :web => 'renamed_wiki1', :action => 'show', :id => 'HomePage'
|
||||
@web = Web.find(@web.id)
|
||||
assert_equal 'renamed_wiki1', @web.address
|
||||
assert_equal 'Renamed Wiki1', @web.name
|
||||
assert_equal :markdown, @web.markup
|
||||
assert_equal 'blue', @web.color
|
||||
assert @web.safe_mode?
|
||||
assert_equal 'new_password', @web.password
|
||||
assert @web.published?
|
||||
assert @web.brackets_only?
|
||||
assert @web.count_pages?
|
||||
assert @web.allow_uploads?
|
||||
assert_equal 300, @web.max_upload_size
|
||||
end
|
||||
|
||||
def test_edit_web_opposite_values
|
||||
@wiki.system.update_attribute(:password, 'pswd')
|
||||
|
||||
process('edit_web', 'system_password' => 'pswd',
|
||||
'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'
|
||||
@web = Web.find(@web.id)
|
||||
assert !@web.safe_mode?
|
||||
assert !@web.published?
|
||||
assert !@web.brackets_only?
|
||||
assert !@web.count_pages?
|
||||
assert !@web.allow_uploads?
|
||||
end
|
||||
|
||||
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
|
||||
assert_response :success
|
||||
assert @response.has_template_object?('error')
|
||||
end
|
||||
|
||||
def test_edit_web_rename_to_already_existing_web_name
|
||||
@wiki.system.update_attribute(:password, 'pswd')
|
||||
|
||||
@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
|
||||
assert_response :success
|
||||
assert @response.has_template_object?('error')
|
||||
end
|
||||
|
||||
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
|
||||
assert_response :success
|
||||
assert @response.has_template_object?('error')
|
||||
end
|
||||
|
||||
|
||||
def test_remove_orphaned_pages
|
||||
@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',
|
||||
"Refers to [[Oak]].\n" +
|
||||
"category: trees",
|
||||
Time.now, Author.new('TreeHugger', '127.0.0.2'), test_renderer)
|
||||
|
||||
r = process('remove_orphaned_pages', 'web' => 'wiki1', 'system_password_orphaned' => 'pswd')
|
||||
|
||||
assert_redirected_to :controller => 'wiki', :web => 'wiki1', :action => 'list'
|
||||
@web.pages(true)
|
||||
assert_equal page_order, @web.select.sort,
|
||||
"Pages are not as expected: #{@web.select.sort.map {|p| p.name}.inspect}"
|
||||
|
||||
# Oak is now orphan, second pass should remove it
|
||||
r = process('remove_orphaned_pages', 'web' => 'wiki1', 'system_password_orphaned' => 'pswd')
|
||||
assert_redirected_to :controller => 'wiki', :web => 'wiki1', :action => 'list'
|
||||
@web.pages(true)
|
||||
page_order.delete(@oak)
|
||||
assert_equal page_order, @web.select.sort,
|
||||
"Pages are not as expected: #{@web.select.sort.map {|p| p.name}.inspect}"
|
||||
|
||||
# third pass does not destroy HomePage
|
||||
r = process('remove_orphaned_pages', 'web' => 'wiki1', 'system_password_orphaned' => 'pswd')
|
||||
assert_redirected_to :action => 'list'
|
||||
@web.pages(true)
|
||||
assert_equal page_order, @web.select.sort,
|
||||
"Pages are not as expected: #{@web.select.sort.map {|p| p.name}.inspect}"
|
||||
end
|
||||
|
||||
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
|
||||
end
|
30
test/functional/application_test.rb
Executable file
30
test/functional/application_test.rb
Executable file
|
@ -0,0 +1,30 @@
|
|||
# Unit tests for ApplicationController (the abstract controller class)
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
require 'wiki_controller'
|
||||
require 'rexml/document'
|
||||
|
||||
# Need some concrete class to test the abstract class features
|
||||
class WikiController; def rescue_action(e) logger.error(e); raise e end; end
|
||||
|
||||
class ApplicationTest < Test::Unit::TestCase
|
||||
fixtures :webs, :pages, :revisions, :system
|
||||
|
||||
def setup
|
||||
@controller = WikiController.new
|
||||
@request = ActionController::TestRequest.new
|
||||
@response = ActionController::TestResponse.new
|
||||
@wiki = Wiki.new
|
||||
end
|
||||
|
||||
def test_utf8_header
|
||||
get :show, :web => 'wiki1', :id => 'HomePage'
|
||||
assert_equal 'text/html; charset=UTF-8', @response.headers['Content-Type']
|
||||
end
|
||||
|
||||
def test_connect_to_model_unknown_wiki
|
||||
get :show, :web => 'unknown_wiki', :id => 'HomePage'
|
||||
assert_response :missing
|
||||
end
|
||||
|
||||
end
|
114
test/functional/file_controller_test.rb
Executable file
114
test/functional/file_controller_test.rb
Executable file
|
@ -0,0 +1,114 @@
|
|||
#!/usr/bin/env ruby
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
require 'file_controller'
|
||||
require 'fileutils'
|
||||
require 'stringio'
|
||||
|
||||
# Raise errors beyond the default web-based presentation
|
||||
class FileController; def rescue_action(e) logger.error(e); raise e end; end
|
||||
|
||||
class FileControllerTest < Test::Unit::TestCase
|
||||
fixtures :webs, :pages, :revisions, :system
|
||||
|
||||
def setup
|
||||
@controller = FileController.new
|
||||
@request = ActionController::TestRequest.new
|
||||
@response = ActionController::TestResponse.new
|
||||
@web = webs(:test_wiki)
|
||||
@wiki = Wiki.new
|
||||
WikiFile.delete_all
|
||||
require 'fileutils'
|
||||
FileUtils.rm_rf("#{RAILS_ROOT}/public/wiki1/files/*")
|
||||
end
|
||||
|
||||
def test_file_upload_form
|
||||
get :file, :web => 'wiki1', :id => 'new_file.txt'
|
||||
assert_success
|
||||
assert_rendered_file 'file/file'
|
||||
end
|
||||
|
||||
def test_file_download_text_file
|
||||
@web.wiki_files.create(:file_name => 'foo.txt', :description => 'Text file',
|
||||
:content => "Contents of the file")
|
||||
|
||||
r = get :file, :web => 'wiki1', :id => 'foo.txt'
|
||||
|
||||
assert_success(bypass_body_parsing = true)
|
||||
assert_equal "Contents of the file", r.body
|
||||
assert_equal 'text/plain', r.headers['Content-Type']
|
||||
end
|
||||
|
||||
def test_file_download_pdf_file
|
||||
@web.wiki_files.create(:file_name => 'foo.pdf', :description => 'PDF file',
|
||||
:content => "aaa\nbbb\n")
|
||||
|
||||
r = get :file, :web => 'wiki1', :id => 'foo.pdf'
|
||||
|
||||
assert_success(bypass_body_parsing = true)
|
||||
assert_equal "aaa\nbbb\n", r.body
|
||||
assert_equal 'application/pdf', r.headers['Content-Type']
|
||||
end
|
||||
|
||||
def test_pic_download_gif
|
||||
pic = File.open("#{RAILS_ROOT}/test/fixtures/rails.gif", 'rb') { |f| f.read }
|
||||
@web.wiki_files.create(:file_name => 'rails.gif', :description => 'An image', :content => pic)
|
||||
|
||||
r = get :file, :web => 'wiki1', :id => 'rails.gif'
|
||||
|
||||
assert_success(bypass_body_parsing = true)
|
||||
assert_equal 'image/gif', r.headers['Content-Type']
|
||||
assert_equal pic.size, r.body.size
|
||||
assert_equal pic, r.body
|
||||
end
|
||||
|
||||
def test_pic_unknown_pic
|
||||
r = get :file, :web => 'wiki1', :id => 'non-existant.gif'
|
||||
|
||||
assert_success
|
||||
assert_rendered_file 'file/file'
|
||||
end
|
||||
|
||||
def test_pic_upload_end_to_end
|
||||
# edit and re-render home page so that it has an "unknown file" link to 'rails-e2e.gif'
|
||||
PageRenderer.setup_url_generator(StubUrlGenerator.new)
|
||||
renderer = PageRenderer.new
|
||||
@wiki.revise_page('wiki1', 'HomePage', '[[rails-e2e.gif:pic]]',
|
||||
Time.now, 'AnonymousBrave', renderer)
|
||||
assert_equal "<p><span class=\"newWikiWord\">rails-e2e.gif<a href=\"../file/rails-e2e.gif\">" +
|
||||
"?</a></span></p>",
|
||||
renderer.display_content
|
||||
|
||||
# rails-e2e.gif is unknown to the system, so pic action goes to the file [upload] form
|
||||
r = get :file, :web => 'wiki1', :id => 'rails-e2e.gif'
|
||||
assert_success
|
||||
assert_rendered_file 'file/file'
|
||||
|
||||
# User uploads the picture
|
||||
picture = File.read("#{RAILS_ROOT}/test/fixtures/rails.gif")
|
||||
r = post :file, :web => 'wiki1',
|
||||
:file => {:file_name => 'rails-e2e.gif', :content => StringIO.new(picture)}
|
||||
assert_redirected_to({})
|
||||
assert @web.has_file?('rails-e2e.gif')
|
||||
assert_equal(picture, WikiFile.find_by_file_name('rails-e2e.gif').content)
|
||||
end
|
||||
|
||||
def test_import
|
||||
r = post :import, :web => 'wiki1', :file => uploaded_file("#{RAILS_ROOT}/test/fixtures/exported_markup.zip")
|
||||
assert_redirect
|
||||
assert @web.has_page?('ImportedPage')
|
||||
end
|
||||
|
||||
def uploaded_file(path, content_type="application/octet-stream", filename=nil)
|
||||
filename ||= File.basename(path)
|
||||
t = Tempfile.new(filename)
|
||||
FileUtils.copy_file(path, t.path)
|
||||
(class << t; self; end;).class_eval do
|
||||
alias local_path path
|
||||
define_method(:original_filename) { filename }
|
||||
define_method(:content_type) { content_type }
|
||||
end
|
||||
return t
|
||||
end
|
||||
|
||||
end
|
51
test/functional/routes_test.rb
Normal file
51
test/functional/routes_test.rb
Normal file
|
@ -0,0 +1,51 @@
|
|||
#!/usr/bin/env ruby
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
|
||||
require 'action_controller/routing'
|
||||
|
||||
class RoutesTest < Test::Unit::TestCase
|
||||
|
||||
def test_parse_uri
|
||||
assert_routing('', :controller => 'wiki', :action => 'index')
|
||||
assert_routing('x', :controller => 'wiki', :action => 'index', :web => 'x')
|
||||
assert_routing('x/y', :controller => 'wiki', :web => 'x', :action => 'y')
|
||||
assert_routing('x/y/z', :controller => 'wiki', :web => 'x', :action => 'y', :id => 'z')
|
||||
assert_recognizes({:web => 'x', :controller => 'wiki', :action => 'y'}, 'x/y/')
|
||||
assert_recognizes({:web => 'x', :controller => 'wiki', :action => 'y', :id => 'z'}, 'x/y/z/')
|
||||
end
|
||||
|
||||
def test_parse_uri_interestng_cases
|
||||
assert_routing('_veeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeery-long_web_/an_action/HomePage',
|
||||
:web => '_veeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeery-long_web_',
|
||||
:controller => 'wiki',
|
||||
:action => 'an_action', :id => 'HomePage'
|
||||
)
|
||||
assert_recognizes({:controller => 'wiki', :action => 'index'}, '///')
|
||||
end
|
||||
|
||||
def test_parse_uri_liberal_with_pagenames
|
||||
|
||||
assert_routing('web/show/%24HOME_PAGE',
|
||||
:controller => 'wiki', :web => 'web', :action => 'show', :id => '$HOME_PAGE')
|
||||
|
||||
assert_routing('web/show/HomePage%3Farg1%3Dvalue1%26arg2%3Dvalue2',
|
||||
:controller => 'wiki', :web => 'web', :action => 'show',
|
||||
:id => 'HomePage?arg1=value1&arg2=value2')
|
||||
|
||||
assert_routing('web/files/abc.zip',
|
||||
:web => 'web', :controller => 'file', :action => 'file', :id => 'abc.zip')
|
||||
assert_routing('web/import', :web => 'web', :controller => 'file', :action => 'import')
|
||||
# default option is wiki
|
||||
assert_recognizes({:controller => 'wiki', :web => 'unknown_path', :action => 'index', },
|
||||
'unknown_path')
|
||||
end
|
||||
|
||||
def test_cases_broken_by_routes
|
||||
# assert_routing('web/show/Page+With+Spaces',
|
||||
# :controller => 'wiki', :web => 'web', :action => 'show', :id => 'Page With Spaces')
|
||||
# assert_routing('web/show/HomePage%2Fsomething_else',
|
||||
# :controller => 'wiki', :web => 'web', :action => 'show', :id => 'HomePage/something_else')
|
||||
end
|
||||
|
||||
end
|
676
test/functional/wiki_controller_test.rb
Executable file
676
test/functional/wiki_controller_test.rb
Executable file
|
@ -0,0 +1,676 @@
|
|||
#!/usr/bin/env ruby
|
||||
|
||||
# Uncomment the line below to enable pdflatex tests; don't forget to comment them again
|
||||
# commiting to SVN
|
||||
# $INSTIKI_TEST_PDFLATEX = true
|
||||
|
||||
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
||||
require 'wiki_controller'
|
||||
require 'rexml/document'
|
||||
require 'tempfile'
|
||||
require 'zip/zipfilesystem'
|
||||
|
||||
# Raise errors beyond the default web-based presentation
|
||||
class WikiController; def rescue_action(e) logger.error(e); raise e end; end
|
||||
|
||||
class WikiControllerTest < Test::Unit::TestCase
|
||||
fixtures :webs, :pages, :revisions, :system, :wiki_references
|
||||
|
||||
def setup
|
||||
@controller = WikiController.new
|
||||
@request = ActionController::TestRequest.new
|
||||
@response = ActionController::TestResponse.new
|
||||
@wiki = Wiki.new
|
||||
@web = webs(:test_wiki)
|
||||
@home = @page = pages(:home_page)
|
||||
@oak = pages(:oak)
|
||||
@elephant = pages(:elephant)
|
||||
end
|
||||
|
||||
def test_authenticate
|
||||
set_web_property :password, 'pswd'
|
||||
|
||||
get :authenticate, :web => 'wiki1', :password => 'pswd'
|
||||
assert_redirected_to :web => 'wiki1', :action => 'show', :id => 'HomePage'
|
||||
assert_equal ['pswd'], @response.cookies['web_address']
|
||||
end
|
||||
|
||||
def test_authenticate_wrong_password
|
||||
set_web_property :password, 'pswd'
|
||||
|
||||
r = process('authenticate', 'web' => 'wiki1', 'password' => 'wrong password')
|
||||
assert_redirected_to :action => 'login', :web => 'wiki1'
|
||||
assert_nil r.cookies['web_address']
|
||||
end
|
||||
|
||||
def test_authors
|
||||
@wiki.write_page('wiki1', 'BreakSortingOrder',
|
||||
"This page breaks the accidentally correct sorting order of authors",
|
||||
Time.now, Author.new('BreakingTheOrder', '127.0.0.2'), test_renderer)
|
||||
|
||||
r = process('authors', 'web' => 'wiki1')
|
||||
|
||||
assert_success
|
||||
assert_equal %w(AnAuthor BreakingTheOrder DavidHeinemeierHansson Guest Me TreeHugger),
|
||||
r.template_objects['authors']
|
||||
page_names_by_author = r.template_objects['page_names_by_author']
|
||||
assert_equal r.template_objects['authors'], page_names_by_author.keys.sort
|
||||
assert_equal %w(FirstPage HomePage), page_names_by_author['DavidHeinemeierHansson']
|
||||
end
|
||||
|
||||
def test_cancel_edit
|
||||
@oak.lock(Time.now, 'Locky')
|
||||
assert @oak.locked?(Time.now)
|
||||
|
||||
r = process('cancel_edit', 'web' => 'wiki1', 'id' => 'Oak')
|
||||
|
||||
assert_redirected_to :action => 'show', :id => 'Oak'
|
||||
assert !Page.find(@oak.id).locked?(Time.now)
|
||||
end
|
||||
|
||||
def test_edit
|
||||
r = process 'edit', 'web' => 'wiki1', 'id' => 'HomePage'
|
||||
assert_success
|
||||
assert_equal @wiki.read_page('wiki1', 'HomePage'), r.template_objects['page']
|
||||
end
|
||||
|
||||
def test_edit_page_locked_page
|
||||
@home.lock(Time.now, 'Locky')
|
||||
process 'edit', 'web' => 'wiki1', 'id' => 'HomePage'
|
||||
assert_redirected_to :action => 'locked'
|
||||
end
|
||||
|
||||
def test_edit_page_break_lock
|
||||
@home.lock(Time.now, 'Locky')
|
||||
process 'edit', 'web' => 'wiki1', 'id' => 'HomePage', 'break_lock' => 'y'
|
||||
assert_success
|
||||
@home = Page.find(@home.id)
|
||||
assert @home.locked?(Time.now)
|
||||
end
|
||||
|
||||
def test_edit_unknown_page
|
||||
process 'edit', 'web' => 'wiki1', 'id' => 'UnknownPage', 'break_lock' => 'y'
|
||||
assert_redirected_to :controller => 'wiki', :action => 'show', :web => 'wiki1',
|
||||
:id => 'HomePage'
|
||||
end
|
||||
|
||||
def test_edit_page_with_special_symbols
|
||||
@wiki.write_page('wiki1', 'With : Special /> symbols',
|
||||
'This page has special symbols in the name', Time.now, Author.new('Special', '127.0.0.3'),
|
||||
test_renderer)
|
||||
|
||||
r = process 'edit', 'web' => 'wiki1', 'id' => 'With : Special /> symbols'
|
||||
assert_success
|
||||
xml = REXML::Document.new(r.body)
|
||||
form = REXML::XPath.first(xml, '//form')
|
||||
assert_equal '/wiki1/save/With+%3A+Special+%2F%3E+symbols', form.attributes['action']
|
||||
end
|
||||
|
||||
def test_export_html
|
||||
# rollback homepage to a version that is easier to match
|
||||
@home.rollback(0, Time.now, 'Rick', test_renderer)
|
||||
r = process 'export_html', 'web' => 'wiki1'
|
||||
|
||||
assert_success(bypass_body_parsing = true)
|
||||
assert_equal 'application/zip', r.headers['Content-Type']
|
||||
assert_match /attachment; filename="wiki1-html-\d\d\d\d-\d\d-\d\d-\d\d-\d\d-\d\d.zip"/,
|
||||
r.headers['Content-Disposition']
|
||||
assert_equal 'PK', r.body[0..1], 'Content is not a zip file'
|
||||
|
||||
# Tempfile doesn't know how to open files with binary flag, hence the two-step process
|
||||
Tempfile.open('instiki_export_file') { |f| @tempfile_path = f.path }
|
||||
begin
|
||||
File.open(@tempfile_path, 'wb') { |f| f.write(r.body); @exported_file = f.path }
|
||||
Zip::ZipFile.open(@exported_file) do |zip|
|
||||
assert_equal %w(Elephant.html FirstPage.html HomePage.html MyWay.html NoWikiWord.html Oak.html SmartEngine.html ThatWay.html index.html), zip.dir.entries('.').sort
|
||||
assert_match /.*<html .*All about elephants.*<\/html>/,
|
||||
zip.file.read('Elephant.html').gsub(/\s+/, ' ')
|
||||
assert_match /.*<html .*All about oak.*<\/html>/,
|
||||
zip.file.read('Oak.html').gsub(/\s+/, ' ')
|
||||
assert_match /.*<html .*First revision of the.*HomePage.*end.*<\/html>/,
|
||||
zip.file.read('HomePage.html').gsub(/\s+/, ' ')
|
||||
assert_equal '<html><head><META HTTP-EQUIV="Refresh" CONTENT="0;URL=HomePage.html"></head></html> ', zip.file.read('index.html').gsub(/\s+/, ' ')
|
||||
end
|
||||
ensure
|
||||
File.delete(@tempfile_path) if File.exist?(@tempfile_path)
|
||||
end
|
||||
end
|
||||
|
||||
def test_export_html_no_layout
|
||||
r = process 'export_html', 'web' => 'wiki1', 'layout' => 'no'
|
||||
|
||||
assert_success(bypass_body_parsing = true)
|
||||
assert_equal 'application/zip', r.headers['Content-Type']
|
||||
assert_match /attachment; filename="wiki1-html-\d\d\d\d-\d\d-\d\d-\d\d-\d\d-\d\d.zip"/,
|
||||
r.headers['Content-Disposition']
|
||||
assert_equal 'PK', r.body[0..1], 'Content is not a zip file'
|
||||
end
|
||||
|
||||
def test_export_markup
|
||||
r = process 'export_markup', 'web' => 'wiki1'
|
||||
|
||||
assert_success(bypass_body_parsing = true)
|
||||
assert_equal 'application/zip', r.headers['Content-Type']
|
||||
assert_match /attachment; filename="wiki1-textile-\d\d\d\d-\d\d-\d\d-\d\d-\d\d-\d\d.zip"/,
|
||||
r.headers['Content-Disposition']
|
||||
assert_equal 'PK', r.body[0..1], 'Content is not a zip file'
|
||||
end
|
||||
|
||||
|
||||
if ENV['INSTIKI_TEST_LATEX'] or defined? $INSTIKI_TEST_PDFLATEX
|
||||
|
||||
def test_export_pdf
|
||||
r = process 'export_pdf', 'web' => 'wiki1'
|
||||
assert_success(bypass_body_parsing = true)
|
||||
assert_equal 'application/pdf', r.headers['Content-Type']
|
||||
assert_match /attachment; filename="wiki1-tex-\d\d\d\d-\d\d-\d\d-\d\d-\d\d-\d\d.pdf"/,
|
||||
r.headers['Content-Disposition']
|
||||
assert_equal '%PDF', r.body[0..3]
|
||||
assert_equal "EOF\n", r.body[-4..-1]
|
||||
end
|
||||
|
||||
else
|
||||
puts 'Warning: tests involving pdflatex are very slow, therefore they are disabled by default.'
|
||||
puts ' Set environment variable INSTIKI_TEST_PDFLATEX or global Ruby variable'
|
||||
puts ' $INSTIKI_TEST_PDFLATEX to enable them.'
|
||||
end
|
||||
|
||||
def test_export_tex
|
||||
r = process 'export_tex', 'web' => 'wiki1'
|
||||
|
||||
assert_success(bypass_body_parsing = true)
|
||||
assert_equal 'application/octet-stream', r.headers['Content-Type']
|
||||
assert_match /attachment; filename="wiki1-tex-\d\d\d\d-\d\d-\d\d-\d\d-\d\d-\d\d.tex"/,
|
||||
r.headers['Content-Disposition']
|
||||
assert_equal '\documentclass', r.body[0..13], 'Content is not a TeX file'
|
||||
end
|
||||
|
||||
def test_feeds
|
||||
process('feeds', 'web' => 'wiki1')
|
||||
end
|
||||
|
||||
def test_index
|
||||
# delete extra web fixture
|
||||
webs(:instiki).destroy
|
||||
process('index')
|
||||
assert_redirected_to :web => 'wiki1', :action => 'show', :id => 'HomePage'
|
||||
end
|
||||
|
||||
def test_index_multiple_webs
|
||||
@wiki.create_web('Test Wiki 2', 'wiki2')
|
||||
process('index')
|
||||
assert_redirected_to :action => 'web_list'
|
||||
end
|
||||
|
||||
def test_index_multiple_webs_web_explicit
|
||||
@wiki.create_web('Test Wiki 2', 'wiki2')
|
||||
process('index', 'web' => 'wiki2')
|
||||
assert_redirected_to :web => 'wiki2', :action => 'show', :id => 'HomePage'
|
||||
end
|
||||
|
||||
def test_index_wiki_not_initialized
|
||||
use_blank_wiki
|
||||
process('index')
|
||||
assert_redirected_to :controller => 'admin', :action => 'create_system'
|
||||
end
|
||||
|
||||
|
||||
def test_list
|
||||
r = process('list', 'web' => 'wiki1')
|
||||
|
||||
assert_equal ['animals', 'trees'], r.template_objects['categories']
|
||||
assert_nil r.template_objects['category']
|
||||
assert_equal [@elephant, pages(:first_page), @home, pages(:my_way), pages(:no_wiki_word),
|
||||
@oak, pages(:smart_engine), pages(:that_way)],
|
||||
r.template_objects['pages_in_category']
|
||||
end
|
||||
|
||||
|
||||
def test_locked
|
||||
@home.lock(Time.now, 'Locky')
|
||||
r = process('locked', 'web' => 'wiki1', 'id' => 'HomePage')
|
||||
assert_success
|
||||
assert_equal @home, r.template_objects['page']
|
||||
end
|
||||
|
||||
|
||||
def test_login
|
||||
r = process 'login', 'web' => 'wiki1'
|
||||
assert_success
|
||||
# this action goes straight to the templates
|
||||
end
|
||||
|
||||
|
||||
def test_new
|
||||
r = process('new', 'id' => 'NewPage', 'web' => 'wiki1')
|
||||
assert_success
|
||||
assert_equal 'AnonymousCoward', r.template_objects['author']
|
||||
assert_equal 'NewPage', r.template_objects['page_name']
|
||||
end
|
||||
|
||||
|
||||
if ENV['INSTIKI_TEST_LATEX'] or defined? $INSTIKI_TEST_PDFLATEX
|
||||
|
||||
def test_pdf
|
||||
assert RedClothForTex.available?, 'Cannot do test_pdf when pdflatex is not available'
|
||||
r = process('pdf', 'web' => 'wiki1', 'id' => 'HomePage')
|
||||
assert_success(bypass_body_parsing = true)
|
||||
|
||||
assert_equal '%PDF', r.body[0..3]
|
||||
assert_equal "EOF\n", r.body[-4..-1]
|
||||
|
||||
assert_equal 'application/pdf', r.headers['Content-Type']
|
||||
assert_match /attachment; filename="HomePage-wiki1-\d\d\d\d-\d\d-\d\d-\d\d-\d\d-\d\d.pdf"/,
|
||||
r.headers['Content-Disposition']
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
def test_print
|
||||
r = process('print', 'web' => 'wiki1', 'id' => 'HomePage')
|
||||
|
||||
assert_success
|
||||
assert_equal :show, r.template_objects['link_mode']
|
||||
end
|
||||
|
||||
|
||||
def test_published
|
||||
set_web_property :published, true
|
||||
|
||||
r = process('published', 'web' => 'wiki1', 'id' => 'HomePage')
|
||||
|
||||
assert_success
|
||||
assert_equal @home, r.template_objects['page']
|
||||
end
|
||||
|
||||
|
||||
def test_published_web_not_published
|
||||
set_web_property :published, false
|
||||
|
||||
r = process('published', 'web' => 'wiki1', 'id' => 'HomePage')
|
||||
|
||||
assert_response :missing
|
||||
end
|
||||
|
||||
def test_published_should_render_homepage_if_no_page_specified
|
||||
set_web_property :published, true
|
||||
|
||||
r = process('published', 'web' => 'wiki1')
|
||||
|
||||
assert_success
|
||||
assert_equal @home, r.template_objects['page']
|
||||
end
|
||||
|
||||
|
||||
def test_recently_revised
|
||||
r = process('recently_revised', 'web' => 'wiki1')
|
||||
assert_success
|
||||
|
||||
assert_equal %w(animals trees), r.template_objects['categories']
|
||||
assert_nil r.template_objects['category']
|
||||
all_pages = @elephant, pages(:first_page), @home, pages(:my_way), pages(:no_wiki_word),
|
||||
@oak, pages(:smart_engine), pages(:that_way)
|
||||
assert_equal all_pages, r.template_objects['pages_in_category']
|
||||
|
||||
pages_by_day = r.template_objects['pages_by_day']
|
||||
assert_not_nil pages_by_day
|
||||
pages_by_day_size = pages_by_day.keys.inject(0) { |sum, day| sum + pages_by_day[day].size }
|
||||
assert_equal all_pages.size, pages_by_day_size
|
||||
all_pages.each do |page|
|
||||
day = Date.new(page.revised_at.year, page.revised_at.month, page.revised_at.day)
|
||||
assert pages_by_day[day].include?(page)
|
||||
end
|
||||
|
||||
assert_equal 'the web', r.template_objects['set_name']
|
||||
end
|
||||
|
||||
def test_recently_revised_with_categorized_page
|
||||
page2 = @wiki.write_page('wiki1', 'Page2',
|
||||
"Page2 contents.\n" +
|
||||
"category: categorized",
|
||||
Time.now, Author.new('AnotherAuthor', '127.0.0.2'), test_renderer)
|
||||
|
||||
r = process('recently_revised', 'web' => 'wiki1')
|
||||
assert_success
|
||||
|
||||
assert_equal %w(animals categorized trees), r.template_objects['categories']
|
||||
# no category is specified in params
|
||||
assert_nil r.template_objects['category']
|
||||
assert_equal [@elephant, pages(:first_page), @home, pages(:my_way), pages(:no_wiki_word), @oak, page2, pages(:smart_engine), pages(:that_way)], r.template_objects['pages_in_category'],
|
||||
"Pages are not as expected: " +
|
||||
r.template_objects['pages_in_category'].map {|p| p.name}.inspect
|
||||
assert_equal 'the web', r.template_objects['set_name']
|
||||
end
|
||||
|
||||
def test_recently_revised_with_categorized_page_multiple_categories
|
||||
r = process('recently_revised', 'web' => 'wiki1')
|
||||
assert_success
|
||||
|
||||
assert_equal ['animals', 'trees'], r.template_objects['categories']
|
||||
# no category is specified in params
|
||||
assert_nil r.template_objects['category']
|
||||
assert_equal [@elephant, pages(:first_page), @home, pages(:my_way), pages(:no_wiki_word), @oak, pages(:smart_engine), pages(:that_way)], r.template_objects['pages_in_category'],
|
||||
"Pages are not as expected: " +
|
||||
r.template_objects['pages_in_category'].map {|p| p.name}.inspect
|
||||
assert_equal 'the web', r.template_objects['set_name']
|
||||
end
|
||||
|
||||
def test_recently_revised_with_specified_category
|
||||
r = process('recently_revised', 'web' => 'wiki1', 'category' => 'animals')
|
||||
assert_success
|
||||
|
||||
assert_equal ['animals', 'trees'], r.template_objects['categories']
|
||||
# no category is specified in params
|
||||
assert_equal 'animals', r.template_objects['category']
|
||||
assert_equal [@elephant], r.template_objects['pages_in_category']
|
||||
assert_equal "category 'animals'", r.template_objects['set_name']
|
||||
end
|
||||
|
||||
|
||||
def test_revision
|
||||
r = process 'revision', 'web' => 'wiki1', 'id' => 'HomePage', 'rev' => '1'
|
||||
|
||||
assert_success
|
||||
assert_equal @home, r.template_objects['page']
|
||||
assert_equal @home.revisions[0], r.template_objects['revision']
|
||||
end
|
||||
|
||||
|
||||
def test_rollback
|
||||
# rollback shows a form where a revision can be edited.
|
||||
# its assigns the same as or revision
|
||||
r = process 'rollback', 'web' => 'wiki1', 'id' => 'HomePage', 'rev' => '1'
|
||||
|
||||
assert_success
|
||||
assert_equal @home, r.template_objects['page']
|
||||
assert_equal @home.revisions[0], r.template_objects['revision']
|
||||
end
|
||||
|
||||
def test_rss_with_content
|
||||
r = process 'rss_with_content', 'web' => 'wiki1'
|
||||
|
||||
assert_success
|
||||
pages = r.template_objects['pages_by_revision']
|
||||
assert_equal [@elephant, @oak, pages(:no_wiki_word), pages(:that_way), pages(:smart_engine), pages(:my_way), pages(:first_page), @home], pages,
|
||||
"Pages are not as expected: #{pages.map {|p| p.name}.inspect}"
|
||||
assert !r.template_objects['hide_description']
|
||||
end
|
||||
|
||||
def test_rss_with_content_when_blocked
|
||||
@web.update_attributes(:password => 'aaa', :published => false)
|
||||
@web = Web.find(@web.id)
|
||||
|
||||
r = process 'rss_with_content', 'web' => 'wiki1'
|
||||
|
||||
assert_equal 403, r.response_code
|
||||
end
|
||||
|
||||
|
||||
def test_rss_with_headlines
|
||||
@title_with_spaces = @wiki.write_page('wiki1', 'Title With Spaces',
|
||||
'About spaces', 1.hour.ago, Author.new('TreeHugger', '127.0.0.2'), test_renderer)
|
||||
|
||||
@request.host = 'localhost'
|
||||
@request.port = 8080
|
||||
|
||||
r = process 'rss_with_headlines', 'web' => 'wiki1'
|
||||
|
||||
assert_success
|
||||
pages = r.template_objects['pages_by_revision']
|
||||
assert_equal [@elephant, @title_with_spaces, @oak, pages(:no_wiki_word), pages(:that_way), pages(:smart_engine), pages(:my_way), pages(:first_page), @home], pages, "Pages are not as expected: #{pages.map {|p| p.name}.inspect}"
|
||||
assert r.template_objects['hide_description']
|
||||
|
||||
xml = REXML::Document.new(r.body)
|
||||
|
||||
expected_page_links =
|
||||
['http://localhost:8080/wiki1/show/Elephant',
|
||||
'http://localhost:8080/wiki1/show/Title+With+Spaces',
|
||||
'http://localhost:8080/wiki1/show/Oak',
|
||||
'http://localhost:8080/wiki1/show/NoWikiWord',
|
||||
'http://localhost:8080/wiki1/show/ThatWay',
|
||||
'http://localhost:8080/wiki1/show/SmartEngine',
|
||||
'http://localhost:8080/wiki1/show/MyWay',
|
||||
'http://localhost:8080/wiki1/show/FirstPage',
|
||||
'http://localhost:8080/wiki1/show/HomePage',
|
||||
]
|
||||
|
||||
assert_template_xpath_match '/rss/channel/link',
|
||||
'http://localhost:8080/wiki1/show/HomePage'
|
||||
assert_template_xpath_match '/rss/channel/item/guid', expected_page_links
|
||||
assert_template_xpath_match '/rss/channel/item/link', expected_page_links
|
||||
end
|
||||
|
||||
def test_rss_switch_links_to_published
|
||||
@web.update_attributes(:password => 'aaa', :published => true)
|
||||
@web = Web.find(@web.id)
|
||||
|
||||
@request.host = 'foo.bar.info'
|
||||
@request.port = 80
|
||||
|
||||
r = process 'rss_with_headlines', 'web' => 'wiki1'
|
||||
|
||||
assert_success
|
||||
xml = REXML::Document.new(r.body)
|
||||
|
||||
expected_page_links =
|
||||
['http://foo.bar.info/wiki1/published/Elephant',
|
||||
'http://foo.bar.info/wiki1/published/Oak',
|
||||
'http://foo.bar.info/wiki1/published/NoWikiWord',
|
||||
'http://foo.bar.info/wiki1/published/ThatWay',
|
||||
'http://foo.bar.info/wiki1/published/SmartEngine',
|
||||
'http://foo.bar.info/wiki1/published/MyWay',
|
||||
'http://foo.bar.info/wiki1/published/FirstPage',
|
||||
'http://foo.bar.info/wiki1/published/HomePage']
|
||||
|
||||
assert_template_xpath_match '/rss/channel/link',
|
||||
'http://foo.bar.info/wiki1/published/HomePage'
|
||||
assert_template_xpath_match '/rss/channel/item/guid', expected_page_links
|
||||
assert_template_xpath_match '/rss/channel/item/link', expected_page_links
|
||||
end
|
||||
|
||||
def test_rss_with_params
|
||||
setup_wiki_with_30_pages
|
||||
|
||||
r = process 'rss_with_headlines', 'web' => 'wiki1'
|
||||
assert_success
|
||||
pages = r.template_objects['pages_by_revision']
|
||||
assert_equal 15, pages.size, 15
|
||||
|
||||
r = process 'rss_with_headlines', 'web' => 'wiki1', 'limit' => '5'
|
||||
assert_success
|
||||
pages = r.template_objects['pages_by_revision']
|
||||
assert_equal 5, pages.size
|
||||
|
||||
r = process 'rss_with_headlines', 'web' => 'wiki1', 'limit' => '25'
|
||||
assert_success
|
||||
pages = r.template_objects['pages_by_revision']
|
||||
assert_equal 25, pages.size
|
||||
|
||||
r = process 'rss_with_headlines', 'web' => 'wiki1', 'limit' => 'all'
|
||||
assert_success
|
||||
pages = r.template_objects['pages_by_revision']
|
||||
assert_equal 38, pages.size
|
||||
|
||||
r = process 'rss_with_headlines', 'web' => 'wiki1', 'start' => '1976-10-16'
|
||||
assert_success
|
||||
pages = r.template_objects['pages_by_revision']
|
||||
assert_equal 23, pages.size
|
||||
|
||||
r = process 'rss_with_headlines', 'web' => 'wiki1', 'end' => '1976-10-16'
|
||||
assert_success
|
||||
pages = r.template_objects['pages_by_revision']
|
||||
assert_equal 15, pages.size
|
||||
|
||||
r = process 'rss_with_headlines', 'web' => 'wiki1', 'start' => '1976-10-01', 'end' => '1976-10-06'
|
||||
assert_success
|
||||
pages = r.template_objects['pages_by_revision']
|
||||
assert_equal 5, pages.size
|
||||
end
|
||||
|
||||
def test_rss_title_with_ampersand
|
||||
# was ticket:143
|
||||
@wiki.write_page('wiki1', 'Title&With&Ampersands',
|
||||
'About spaces', 1.hour.ago, Author.new('NitPicker', '127.0.0.3'), test_renderer)
|
||||
|
||||
r = process 'rss_with_headlines', 'web' => 'wiki1'
|
||||
|
||||
assert r.body.include?('<title>Home Page</title>')
|
||||
assert r.body.include?('<title>Title&With&Ampersands</title>')
|
||||
end
|
||||
|
||||
def test_rss_timestamp
|
||||
new_page = @wiki.write_page('wiki1', 'PageCreatedAtTheBeginningOfCtime',
|
||||
'Created on 1 Jan 1970 at 0:00:00 Z', Time.at(0), Author.new('NitPicker', '127.0.0.3'),
|
||||
test_renderer)
|
||||
|
||||
r = process 'rss_with_headlines', 'web' => 'wiki1'
|
||||
assert_template_xpath_match '/rss/channel/item/pubDate[9]', "Thu, 01 Jan 1970 00:00:00 Z"
|
||||
end
|
||||
|
||||
def test_save
|
||||
r = process 'save', 'web' => 'wiki1', 'id' => 'NewPage', 'content' => 'Contents of a new page',
|
||||
'author' => 'AuthorOfNewPage'
|
||||
|
||||
assert_redirected_to :web => 'wiki1', :action => 'show', :id => 'NewPage'
|
||||
assert_equal ['AuthorOfNewPage'], r.cookies['author'].value
|
||||
assert_equal Time.utc(2030), r.cookies['author'].expires
|
||||
new_page = @wiki.read_page('wiki1', 'NewPage')
|
||||
assert_equal 'Contents of a new page', new_page.content
|
||||
assert_equal 'AuthorOfNewPage', new_page.author
|
||||
end
|
||||
|
||||
def test_save_new_revision_of_existing_page
|
||||
@home.lock(Time.now, 'Batman')
|
||||
current_revisions = @home.revisions.size
|
||||
|
||||
r = process 'save', 'web' => 'wiki1', 'id' => 'HomePage', 'content' => 'Revised HomePage',
|
||||
'author' => 'Batman'
|
||||
|
||||
assert_redirected_to :web => 'wiki1', :action => 'show', :id => 'HomePage'
|
||||
assert_equal ['Batman'], r.cookies['author'].value
|
||||
home_page = @wiki.read_page('wiki1', 'HomePage')
|
||||
assert_equal current_revisions+1, home_page.revisions.size
|
||||
assert_equal 'Revised HomePage', home_page.content
|
||||
assert_equal 'Batman', home_page.author
|
||||
assert !home_page.locked?(Time.now)
|
||||
end
|
||||
|
||||
def test_save_new_revision_identical_to_last
|
||||
revisions_before = @home.revisions.size
|
||||
@home.lock(Time.now, 'AnAuthor')
|
||||
|
||||
r = process 'save', {'web' => 'wiki1', 'id' => 'HomePage',
|
||||
'content' => @home.revisions.last.content.dup,
|
||||
'author' => 'SomeOtherAuthor'}, {:return_to => '/wiki1/show/HomePage'}
|
||||
|
||||
assert_redirected_to :action => 'edit', :web => 'wiki1', :id => 'HomePage'
|
||||
assert_flash_has :error
|
||||
assert r.flash[:error].kind_of?(Instiki::ValidationError)
|
||||
|
||||
revisions_after = @home.revisions.size
|
||||
assert_equal revisions_before, revisions_after
|
||||
@home = Page.find(@home.id)
|
||||
assert !@home.locked?(Time.now), 'HomePage should be unlocked if an edit was unsuccessful'
|
||||
end
|
||||
|
||||
def test_save_blank_author
|
||||
r = process 'save', 'web' => 'wiki1', 'id' => 'NewPage', 'content' => 'Contents of a new page',
|
||||
'author' => ''
|
||||
new_page = @wiki.read_page('wiki1', 'NewPage')
|
||||
assert_equal 'AnonymousCoward', new_page.author
|
||||
|
||||
r = process 'save', 'web' => 'wiki1', 'id' => 'AnotherPage', 'content' => 'Contents of a new page',
|
||||
'author' => ' '
|
||||
|
||||
another_page = @wiki.read_page('wiki1', 'AnotherPage')
|
||||
assert_equal 'AnonymousCoward', another_page.author
|
||||
end
|
||||
|
||||
|
||||
def test_search
|
||||
r = process 'search', 'web' => 'wiki1', 'query' => '\s[A-Z]ak'
|
||||
|
||||
assert_redirected_to :action => 'show', :id => 'Oak'
|
||||
end
|
||||
|
||||
def test_search_multiple_results
|
||||
r = process 'search', 'web' => 'wiki1', 'query' => 'All about'
|
||||
|
||||
assert_success
|
||||
assert_equal 'All about', r.template_objects['query']
|
||||
assert_equal [@elephant, @oak], r.template_objects['results']
|
||||
assert_equal [], r.template_objects['title_results']
|
||||
end
|
||||
|
||||
def test_search_by_content_and_title
|
||||
r = process 'search', 'web' => 'wiki1', 'query' => '(Oak|Elephant)'
|
||||
|
||||
assert_success
|
||||
assert_equal '(Oak|Elephant)', r.template_objects['query']
|
||||
assert_equal [@elephant, @oak], r.template_objects['results']
|
||||
assert_equal [@elephant, @oak], r.template_objects['title_results']
|
||||
end
|
||||
|
||||
def test_search_zero_results
|
||||
r = process 'search', 'web' => 'wiki1', 'query' => 'non-existant text'
|
||||
|
||||
assert_success
|
||||
assert_equal [], r.template_objects['results']
|
||||
assert_equal [], r.template_objects['title_results']
|
||||
end
|
||||
|
||||
def test_show_page
|
||||
r = process('show', 'id' => 'Oak', 'web' => 'wiki1')
|
||||
assert_success
|
||||
assert_tag :content => /All about oak/
|
||||
end
|
||||
|
||||
def test_show_page_with_multiple_revisions
|
||||
@wiki.write_page('wiki1', 'HomePage', 'Second revision of the HomePage end', Time.now,
|
||||
Author.new('AnotherAuthor', '127.0.0.2'), test_renderer)
|
||||
|
||||
r = process('show', 'id' => 'HomePage', 'web' => 'wiki1')
|
||||
|
||||
assert_success
|
||||
assert_match /Second revision of the <a.*HomePage.*<\/a> end/, r.body
|
||||
end
|
||||
|
||||
def test_show_page_nonexistant_page
|
||||
process('show', 'id' => 'UnknownPage', 'web' => 'wiki1')
|
||||
assert_redirected_to :web => 'wiki1', :action => 'new', :id => 'UnknownPage'
|
||||
end
|
||||
|
||||
def test_show_no_page
|
||||
r = process('show', 'id' => '', 'web' => 'wiki1')
|
||||
assert_response :missing
|
||||
|
||||
r = process('show', 'web' => 'wiki1')
|
||||
assert_response :missing
|
||||
end
|
||||
|
||||
def test_tex
|
||||
r = process('tex', 'web' => 'wiki1', 'id' => 'HomePage')
|
||||
assert_success
|
||||
|
||||
assert_equal "\\documentclass[12pt,titlepage]{article}\n\n\\usepackage[danish]{babel} " +
|
||||
"%danske tekster\n\\usepackage[OT1]{fontenc} %rigtige danske bogstaver...\n" +
|
||||
"\\usepackage{a4}\n\\usepackage{graphicx}\n\\usepackage{ucs}\n\\usepackage[utf8x]" +
|
||||
"{inputenc}\n\\input epsf \n\n%----------------------------------------------------" +
|
||||
"---------------\n\n\\begin{document}\n\n\\sloppy\n\n%-----------------------------" +
|
||||
"--------------------------------------\n\n\\section*{HomePage}\n\nHisWay would be " +
|
||||
"MyWay in kinda ThatWay in HisWay though MyWay \\OverThere -- see SmartEngine in that " +
|
||||
"SmartEngineGUI\n\n\\end{document}", r.body
|
||||
end
|
||||
|
||||
|
||||
def test_web_list
|
||||
another_wiki = @wiki.create_web('Another Wiki', 'another_wiki')
|
||||
|
||||
r = process('web_list')
|
||||
|
||||
assert_success
|
||||
assert_equal [another_wiki, webs(:instiki), @web], r.template_objects['webs']
|
||||
end
|
||||
|
||||
end
|
168
test/test_helper.rb
Normal file
168
test/test_helper.rb
Normal file
|
@ -0,0 +1,168 @@
|
|||
ENV['RAILS_ENV'] = 'test'
|
||||
|
||||
# Expand the path to environment so that Ruby does not load it multiple times
|
||||
# File.expand_path can be removed if Ruby 1.9 is in use.
|
||||
require File.expand_path(File.dirname(__FILE__) + '/../config/environment')
|
||||
require 'application'
|
||||
|
||||
require 'test/unit'
|
||||
require 'active_record/fixtures'
|
||||
require 'action_controller/test_process'
|
||||
require 'action_web_service/test_invoke'
|
||||
require 'breakpoint'
|
||||
require 'wiki_content'
|
||||
require 'url_generator'
|
||||
|
||||
Test::Unit::TestCase.pre_loaded_fixtures = false
|
||||
Test::Unit::TestCase.use_transactional_fixtures = true
|
||||
Test::Unit::TestCase.use_instantiated_fixtures = false
|
||||
Test::Unit::TestCase.fixture_path = File.dirname(__FILE__) + "/fixtures/"
|
||||
|
||||
# activate PageObserver
|
||||
PageObserver.instance
|
||||
|
||||
class Test::Unit::TestCase
|
||||
def create_fixtures(*table_names)
|
||||
Fixtures.create_fixtures(File.dirname(__FILE__) + "/fixtures", table_names)
|
||||
end
|
||||
|
||||
# Add more helper methods to be used by all tests here...
|
||||
def set_web_property(property, value)
|
||||
@web.update_attribute(property, value)
|
||||
@page = Page.find(@page.id)
|
||||
@wiki.webs[@web.name] = @web
|
||||
end
|
||||
|
||||
def setup_wiki_with_30_pages
|
||||
ActiveRecord::Base.silence do
|
||||
(1..30).each do |i|
|
||||
@wiki.write_page('wiki1', "page#{i}", "Test page #{i}\ncategory: test",
|
||||
Time.local(1976, 10, i, 12, 00, 00), Author.new('Dema', '127.0.0.2'),
|
||||
test_renderer)
|
||||
end
|
||||
end
|
||||
@web = Web.find(@web.id)
|
||||
end
|
||||
|
||||
def test_renderer(revision = nil)
|
||||
PageRenderer.setup_url_generator(StubUrlGenerator.new)
|
||||
PageRenderer.new(revision)
|
||||
end
|
||||
|
||||
def use_blank_wiki
|
||||
Revision.destroy_all
|
||||
Page.destroy_all
|
||||
Web.destroy_all
|
||||
end
|
||||
end
|
||||
|
||||
# This module is to be included in unit tests that involve matching chunks.
|
||||
# It provides a easy way to test whether a chunk matches a particular string
|
||||
# and any the values of any fields that should be set after a match.
|
||||
class ContentStub < String
|
||||
include ChunkManager
|
||||
def initialize(str)
|
||||
super
|
||||
init_chunk_manager
|
||||
end
|
||||
def page_link(*); end
|
||||
end
|
||||
|
||||
module ChunkMatch
|
||||
|
||||
# Asserts a number of tests for the given type and text.
|
||||
def match(chunk_type, test_text, expected_chunk_state)
|
||||
if chunk_type.respond_to? :pattern
|
||||
assert_match(chunk_type.pattern, test_text)
|
||||
end
|
||||
|
||||
content = ContentStub.new(test_text)
|
||||
chunk_type.apply_to(content)
|
||||
|
||||
# Test if requested parts are correct.
|
||||
expected_chunk_state.each_pair do |a_method, expected_value|
|
||||
assert content.chunks.last.kind_of?(chunk_type)
|
||||
assert_respond_to(content.chunks.last, a_method)
|
||||
assert_equal(expected_value, content.chunks.last.send(a_method.to_sym),
|
||||
"Wrong #{a_method} value")
|
||||
end
|
||||
end
|
||||
|
||||
# Asserts that test_text doesn't match the chunk_type
|
||||
def no_match(chunk_type, test_text)
|
||||
if chunk_type.respond_to? :pattern
|
||||
assert_no_match(chunk_type.pattern, test_text)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class StubUrlGenerator < AbstractUrlGenerator
|
||||
|
||||
def initialize
|
||||
super(:doesnt_need_controller)
|
||||
end
|
||||
|
||||
def file_link(mode, name, text, web_name, known_file)
|
||||
link = CGI.escape(name)
|
||||
case mode
|
||||
when :export
|
||||
if known_file then %{<a class="existingWikiWord" href="#{link}.html">#{text}</a>}
|
||||
else %{<span class="newWikiWord">#{text}</span>} end
|
||||
when :publish
|
||||
if known_file then %{<a class="existingWikiWord" href="../published/#{link}">#{text}</a>}
|
||||
else %{<span class=\"newWikiWord\">#{text}</span>} end
|
||||
else
|
||||
if known_file
|
||||
%{<a class=\"existingWikiWord\" href=\"../file/#{link}\">#{text}</a>}
|
||||
else
|
||||
%{<span class=\"newWikiWord\">#{text}<a href=\"../file/#{link}\">?</a></span>}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def page_link(mode, name, text, web_address, known_page)
|
||||
link = CGI.escape(name)
|
||||
case mode.to_sym
|
||||
when :export
|
||||
if known_page then %{<a class="existingWikiWord" href="#{link}.html">#{text}</a>}
|
||||
else %{<span class="newWikiWord">#{text}</span>} end
|
||||
when :publish
|
||||
if known_page then %{<a class="existingWikiWord" href="../published/#{link}">#{text}</a>}
|
||||
else %{<span class="newWikiWord">#{text}</span>} end
|
||||
else
|
||||
if known_page
|
||||
%{<a class="existingWikiWord" href="../show/#{link}">#{text}</a>}
|
||||
else
|
||||
%{<span class="newWikiWord">#{text}<a href="../show/#{link}">?</a></span>}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def pic_link(mode, name, text, web_name, known_pic)
|
||||
link = CGI.escape(name)
|
||||
case mode.to_sym
|
||||
when :export
|
||||
if known_pic then %{<img alt="#{text}" src="#{link}" />}
|
||||
else %{<img alt="#{text}" src="no image" />} end
|
||||
when :publish
|
||||
if known_pic then %{<img alt="#{text}" src="#{link}" />}
|
||||
else %{<span class="newWikiWord">#{text}</span>} end
|
||||
else
|
||||
if known_pic then %{<img alt="#{text}" src="../file/#{link}" />}
|
||||
else %{<span class="newWikiWord">#{text}<a href="../file/#{link}">?</a></span>} end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
module Test
|
||||
module Unit
|
||||
module Assertions
|
||||
def assert_success(bypass_body_parsing = false)
|
||||
assert_response :success
|
||||
unless bypass_body_parsing
|
||||
assert_nothing_raised(@response.body) { REXML::Document.new(@response.body) }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
22
test/unit/chunks/category_test.rb
Executable file
22
test/unit/chunks/category_test.rb
Executable file
|
@ -0,0 +1,22 @@
|
|||
#!/usr/bin/env ruby
|
||||
|
||||
require File.dirname(__FILE__) + '/../../test_helper'
|
||||
require 'chunks/category'
|
||||
|
||||
class CategoryTest < Test::Unit::TestCase
|
||||
include ChunkMatch
|
||||
|
||||
def test_single_category
|
||||
match(Category, 'category: test', :list => ['test'], :hidden => nil)
|
||||
match(Category, 'category : chunk test ', :list => ['chunk test'], :hidden => nil)
|
||||
match(Category, ':category: test', :list => ['test'], :hidden => ':')
|
||||
end
|
||||
|
||||
def test_multiple_categories
|
||||
match(Category, 'category: test, multiple', :list => ['test', 'multiple'], :hidden => nil)
|
||||
match(Category, 'category : chunk test , multi category,regression test case ',
|
||||
:list => ['chunk test','multi category','regression test case'], :hidden => nil
|
||||
)
|
||||
end
|
||||
|
||||
end
|
15
test/unit/chunks/nowiki_test.rb
Executable file
15
test/unit/chunks/nowiki_test.rb
Executable file
|
@ -0,0 +1,15 @@
|
|||
#!/usr/bin/env ruby
|
||||
|
||||
require File.dirname(__FILE__) + '/../../test_helper'
|
||||
require 'chunks/nowiki'
|
||||
|
||||
class NoWikiTest < Test::Unit::TestCase
|
||||
include ChunkMatch
|
||||
|
||||
def test_simple_nowiki
|
||||
match(NoWiki, 'This sentence contains <nowiki>[[raw text]]</nowiki>. Do not touch!',
|
||||
:plain_text => '[[raw text]]'
|
||||
)
|
||||
end
|
||||
|
||||
end
|
98
test/unit/chunks/wiki_test.rb
Executable file
98
test/unit/chunks/wiki_test.rb
Executable file
|
@ -0,0 +1,98 @@
|
|||
#!/usr/bin/env ruby
|
||||
|
||||
require File.dirname(__FILE__) + '/../../test_helper'
|
||||
require 'chunks/wiki'
|
||||
|
||||
class WikiTest < Test::Unit::TestCase
|
||||
|
||||
include ChunkMatch
|
||||
|
||||
def test_simple
|
||||
match(WikiChunk::Word, 'This is a WikiWord okay?', :page_name => 'WikiWord')
|
||||
end
|
||||
|
||||
def test_escaped
|
||||
# escape is only implemented in WikiChunk::Word
|
||||
match(WikiChunk::Word, 'Do not link to an \EscapedWord',
|
||||
:page_name => 'EscapedWord', :escaped_text => 'EscapedWord'
|
||||
)
|
||||
end
|
||||
|
||||
def test_simple_brackets
|
||||
match(WikiChunk::Link, 'This is a [[bracketted link]]', :page_name => 'bracketted link')
|
||||
end
|
||||
|
||||
def test_void_brackets
|
||||
# double brackets woith only spaces inside are not a WikiLink
|
||||
no_match(WikiChunk::Link, "This [[ ]] are [[]] no [[ \t ]] links")
|
||||
end
|
||||
|
||||
def test_brackets_strip_spaces
|
||||
match(WikiChunk::Link,
|
||||
"This is a [[Sperberg-McQueen \t ]] link with trailing spaces to strip",
|
||||
:page_name => 'Sperberg-McQueen')
|
||||
match(WikiChunk::Link,
|
||||
"This is a [[ \t Sperberg-McQueen]] link with leading spaces to strip",
|
||||
:page_name => 'Sperberg-McQueen')
|
||||
match(WikiChunk::Link,
|
||||
'This is a [[ Sperberg-McQueen ]] link with spaces around it to strip',
|
||||
:page_name => 'Sperberg-McQueen')
|
||||
match(WikiChunk::Link,
|
||||
'This is a [[ Sperberg McQueen ]] link with spaces inside and around it',
|
||||
:page_name => 'Sperberg McQueen')
|
||||
end
|
||||
|
||||
def test_complex_brackets
|
||||
match(WikiChunk::Link, 'This is a tricky link [[Sperberg-McQueen]]',
|
||||
:page_name => 'Sperberg-McQueen')
|
||||
end
|
||||
|
||||
def test_include_chunk_pattern
|
||||
content = 'This is a [[!include pagename]] and [[!include WikiWord]] but [[blah]]'
|
||||
recognized_includes = content.scan(Include.pattern).collect { |m| m[0] }
|
||||
assert_equal %w(pagename WikiWord), recognized_includes
|
||||
end
|
||||
|
||||
def test_textile_link
|
||||
textile_link = ContentStub.new('"Here is a special link":SpecialLink')
|
||||
WikiChunk::Word.apply_to(textile_link)
|
||||
assert_equal '"Here is a special link":SpecialLink', textile_link
|
||||
assert textile_link.chunks.empty?
|
||||
end
|
||||
|
||||
def test_file_types
|
||||
# only link
|
||||
assert_link_parsed_as 'only text', 'only text', :show, '[[only text]]'
|
||||
# link and text
|
||||
assert_link_parsed_as 'page name', 'link text', :show, '[[page name|link text]]'
|
||||
# link and type (file)
|
||||
assert_link_parsed_as 'foo.tar.gz', 'foo.tar.gz', :file, '[[foo.tar.gz:file]]'
|
||||
# link and type (pic)
|
||||
assert_link_parsed_as 'foo.tar.gz', 'foo.tar.gz', :pic, '[[foo.tar.gz:pic]]'
|
||||
# link, text and type
|
||||
assert_link_parsed_as 'foo.tar.gz', 'FooTar', :file, '[[foo.tar.gz|FooTar:file]]'
|
||||
|
||||
# NEGATIVE TEST CASES
|
||||
|
||||
# empty page name
|
||||
assert_link_parsed_as '|link text?', '|link text?', :file, '[[|link text?:file]]'
|
||||
# empty link text
|
||||
assert_link_parsed_as 'page name?|', 'page name?|', :file, '[[page name?|:file]]'
|
||||
# empty link type
|
||||
assert_link_parsed_as 'page name', 'link?:', :show, '[[page name|link?:]]'
|
||||
# unknown link type
|
||||
assert_link_parsed_as 'page name:create_system', 'page name:create_system', :show,
|
||||
'[[page name:create_system]]'
|
||||
end
|
||||
|
||||
def assert_link_parsed_as(expected_page_name, expected_link_text, expected_link_type, link)
|
||||
link_to_file = ContentStub.new(link)
|
||||
WikiChunk::Link.apply_to(link_to_file)
|
||||
chunk = link_to_file.chunks.last
|
||||
assert chunk
|
||||
assert_equal expected_page_name, chunk.page_name
|
||||
assert_equal expected_link_text, chunk.link_text
|
||||
assert_equal expected_link_type, chunk.link_type
|
||||
end
|
||||
|
||||
end
|
110
test/unit/diff_test.rb
Executable file
110
test/unit/diff_test.rb
Executable file
|
@ -0,0 +1,110 @@
|
|||
#!/usr/bin/env ruby
|
||||
|
||||
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
||||
require 'diff'
|
||||
|
||||
class DiffTest < Test::Unit::TestCase
|
||||
|
||||
include HTMLDiff
|
||||
|
||||
def setup
|
||||
@builder = DiffBuilder.new('old', 'new')
|
||||
end
|
||||
|
||||
def test_start_of_tag
|
||||
assert @builder.start_of_tag?('<')
|
||||
assert(!@builder.start_of_tag?('>'))
|
||||
assert(!@builder.start_of_tag?('a'))
|
||||
end
|
||||
|
||||
def test_end_of_tag
|
||||
assert @builder.end_of_tag?('>')
|
||||
assert(!@builder.end_of_tag?('<'))
|
||||
assert(!@builder.end_of_tag?('a'))
|
||||
end
|
||||
|
||||
def test_whitespace
|
||||
assert @builder.whitespace?(" ")
|
||||
assert @builder.whitespace?("\n")
|
||||
assert @builder.whitespace?("\r")
|
||||
assert(!@builder.whitespace?("a"))
|
||||
end
|
||||
|
||||
def test_convert_html_to_list_of_words_simple
|
||||
assert_equal(
|
||||
['the', ' ', 'original', ' ', 'text'],
|
||||
@builder.convert_html_to_list_of_words('the original text'))
|
||||
end
|
||||
|
||||
def test_convert_html_to_list_of_words_should_separate_endlines
|
||||
assert_equal(
|
||||
['a', "\n", 'b', "\r", 'c'],
|
||||
@builder.convert_html_to_list_of_words("a\nb\rc"))
|
||||
end
|
||||
|
||||
def test_convert_html_to_list_of_words_should_not_compress_whitespace
|
||||
assert_equal(
|
||||
['a', ' ', 'b', ' ', 'c', "\r \n ", 'd'],
|
||||
@builder.convert_html_to_list_of_words("a b c\r \n d"))
|
||||
end
|
||||
|
||||
def test_convert_html_to_list_of_words_should_handle_tags_well
|
||||
assert_equal(
|
||||
['<p>', 'foo', ' ', 'bar', '</p>'],
|
||||
@builder.convert_html_to_list_of_words("<p>foo bar</p>"))
|
||||
end
|
||||
|
||||
def test_convert_html_to_list_of_words_interesting
|
||||
assert_equal(
|
||||
['<p>', 'this', ' ', 'is', '</p>', "\r\n", '<p>', 'the', ' ', 'new', ' ', 'string',
|
||||
'</p>', "\r\n", '<p>', 'around', ' ', 'the', ' ', 'world', '</p>'],
|
||||
@builder.convert_html_to_list_of_words(
|
||||
"<p>this is</p>\r\n<p>the new string</p>\r\n<p>around the world</p>"))
|
||||
end
|
||||
|
||||
def test_html_diff_simple
|
||||
a = 'this was the original string'
|
||||
b = 'this is the new string'
|
||||
assert_equal('this <del class="diffmod">was</del><ins class="diffmod">is</ins> the ' +
|
||||
'<del class="diffmod">original</del><ins class="diffmod">new</ins> string',
|
||||
diff(a, b))
|
||||
end
|
||||
|
||||
def test_html_diff_with_multiple_paragraphs
|
||||
a = "<p>this was the original string</p>"
|
||||
b = "<p>this is</p>\r\n<p> the new string</p>\r\n<p>around the world</p>"
|
||||
|
||||
# Some of this expected result is accidental to implementation.
|
||||
# At least it's well-formed and more or less correct.
|
||||
assert_equal(
|
||||
"<p>this <del class=\"diffmod\">was</del><ins class=\"diffmod\">is</ins></p>"+
|
||||
"<ins class=\"diffmod\">\r\n</ins><p> the " +
|
||||
"<del class=\"diffmod\">original</del><ins class=\"diffmod\">new</ins>" +
|
||||
" string</p><ins class=\"diffins\">\r\n</ins>" +
|
||||
"<p><ins class=\"diffins\">around the world</ins></p>",
|
||||
diff(a, b))
|
||||
end
|
||||
|
||||
# FIXME this test fails (ticket #67, http://dev.instiki.org/ticket/67)
|
||||
def test_html_diff_preserves_endlines_in_pre
|
||||
a = "<pre>\na\nb\nc\n</pre>"
|
||||
b = "<pre>\n</pre>"
|
||||
assert_equal(
|
||||
"<pre>\n<del class=\"diffdel\">a\nb\nc\n</del></pre>",
|
||||
diff(a, b))
|
||||
end
|
||||
|
||||
def test_html_diff_with_tags
|
||||
a = ""
|
||||
b = "<div>foo</div>"
|
||||
assert_equal '<div><ins class="diffins">foo</ins></div>', diff(a, b)
|
||||
end
|
||||
|
||||
def test_diff_for_tag_change
|
||||
a = "<a>x</a>"
|
||||
b = "<b>x</b>"
|
||||
# FIXME sad, but true - this case produces an invalid XML. If handle this you can, strong your foo is.
|
||||
assert_equal '<a><b>x</a></b>', diff(a, b)
|
||||
end
|
||||
|
||||
end
|
389
test/unit/page_renderer_test.rb
Normal file
389
test/unit/page_renderer_test.rb
Normal file
|
@ -0,0 +1,389 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
||||
|
||||
class PageRendererTest < Test::Unit::TestCase
|
||||
fixtures :webs, :pages, :revisions, :system, :wiki_references
|
||||
|
||||
def setup
|
||||
@wiki = Wiki.new
|
||||
@web = webs(:test_wiki)
|
||||
@page = pages(:home_page)
|
||||
@revision = revisions(:home_page_second_revision)
|
||||
end
|
||||
|
||||
def test_wiki_word_linking
|
||||
@web.add_page('SecondPage', 'Yo, yo. Have you EverBeenHated',
|
||||
Time.now, 'DavidHeinemeierHansson', test_renderer)
|
||||
|
||||
assert_equal('<p>Yo, yo. Have you <span class="newWikiWord">Ever Been Hated' +
|
||||
'<a href="../show/EverBeenHated">?</a></span></p>',
|
||||
rendered_content(@web.page("SecondPage")))
|
||||
|
||||
@web.add_page('EverBeenHated', 'Yo, yo. Have you EverBeenHated', Time.now,
|
||||
'DavidHeinemeierHansson', test_renderer)
|
||||
assert_equal('<p>Yo, yo. Have you <a class="existingWikiWord" ' +
|
||||
'href="../show/EverBeenHated">Ever Been Hated</a></p>',
|
||||
rendered_content(@web.page("SecondPage")))
|
||||
end
|
||||
|
||||
def test_wiki_words
|
||||
assert_equal %w( HisWay MyWay SmartEngine SmartEngineGUI ThatWay ),
|
||||
test_renderer(@revision).wiki_words.sort
|
||||
|
||||
@wiki.write_page('wiki1', 'NoWikiWord', 'hey you!', Time.now, 'Me', test_renderer)
|
||||
assert_equal [], test_renderer(@wiki.read_page('wiki1', 'NoWikiWord').revisions.last).wiki_words
|
||||
end
|
||||
|
||||
def test_existing_pages
|
||||
assert_equal %w( MyWay SmartEngine ThatWay ), test_renderer(@revision).existing_pages.sort
|
||||
end
|
||||
|
||||
def test_unexisting_pages
|
||||
assert_equal %w( HisWay SmartEngineGUI ), test_renderer(@revision).unexisting_pages.sort
|
||||
end
|
||||
|
||||
def test_content_with_wiki_links
|
||||
assert_equal '<p><span class="newWikiWord">His Way<a href="../show/HisWay">?</a></span> ' +
|
||||
'would be <a class="existingWikiWord" href="../show/MyWay">My Way</a> in kinda ' +
|
||||
'<a class="existingWikiWord" href="../show/ThatWay">That Way</a> in ' +
|
||||
'<span class="newWikiWord">His Way<a href="../show/HisWay">?</a></span> ' +
|
||||
'though <a class="existingWikiWord" href="../show/MyWay">My Way</a> OverThere—see ' +
|
||||
'<a class="existingWikiWord" href="../show/SmartEngine">Smart Engine</a> in that ' +
|
||||
'<span class="newWikiWord">Smart Engine GUI' +
|
||||
'<a href="../show/SmartEngineGUI">?</a></span></p>',
|
||||
test_renderer(@revision).display_content
|
||||
end
|
||||
|
||||
def test_markdown
|
||||
set_web_property :markup, :markdown
|
||||
|
||||
assert_markup_parsed_as(
|
||||
%{<h1>My Headline</h1>\n\n<p>that <span class="newWikiWord">} +
|
||||
%{Smart Engine GUI<a href="../show/SmartEngineGUI">?</a></span></p>},
|
||||
"My Headline\n===========\n\nthat SmartEngineGUI")
|
||||
|
||||
code_block = [
|
||||
'This is a code block:',
|
||||
'',
|
||||
' def a_method(arg)',
|
||||
' return ThatWay',
|
||||
'',
|
||||
'Nice!'
|
||||
].join("\n")
|
||||
|
||||
assert_markup_parsed_as(
|
||||
%{<p>This is a code block:</p>\n\n<pre><code>def a_method(arg)\n} +
|
||||
%{return ThatWay\n</code></pre>\n\n<p>Nice!</p>},
|
||||
code_block)
|
||||
end
|
||||
|
||||
def test_markdown_hyperlink_with_slash
|
||||
# in response to a bug, see http://dev.instiki.org/attachment/ticket/177
|
||||
set_web_property :markup, :markdown
|
||||
|
||||
assert_markup_parsed_as(
|
||||
'<p><a href="http://example/with/slash">text</a></p>',
|
||||
'[text](http://example/with/slash)')
|
||||
end
|
||||
|
||||
def test_mixed_formatting
|
||||
textile_and_markdown = [
|
||||
'Markdown heading',
|
||||
'================',
|
||||
'',
|
||||
'h2. Textile heading',
|
||||
'',
|
||||
'*some* **text** _with_ -styles-',
|
||||
'',
|
||||
'* list 1',
|
||||
'* list 2'
|
||||
].join("\n")
|
||||
|
||||
set_web_property :markup, :markdown
|
||||
assert_markup_parsed_as(
|
||||
"<h1>Markdown heading</h1>\n\n" +
|
||||
"<p>h2. Textile heading</p>\n\n" +
|
||||
"<p><em>some</em> <strong>text</strong> <em>with</em> -styles-</p>\n\n" +
|
||||
"<ul>\n<li>list 1</li>\n<li>list 2</li>\n</ul>",
|
||||
textile_and_markdown)
|
||||
|
||||
set_web_property :markup, :textile
|
||||
assert_markup_parsed_as(
|
||||
"<p>Markdown heading<br />================</p>\n\n\n\t<h2>Textile heading</h2>" +
|
||||
"\n\n\n\t<p><strong>some</strong> <b>text</b> <em>with</em> <del>styles</del></p>" +
|
||||
"\n\n\n\t<ul>\n\t<li>list 1</li>\n\t\t<li>list 2</li>\n\t</ul>",
|
||||
textile_and_markdown)
|
||||
|
||||
set_web_property :markup, :mixed
|
||||
assert_markup_parsed_as(
|
||||
"<h1>Markdown heading</h1>\n\n\n\t<h2>Textile heading</h2>\n\n\n\t" +
|
||||
"<p><strong>some</strong> <b>text</b> <em>with</em> <del>styles</del></p>\n\n\n\t" +
|
||||
"<ul>\n\t<li>list 1</li>\n\t\t<li>list 2</li>\n\t</ul>",
|
||||
textile_and_markdown)
|
||||
end
|
||||
|
||||
def test_rdoc
|
||||
set_web_property :markup, :rdoc
|
||||
|
||||
@revision = Revision.new(:page => @page, :content => '+hello+ that SmartEngineGUI',
|
||||
:author => Author.new('DavidHeinemeierHansson'))
|
||||
|
||||
assert_equal "<tt>hello</tt> that <span class=\"newWikiWord\">Smart Engine GUI" +
|
||||
"<a href=\"../show/SmartEngineGUI\">?</a></span>\n\n",
|
||||
test_renderer(@revision).display_content
|
||||
end
|
||||
|
||||
def test_content_with_auto_links
|
||||
assert_markup_parsed_as(
|
||||
'<p><a href="http://www.loudthinking.com/">http://www.loudthinking.com/</a> ' +
|
||||
'points to <a class="existingWikiWord" href="../show/ThatWay">That Way</a> from ' +
|
||||
'<a href="mailto:david@loudthinking.com">david@loudthinking.com</a></p>',
|
||||
'http://www.loudthinking.com/ points to ThatWay from david@loudthinking.com')
|
||||
|
||||
end
|
||||
|
||||
def test_content_with_aliased_links
|
||||
assert_markup_parsed_as(
|
||||
'<p>Would a <a class="existingWikiWord" href="../show/SmartEngine">clever motor' +
|
||||
'</a> go by any other name?</p>',
|
||||
'Would a [[SmartEngine|clever motor]] go by any other name?')
|
||||
end
|
||||
|
||||
def test_content_with_wikiword_in_em
|
||||
assert_markup_parsed_as(
|
||||
'<p><em>should we go <a class="existingWikiWord" href="../show/ThatWay">' +
|
||||
'That Way</a> or <span class="newWikiWord">This Way<a href="../show/ThisWay">?</a>' +
|
||||
'</span> </em></p>',
|
||||
'_should we go ThatWay or ThisWay _')
|
||||
end
|
||||
|
||||
def test_content_with_wikiword_in_tag
|
||||
assert_markup_parsed_as(
|
||||
'<p>That is some <em style="WikiWord">Stylish Emphasis</em></p>',
|
||||
'That is some <em style="WikiWord">Stylish Emphasis</em>')
|
||||
end
|
||||
|
||||
def test_content_with_escaped_wikiword
|
||||
# there should be no wiki link
|
||||
assert_markup_parsed_as('<p>WikiWord</p>', '\WikiWord')
|
||||
end
|
||||
|
||||
def test_content_with_pre_blocks
|
||||
assert_markup_parsed_as(
|
||||
'<p>A <code>class SmartEngine end</code> would not mark up <pre>CodeBlocks</pre></p>',
|
||||
'A <code>class SmartEngine end</code> would not mark up <pre>CodeBlocks</pre>')
|
||||
end
|
||||
|
||||
def test_content_with_autolink_in_parentheses
|
||||
assert_markup_parsed_as(
|
||||
'<p>The <span class="caps">W3C</span> body (<a href="http://www.w3c.org">' +
|
||||
'http://www.w3c.org</a>) sets web standards</p>',
|
||||
'The W3C body (http://www.w3c.org) sets web standards')
|
||||
end
|
||||
|
||||
def test_content_with_link_in_parentheses
|
||||
assert_markup_parsed_as(
|
||||
'<p>(<a href="http://wiki.org/wiki.cgi?WhatIsWiki">What is a wiki?</a>)</p>',
|
||||
'("What is a wiki?":http://wiki.org/wiki.cgi?WhatIsWiki)')
|
||||
end
|
||||
|
||||
def test_content_with_image_link
|
||||
assert_markup_parsed_as(
|
||||
'<p>This <img src="http://hobix.com/sample.jpg" alt="" /> is a Textile image link.</p>',
|
||||
'This !http://hobix.com/sample.jpg! is a Textile image link.')
|
||||
end
|
||||
|
||||
def test_content_with_inlined_img_tag
|
||||
assert_markup_parsed_as(
|
||||
'<p>This <img src="http://hobix.com/sample.jpg" alt="" /> is an inline image link.</p>',
|
||||
'This <img src="http://hobix.com/sample.jpg" alt="" /> is an inline image link.')
|
||||
|
||||
assert_markup_parsed_as(
|
||||
'<p>This <IMG SRC="http://hobix.com/sample.jpg" alt=""> is an inline image link.</p>',
|
||||
'This <IMG SRC="http://hobix.com/sample.jpg" alt=""> is an inline image link.')
|
||||
end
|
||||
|
||||
def test_nowiki_tag
|
||||
assert_markup_parsed_as(
|
||||
'<p>Do not mark up [[this text]] or http://www.thislink.com.</p>',
|
||||
'Do not mark up <nowiki>[[this text]]</nowiki> ' +
|
||||
'or <nowiki>http://www.thislink.com</nowiki>.')
|
||||
end
|
||||
|
||||
def test_multiline_nowiki_tag
|
||||
assert_markup_parsed_as(
|
||||
"<p>Do not mark \n up [[this text]] \nand http://this.url.com but markup " +
|
||||
'<span class="newWikiWord">this<a href="../show/this">?</a></span></p>',
|
||||
"Do not <nowiki>mark \n up [[this text]] \n" +
|
||||
"and http://this.url.com </nowiki> but markup [[this]]")
|
||||
end
|
||||
|
||||
def test_content_with_bracketted_wiki_word
|
||||
set_web_property :brackets_only, true
|
||||
assert_markup_parsed_as(
|
||||
'<p>This is a WikiWord and a tricky name <span class="newWikiWord">' +
|
||||
'Sperberg-McQueen<a href="../show/Sperberg-McQueen">?</a></span>.</p>',
|
||||
'This is a WikiWord and a tricky name [[Sperberg-McQueen]].')
|
||||
end
|
||||
|
||||
def test_content_for_export
|
||||
assert_equal '<p><span class="newWikiWord">His Way</span> would be ' +
|
||||
'<a class="existingWikiWord" href="MyWay.html">My Way</a> in kinda ' +
|
||||
'<a class="existingWikiWord" href="ThatWay.html">That Way</a> in ' +
|
||||
'<span class="newWikiWord">His Way</span> though ' +
|
||||
'<a class="existingWikiWord" href="MyWay.html">My Way</a> OverThere—see ' +
|
||||
'<a class="existingWikiWord" href="SmartEngine.html">Smart Engine</a> in that ' +
|
||||
'<span class="newWikiWord">Smart Engine GUI</span></p>',
|
||||
test_renderer(@revision).display_content_for_export
|
||||
end
|
||||
|
||||
def test_double_replacing
|
||||
@revision.content = "VersionHistory\r\n\r\ncry VersionHistory"
|
||||
assert_equal '<p><span class="newWikiWord">Version History' +
|
||||
"<a href=\"../show/VersionHistory\">?</a></span></p>\n\n\n\t<p>cry " +
|
||||
'<span class="newWikiWord">Version History<a href="../show/VersionHistory">?</a>' +
|
||||
'</span></p>',
|
||||
test_renderer(@revision).display_content
|
||||
|
||||
@revision.content = "f\r\nVersionHistory\r\n\r\ncry VersionHistory"
|
||||
assert_equal "<p>f<br /><span class=\"newWikiWord\">Version History" +
|
||||
"<a href=\"../show/VersionHistory\">?</a></span></p>\n\n\n\t<p>cry " +
|
||||
"<span class=\"newWikiWord\">Version History<a href=\"../show/VersionHistory\">?</a>" +
|
||||
"</span></p>",
|
||||
test_renderer(@revision).display_content
|
||||
end
|
||||
|
||||
def test_difficult_wiki_words
|
||||
@revision.content = "[[It's just awesome GUI!]]"
|
||||
assert_equal "<p><span class=\"newWikiWord\">It's just awesome GUI!" +
|
||||
"<a href=\"../show/It%27s+just+awesome+GUI%21\">?</a></span></p>",
|
||||
test_renderer(@revision).display_content
|
||||
end
|
||||
|
||||
def test_revisions_diff
|
||||
Revision.create(:page => @page, :content => 'What a blue and lovely morning',
|
||||
:author => Author.new('DavidHeinemeierHansson'), :revised_at => Time.now)
|
||||
Revision.create(:page => @page, :content => 'What a red and lovely morning today',
|
||||
:author => Author.new('DavidHeinemeierHansson'), :revised_at => Time.now)
|
||||
|
||||
assert_equal "<p>What a <del class=\"diffmod\">blue</del><ins class=\"diffmod\">red" +
|
||||
"</ins> and lovely morning<ins class=\"diffins\"> today</ins></p>", test_renderer(@page.revisions.last).display_diff
|
||||
end
|
||||
|
||||
def test_link_to_file
|
||||
assert_markup_parsed_as(
|
||||
'<p><span class="newWikiWord">doc.pdf<a href="../file/doc.pdf">?</a></span></p>',
|
||||
'[[doc.pdf:file]]')
|
||||
end
|
||||
|
||||
def test_link_to_pic
|
||||
WikiFile.delete_all
|
||||
require 'fileutils'
|
||||
FileUtils.rm_rf("#{RAILS_ROOT}/public/wiki1/files/*")
|
||||
@web.wiki_files.create(:file_name => 'square.jpg', :description => 'Square', :content => 'never mind')
|
||||
assert_markup_parsed_as(
|
||||
'<p><img alt="Square" src="../file/square.jpg" /></p>',
|
||||
'[[square.jpg|Square:pic]]')
|
||||
assert_markup_parsed_as(
|
||||
'<p><img alt="square.jpg" src="../file/square.jpg" /></p>',
|
||||
'[[square.jpg:pic]]')
|
||||
end
|
||||
|
||||
def test_link_to_non_existant_pic
|
||||
assert_markup_parsed_as(
|
||||
'<p><span class="newWikiWord">NonExistant<a href="../file/NonExistant.jpg">?</a>' +
|
||||
'</span></p>',
|
||||
'[[NonExistant.jpg|NonExistant:pic]]')
|
||||
assert_markup_parsed_as(
|
||||
'<p><span class="newWikiWord">NonExistant.jpg<a href="../file/NonExistant.jpg">?</a>' +
|
||||
'</span></p>',
|
||||
'[[NonExistant.jpg:pic]]')
|
||||
end
|
||||
|
||||
def test_wiki_link_with_colon
|
||||
assert_markup_parsed_as(
|
||||
'<p><span class="newWikiWord">With:Colon<a href="../show/With%3AColon">?</a></span></p>',
|
||||
'[[With:Colon]]')
|
||||
end
|
||||
|
||||
def test_list_with_tildas
|
||||
list_with_tildas = <<-EOL
|
||||
* "a":~b
|
||||
* c~ d
|
||||
EOL
|
||||
|
||||
assert_markup_parsed_as(
|
||||
"<ul>\n\t<li><a href=\"~b\">a</a></li>\n\t\t<li>c~ d</li>\n\t</ul>",
|
||||
list_with_tildas)
|
||||
end
|
||||
|
||||
def test_textile_image_in_mixed_wiki
|
||||
set_web_property :markup, :mixed
|
||||
assert_markup_parsed_as(
|
||||
"<p><img src=\"http://google.com\" alt=\"\" />\nss</p>",
|
||||
"!http://google.com!\r\nss")
|
||||
end
|
||||
|
||||
|
||||
def test_references_creation_links
|
||||
new_page = @web.add_page('NewPage', 'HomePage NewPage',
|
||||
Time.local(2004, 4, 4, 16, 50), 'AlexeyVerkhovsky', test_renderer)
|
||||
|
||||
references = new_page.wiki_references(true)
|
||||
assert_equal 2, references.size
|
||||
assert_equal 'HomePage', references[0].referenced_name
|
||||
assert_equal WikiReference::LINKED_PAGE, references[0].link_type
|
||||
assert_equal 'NewPage', references[1].referenced_name
|
||||
assert_equal WikiReference::LINKED_PAGE, references[1].link_type
|
||||
end
|
||||
|
||||
def test_references_creation_includes
|
||||
new_page = @web.add_page('NewPage', '[[!include IncludedPage]]',
|
||||
Time.local(2004, 4, 4, 16, 50), 'AlexeyVerkhovsky', test_renderer)
|
||||
|
||||
references = new_page.wiki_references(true)
|
||||
assert_equal 1, references.size
|
||||
assert_equal 'IncludedPage', references[0].referenced_name
|
||||
assert_equal WikiReference::INCLUDED_PAGE, references[0].link_type
|
||||
end
|
||||
|
||||
def test_references_creation_categories
|
||||
new_page = @web.add_page('NewPage', "Foo\ncategory: NewPageCategory",
|
||||
Time.local(2004, 4, 4, 16, 50), 'AlexeyVerkhovsky', test_renderer)
|
||||
|
||||
references = new_page.wiki_references(true)
|
||||
assert_equal 1, references.size
|
||||
assert_equal 'NewPageCategory', references[0].referenced_name
|
||||
assert_equal WikiReference::CATEGORY, references[0].link_type
|
||||
end
|
||||
|
||||
def test_rendering_included_page_under_different_modes
|
||||
included = @web.add_page('Included', 'link to HomePage', Time.now, 'AnAuthor', test_renderer)
|
||||
main = @web.add_page('Main', '[[!include Included]]', Time.now, 'AnAuthor', test_renderer)
|
||||
|
||||
assert_equal '<p>link to <a class="existingWikiWord" href="../show/HomePage">Home Page</a></p>',
|
||||
test_renderer(main).display_content
|
||||
assert_equal '<p>link to <a class="existingWikiWord" href="../published/HomePage">Home Page</a></p>',
|
||||
test_renderer(main).display_published
|
||||
assert_equal '<p>link to <a class="existingWikiWord" href="HomePage.html">Home Page</a></p>',
|
||||
test_renderer(main).display_content_for_export
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def add_sample_pages
|
||||
@in_love = @web.add_page('EverBeenInLove', 'Who am I me',
|
||||
Time.local(2004, 4, 4, 16, 50), 'DavidHeinemeierHansson', test_renderer)
|
||||
@hated = @web.add_page('EverBeenHated', 'I am me EverBeenHated',
|
||||
Time.local(2004, 4, 4, 16, 51), 'DavidHeinemeierHansson', test_renderer)
|
||||
end
|
||||
|
||||
def assert_markup_parsed_as(expected_output, input)
|
||||
revision = Revision.new(:page => @page, :content => input, :author => Author.new('AnAuthor'))
|
||||
assert_equal expected_output, test_renderer(revision).display_content, 'Rendering output not as expected'
|
||||
end
|
||||
|
||||
def rendered_content(page)
|
||||
test_renderer(page.revisions.last).display_content
|
||||
end
|
||||
|
||||
end
|
122
test/unit/page_test.rb
Normal file
122
test/unit/page_test.rb
Normal file
|
@ -0,0 +1,122 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
||||
|
||||
class PageTest < Test::Unit::TestCase
|
||||
fixtures :webs, :pages, :revisions, :system
|
||||
|
||||
def setup
|
||||
@page = pages(:first_page)
|
||||
end
|
||||
|
||||
|
||||
def test_lock
|
||||
assert !@page.locked?(Time.local(2004, 4, 4, 16, 50))
|
||||
|
||||
@page.lock(Time.local(2004, 4, 4, 16, 30), "DavidHeinemeierHansson")
|
||||
|
||||
assert @page.locked?(Time.local(2004, 4, 4, 16, 50))
|
||||
assert !@page.locked?(Time.local(2004, 4, 4, 17, 1))
|
||||
|
||||
@page.unlock
|
||||
|
||||
assert !@page.locked?(Time.local(2004, 4, 4, 16, 50))
|
||||
end
|
||||
|
||||
def test_lock_duration
|
||||
@page.lock(Time.local(2004, 4, 4, 16, 30), "DavidHeinemeierHansson")
|
||||
|
||||
assert_equal 15, @page.lock_duration(Time.local(2004, 4, 4, 16, 45))
|
||||
end
|
||||
|
||||
def test_plain_name
|
||||
assert_equal "First Page", @page.plain_name
|
||||
end
|
||||
|
||||
def test_revise
|
||||
@page.revise('HisWay would be MyWay in kinda lame', Time.local(2004, 4, 4, 16, 55),
|
||||
'MarianneSyhler', test_renderer)
|
||||
@page.reload
|
||||
|
||||
assert_equal 2, @page.revisions.length, 'Should have two revisions'
|
||||
assert_equal 'MarianneSyhler', @page.current_revision.author.to_s,
|
||||
'Mary should be the author now'
|
||||
assert_equal 'DavidHeinemeierHansson', @page.revisions.first.author.to_s,
|
||||
'David was the first author'
|
||||
end
|
||||
|
||||
def test_revise_continous_revision
|
||||
@page.revise('HisWay would be MyWay in kinda lame', Time.local(2004, 4, 4, 16, 55),
|
||||
'MarianneSyhler', test_renderer)
|
||||
@page.reload
|
||||
assert_equal 2, @page.revisions.length
|
||||
assert_equal 'HisWay would be MyWay in kinda lame', @page.content
|
||||
|
||||
# consecutive revision by the same author within 30 minutes doesn't create a new revision
|
||||
@page.revise('HisWay would be MyWay in kinda update', Time.local(2004, 4, 4, 16, 57),
|
||||
'MarianneSyhler', test_renderer)
|
||||
@page.reload
|
||||
assert_equal 2, @page.revisions.length
|
||||
assert_equal 'HisWay would be MyWay in kinda update', @page.content
|
||||
assert_equal Time.local(2004, 4, 4, 16, 57), @page.revised_at
|
||||
|
||||
# but consecutive revision by another author results in a new revision
|
||||
@page.revise('HisWay would be MyWay in the house', Time.local(2004, 4, 4, 16, 58),
|
||||
'DavidHeinemeierHansson', test_renderer)
|
||||
@page.reload
|
||||
assert_equal 3, @page.revisions.length
|
||||
assert_equal 'HisWay would be MyWay in the house', @page.content
|
||||
|
||||
# consecutive update after 30 minutes since the last one also creates a new revision,
|
||||
# even when it is by the same author
|
||||
@page.revise('HisWay would be MyWay in my way', Time.local(2004, 4, 4, 17, 30),
|
||||
'DavidHeinemeierHansson', test_renderer)
|
||||
@page.reload
|
||||
assert_equal 4, @page.revisions.length
|
||||
end
|
||||
|
||||
def test_revise_content_unchanged
|
||||
last_revision_before = @page.current_revision
|
||||
revisions_number_before = @page.revisions.size
|
||||
|
||||
assert_raises(Instiki::ValidationError) {
|
||||
@page.revise(@page.current_revision.content, Time.now, 'AlexeyVerkhovsky', test_renderer)
|
||||
}
|
||||
|
||||
assert_equal last_revision_before, @page.current_revision(true)
|
||||
assert_equal revisions_number_before, @page.revisions.size
|
||||
end
|
||||
|
||||
def test_revise_changes_references_from_wanted_to_linked_for_new_pages
|
||||
web = Web.find(1)
|
||||
new_page = Page.new(:web => web, :name => 'NewPage')
|
||||
new_page.revise('Reference to WantedPage, and to WantedPage2', Time.now, 'AlexeyVerkhovsky',
|
||||
test_renderer)
|
||||
|
||||
references = new_page.wiki_references(true)
|
||||
assert_equal 2, references.size
|
||||
assert_equal 'WantedPage', references[0].referenced_name
|
||||
assert_equal WikiReference::WANTED_PAGE, references[0].link_type
|
||||
assert_equal 'WantedPage2', references[1].referenced_name
|
||||
assert_equal WikiReference::WANTED_PAGE, references[1].link_type
|
||||
|
||||
wanted_page = Page.new(:web => web, :name => 'WantedPage')
|
||||
wanted_page.revise('And here it is!', Time.now, 'AlexeyVerkhovsky', test_renderer)
|
||||
|
||||
# link type stored for NewPage -> WantedPage reference should change from WANTED to LINKED
|
||||
# reference NewPage -> WantedPage2 should remain the same
|
||||
references = new_page.wiki_references(true)
|
||||
assert_equal 2, references.size
|
||||
assert_equal 'WantedPage', references[0].referenced_name
|
||||
assert_equal WikiReference::LINKED_PAGE, references[0].link_type
|
||||
assert_equal 'WantedPage2', references[1].referenced_name
|
||||
assert_equal WikiReference::WANTED_PAGE, references[1].link_type
|
||||
end
|
||||
|
||||
def test_rollback
|
||||
@page.revise("spot two", Time.now, "David", test_renderer)
|
||||
@page.revise("spot three", Time.now + 2000, "David", test_renderer)
|
||||
assert_equal 3, @page.revisions(true).length, "Should have three revisions"
|
||||
@page.current_revision(true)
|
||||
@page.rollback(0, Time.now, '127.0.0.1', test_renderer)
|
||||
assert_equal "HisWay would be MyWay in kinda ThatWay in HisWay though MyWay \\\\OverThere -- see SmartEngine in that SmartEngineGUI", @page.current_revision(true).content
|
||||
end
|
||||
end
|
69
test/unit/redcloth_for_tex_test.rb
Executable file
69
test/unit/redcloth_for_tex_test.rb
Executable file
|
@ -0,0 +1,69 @@
|
|||
#!/usr/bin/env ruby
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
require 'redcloth_for_tex'
|
||||
|
||||
class RedClothForTexTest < Test::Unit::TestCase
|
||||
def test_basics
|
||||
assert_equal '{\bf First Page}', RedClothForTex.new("*First Page*").to_tex
|
||||
assert_equal '{\em First Page}', RedClothForTex.new("_First Page_").to_tex
|
||||
assert_equal "\\begin{itemize}\n\t\\item A\n\t\t\\item B\n\t\t\\item C\n\t\\end{itemize}", RedClothForTex.new("* A\n* B\n* C").to_tex
|
||||
end
|
||||
|
||||
def test_blocks
|
||||
assert_equal '\section*{hello}', RedClothForTex.new("h1. hello").to_tex
|
||||
assert_equal '\subsection*{hello}', RedClothForTex.new("h2. hello").to_tex
|
||||
end
|
||||
|
||||
def test_table_of_contents
|
||||
|
||||
source = <<EOL
|
||||
* [[A]]
|
||||
** [[B]]
|
||||
** [[C]]
|
||||
* D
|
||||
** [[E]]
|
||||
*** F
|
||||
EOL
|
||||
|
||||
expected_result = <<EOL
|
||||
\\pagebreak
|
||||
|
||||
\\section{A}
|
||||
Abe
|
||||
|
||||
\\subsection{B}
|
||||
Babe
|
||||
|
||||
\\subsection{C}
|
||||
\\pagebreak
|
||||
|
||||
\\section{D}
|
||||
|
||||
\\subsection{E}
|
||||
|
||||
\\subsubsection{F}
|
||||
EOL
|
||||
expected_result.chop!
|
||||
assert_equal(expected_result, table_of_contents(source, 'A' => 'Abe', 'B' => 'Babe'))
|
||||
end
|
||||
|
||||
def test_entities
|
||||
assert_equal "Beck \\& Fowler are 100\\% cool", RedClothForTex.new("Beck & Fowler are 100% cool").to_tex
|
||||
end
|
||||
|
||||
def test_bracket_links
|
||||
assert_equal "such a Horrible Day, but I won't be Made Useless", RedClothForTex.new("such a [[Horrible Day]], but I won't be [[Made Useless]]").to_tex
|
||||
end
|
||||
|
||||
def test_footnotes_on_abbreviations
|
||||
assert_equal(
|
||||
"such a Horrible Day\\footnote{1}, but I won't be Made Useless",
|
||||
RedClothForTex.new("such a [[Horrible Day]][1], but I won't be [[Made Useless]]").to_tex
|
||||
)
|
||||
end
|
||||
|
||||
def test_subsection_depth
|
||||
assert_equal "\\subsubsection*{Hello}", RedClothForTex.new("h4. Hello").to_tex
|
||||
end
|
||||
end
|
217
test/unit/uri_test.rb
Executable file
217
test/unit/uri_test.rb
Executable file
|
@ -0,0 +1,217 @@
|
|||
#!/usr/bin/env ruby
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
require 'chunks/uri'
|
||||
|
||||
class URITest < Test::Unit::TestCase
|
||||
include ChunkMatch
|
||||
|
||||
def test_non_matches
|
||||
assert_conversion_does_not_apply(URIChunk, 'There is no URI here')
|
||||
assert_conversion_does_not_apply(URIChunk,
|
||||
'One gemstone is the garnet:reddish in colour, like ruby')
|
||||
end
|
||||
|
||||
def test_simple_uri
|
||||
# Simplest case
|
||||
match(URIChunk, 'http://www.example.com',
|
||||
:scheme =>'http', :host =>'www.example.com', :path => nil,
|
||||
:link_text => 'http://www.example.com'
|
||||
)
|
||||
# With trailing slash
|
||||
match(URIChunk, 'http://www.example.com/',
|
||||
:scheme =>'http', :host =>'www.example.com', :path => '/',
|
||||
:link_text => 'http://www.example.com/'
|
||||
)
|
||||
# Without http://
|
||||
match(URIChunk, 'www.example.com',
|
||||
:scheme =>'http', :host =>'www.example.com', :link_text => 'www.example.com'
|
||||
)
|
||||
# two parts
|
||||
match(URIChunk, 'example.com',
|
||||
:scheme =>'http',:host =>'example.com', :link_text => 'example.com'
|
||||
)
|
||||
# "unusual" base domain (was a bug in an early version)
|
||||
match(URIChunk, 'http://example.com.au/',
|
||||
:scheme =>'http', :host =>'example.com.au', :link_text => 'http://example.com.au/'
|
||||
)
|
||||
# "unusual" base domain without http://
|
||||
match(URIChunk, 'example.com.au',
|
||||
:scheme =>'http', :host =>'example.com.au', :link_text => 'example.com.au'
|
||||
)
|
||||
# Another "unusual" base domain
|
||||
match(URIChunk, 'http://www.example.co.uk/',
|
||||
:scheme =>'http', :host =>'www.example.co.uk',
|
||||
:link_text => 'http://www.example.co.uk/'
|
||||
)
|
||||
match(URIChunk, 'example.co.uk',
|
||||
:scheme =>'http', :host =>'example.co.uk', :link_text => 'example.co.uk'
|
||||
)
|
||||
# With some path at the end
|
||||
match(URIChunk, 'http://moinmoin.wikiwikiweb.de/HelpOnNavigation',
|
||||
:scheme => 'http', :host => 'moinmoin.wikiwikiweb.de', :path => '/HelpOnNavigation',
|
||||
:link_text => 'http://moinmoin.wikiwikiweb.de/HelpOnNavigation'
|
||||
)
|
||||
# With some path at the end, and withot http:// prefix
|
||||
match(URIChunk, 'moinmoin.wikiwikiweb.de/HelpOnNavigation',
|
||||
:scheme => 'http', :host => 'moinmoin.wikiwikiweb.de', :path => '/HelpOnNavigation',
|
||||
:link_text => 'moinmoin.wikiwikiweb.de/HelpOnNavigation'
|
||||
)
|
||||
# With a port number
|
||||
match(URIChunk, 'http://www.example.com:80',
|
||||
:scheme =>'http', :host =>'www.example.com', :port => '80', :path => nil,
|
||||
:link_text => 'http://www.example.com:80')
|
||||
# With a port number and a path
|
||||
match(URIChunk, 'http://www.example.com.tw:80/HelpOnNavigation',
|
||||
:scheme =>'http', :host =>'www.example.com.tw', :port => '80', :path => '/HelpOnNavigation',
|
||||
:link_text => 'http://www.example.com.tw:80/HelpOnNavigation')
|
||||
# With a query
|
||||
match(URIChunk, 'http://www.example.com.tw:80/HelpOnNavigation?arg=val',
|
||||
:scheme =>'http', :host =>'www.example.com.tw', :port => '80', :path => '/HelpOnNavigation',
|
||||
:query => 'arg=val',
|
||||
:link_text => 'http://www.example.com.tw:80/HelpOnNavigation?arg=val')
|
||||
# Query with two arguments
|
||||
match(URIChunk, 'http://www.example.com.tw:80/HelpOnNavigation?arg=val&arg2=val2',
|
||||
:scheme =>'http', :host =>'www.example.com.tw', :port => '80', :path => '/HelpOnNavigation',
|
||||
:query => 'arg=val&arg2=val2',
|
||||
:link_text => 'http://www.example.com.tw:80/HelpOnNavigation?arg=val&arg2=val2')
|
||||
# HTTPS
|
||||
match(URIChunk, 'https://www.example.com',
|
||||
:scheme =>'https', :host =>'www.example.com', :port => nil, :path => nil, :query => nil,
|
||||
:link_text => 'https://www.example.com')
|
||||
# FTP
|
||||
match(URIChunk, 'ftp://www.example.com',
|
||||
:scheme =>'ftp', :host =>'www.example.com', :port => nil, :path => nil, :query => nil,
|
||||
:link_text => 'ftp://www.example.com')
|
||||
# mailto
|
||||
match(URIChunk, 'mailto:jdoe123@example.com',
|
||||
:scheme =>'mailto', :host =>'example.com', :port => nil, :path => nil, :query => nil,
|
||||
:user => 'jdoe123', :link_text => 'mailto:jdoe123@example.com')
|
||||
# something nonexistant
|
||||
match(URIChunk, 'foobar://www.example.com',
|
||||
:scheme =>'foobar', :host =>'www.example.com', :port => nil, :path => nil, :query => nil,
|
||||
:link_text => 'foobar://www.example.com')
|
||||
|
||||
# Soap opera (the most complex case imaginable... well, not really, there should be more evil)
|
||||
match(URIChunk, 'http://www.example.com.tw:80/~jdoe123/Help%20Me%20?arg=val&arg2=val2',
|
||||
:scheme =>'http', :host =>'www.example.com.tw', :port => '80',
|
||||
:path => '/~jdoe123/Help%20Me%20', :query => 'arg=val&arg2=val2',
|
||||
:link_text => 'http://www.example.com.tw:80/~jdoe123/Help%20Me%20?arg=val&arg2=val2')
|
||||
|
||||
# from 0.9 bug reports
|
||||
match(URIChunk, 'http://www2.pos.to/~tosh/ruby/rdtool/en/doc/rd-draft.html',
|
||||
:scheme =>'http', :host => 'www2.pos.to',
|
||||
:path => '/~tosh/ruby/rdtool/en/doc/rd-draft.html')
|
||||
|
||||
match(URIChunk, 'http://support.microsoft.com/default.aspx?scid=kb;en-us;234562',
|
||||
:scheme =>'http', :host => 'support.microsoft.com', :path => '/default.aspx',
|
||||
:query => 'scid=kb;en-us;234562')
|
||||
end
|
||||
|
||||
def test_email_uri
|
||||
match(URIChunk, 'mail@example.com',
|
||||
:user => 'mail', :host => 'example.com', :link_text => 'mail@example.com'
|
||||
)
|
||||
end
|
||||
|
||||
def test_non_email
|
||||
# The @ is part of the normal text, but 'example.com' is marked up.
|
||||
match(URIChunk, 'Not an email: @example.com', :user => nil, :uri => 'http://example.com')
|
||||
end
|
||||
|
||||
def test_textile_image
|
||||
assert_conversion_does_not_apply(URIChunk,
|
||||
'This !http://hobix.com/sample.jpg! is a Textile image link.')
|
||||
end
|
||||
|
||||
def test_textile_link
|
||||
assert_conversion_does_not_apply(URIChunk,
|
||||
'This "hobix (hobix)":http://hobix.com/sample.jpg is a Textile link.')
|
||||
# just to be sure ...
|
||||
match(URIChunk, 'This http://hobix.com/sample.jpg should match',
|
||||
:link_text => 'http://hobix.com/sample.jpg')
|
||||
end
|
||||
|
||||
def test_inline_html
|
||||
assert_conversion_does_not_apply(URIChunk, '<IMG SRC="http://hobix.com/sample.jpg">')
|
||||
assert_conversion_does_not_apply(URIChunk, "<img src='http://hobix.com/sample.jpg'/>")
|
||||
end
|
||||
|
||||
def test_non_uri
|
||||
# "so" is a valid country code; "libproxy.so" is a valid url
|
||||
match(URIChunk, 'libproxy.so', :link_text => 'libproxy.so')
|
||||
|
||||
assert_conversion_does_not_apply URIChunk, 'httpd.conf'
|
||||
assert_conversion_does_not_apply URIChunk, 'ld.so.conf'
|
||||
assert_conversion_does_not_apply URIChunk, 'index.jpeg'
|
||||
assert_conversion_does_not_apply URIChunk, 'index.jpg'
|
||||
assert_conversion_does_not_apply URIChunk, 'file.txt'
|
||||
assert_conversion_does_not_apply URIChunk, 'file.doc'
|
||||
assert_conversion_does_not_apply URIChunk, 'file.pdf'
|
||||
assert_conversion_does_not_apply URIChunk, 'file.png'
|
||||
assert_conversion_does_not_apply URIChunk, 'file.ps'
|
||||
end
|
||||
|
||||
def test_uri_in_text
|
||||
match(URIChunk, 'Go to: http://www.example.com/', :host => 'www.example.com', :path =>'/')
|
||||
match(URIChunk, 'http://www.example.com/ is a link.', :host => 'www.example.com')
|
||||
match(URIChunk,
|
||||
'Email david@loudthinking.com',
|
||||
:scheme =>'mailto', :user =>'david', :host =>'loudthinking.com')
|
||||
# check that trailing punctuation is not included in the hostname
|
||||
match(URIChunk, 'Hey dude, http://fake.link.com.', :scheme => 'http', :host => 'fake.link.com')
|
||||
# this is a textile link, no match please.
|
||||
assert_conversion_does_not_apply(URIChunk, '"link":http://fake.link.com.')
|
||||
end
|
||||
|
||||
def test_uri_in_parentheses
|
||||
match(URIChunk, 'URI (http://brackets.com.de) in brackets', :host => 'brackets.com.de')
|
||||
match(URIChunk, 'because (as shown at research.net) the results', :host => 'research.net')
|
||||
match(URIChunk,
|
||||
'A wiki (http://wiki.org/wiki.cgi?WhatIsWiki) page',
|
||||
:scheme => 'http', :host => 'wiki.org', :path => '/wiki.cgi', :query => 'WhatIsWiki'
|
||||
)
|
||||
end
|
||||
|
||||
def test_uri_list_item
|
||||
match(
|
||||
URIChunk,
|
||||
'* http://www.btinternet.com/~mail2minh/SonyEricssonP80xPlatform.sis',
|
||||
:path => '/~mail2minh/SonyEricssonP80xPlatform.sis'
|
||||
)
|
||||
end
|
||||
|
||||
def test_interesting_uri_with__comma
|
||||
# Counter-intuitively, this URL matches, but the query part includes the trailing comma.
|
||||
# It has no way to know that the query does not include the comma.
|
||||
match(
|
||||
URIChunk,
|
||||
"This text contains a URL http://someplace.org:8080/~person/stuff.cgi?arg=val, doesn't it?",
|
||||
:scheme => 'http', :host => 'someplace.org', :port => '8080', :path => '/~person/stuff.cgi',
|
||||
:query => 'arg=val,')
|
||||
end
|
||||
|
||||
def test_local_urls
|
||||
# normal
|
||||
match(LocalURIChunk, 'http://perforce:8001/toto.html',
|
||||
:scheme => 'http', :host => 'perforce',
|
||||
:port => '8001', :link_text => 'http://perforce:8001/toto.html')
|
||||
|
||||
# in parentheses
|
||||
match(LocalURIChunk, 'URI (http://localhost:2500) in brackets',
|
||||
:host => 'localhost', :port => '2500')
|
||||
match(LocalURIChunk, 'because (as shown at http://perforce:8001) the results',
|
||||
:host => 'perforce', :port => '8001')
|
||||
match(LocalURIChunk,
|
||||
'A wiki (http://localhost:2500/wiki.cgi?WhatIsWiki) page',
|
||||
:scheme => 'http', :host => 'localhost', :path => '/wiki.cgi',
|
||||
:port => '2500', :query => 'WhatIsWiki')
|
||||
end
|
||||
|
||||
def assert_conversion_does_not_apply(chunk_type, str)
|
||||
processed_str = ContentStub.new(str.dup)
|
||||
chunk_type.apply_to(processed_str)
|
||||
assert_equal(str, processed_str)
|
||||
end
|
||||
|
||||
end
|
105
test/unit/web_test.rb
Normal file
105
test/unit/web_test.rb
Normal file
|
@ -0,0 +1,105 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
||||
|
||||
class WebTest < Test::Unit::TestCase
|
||||
fixtures :webs, :pages, :revisions, :system, :wiki_references
|
||||
|
||||
def setup
|
||||
@web = webs(:instiki)
|
||||
end
|
||||
|
||||
def test_pages_by_revision
|
||||
add_sample_pages
|
||||
assert_equal 'EverBeenHated', @web.select.by_revision.first.name
|
||||
end
|
||||
|
||||
def test_pages_by_match
|
||||
add_sample_pages
|
||||
assert_equal 2, @web.select { |page| page.content =~ /me/i }.length
|
||||
assert_equal 1, @web.select { |page| page.content =~ /Who/i }.length
|
||||
assert_equal 0, @web.select { |page| page.content =~ /none/i }.length
|
||||
end
|
||||
|
||||
def test_002_references
|
||||
add_sample_pages
|
||||
assert_equal 1, @web.select.pages_that_reference('EverBeenHated').length
|
||||
assert_equal 0, @web.select.pages_that_reference('EverBeenInLove').length
|
||||
end
|
||||
|
||||
def test_delete
|
||||
add_sample_pages
|
||||
assert_equal 2, @web.pages.length
|
||||
@web.remove_pages([ @web.page('EverBeenInLove') ])
|
||||
assert_equal 1, @web.pages(true).length
|
||||
end
|
||||
|
||||
def test_initialize
|
||||
web = Web.new(:name => 'Wiki2', :address => 'wiki2', :password => '123')
|
||||
|
||||
assert_equal 'Wiki2', web.name
|
||||
assert_equal 'wiki2', web.address
|
||||
assert_equal '123', web.password
|
||||
|
||||
# new web should be set for maximum features enabled
|
||||
assert_equal :textile, web.markup
|
||||
assert_equal '008B26', web.color
|
||||
assert !web.safe_mode?
|
||||
assert_equal([], web.pages)
|
||||
assert web.allow_uploads?
|
||||
assert_nil web.additional_style
|
||||
assert !web.published?
|
||||
assert !web.brackets_only?
|
||||
assert !web.count_pages?
|
||||
assert_equal 100, web.max_upload_size
|
||||
end
|
||||
|
||||
def test_initialize_invalid_name
|
||||
assert_raises(Instiki::ValidationError) {
|
||||
Web.create(:name => 'Wiki2', :address => "wiki\234", :password => '123')
|
||||
}
|
||||
end
|
||||
|
||||
def test_new_page_linked_from_mother_page
|
||||
# this was a bug in revision 204
|
||||
home = @web.add_page('HomePage', 'This page refers to AnotherPage',
|
||||
Time.local(2004, 4, 4, 16, 50), 'Alexey Verkhovsky', test_renderer)
|
||||
@web.add_page('AnotherPage', 'This is \AnotherPage',
|
||||
Time.local(2004, 4, 4, 16, 51), 'Alexey Verkhovsky', test_renderer)
|
||||
|
||||
@web.pages(true)
|
||||
assert_equal [home], @web.select.pages_that_link_to('AnotherPage')
|
||||
end
|
||||
|
||||
def test_001_orphaned_pages
|
||||
add_sample_pages
|
||||
home = @web.add_page('HomePage',
|
||||
'This is a home page, it should not be an orphan',
|
||||
Time.local(2004, 4, 4, 16, 50), 'AlexeyVerkhovsky', test_renderer)
|
||||
author = @web.add_page('AlexeyVerkhovsky',
|
||||
'This is an author page, it should not be an orphan',
|
||||
Time.local(2004, 4, 4, 16, 50), 'AlexeyVerkhovsky', test_renderer)
|
||||
self_linked = @web.add_page('SelfLinked',
|
||||
'I am SelfLinked and link to EverBeenInLove',
|
||||
Time.local(2004, 4, 4, 16, 50), 'AnonymousCoward', test_renderer)
|
||||
|
||||
# page that links to itself, and nobody else links to it must be an orphan
|
||||
assert_equal ['EverBeenHated', 'SelfLinked'],
|
||||
@web.select.orphaned_pages.collect{ |page| page.name }.sort
|
||||
end
|
||||
|
||||
def test_page_names_by_author
|
||||
page_names_by_author = webs(:test_wiki).page_names_by_author
|
||||
assert_equal %w(AnAuthor DavidHeinemeierHansson Guest Me TreeHugger),
|
||||
page_names_by_author.keys.sort
|
||||
assert_equal %w(FirstPage HomePage), page_names_by_author['DavidHeinemeierHansson']
|
||||
assert_equal %w(Oak), page_names_by_author['TreeHugger']
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def add_sample_pages
|
||||
@in_love = @web.add_page('EverBeenInLove', 'Who am I me',
|
||||
Time.local(2004, 4, 4, 16, 50), 'DavidHeinemeierHansson', test_renderer)
|
||||
@hated = @web.add_page('EverBeenHated', 'I am me EverBeenHated',
|
||||
Time.local(2004, 4, 4, 16, 51), 'DavidHeinemeierHansson', test_renderer)
|
||||
end
|
||||
end
|
84
test/unit/wiki_file_test.rb
Normal file
84
test/unit/wiki_file_test.rb
Normal file
|
@ -0,0 +1,84 @@
|
|||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
require 'fileutils'
|
||||
|
||||
class WikiFileTest < Test::Unit::TestCase
|
||||
include FileUtils
|
||||
fixtures :webs, :pages, :revisions, :system, :wiki_references
|
||||
|
||||
def setup
|
||||
@web = webs(:test_wiki)
|
||||
mkdir_p("#{RAILS_ROOT}/public/wiki1/files/")
|
||||
rm_rf("#{RAILS_ROOT}/public/wiki1/files/*")
|
||||
WikiFile.delete_all
|
||||
end
|
||||
|
||||
def test_basic_store_and_retrieve_ascii_file
|
||||
@web.wiki_files.create(:file_name => 'binary_file', :description => 'Binary file', :content => "\001\002\003")
|
||||
binary = WikiFile.find_by_file_name('binary_file')
|
||||
assert_equal "\001\002\003", binary.content
|
||||
end
|
||||
|
||||
def test_basic_store_and_retrieve_binary_file
|
||||
@web.wiki_files.create(:file_name => 'text_file', :description => 'Text file', :content => "abc")
|
||||
text = WikiFile.find_by_file_name('text_file')
|
||||
assert_equal "abc", text.content
|
||||
end
|
||||
|
||||
def test_storing_an_image
|
||||
rails_gif = File.open("#{RAILS_ROOT}/test/fixtures/rails.gif", 'rb') { |f| f.read }
|
||||
assert_equal rails_gif.size, File.size("#{RAILS_ROOT}/test/fixtures/rails.gif")
|
||||
|
||||
@web.wiki_files.create(:file_name => 'rails.gif', :description => 'Rails logo', :content => rails_gif)
|
||||
|
||||
rails_gif_from_db = WikiFile.find_by_file_name('rails.gif')
|
||||
assert_equal rails_gif.size, rails_gif_from_db.content.size
|
||||
assert_equal rails_gif, rails_gif_from_db.content
|
||||
end
|
||||
|
||||
def test_mandatory_fields_validations
|
||||
assert_validation(:file_name, '', :fail)
|
||||
assert_validation(:file_name, nil, :fail)
|
||||
assert_validation(:content, '', :fail)
|
||||
assert_validation(:content, nil, :fail)
|
||||
end
|
||||
|
||||
def test_upload_size_validation
|
||||
assert_validation(:content, 'a' * 100.kilobytes, :pass)
|
||||
assert_validation(:content, 'a' * (100.kilobytes + 1), :fail)
|
||||
end
|
||||
|
||||
def test_file_name_size_validation
|
||||
assert_validation(:file_name, '', :fail)
|
||||
assert_validation(:file_name, 'a', :pass)
|
||||
assert_validation(:file_name, 'a' * 50, :pass)
|
||||
assert_validation(:file_name, 'a' * 51, :fail)
|
||||
end
|
||||
|
||||
def test_file_name_pattern_validation
|
||||
assert_validation(:file_name, ".. Accep-table File.name", :pass)
|
||||
assert_validation(:file_name, "/bad", :fail)
|
||||
assert_validation(:file_name, "~bad", :fail)
|
||||
assert_validation(:file_name, "..\bad", :fail)
|
||||
assert_validation(:file_name, "\001bad", :fail)
|
||||
assert_validation(:file_name, ".", :fail)
|
||||
assert_validation(:file_name, "..", :fail)
|
||||
end
|
||||
|
||||
def test_find_by_file_name
|
||||
assert_equal @file1, WikiFile.find_by_file_name('file1.txt')
|
||||
assert_nil WikiFile.find_by_file_name('unknown_file')
|
||||
end
|
||||
|
||||
def assert_validation(field, value, expected_result)
|
||||
values = {:file_name => '0', :description => '0', :content => '0'}
|
||||
raise "WikiFile has no attribute named #{field.inspect}" unless values.has_key?(field)
|
||||
values[field] = value
|
||||
|
||||
new_object = @web.wiki_files.create(values)
|
||||
if expected_result == :pass then assert(new_object.valid?, new_object.errors.inspect)
|
||||
elsif expected_result == :fail then assert(!new_object.valid?)
|
||||
else raise "Unknown value of expected_result: #{expected_result.inspect}"
|
||||
end
|
||||
end
|
||||
|
||||
end
|
14
test/unit/wiki_words_test.rb
Executable file
14
test/unit/wiki_words_test.rb
Executable file
|
@ -0,0 +1,14 @@
|
|||
#!/usr/bin/env ruby
|
||||
|
||||
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
||||
require 'wiki_words'
|
||||
|
||||
class WikiWordsTest < Test::Unit::TestCase
|
||||
|
||||
def test_utf8_characters_in_wiki_word
|
||||
assert_equal "Æåle Øen", WikiWords.separate("ÆåleØen")
|
||||
assert_equal "ÆÅØle Øen", WikiWords.separate("ÆÅØleØen")
|
||||
assert_equal "Æe ÅØle Øen", WikiWords.separate("ÆeÅØleØen")
|
||||
assert_equal "Legetøj", WikiWords.separate("Legetøj")
|
||||
end
|
||||
end
|
370
test/watir/e2e.rb
Normal file
370
test/watir/e2e.rb
Normal file
|
@ -0,0 +1,370 @@
|
|||
require 'fileutils'
|
||||
require 'cgi'
|
||||
require 'test/unit'
|
||||
require 'rexml/document'
|
||||
|
||||
INSTIKI_ROOT = File.expand_path(File.dirname(__FILE__) + "/../..")
|
||||
require(File.expand_path(File.dirname(__FILE__) + "/../../config/environment"))
|
||||
|
||||
# TODO Create tests for:
|
||||
# * exporting HTML
|
||||
# * exporting markup
|
||||
# * include tag
|
||||
|
||||
# Use instiki/../watir, if such a directory exists; This can be a CVS HEAD version of Watir.
|
||||
# Otherwise Watir has to be installed in ruby/lib.
|
||||
$:.unshift INSTIKI_ROOT + '/../watir' if File.exists?(INSTIKI_ROOT + '/../watir/watir.rb')
|
||||
require 'watir'
|
||||
|
||||
INSTIKI_PORT = 2501
|
||||
HOME = "http://localhost:#{INSTIKI_PORT}"
|
||||
|
||||
class E2EInstikiTest < Test::Unit::TestCase
|
||||
|
||||
def startup
|
||||
@@instiki = InstikiController.start
|
||||
|
||||
sleep 8
|
||||
@@ie = Watir::IE.start(HOME)
|
||||
@@ie.set_fast_speed if (ARGV & ['-d', '--demo', '-demo', 'demo']).empty?
|
||||
|
||||
setup_web
|
||||
setup_home_page
|
||||
|
||||
@@ie
|
||||
end
|
||||
|
||||
def self.shutdown
|
||||
@@ie.close if defined? @@ie
|
||||
@@instiki.stop
|
||||
end
|
||||
|
||||
def ie
|
||||
if defined? @@ie
|
||||
@@ie
|
||||
else
|
||||
startup
|
||||
end
|
||||
end
|
||||
|
||||
def setup
|
||||
ie.goto HOME
|
||||
ie
|
||||
end
|
||||
|
||||
# Numbers like _00010_ determine the sequence in which the test cases are executed by Test::Unit
|
||||
# Unfortunately, this sequence is important.
|
||||
|
||||
def test_00010_home_page_contents
|
||||
check_main_menu
|
||||
check_bottom_menu
|
||||
check_footnote
|
||||
end
|
||||
|
||||
def test_00020_add_a_page
|
||||
# Add reference to a non-existant wiki page
|
||||
enter_markup('HomePage', '[[Another Wiki Page]]')
|
||||
assert_equal '?', ie.link(:url, url(:new, 'Another Wiki Page')).text
|
||||
|
||||
# Edit the first revision of a page
|
||||
enter_markup('Another Wiki Page', 'First revision of Another Wiki Page, linked from HomePage')
|
||||
|
||||
# Check contents of the new page
|
||||
assert_equal url(:show, 'Another Wiki Page'), ie.url
|
||||
assert_match /First revision of Another Wiki Page, linked from Home Page/, ie.text
|
||||
assert_match /Linked from: Home Page/, ie.text
|
||||
|
||||
# There must be three links to HomePage - main menu, contents of the page and navigation bar
|
||||
links_to_homepage = ie.links.to_a.select { |link| link.text == 'Home Page' }
|
||||
assert_equal 3, links_to_homepage.size
|
||||
links_to_homepage.each { |link| assert_equal url(:show, 'HomePage'), link.href }
|
||||
|
||||
# Check also the "created on ... by ..." footnote
|
||||
assert_match Regexp.new('Created on ' + date_pattern + ' by Anonymous Coward\?'), ie.text
|
||||
end
|
||||
|
||||
def test_00030_edit_page
|
||||
enter_markup('TestEditPage', 'Test Edit Page, revision 1')
|
||||
assert_match /Test Edit Page, revision 1/, ie.text
|
||||
|
||||
# subsequent revision by the anonymous author
|
||||
enter_markup('TestEditPage', 'Test Edit Page, revision 1, altered')
|
||||
assert_match /Test Edit Page, revision 1, altered/, ie.text
|
||||
assert_match Regexp.new('Created on ' + date_pattern + ' by Anonymous Coward\?'), ie.text
|
||||
|
||||
# revision by a named author
|
||||
enter_markup('TestEditPage', 'Test Edit Page, revision 2', 'Author')
|
||||
assert_match /Test Edit Page, revision 2/, ie.text
|
||||
assert_match Regexp.new('Revised on ' + date_pattern + ' by Author\?'), ie.text
|
||||
|
||||
link_to_previous_revision = ie.link(:name, 'to_previous_revision')
|
||||
assert_equal url(:revision, 'TestEditPage', 1), link_to_previous_revision.href
|
||||
assert_equal 'Back in time', link_to_previous_revision.text
|
||||
assert_match /Edit \| Back in time \(1 revision\) \| See changes/, ie.text
|
||||
|
||||
# another anonymous revision
|
||||
enter_markup('TestEditPage', 'Test Edit Page, revision 3')
|
||||
assert_match /Test Edit Page, revision 3/, ie.text
|
||||
assert_match /Edit \| Back in time \(2 revisions\) \| See changes /, ie.text
|
||||
end
|
||||
|
||||
def test_00040_traversing_revisions
|
||||
ie.goto url(:revision, 'TestEditPage', 2)
|
||||
assert_match /Test Edit Page, revision 2/, ie.text
|
||||
assert_match(Regexp.new(
|
||||
'Forward in time \(to current\) \| Back in time \(1 more\) \| See current \| See changes \| Rollback'),
|
||||
ie.text)
|
||||
|
||||
ie.link(:name, 'to_previous_revision').click
|
||||
assert_match /Test Edit Page, revision 1, altered/, ie.text
|
||||
assert_match /Forward in time \(2 more\) \| See current \| Rollback/, ie.text
|
||||
|
||||
ie.link(:name, 'to_next_revision').click
|
||||
assert_match /Test Edit Page, revision 2/, ie.text
|
||||
|
||||
ie.link(:name, 'to_next_revision').click
|
||||
assert_match /Test Edit Page, revision 3/, ie.text
|
||||
end
|
||||
|
||||
def test_00050_rollback
|
||||
ie.goto url(:revision, 'TestEditPage', 2)
|
||||
assert_match /Test Edit Page, revision 2/, ie.text
|
||||
ie.link(:name, 'rollback').click
|
||||
assert_equal url(:rollback, 'TestEditPage', 2), ie.url
|
||||
assert_equal 'Test Edit Page, revision 2', ie.text_field(:name, 'content').value
|
||||
|
||||
ie.text_field(:name, 'content').set('Test Edit Page, revision 2, rolled back')
|
||||
ie.button(:value, 'Update').click
|
||||
|
||||
assert_equal url(:show, 'TestEditPage'), ie.url
|
||||
assert_match /Test Edit Page, revision 2, rolled back/, ie.text
|
||||
end
|
||||
|
||||
def test_0060_see_changes
|
||||
ie.goto url(:show, 'TestEditPage')
|
||||
|
||||
assert_match /Test Edit Page, revision 2, rolled back/, ie.text
|
||||
|
||||
ie.link(:text, 'See changes').click
|
||||
|
||||
assert_match /Showing changes from revision #2 to #3: Added \| Removed/, ie.text
|
||||
assert_match /Test Edit Page, revision 22, rolled back/, ie.text
|
||||
|
||||
ie.link(:text, 'Hide changes').click
|
||||
|
||||
assert_match /Test Edit Page, revision 2, rolled back/, ie.text
|
||||
end
|
||||
|
||||
def test_0070_all_pages
|
||||
# create a wanted page, and unlink Another Wiki Page from Home Page
|
||||
# (to see that it doesn't show up in the orphans, regardless)
|
||||
enter_markup('Another Wiki Page', 'Reference to a NonExistantPage')
|
||||
|
||||
ie.link(:text, 'All Pages').click
|
||||
|
||||
page_links = ie.links.map { |l| l.text }
|
||||
expected_page_links = ['Another Wiki Page', 'Home Page', 'Test Edit Page', '?',
|
||||
'Another Wiki Page', 'Test Edit Page']
|
||||
assert_equal expected_page_links, page_links[-6..-1]
|
||||
links_sequence =
|
||||
'All Pages.*Another Wiki Page.*Home Page.*Test Edit Page.*' +
|
||||
'Wanted Pages.*Non Existant Page\? wanted by Another Wiki Page.*'+
|
||||
'Orphaned Pages.*Test Edit Page.*'
|
||||
assert_match Regexp.new(links_sequence, Regexp::MULTILINE), ie.text
|
||||
# and before that, we have the tail of the main menu
|
||||
|
||||
|
||||
require 'breakpoint'; breakpoint
|
||||
|
||||
|
||||
assert_equal 'Export', page_links[-7]
|
||||
end
|
||||
|
||||
def test_0080_recently_revised
|
||||
ie.link(:text, 'Recently Revised').click
|
||||
|
||||
links = ie.links.map { |l| l.text }
|
||||
assert_equal ['Another Wiki Page', '?', 'Test Edit Page', '?', 'Home Page', '?'], links[-6..-1]
|
||||
|
||||
expected_text =
|
||||
'Another Wiki Page.*by Anonymous Coward\?.*' +
|
||||
'Test Edit Page.*by Anonymous Coward\?.*' +
|
||||
'Home Page.*by Anonymous Coward\?.*'
|
||||
assert_match Regexp.new(expected_text, Regexp::MULTILINE), ie.text
|
||||
end
|
||||
|
||||
def test_0090_authors
|
||||
# create a revision of TestEditPage, and a corresponding author page
|
||||
enter_markup('TestEditPage', '3rd revision of this page', 'Another Author')
|
||||
ie.link(:afterText, 'Another Author').click
|
||||
assert_equal url(:new, 'Another Author'), ie.url
|
||||
enter_markup('Another Author', 'Email me at another_author@foo.bar.com', 'Another Author')
|
||||
|
||||
ie.link(:text, 'Authors').click
|
||||
|
||||
expected_authors =
|
||||
'Anonymous Coward\? co- or authored: Another Wiki Page, Home Page, Test Edit Page.*' +
|
||||
'Another Author co- or authored: Another Author, Test Edit Page.*' +
|
||||
'Author\? co- or authored: Test Edit Page'
|
||||
assert_match Regexp.new(expected_authors, Regexp::MULTILINE), ie.text
|
||||
|
||||
ie.link(:text, 'Another Author').click
|
||||
assert_equal url(:show, 'Another Author'), ie.url
|
||||
ie.back
|
||||
ie.link(:text, 'Test Edit Page').click
|
||||
assert_equal url(:show, 'TestEditPage'), ie.url
|
||||
end
|
||||
|
||||
def test_0100_feeds
|
||||
ie.link(:text, 'Feeds').click
|
||||
assert_equal url(:rss_with_content), ie.link(:text, 'Full content (RSS 2.0)').href
|
||||
assert_equal url(:rss_with_headlines), ie.link(:text, 'Headlines (RSS 2.0)').href
|
||||
|
||||
ie.link(:text, 'Full content (RSS 2.0)').click
|
||||
assert_nothing_raised { REXML::Document.new ie.text }
|
||||
|
||||
ie.back
|
||||
ie.link(:text, 'Headlines (RSS 2.0)').click
|
||||
assert_nothing_raised { REXML::Document.new ie.text }
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def bp
|
||||
require 'breakpoint'
|
||||
breakpoint
|
||||
end
|
||||
|
||||
def check_main_menu
|
||||
assert_equal HOME + '/wiki/list', ie.link(:text, 'All Pages').href
|
||||
assert_equal HOME + '/wiki/recently_revised', ie.link(:text, 'Recently Revised').href
|
||||
assert_equal HOME + '/wiki/authors', ie.link(:text, 'Authors').href
|
||||
assert_equal HOME + '/wiki/feeds', ie.link(:text, 'Feeds').href
|
||||
assert_equal HOME + '/wiki/export', ie.link(:text, 'Export').href
|
||||
end
|
||||
|
||||
def check_bottom_menu
|
||||
assert_equal url(:edit, 'HomePage'), ie.link(:text, 'Edit Page').href
|
||||
assert_equal HOME + '/wiki/edit_web', ie.link(:text, 'Edit Web').href
|
||||
assert_equal url(:print, 'HomePage'), ie.link(:text, 'Print').href
|
||||
end
|
||||
|
||||
def check_footnote
|
||||
assert_match /This site is running on Instiki/, ie.text
|
||||
assert_equal 'http://instiki.org/', ie.link(:text, 'Instiki').href
|
||||
assert_match /Powered by Ruby on Rails/, ie.text
|
||||
assert_equal 'http://rubyonrails.com/', ie.link(:text, 'Ruby on Rails').href
|
||||
end
|
||||
|
||||
def date_pattern
|
||||
'(January|February|March|April|May|June|July|August|September|October|November|December) ' +
|
||||
'\d\d?, \d\d\d\d \d\d:\d\d:\d\d'
|
||||
end
|
||||
|
||||
def enter_markup(page, content, author = nil)
|
||||
ie.goto url(:show, page)
|
||||
if ie.url == url(:show, page)
|
||||
ie.link(:name, 'edit').click
|
||||
assert_equal url(:edit, page), ie.url
|
||||
else
|
||||
assert_equal url(:new, page), ie.url
|
||||
end
|
||||
|
||||
ie.text_field(:name, 'content').set(content)
|
||||
ie.text_field(:name, 'author').set(author || '')
|
||||
ie.button(:value, 'Submit').click
|
||||
|
||||
assert_equal url(:show, page), ie.url
|
||||
end
|
||||
|
||||
def setup_web
|
||||
assert_equal 'Wiki', ie.text_field(:name, 'web_name').value
|
||||
assert_equal 'wiki', ie.text_field(:name, 'web_address').value
|
||||
assert_equal '', ie.text_field(:name, 'password').value
|
||||
assert_equal '', ie.text_field(:name, 'password_check').value
|
||||
|
||||
ie.text_field(:name, 'password').set('123')
|
||||
ie.text_field(:name, 'password_check').set('123')
|
||||
ie.button(:value, 'Setup').click
|
||||
assert_equal url(:new, 'HomePage'), ie.url
|
||||
end
|
||||
|
||||
def setup_home_page
|
||||
ie.text_field(:name, 'content').set('Homepage of a test wiki')
|
||||
ie.button(:value, 'Submit').click
|
||||
assert_equal url(:show, 'HomePage'), ie.url
|
||||
end
|
||||
|
||||
def url(operation, page_name = nil, revision = nil)
|
||||
page_name = CGI.escape(page_name) if page_name
|
||||
case operation
|
||||
when :edit, :new, :show, :print, :revision, :rollback
|
||||
"#{HOME}/wiki/#{operation}/#{page_name}" + (revision ? "?rev=#{revision}" : '')
|
||||
when :rss_with_content, :rss_with_headlines
|
||||
"#{HOME}/wiki/#{operation}"
|
||||
else
|
||||
raise "Unsupported operation: '#{operation}"
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class InstikiController
|
||||
|
||||
attr_reader :process_id
|
||||
|
||||
def self.start
|
||||
startup_info = [68].pack('lx64')
|
||||
process_info = [0, 0, 0, 0].pack('llll')
|
||||
|
||||
clear_database
|
||||
startup_command =
|
||||
"ruby #{RAILS_ROOT}/instiki.rb --port #{INSTIKI_PORT} --environment development"
|
||||
|
||||
result = Win32API.new('kernel32.dll', 'CreateProcess', 'pplllllppp', 'L').call(
|
||||
nil,
|
||||
startup_command,
|
||||
0, 0, 1, 0, 0, '.', startup_info, process_info)
|
||||
|
||||
# TODO print the error code, or better yet a text message
|
||||
raise "Failed to start Instiki." if result == 0
|
||||
|
||||
process_id = process_info.unpack('llll')[2]
|
||||
return self.new(process_id)
|
||||
end
|
||||
|
||||
def self.clear_database
|
||||
ENV['RAILS_ENV'] = 'development'
|
||||
require INSTIKI_ROOT + '/config/environment.rb'
|
||||
[WikiReference, Revision, Page, WikiFile, Web, System].each { |entity| entity.delete_all }
|
||||
end
|
||||
|
||||
def initialize(pid)
|
||||
@process_id = pid
|
||||
end
|
||||
|
||||
def stop
|
||||
right_to_terminate_process = 1
|
||||
handle = Win32API.new('kernel32.dll', 'OpenProcess', 'lil', 'l').call(
|
||||
right_to_terminate_process, 0, @process_id)
|
||||
Win32API.new('kernel32.dll', 'TerminateProcess', 'll', 'L').call(handle, 0)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
begin
|
||||
require 'test/unit/ui/console/testrunner'
|
||||
Test::Unit::UI::Console::TestRunner.new(E2EInstikiTest.suite).start
|
||||
rescue => e
|
||||
$stderr.puts 'Unhandled error during test execution'
|
||||
$stderr.puts e.message
|
||||
$stderr.puts e.backtrace
|
||||
ensure
|
||||
begin
|
||||
E2EInstikiTest::shutdown
|
||||
rescue => e
|
||||
$stderr.puts 'Error during shutdown'
|
||||
$stderr.puts e.message
|
||||
$stderr.puts e.backtrace
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue