Line ending cleanup. Most of these are svn propsets which should make
the files check out appropriately in the future. The three files in app/models had inconsitent line endings, so they had to be fixed by hand.
This commit is contained in:
parent
4849ca62fb
commit
b29c59e470
14 changed files with 1578 additions and 1578 deletions
108
test/fixtures/pages.yml
vendored
108
test/fixtures/pages.yml
vendored
|
@ -1,55 +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
|
||||
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
|
166
test/fixtures/revisions.yml
vendored
166
test/fixtures/revisions.yml
vendored
|
@ -1,83 +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
|
||||
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
|
||||
|
|
28
test/fixtures/webs.yml
vendored
28
test/fixtures/webs.yml
vendored
|
@ -1,15 +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
|
||||
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
|
|
@ -1,106 +1,106 @@
|
|||
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'
|
||||
|
||||
# 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
|
||||
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'))
|
||||
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
|
||||
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'
|
||||
|
||||
# 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
|
||||
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'))
|
||||
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,88 +1,88 @@
|
|||
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')
|
||||
@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')
|
||||
@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')
|
||||
@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')
|
||||
@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')
|
||||
@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')
|
||||
}
|
||||
|
||||
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(0, 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
|
||||
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')
|
||||
@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')
|
||||
@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')
|
||||
@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')
|
||||
@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')
|
||||
@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')
|
||||
}
|
||||
|
||||
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(0, 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,317 +1,317 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
||||
|
||||
class RevisionTest < Test::Unit::TestCase
|
||||
fixtures :webs, :pages, :revisions, :system
|
||||
|
||||
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'), :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 <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
|
||||
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
||||
|
||||
class RevisionTest < Test::Unit::TestCase
|
||||
fixtures :webs, :pages, :revisions, :system
|
||||
|
||||
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'), :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 <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,158 +1,158 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
||||
|
||||
class WebTest < Test::Unit::TestCase
|
||||
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
|
||||
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
||||
|
||||
class WebTest < Test::Unit::TestCase
|
||||
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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue