move to AR
This commit is contained in:
parent
c4b7b2d9f2
commit
26c046cdfa
51 changed files with 2345 additions and 516 deletions
56
test/fixtures/pages.yml
vendored
56
test/fixtures/pages.yml
vendored
|
@ -1,5 +1,55 @@
|
|||
home_page:
|
||||
id: 1
|
||||
created_at: 2004-08-01
|
||||
updated_at: 2005-08-01
|
||||
web_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
|
84
test/fixtures/revisions.yml
vendored
84
test/fixtures/revisions.yml
vendored
|
@ -1,6 +1,84 @@
|
|||
home_page_first_revision:
|
||||
id: 1
|
||||
created_at: 2004-08-01
|
||||
updated_at: 2005-08-01
|
||||
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) %>
|
||||
page_id: 1
|
||||
content: some text
|
||||
number: 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) %>
|
||||
page_id: 2
|
||||
number: 1
|
||||
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) %>
|
||||
page_id: 3
|
||||
number: 1
|
||||
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) %>
|
||||
page_id: 4
|
||||
number: 1
|
||||
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) %>
|
||||
page_id: 5
|
||||
number: 1
|
||||
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) %>
|
||||
page_id: 1
|
||||
number: 2
|
||||
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) %>
|
||||
page_id: 6
|
||||
number: 1
|
||||
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) %>
|
||||
page_id: 7
|
||||
number: 1
|
||||
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) %>
|
||||
page_id: 8
|
||||
number: 1
|
||||
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
|
13
test/fixtures/webs.yml
vendored
13
test/fixtures/webs.yml
vendored
|
@ -2,5 +2,14 @@ test_wiki:
|
|||
id: 1
|
||||
created_at: 2004-08-01
|
||||
updated_at: 2005-08-01
|
||||
name: wiki
|
||||
address: wiki
|
||||
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
|
|
@ -1,70 +1,73 @@
|
|||
#!/bin/env ruby -w
|
||||
#!/bin/env ruby
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
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
|
||||
|
||||
def setup
|
||||
setup_test_wiki
|
||||
setup_controller_test
|
||||
@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 tear_down
|
||||
tear_down_wiki
|
||||
end
|
||||
|
||||
|
||||
def test_create_system_form_displayed
|
||||
ApplicationController.wiki = WikiServiceWithNoPersistence.new
|
||||
use_blank_wiki
|
||||
process('create_system')
|
||||
assert_success
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
def test_create_system_form_submitted
|
||||
ApplicationController.wiki = WikiServiceWithNoPersistence.new
|
||||
assert !ApplicationController.wiki.setup?
|
||||
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 ApplicationController.wiki.setup?
|
||||
assert_equal 'a_password', ApplicationController.wiki.system[:password]
|
||||
assert_equal 1, ApplicationController.wiki.webs.size
|
||||
new_web = ApplicationController.wiki.webs['my_wiki']
|
||||
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 = ApplicationController.wiki
|
||||
assert ApplicationController.wiki.setup?
|
||||
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 => 'wiki1', :action => 'show', :id => 'HomePage'
|
||||
assert_equal wiki_before, ApplicationController.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 1, ApplicationController.wiki.webs.size
|
||||
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 => 'wiki1', :action => 'show', :id => 'HomePage'
|
||||
assert_redirected_to :web => @wiki.webs.keys.first, :action => 'show', :id => 'HomePage'
|
||||
assert_flash_has :error
|
||||
end
|
||||
|
||||
|
||||
def test_create_web
|
||||
@wiki.system[:password] = 'pswd'
|
||||
@wiki.system.update_attribute(:password, 'pswd')
|
||||
|
||||
process 'create_web', 'system_password' => 'pswd', 'name' => 'Wiki Two', 'address' => 'wiki2'
|
||||
|
||||
|
@ -76,7 +79,7 @@ class AdminControllerTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_create_web_default_password
|
||||
@wiki.system[:password] = nil
|
||||
@wiki.system.update_attribute(:password, nil)
|
||||
|
||||
process 'create_web', 'system_password' => 'instiki', 'name' => 'Wiki Two', 'address' => 'wiki2'
|
||||
|
||||
|
@ -84,7 +87,7 @@ class AdminControllerTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_create_web_failed_authentication
|
||||
@wiki.system[:password] = 'pswd'
|
||||
@wiki.system.update_attribute(:password, 'pswd')
|
||||
|
||||
process 'create_web', 'system_password' => 'wrong', 'name' => 'Wiki Two', 'address' => 'wiki2'
|
||||
|
||||
|
@ -93,20 +96,20 @@ class AdminControllerTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_create_web_no_form_submitted
|
||||
@wiki.system[:password] = 'pswd'
|
||||
@wiki.system.update_attribute(:password, 'pswd')
|
||||
process 'create_web'
|
||||
assert_success
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
|
||||
def test_edit_web_no_form
|
||||
process 'edit_web', 'web' => 'wiki1'
|
||||
# this action simply renders a form
|
||||
assert_success
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
def test_edit_web_form_submitted
|
||||
@wiki.system[:password] = 'pswd'
|
||||
@wiki.system.update_attribute(:password, 'pswd')
|
||||
|
||||
process('edit_web', 'system_password' => 'pswd',
|
||||
'web' => 'wiki1', 'address' => 'renamed_wiki1', 'name' => 'Renamed Wiki1',
|
||||
|
@ -116,21 +119,22 @@ class AdminControllerTest < Test::Unit::TestCase
|
|||
'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 @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 @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[:password] = 'pswd'
|
||||
@wiki.system.update_attribute(:password, 'pswd')
|
||||
|
||||
process('edit_web', 'system_password' => 'pswd',
|
||||
'web' => 'wiki1', 'address' => 'renamed_wiki1', 'name' => 'Renamed Wiki1',
|
||||
|
@ -140,11 +144,12 @@ class AdminControllerTest < Test::Unit::TestCase
|
|||
# and should become false
|
||||
|
||||
assert_redirected_to :web => 'renamed_wiki1', :action => 'show', :id => 'HomePage'
|
||||
assert !@web.safe_mode
|
||||
assert !@web.published
|
||||
assert !@web.brackets_only
|
||||
assert !@web.count_pages
|
||||
assert !@web.allow_uploads
|
||||
@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
|
||||
|
@ -154,12 +159,12 @@ class AdminControllerTest < Test::Unit::TestCase
|
|||
'password' => 'new_password')
|
||||
|
||||
#returns to the same form
|
||||
assert_success
|
||||
assert_response :success
|
||||
assert @response.has_template_object?('error')
|
||||
end
|
||||
|
||||
def test_edit_web_rename_to_already_existing_web_name
|
||||
@wiki.system[:password] = 'pswd'
|
||||
@wiki.system.update_attribute(:password, 'pswd')
|
||||
|
||||
@wiki.create_web('Another', 'another')
|
||||
process('edit_web', 'system_password' => 'pswd',
|
||||
|
@ -168,7 +173,7 @@ class AdminControllerTest < Test::Unit::TestCase
|
|||
'password' => 'new_password')
|
||||
|
||||
#returns to the same form
|
||||
assert_success
|
||||
assert_response :success
|
||||
assert @response.has_template_object?('error')
|
||||
end
|
||||
|
||||
|
@ -179,15 +184,15 @@ class AdminControllerTest < Test::Unit::TestCase
|
|||
'password' => 'new_password')
|
||||
|
||||
#returns to the same form
|
||||
assert_success
|
||||
assert_response :success
|
||||
assert @response.has_template_object?('error')
|
||||
end
|
||||
|
||||
|
||||
def test_remove_orphaned_pages
|
||||
setup_wiki_with_three_pages
|
||||
@wiki.system[:password] = 'pswd'
|
||||
orhan_page_linking_to_oak = @wiki.write_page('wiki1', 'Pine',
|
||||
@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'))
|
||||
|
@ -195,25 +200,28 @@ class AdminControllerTest < Test::Unit::TestCase
|
|||
r = process('remove_orphaned_pages', 'web' => 'wiki1', 'system_password_orphaned' => 'pswd')
|
||||
|
||||
assert_redirected_to :controller => 'wiki', :web => 'wiki1', :action => 'list'
|
||||
assert_equal [@home, @oak], @web.select.sort,
|
||||
@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'
|
||||
assert_equal [@home], @web.select.sort,
|
||||
@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'
|
||||
assert_equal [@home], @web.select.sort,
|
||||
@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
|
||||
setup_wiki_with_three_pages
|
||||
@wiki.system[:password] = 'pswd'
|
||||
|
||||
process('remove_orphaned_pages', 'web' => 'wiki1')
|
||||
|
@ -224,5 +232,4 @@ class AdminControllerTest < Test::Unit::TestCase
|
|||
assert_redirected_to(:controller => 'admin', :action => 'edit_web', :web => 'wiki1')
|
||||
assert @response.flash[:error]
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -8,24 +8,23 @@ require 'rexml/document'
|
|||
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
|
||||
setup_test_wiki
|
||||
setup_controller_test(WikiController)
|
||||
@controller = WikiController.new
|
||||
@request = ActionController::TestRequest.new
|
||||
@response = ActionController::TestResponse.new
|
||||
@wiki = Wiki.new
|
||||
end
|
||||
|
||||
def tear_down
|
||||
tear_down_wiki
|
||||
end
|
||||
|
||||
|
||||
def test_utf8_header
|
||||
r = process('show', 'web' => 'wiki1', 'id' => 'HomePage')
|
||||
assert_equal 'text/html; charset=UTF-8', r.headers['Content-Type']
|
||||
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
|
||||
r = process('show', 'web' => 'unknown_wiki', 'id' => 'HomePage')
|
||||
assert_equal 404, r.response_code
|
||||
get :show, :web => 'unknown_wiki', :id => 'HomePage'
|
||||
assert_response :missing
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#!/bin/env ruby -w
|
||||
#!/bin/env ruby
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
require 'file_controller'
|
||||
|
@ -8,24 +8,26 @@ require 'fileutils'
|
|||
class FileController; def rescue_action(e) logger.error(e); raise e end; end
|
||||
|
||||
class FileControllerTest < Test::Unit::TestCase
|
||||
fixtures :webs, :pages, :revisions, :system
|
||||
|
||||
FILE_AREA = RAILS_ROOT + '/storage/test/wiki1'
|
||||
Wiki.storage_path += "test/"
|
||||
FILE_AREA = Wiki.storage_path + 'wiki1'
|
||||
FileUtils.mkdir_p(FILE_AREA) unless File.directory?(FILE_AREA)
|
||||
FileUtils.rm(Dir["#{FILE_AREA}/*"])
|
||||
|
||||
def setup
|
||||
setup_test_wiki
|
||||
setup_controller_test
|
||||
end
|
||||
|
||||
def tear_down
|
||||
tear_down_wiki
|
||||
@controller = FileController.new
|
||||
@request = ActionController::TestRequest.new
|
||||
@response = ActionController::TestResponse.new
|
||||
@wiki = Wiki.new
|
||||
@web = webs(:test_wiki)
|
||||
@home = @page = pages(:home_page)
|
||||
end
|
||||
|
||||
def test_file
|
||||
process 'file', 'web' => 'wiki1', 'id' => 'foo.tgz'
|
||||
|
||||
assert_success
|
||||
assert_response :success
|
||||
assert_rendered_file 'file/file'
|
||||
end
|
||||
|
||||
|
@ -34,7 +36,7 @@ class FileControllerTest < Test::Unit::TestCase
|
|||
|
||||
r = process 'file', 'web' => 'wiki1', 'id' => 'foo.txt'
|
||||
|
||||
assert_success
|
||||
assert_response :success
|
||||
assert_equal "aaa\nbbb\n", r.binary_content
|
||||
assert_equal 'text/plain', r.headers['Content-Type']
|
||||
end
|
||||
|
@ -44,7 +46,7 @@ class FileControllerTest < Test::Unit::TestCase
|
|||
|
||||
r = process 'file', 'web' => 'wiki1', 'id' => 'foo.pdf'
|
||||
|
||||
assert_success
|
||||
assert_response :success
|
||||
assert_equal "aaa\nbbb\n", r.binary_content
|
||||
assert_equal 'application/pdf', r.headers['Content-Type']
|
||||
end
|
||||
|
@ -54,14 +56,14 @@ class FileControllerTest < Test::Unit::TestCase
|
|||
|
||||
r = process 'pic', 'web' => 'wiki1', 'id' => 'rails.gif'
|
||||
|
||||
assert_success
|
||||
assert_response :success
|
||||
assert_equal File.size("#{FILE_AREA}/rails.gif"), r.binary_content.size
|
||||
end
|
||||
|
||||
def test_pic_unknown_pic
|
||||
r = process 'pic', 'web' => 'wiki1', 'id' => 'non-existant.gif'
|
||||
|
||||
assert_success
|
||||
assert_response :success
|
||||
assert_rendered_file 'file/file'
|
||||
end
|
||||
|
||||
|
@ -74,7 +76,7 @@ class FileControllerTest < Test::Unit::TestCase
|
|||
|
||||
# rails-e2e.gif is unknown to the system, so pic action goes to the file [upload] form
|
||||
r = process 'pic', 'web' => 'wiki1', 'id' => 'rails-e2e.gif'
|
||||
assert_success
|
||||
assert_response :success
|
||||
assert_rendered_file 'file/file'
|
||||
|
||||
# User uploads the picture
|
||||
|
@ -98,7 +100,7 @@ class FileControllerTest < Test::Unit::TestCase
|
|||
|
||||
# rails-e2e.gif is unknown to the system, so pic action goes to the file [upload] form
|
||||
r = process 'file', 'web' => 'wiki1', 'id' => 'instiki-e2e.txt'
|
||||
assert_success
|
||||
assert_response :success
|
||||
assert_rendered_file 'file/file'
|
||||
|
||||
# User uploads the picture
|
||||
|
@ -109,17 +111,18 @@ class FileControllerTest < Test::Unit::TestCase
|
|||
assert_equal(file, File.read("#{RAILS_ROOT}/storage/test/wiki1/instiki-e2e.txt"))
|
||||
|
||||
# this should refresh the page display content (cached)
|
||||
@home = Page.find(@home.id)
|
||||
assert_equal "<p><a class=\"existingWikiWord\" href=\"../file/instiki-e2e.txt\">" +
|
||||
"instiki-e2e.txt</a></p>",
|
||||
@home.display_content
|
||||
end
|
||||
|
||||
def test_uploads_blocking
|
||||
@web.allow_uploads = true
|
||||
set_web_property :allow_uploads, true
|
||||
r = process 'file', 'web' => 'wiki1', 'id' => 'filename'
|
||||
assert_success
|
||||
assert_response :success
|
||||
|
||||
@web.allow_uploads = false
|
||||
set_web_property :allow_uploads, false
|
||||
r = process 'file', 'web' => 'wiki1', 'id' => 'filename'
|
||||
assert_equal '403 Forbidden', r.headers['Status']
|
||||
end
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#!/bin/env ruby -w
|
||||
#!/bin/env ruby
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
#!/bin/env ruby -w
|
||||
#!/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.dirname(__FILE__) + '/../test_helper'
|
||||
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
||||
require 'wiki_controller'
|
||||
require 'rexml/document'
|
||||
require 'tempfile'
|
||||
|
@ -14,63 +14,60 @@ require 'zip/zipfilesystem'
|
|||
class WikiController; def rescue_action(e) logger.error(e); raise e end; end
|
||||
|
||||
class WikiControllerTest < Test::Unit::TestCase
|
||||
|
||||
fixtures :webs, :pages, :revisions, :system
|
||||
|
||||
def setup
|
||||
setup_test_wiki
|
||||
setup_controller_test
|
||||
@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 tear_down
|
||||
tear_down_wiki
|
||||
end
|
||||
|
||||
|
||||
def test_authenticate
|
||||
@web.password = 'pswd'
|
||||
set_web_property :password, 'pswd'
|
||||
|
||||
r = process('authenticate', 'web' => 'wiki1', 'password' => 'pswd')
|
||||
get :authenticate, :web => 'wiki1', :password => 'pswd'
|
||||
assert_redirected_to :web => 'wiki1', :action => 'show', :id => 'HomePage'
|
||||
assert_equal ['pswd'], r.cookies['web_address']
|
||||
assert_equal ['pswd'], @response.cookies['web_address']
|
||||
end
|
||||
|
||||
def test_authenticate_wrong_password
|
||||
@web.password = 'pswd'
|
||||
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
|
||||
setup_wiki_with_three_pages
|
||||
@wiki.write_page('wiki1', 'BreakSortingOrder',
|
||||
"This page breaks the accidentally correct sorting order of authors",
|
||||
Time.now, Author.new('BreakingTheOrder', '127.0.0.2'))
|
||||
|
||||
r = process('authors', 'web' => 'wiki1')
|
||||
|
||||
assert_success
|
||||
assert_equal ['AnAuthor', 'BreakingTheOrder', 'Guest', 'TreeHugger'],
|
||||
assert_response :success
|
||||
assert_equal %w(AnAuthor BreakingTheOrder DavidHeinemeierHansson Guest Me TreeHugger),
|
||||
r.template_objects['authors']
|
||||
end
|
||||
|
||||
|
||||
def test_cancel_edit
|
||||
setup_wiki_with_three_pages
|
||||
@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 !@oak.locked?(Time.now)
|
||||
assert !Page.find(@oak.id).locked?(Time.now)
|
||||
end
|
||||
|
||||
|
||||
def test_edit
|
||||
r = process 'edit', 'web' => 'wiki1', 'id' => 'HomePage'
|
||||
assert_success
|
||||
assert_response :success
|
||||
assert_equal @wiki.read_page('wiki1', 'HomePage'), r.template_objects['page']
|
||||
end
|
||||
|
||||
|
@ -83,7 +80,8 @@ class WikiControllerTest < Test::Unit::TestCase
|
|||
def test_edit_page_break_lock
|
||||
@home.lock(Time.now, 'Locky')
|
||||
process 'edit', 'web' => 'wiki1', 'id' => 'HomePage', 'break_lock' => 'y'
|
||||
assert_success
|
||||
assert_response :success
|
||||
@home = Page.find(@home.id)
|
||||
assert @home.locked?(Time.now)
|
||||
end
|
||||
|
||||
|
@ -99,19 +97,17 @@ class WikiControllerTest < Test::Unit::TestCase
|
|||
Time.now, Author.new('Special', '127.0.0.3'))
|
||||
|
||||
r = process 'edit', 'web' => 'wiki1', 'id' => 'With : Special /> symbols'
|
||||
assert_success
|
||||
assert_response :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
|
||||
setup_wiki_with_three_pages
|
||||
|
||||
@home.rollback(1, Time.now, 'Rick') # much simpler regex statement to match
|
||||
r = process 'export_html', 'web' => 'wiki1'
|
||||
|
||||
assert_success
|
||||
assert_response :success
|
||||
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']
|
||||
|
@ -124,7 +120,7 @@ class WikiControllerTest < Test::Unit::TestCase
|
|||
begin
|
||||
File.open(@tempfile_path, 'wb') { |f| f.write(content); @exported_file = f.path }
|
||||
Zip::ZipFile.open(@exported_file) do |zip|
|
||||
assert_equal %w(Elephant.html HomePage.html Oak.html index.html), zip.dir.entries('.').sort
|
||||
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>/,
|
||||
|
@ -138,12 +134,10 @@ class WikiControllerTest < Test::Unit::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
def test_export_html_no_layout
|
||||
setup_wiki_with_three_pages
|
||||
|
||||
def test_export_html_no_layout
|
||||
r = process 'export_html', 'web' => 'wiki1', 'layout' => 'no'
|
||||
|
||||
assert_success
|
||||
assert_response :success
|
||||
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']
|
||||
|
@ -155,7 +149,7 @@ class WikiControllerTest < Test::Unit::TestCase
|
|||
def test_export_markup
|
||||
r = process 'export_markup', 'web' => 'wiki1'
|
||||
|
||||
assert_success
|
||||
assert_response :success
|
||||
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']
|
||||
|
@ -168,7 +162,7 @@ class WikiControllerTest < Test::Unit::TestCase
|
|||
|
||||
def test_export_pdf
|
||||
r = process 'export_pdf', 'web' => 'wiki1'
|
||||
assert_success
|
||||
assert_response :success
|
||||
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']
|
||||
|
@ -183,13 +177,10 @@ class WikiControllerTest < Test::Unit::TestCase
|
|||
puts ' $INSTIKI_TEST_PDFLATEX to enable them.'
|
||||
end
|
||||
|
||||
|
||||
def test_export_tex
|
||||
setup_wiki_with_three_pages
|
||||
|
||||
def test_export_tex
|
||||
r = process 'export_tex', 'web' => 'wiki1'
|
||||
|
||||
assert_success
|
||||
assert_response :success
|
||||
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']
|
||||
|
@ -202,6 +193,8 @@ class WikiControllerTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_index
|
||||
# delete extra web fixture
|
||||
webs(:instiki).destroy
|
||||
process('index')
|
||||
assert_redirected_to :web => 'wiki1', :action => 'show', :id => 'HomePage'
|
||||
end
|
||||
|
@ -219,41 +212,39 @@ class WikiControllerTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_index_wiki_not_initialized
|
||||
ApplicationController.wiki = WikiServiceWithNoPersistence.new
|
||||
use_blank_wiki
|
||||
process('index')
|
||||
assert_redirected_to :controller => 'admin', :action => 'create_system'
|
||||
end
|
||||
|
||||
|
||||
def test_list
|
||||
setup_wiki_with_three_pages
|
||||
|
||||
r = process('list', 'web' => 'wiki1')
|
||||
|
||||
assert_equal ['animals', 'trees'], r.template_objects['categories']
|
||||
assert_nil r.template_objects['category']
|
||||
assert_equal [@elephant, @home, @oak], r.template_objects['pages_in_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_response :success
|
||||
assert_equal @home, r.template_objects['page']
|
||||
end
|
||||
|
||||
|
||||
def test_login
|
||||
r = process 'login', 'web' => 'wiki1'
|
||||
assert_success
|
||||
assert_response :success
|
||||
# this action goes straight to the templates
|
||||
end
|
||||
|
||||
|
||||
def test_new
|
||||
r = process('new', 'id' => 'NewPage', 'web' => 'wiki1')
|
||||
assert_success
|
||||
assert_response :success
|
||||
assert_equal 'AnonymousCoward', r.template_objects['author']
|
||||
assert_equal 'NewPage', r.template_objects['page_name']
|
||||
end
|
||||
|
@ -264,7 +255,7 @@ class WikiControllerTest < Test::Unit::TestCase
|
|||
def test_pdf
|
||||
assert RedClothForTex.available?, 'Cannot do test_pdf when pdflatex is not available'
|
||||
r = process('pdf', 'web' => 'wiki1', 'id' => 'HomePage')
|
||||
assert_success
|
||||
assert_response :success
|
||||
|
||||
content = r.binary_content
|
||||
|
||||
|
@ -282,23 +273,23 @@ class WikiControllerTest < Test::Unit::TestCase
|
|||
def test_print
|
||||
r = process('print', 'web' => 'wiki1', 'id' => 'HomePage')
|
||||
|
||||
assert_success
|
||||
assert_response :success
|
||||
assert_equal :show, r.template_objects['link_mode']
|
||||
end
|
||||
|
||||
|
||||
def test_published
|
||||
@web.published = true
|
||||
set_web_property :published, true
|
||||
|
||||
r = process('published', 'web' => 'wiki1', 'id' => 'HomePage')
|
||||
|
||||
assert_success
|
||||
assert_response :success
|
||||
assert_equal @home, r.template_objects['page']
|
||||
end
|
||||
|
||||
|
||||
def test_published_web_not_published
|
||||
@web.published = false
|
||||
set_web_property :published, false
|
||||
|
||||
r = process('published', 'web' => 'wiki1', 'id' => 'HomePage')
|
||||
|
||||
|
@ -308,11 +299,11 @@ class WikiControllerTest < Test::Unit::TestCase
|
|||
|
||||
def test_recently_revised
|
||||
r = process('recently_revised', 'web' => 'wiki1')
|
||||
assert_success
|
||||
assert_response :success
|
||||
|
||||
assert_equal [], r.template_objects['categories']
|
||||
assert_equal %w(animals trees), r.template_objects['categories']
|
||||
assert_nil r.template_objects['category']
|
||||
assert_equal [@home], r.template_objects['pages_in_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']
|
||||
assert_equal 'the web', r.template_objects['set_name']
|
||||
end
|
||||
|
||||
|
@ -323,37 +314,33 @@ class WikiControllerTest < Test::Unit::TestCase
|
|||
Time.now, Author.new('AnotherAuthor', '127.0.0.2'))
|
||||
|
||||
r = process('recently_revised', 'web' => 'wiki1')
|
||||
assert_success
|
||||
assert_response :success
|
||||
|
||||
assert_equal ['categorized'], r.template_objects['categories']
|
||||
assert_equal %w(animals categorized trees), r.template_objects['categories']
|
||||
# no category is specified in params
|
||||
assert_nil r.template_objects['category']
|
||||
assert_equal [@home, page2], r.template_objects['pages_in_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
|
||||
setup_wiki_with_three_pages
|
||||
|
||||
r = process('recently_revised', 'web' => 'wiki1')
|
||||
assert_success
|
||||
assert_response :success
|
||||
|
||||
assert_equal ['animals', 'trees'], r.template_objects['categories']
|
||||
# no category is specified in params
|
||||
assert_nil r.template_objects['category']
|
||||
assert_equal [@elephant, @home, @oak], r.template_objects['pages_in_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
|
||||
setup_wiki_with_three_pages
|
||||
|
||||
r = process('recently_revised', 'web' => 'wiki1', 'category' => 'animals')
|
||||
assert_success
|
||||
assert_response :success
|
||||
|
||||
assert_equal ['animals', 'trees'], r.template_objects['categories']
|
||||
# no category is specified in params
|
||||
|
@ -366,7 +353,7 @@ class WikiControllerTest < Test::Unit::TestCase
|
|||
def test_revision
|
||||
r = process 'revision', 'web' => 'wiki1', 'id' => 'HomePage', 'rev' => '0'
|
||||
|
||||
assert_success
|
||||
assert_response :success
|
||||
assert_equal @home, r.template_objects['page']
|
||||
assert_equal @home.revisions[0], r.template_objects['revision']
|
||||
end
|
||||
|
@ -377,27 +364,24 @@ class WikiControllerTest < Test::Unit::TestCase
|
|||
# its assigns the same as or revision
|
||||
r = process 'rollback', 'web' => 'wiki1', 'id' => 'HomePage', 'rev' => '0'
|
||||
|
||||
assert_success
|
||||
assert_response :success
|
||||
assert_equal @home, r.template_objects['page']
|
||||
assert_equal @home.revisions[0], r.template_objects['revision']
|
||||
end
|
||||
|
||||
def test_rss_with_content
|
||||
setup_wiki_with_three_pages
|
||||
|
||||
r = process 'rss_with_content', 'web' => 'wiki1'
|
||||
|
||||
assert_success
|
||||
assert_response :success
|
||||
pages = r.template_objects['pages_by_revision']
|
||||
assert_equal [@home, @oak, @elephant], pages,
|
||||
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
|
||||
setup_wiki_with_three_pages
|
||||
@web.password = 'aaa'
|
||||
@web.published = false
|
||||
@web.update_attributes(:password => 'aaa', :published => false)
|
||||
@web = Web.find(@web.id)
|
||||
|
||||
r = process 'rss_with_content', 'web' => 'wiki1'
|
||||
|
||||
|
@ -406,7 +390,6 @@ class WikiControllerTest < Test::Unit::TestCase
|
|||
|
||||
|
||||
def test_rss_with_headlines
|
||||
setup_wiki_with_three_pages
|
||||
@title_with_spaces = @wiki.write_page('wiki1', 'Title With Spaces',
|
||||
'About spaces', 1.hour.ago, Author.new('TreeHugger', '127.0.0.2'))
|
||||
|
||||
|
@ -415,19 +398,24 @@ class WikiControllerTest < Test::Unit::TestCase
|
|||
|
||||
r = process 'rss_with_headlines', 'web' => 'wiki1'
|
||||
|
||||
assert_success
|
||||
assert_response :success
|
||||
pages = r.template_objects['pages_by_revision']
|
||||
assert_equal [@home, @oak, @elephant, @title_with_spaces], pages,
|
||||
"Pages are not as expected: #{pages.map {|p| p.name}.inspect}"
|
||||
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/HomePage',
|
||||
['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/Elephant',
|
||||
'http://localhost:8080/wiki1/show/Title+With+Spaces']
|
||||
'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'
|
||||
|
@ -436,22 +424,26 @@ class WikiControllerTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_rss_switch_links_to_published
|
||||
setup_wiki_with_three_pages
|
||||
@web.password = 'aaa'
|
||||
@web.published = true
|
||||
@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
|
||||
assert_response :success
|
||||
xml = REXML::Document.new(r.body)
|
||||
|
||||
expected_page_links =
|
||||
['http://foo.bar.info/wiki1/published/HomePage',
|
||||
['http://foo.bar.info/wiki1/published/Elephant',
|
||||
'http://foo.bar.info/wiki1/published/Oak',
|
||||
'http://foo.bar.info/wiki1/published/Elephant']
|
||||
'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'
|
||||
|
@ -463,45 +455,43 @@ class WikiControllerTest < Test::Unit::TestCase
|
|||
setup_wiki_with_30_pages
|
||||
|
||||
r = process 'rss_with_headlines', 'web' => 'wiki1'
|
||||
assert_success
|
||||
assert_response :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
|
||||
assert_response :success
|
||||
pages = r.template_objects['pages_by_revision']
|
||||
assert_equal 5, pages.size
|
||||
|
||||
r = process 'rss_with_headlines', 'web' => 'wiki1', 'limit' => '25'
|
||||
assert_success
|
||||
assert_response :success
|
||||
pages = r.template_objects['pages_by_revision']
|
||||
assert_equal 25, pages.size
|
||||
|
||||
r = process 'rss_with_headlines', 'web' => 'wiki1', 'limit' => 'all'
|
||||
assert_success
|
||||
assert_response :success
|
||||
pages = r.template_objects['pages_by_revision']
|
||||
assert_equal 31, pages.size
|
||||
assert_equal 38, pages.size
|
||||
|
||||
r = process 'rss_with_headlines', 'web' => 'wiki1', 'start' => '1976-10-16'
|
||||
assert_success
|
||||
assert_response :success
|
||||
pages = r.template_objects['pages_by_revision']
|
||||
assert_equal 16, pages.size
|
||||
assert_equal 23, pages.size
|
||||
|
||||
r = process 'rss_with_headlines', 'web' => 'wiki1', 'end' => '1976-10-16'
|
||||
assert_success
|
||||
assert_response :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
|
||||
assert_response :success
|
||||
pages = r.template_objects['pages_by_revision']
|
||||
assert_equal 5, pages.size
|
||||
end
|
||||
|
||||
def test_rss_title_with_ampersand
|
||||
# was ticket:143
|
||||
setup_wiki_with_three_pages
|
||||
|
||||
# was ticket:143
|
||||
@wiki.write_page('wiki1', 'Title&With&Ampersands',
|
||||
'About spaces', 1.hour.ago, Author.new('NitPicker', '127.0.0.3'))
|
||||
|
||||
|
@ -511,15 +501,12 @@ class WikiControllerTest < Test::Unit::TestCase
|
|||
assert r.body.include?('<title>Title&With&Ampersands</title>')
|
||||
end
|
||||
|
||||
def test_rss_timestamp
|
||||
setup_wiki_with_three_pages
|
||||
|
||||
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'))
|
||||
|
||||
r = process 'rss_with_headlines', 'web' => 'wiki1'
|
||||
|
||||
assert_template_xpath_match '/rss/channel/item/pubDate[4]', "Thu, 01 Jan 1970 00:00:00 Z"
|
||||
assert_template_xpath_match '/rss/channel/item/pubDate[9]', "Thu, 01 Jan 1970 00:00:00 Z"
|
||||
end
|
||||
|
||||
def test_save
|
||||
|
@ -535,6 +522,7 @@ class WikiControllerTest < Test::Unit::TestCase
|
|||
|
||||
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'
|
||||
|
@ -542,8 +530,7 @@ class WikiControllerTest < Test::Unit::TestCase
|
|||
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 [home_page], @web.pages.values
|
||||
assert_equal 2, home_page.revisions.size
|
||||
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)
|
||||
|
@ -563,57 +550,47 @@ class WikiControllerTest < Test::Unit::TestCase
|
|||
|
||||
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_search
|
||||
setup_wiki_with_three_pages
|
||||
|
||||
r = process 'search', 'web' => 'wiki1', 'query' => '\s[A-Z]ak'
|
||||
|
||||
assert_redirected_to :action => 'show', :id => 'Oak'
|
||||
end
|
||||
|
||||
def test_search_multiple_results
|
||||
setup_wiki_with_three_pages
|
||||
|
||||
r = process 'search', 'web' => 'wiki1', 'query' => 'All about'
|
||||
|
||||
assert_success
|
||||
assert_response :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
|
||||
setup_wiki_with_three_pages
|
||||
|
||||
r = process 'search', 'web' => 'wiki1', 'query' => '(Oak|Elephant)'
|
||||
|
||||
assert_success
|
||||
assert_response :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
|
||||
setup_wiki_with_three_pages
|
||||
|
||||
r = process 'search', 'web' => 'wiki1', 'query' => 'non-existant text'
|
||||
|
||||
assert_success
|
||||
assert_response :success
|
||||
assert_equal [], r.template_objects['results']
|
||||
assert_equal [], r.template_objects['title_results']
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
def test_show_page
|
||||
r = process('show', 'id' => 'HomePage', 'web' => 'wiki1')
|
||||
assert_success
|
||||
assert_match /First revision of the <a.*HomePage.*<\/a> end/, r.body
|
||||
r = process('show', 'id' => 'Oak', 'web' => 'wiki1')
|
||||
assert_response :success
|
||||
assert_tag :content => /All about oak/
|
||||
end
|
||||
|
||||
def test_show_page_with_multiple_revisions
|
||||
|
@ -622,7 +599,7 @@ class WikiControllerTest < Test::Unit::TestCase
|
|||
|
||||
r = process('show', 'id' => 'HomePage', 'web' => 'wiki1')
|
||||
|
||||
assert_success
|
||||
assert_response :success
|
||||
assert_match /Second revision of the <a.*HomePage.*<\/a> end/, r.body
|
||||
end
|
||||
|
||||
|
@ -633,24 +610,25 @@ class WikiControllerTest < Test::Unit::TestCase
|
|||
|
||||
def test_show_no_page
|
||||
r = process('show', 'id' => '', 'web' => 'wiki1')
|
||||
assert_equal 404, r.response_code
|
||||
assert_response :missing
|
||||
|
||||
r = process('show', 'web' => 'wiki1')
|
||||
assert_equal 404, r.response_code
|
||||
assert_response :missing
|
||||
end
|
||||
|
||||
|
||||
def test_tex
|
||||
r = process('tex', 'web' => 'wiki1', 'id' => 'HomePage')
|
||||
assert_success
|
||||
assert_response :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\nFirst revision of " +
|
||||
"the HomePage end\n\n\\end{document}", r.body
|
||||
"--------------------------------------\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
|
||||
|
||||
|
||||
|
@ -659,8 +637,8 @@ class WikiControllerTest < Test::Unit::TestCase
|
|||
|
||||
r = process('web_list')
|
||||
|
||||
assert_success
|
||||
assert_equal [another_wiki, @web], r.template_objects['webs']
|
||||
assert_response :success
|
||||
assert_equal [another_wiki, webs(:instiki), @web], r.template_objects['webs']
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -10,17 +10,97 @@ require 'active_record/fixtures'
|
|||
require 'action_controller/test_process'
|
||||
require 'action_web_service/test_invoke'
|
||||
require 'breakpoint'
|
||||
require 'wiki_content'
|
||||
|
||||
# Uncomment these and hang on, because the tests will be FAST
|
||||
#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/"
|
||||
|
||||
class Test::Unit::TestCase
|
||||
# Turn these on to use transactional fixtures with table_name(:fixture_name) instantiation of fixtures
|
||||
# self.use_transactional_fixtures = true
|
||||
# self.use_instantiated_fixtures = false
|
||||
|
||||
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...
|
||||
end
|
||||
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'))
|
||||
end
|
||||
end
|
||||
@web = Web.find(@web.id)
|
||||
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
|
||||
|
||||
if defined? $validate_xml_in_assert_success and $validate_xml_in_assert_success == true
|
||||
module Test
|
||||
module Unit
|
||||
module Assertions
|
||||
unless method_defined? :__assert_success_before_override_by_instiki
|
||||
alias :__assert_success_before_override_by_instiki :assert_success
|
||||
end
|
||||
def assert_success
|
||||
__assert_success_before_override_by_instiki
|
||||
if @response.body.kind_of?(Proc) then # it's a file download, not an HTML content
|
||||
else assert_nothing_raised(@response.body) { REXML::Document.new(@response.body) } end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#!/bin/env ruby -w
|
||||
#!/bin/env ruby
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
||||
require 'diff'
|
||||
|
||||
include Diff
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#!/bin/env ruby -w
|
||||
#!/bin/env ruby
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
require 'fileutils'
|
||||
|
@ -67,4 +67,4 @@ class FileYardTest < Test::Unit::TestCase
|
|||
"#{RAILS_ROOT}/storage/test/instiki"
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,7 +1,78 @@
|
|||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
||||
|
||||
class PageTest < Test::Unit::TestCase
|
||||
|
||||
fixtures 'webs', 'pages', 'revisions'
|
||||
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')
|
||||
assert_equal 2, @page.revisions(true).length, 'Should have two revisions'
|
||||
assert_equal 'MarianneSyhler', @page.current_revision(true).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')
|
||||
assert_equal 2, @page.revisions(true).length
|
||||
|
||||
@page.current_revision(true)
|
||||
@page.revise('HisWay would be MyWay in kinda update', Time.local(2004, 4, 4, 16, 57), 'MarianneSyhler')
|
||||
assert_equal 2, @page.revisions(true).length
|
||||
assert_equal 'HisWay would be MyWay in kinda update', @page.revisions.last.content
|
||||
assert_equal Time.local(2004, 4, 4, 16, 57), @page.revisions.last.created_at
|
||||
|
||||
@page.revise('HisWay would be MyWay in the house', Time.local(2004, 4, 4, 16, 58), 'DavidHeinemeierHansson')
|
||||
assert_equal 3, @page.revisions(true).length
|
||||
assert_equal 'HisWay would be MyWay in the house', @page.revisions.last.content
|
||||
|
||||
@page.revise('HisWay would be MyWay in my way', Time.local(2004, 4, 4, 17, 30), 'DavidHeinemeierHansson')
|
||||
assert_equal 4, @page.revisions(true).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')
|
||||
}
|
||||
|
||||
assert_equal last_revision_before, @page.current_revision(true)
|
||||
assert_equal revisions_number_before, @page.revisions.size
|
||||
end
|
||||
|
||||
def test_rollback
|
||||
@page.revise("spot two", Time.now, "David")
|
||||
@page.revise("spot three", Time.now + 2000, "David")
|
||||
assert_equal 3, @page.revisions(true).length, "Should have three revisions"
|
||||
@page.current_revision(true)
|
||||
@page.rollback(1, Time.now)
|
||||
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
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#!/bin/env ruby -w
|
||||
#!/bin/env ruby
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
require 'redcloth_for_tex'
|
||||
|
@ -66,4 +66,4 @@ EOL
|
|||
def test_subsection_depth
|
||||
assert_equal "\\subsubsection*{Hello}", RedClothForTex.new("h4. Hello").to_tex
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,7 +1,315 @@
|
|||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
||||
|
||||
class RevisionTest < Test::Unit::TestCase
|
||||
fixtures :webs, :pages, :revisions, :system
|
||||
|
||||
fixtures 'webs', 'pages', 'revisions'
|
||||
def setup
|
||||
@wiki = Wiki.new
|
||||
@web = webs(:test_wiki)
|
||||
@page = pages(:home_page)
|
||||
@revision = revisions(:home_page_second_revision)
|
||||
end
|
||||
|
||||
def test_wiki_words
|
||||
assert_equal %w( HisWay MyWay SmartEngine SmartEngineGUI ThatWay ), @revision.wiki_words.sort
|
||||
|
||||
@wiki.write_page('wiki1', 'NoWikiWord', 'hey you!', Time.now, 'Me')
|
||||
assert_equal [], @wiki.read_page('wiki1', 'NoWikiWord').wiki_words
|
||||
end
|
||||
|
||||
def test_existing_pages
|
||||
assert_equal %w( MyWay SmartEngine ThatWay ), @revision.existing_pages.sort
|
||||
end
|
||||
|
||||
def test_unexisting_pages
|
||||
assert_equal %w( HisWay SmartEngineGUI ), @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>',
|
||||
@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", @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>',
|
||||
@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>',
|
||||
@revision.display_content
|
||||
|
||||
@revision.clear_display_cache
|
||||
|
||||
@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>",
|
||||
@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>",
|
||||
@revision.display_content
|
||||
end
|
||||
|
||||
def test_revisions_diff
|
||||
Revision.create(:page => @page, :content => 'What a blue and lovely morning', :author => Author.new('DavidHeinemeierHansson'))
|
||||
Revision.create(:page => @page, :content => 'What a red and lovely morning today', :author => Author.new('DavidHeinemeierHansson'))
|
||||
|
||||
assert_equal "<p>What a <del class=\"diffmod\">blue </del><ins class=\"diffmod\">red " +
|
||||
"</ins>and lovely <del class=\"diffmod\">morning</del><ins class=\"diffmod\">morning " +
|
||||
"today</ins></p>", @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
|
||||
FileUtils.mkdir_p "#{RAILS_ROOT}/storage/test/wiki1"
|
||||
FileUtils.rm(Dir["#{RAILS_ROOT}/storage/test/wiki1/*"])
|
||||
@wiki.file_yard(@web).upload_file('square.jpg', StringIO.new(''))
|
||||
assert_markup_parsed_as(
|
||||
'<p><img alt="Square" src="../pic/square.jpg" /></p>',
|
||||
'[[square.jpg|Square:pic]]')
|
||||
assert_markup_parsed_as(
|
||||
'<p><img alt="square.jpg" src="../pic/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="../pic/NonExistant.jpg">?</a>' +
|
||||
'</span></p>',
|
||||
'[[NonExistant.jpg|NonExistant:pic]]')
|
||||
assert_markup_parsed_as(
|
||||
'<p><span class="newWikiWord">NonExistant.jpg<a href="../pic/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
|
||||
|
||||
# TODO Remove the leading underscores from this test when upgrading to RedCloth 3.0.1;
|
||||
# also add a test for the "Unhappy Face" problem (another interesting RedCloth bug)
|
||||
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 assert_markup_parsed_as(expected_output, input)
|
||||
revision = Revision.new(:page => @page, :content => input, :author => Author.new('AnAuthor'))
|
||||
assert_equal expected_output, revision.display_content, 'Textile output not as expected'
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#!/bin/env ruby -w
|
||||
#!/bin/env ruby
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
require 'chunks/uri'
|
||||
|
|
|
@ -1,7 +1,158 @@
|
|||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
||||
|
||||
class WebTest < Test::Unit::TestCase
|
||||
|
||||
fixtures 'webs', 'pages', 'revisions'
|
||||
fixtures :webs, :pages, :revisions, :system
|
||||
|
||||
def setup
|
||||
@web = webs(:instiki)
|
||||
end
|
||||
|
||||
def test_wiki_word_linking
|
||||
@web.add_page('SecondPage', 'Yo, yo. Have you EverBeenHated',
|
||||
Time.now, 'DavidHeinemeierHansson')
|
||||
|
||||
assert_equal('<p>Yo, yo. Have you <span class="newWikiWord">Ever Been Hated' +
|
||||
'<a href="../show/EverBeenHated">?</a></span></p>',
|
||||
@web.page("SecondPage").display_content)
|
||||
|
||||
@web.add_page('EverBeenHated', 'Yo, yo. Have you EverBeenHated', Time.now,
|
||||
'DavidHeinemeierHansson')
|
||||
assert_equal('<p>Yo, yo. Have you <a class="existingWikiWord" ' +
|
||||
'href="../show/EverBeenHated">Ever Been Hated</a></p>',
|
||||
@web.page("SecondPage").display_content)
|
||||
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_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_make_link
|
||||
add_sample_pages
|
||||
|
||||
existing_page_wiki_url =
|
||||
'<a class="existingWikiWord" href="../show/EverBeenInLove">Ever Been In Love</a>'
|
||||
existing_page_published_url =
|
||||
'<a class="existingWikiWord" href="../published/EverBeenInLove">Ever Been In Love</a>'
|
||||
existing_page_static_url =
|
||||
'<a class="existingWikiWord" href="EverBeenInLove.html">Ever Been In Love</a>'
|
||||
new_page_wiki_url =
|
||||
'<span class="newWikiWord">Unknown Word<a href="../show/UnknownWord">?</a></span>'
|
||||
new_page_published_url =
|
||||
new_page_static_url =
|
||||
'<span class="newWikiWord">Unknown Word</span>'
|
||||
|
||||
# no options
|
||||
assert_equal existing_page_wiki_url, @web.make_link('EverBeenInLove')
|
||||
|
||||
# :mode => :export
|
||||
assert_equal existing_page_static_url, @web.make_link('EverBeenInLove', nil, :mode => :export)
|
||||
|
||||
# :mode => :publish
|
||||
assert_equal existing_page_published_url,
|
||||
@web.make_link('EverBeenInLove', nil, :mode => :publish)
|
||||
|
||||
# new page, no options
|
||||
assert_equal new_page_wiki_url, @web.make_link('UnknownWord')
|
||||
|
||||
# new page, :mode => :export
|
||||
assert_equal new_page_static_url, @web.make_link('UnknownWord', nil, :mode => :export)
|
||||
|
||||
# new page, :mode => :publish
|
||||
assert_equal new_page_published_url, @web.make_link('UnknownWord', nil, :mode => :publish)
|
||||
|
||||
# Escaping special characters in the name
|
||||
assert_equal(
|
||||
'<span class="newWikiWord">Smith & Wesson<a href="../show/Smith+%26+Wesson">?</a></span>',
|
||||
@web.make_link('Smith & Wesson'))
|
||||
|
||||
# optionally using text as the link text
|
||||
assert_equal(
|
||||
existing_page_published_url.sub(/>Ever Been In Love</, ">Haven't you ever been in love?<"),
|
||||
@web.make_link('EverBeenInLove', "Haven't you ever been in love?", :mode => :publish))
|
||||
|
||||
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')
|
||||
@web.add_page('AnotherPage', 'This is \AnotherPage',
|
||||
Time.local(2004, 4, 4, 16, 51), 'Alexey Verkhovsky')
|
||||
|
||||
@web.pages(true)
|
||||
assert_equal [home], @web.select.pages_that_link_to('AnotherPage')
|
||||
end
|
||||
|
||||
def test_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')
|
||||
author = @web.add_page('AlexeyVerkhovsky',
|
||||
'This is an author page, it should not be an orphan',
|
||||
Time.local(2004, 4, 4, 16, 50), 'AlexeyVerkhovsky')
|
||||
self_linked = @web.add_page('SelfLinked',
|
||||
'I am me SelfLinked and link to EverBeenInLove',
|
||||
Time.local(2004, 4, 4, 16, 50), 'AnonymousCoward')
|
||||
|
||||
# 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
|
||||
|
||||
private
|
||||
|
||||
def add_sample_pages
|
||||
@in_love = @web.add_page('EverBeenInLove', 'Who am I me',
|
||||
Time.local(2004, 4, 4, 16, 50), 'DavidHeinemeierHansson')
|
||||
@hated = @web.add_page('EverBeenHated', 'I am me EverBeenHated',
|
||||
Time.local(2004, 4, 4, 16, 51), 'DavidHeinemeierHansson')
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#!/bin/env ruby -w
|
||||
#!/bin/env ruby
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
||||
require 'wiki_words'
|
||||
|
||||
class WikiWordsTest < Test::Unit::TestCase
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue