Massive change of SVN properties to deal with EOL style problem

This commit is contained in:
Alexey Verkhovsky 2005-01-24 18:52:04 +00:00
parent b747b611b3
commit 3b6566577c
108 changed files with 12417 additions and 12417 deletions

18
test/all_tests.rb Normal file → Executable file
View file

@ -1,9 +1,9 @@
require 'test_helper'
require 'find'
test_root = File.dirname(__FILE__)
Find.find(test_root) { |path|
if File.file?(path) and path =~ /.*_test\.rb$/
require path[(test_root.size + 1)..-4]
end
}
require 'test_helper'
require 'find'
test_root = File.dirname(__FILE__)
Find.find(test_root) { |path|
if File.file?(path) and path =~ /.*_test\.rb$/
require path[(test_root.size + 1)..-4]
end
}

0
test/fixtures/rails.gif vendored Normal file → Executable file
View file

Before

Width:  |  Height:  |  Size: 8.3 KiB

After

Width:  |  Height:  |  Size: 8.3 KiB

Before After
Before After

52
test/functional/application_test.rb Normal file → Executable file
View file

@ -1,26 +1,26 @@
# Unit tests for ApplicationController (the abstract controller class)
require File.dirname(__FILE__) + '/../test_helper'
require 'wiki_controller'
require 'rexml/document'
# Need some concrete class to test the abstract class features
class WikiController; def rescue_action(e) logger.error(e); raise e end; end
class ApplicationTest < Test::Unit::TestCase
def setup
setup_test_wiki
setup_controller_test(WikiController)
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']
end
end
# Unit tests for ApplicationController (the abstract controller class)
require File.dirname(__FILE__) + '/../test_helper'
require 'wiki_controller'
require 'rexml/document'
# Need some concrete class to test the abstract class features
class WikiController; def rescue_action(e) logger.error(e); raise e end; end
class ApplicationTest < Test::Unit::TestCase
def setup
setup_test_wiki
setup_controller_test(WikiController)
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']
end
end

254
test/functional/file_controller_test.rb Normal file → Executable file
View file

@ -1,127 +1,127 @@
#!/bin/env ruby -w
require File.dirname(__FILE__) + '/../test_helper'
require 'file_controller'
require 'fileutils'
# Raise errors beyond the default web-based presentation
class FileController; def rescue_action(e) logger.error(e); raise e end; end
class FileControllerTest < Test::Unit::TestCase
FILE_AREA = RAILS_ROOT + '/storage/test/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
end
def test_file
process 'file', 'web' => 'wiki1', 'id' => 'foo.tgz'
assert_success
assert_rendered_file 'file/file'
end
def test_file_download_text_file
File.open("#{FILE_AREA}/foo.txt", 'wb') { |f| f.write "aaa\nbbb\n" }
r = process 'file', 'web' => 'wiki1', 'id' => 'foo.txt'
assert_success
assert_equal "aaa\nbbb\n", r.binary_content
assert_equal 'text/plain', r.headers['Content-Type']
end
def test_file_download_pdf_file
File.open("#{FILE_AREA}/foo.pdf", 'wb') { |f| f.write "aaa\nbbb\n" }
r = process 'file', 'web' => 'wiki1', 'id' => 'foo.pdf'
assert_success
assert_equal "aaa\nbbb\n", r.binary_content
assert_equal 'application/pdf', r.headers['Content-Type']
end
def test_pic_download_gif
FileUtils.cp("#{RAILS_ROOT}/test/fixtures/rails.gif", FILE_AREA)
r = process 'pic', 'web' => 'wiki1', 'id' => 'rails.gif'
assert_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_rendered_file 'file/file'
end
def test_pic_upload_end_to_end
# edit and re-render home page so that it has an "unknown file" link to 'rails-e2e.gif'
@wiki.revise_page('wiki1', 'HomePage', '[[rails-e2e.gif:pic]]', Time.now, 'AnonymousBrave')
assert_equal "<p><span class=\"newWikiWord\">rails-e2e.gif<a href=\"../pic/rails-e2e.gif\">" +
"?</a></span></p>",
@home.display_content
# 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_rendered_file 'file/file'
# User uploads the picture
picture = File.read("#{RAILS_ROOT}/test/fixtures/rails.gif")
r = process 'pic', 'web' => 'wiki1', 'id' => 'rails-e2e.gif', 'file' => StringIO.new(picture)
assert_redirect_url '/'
assert @wiki.file_yard(@web).has_file?('rails-e2e.gif')
assert_equal(picture, File.read("#{RAILS_ROOT}/storage/test/wiki1/rails-e2e.gif"))
# this should refresh the page display content (cached)
assert_equal "<p><img alt=\"rails-e2e.gif\" src=\"../pic/rails-e2e.gif\" /></p>",
@home.display_content
end
def test_pic_upload_end_to_end
# edit and re-render home page so that it has an "unknown file" link to 'rails-e2e.gif'
@wiki.revise_page('wiki1', 'HomePage', '[[instiki-e2e.txt:file]]', Time.now, 'AnonymousBrave')
assert_equal "<p><span class=\"newWikiWord\">instiki-e2e.txt" +
"<a href=\"../file/instiki-e2e.txt\">?</a></span></p>",
@home.display_content
# 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_rendered_file 'file/file'
# User uploads the picture
file = "abcdefgh\n123"
r = process 'file', 'web' => 'wiki1', 'id' => 'instiki-e2e.txt', 'file' => StringIO.new(file)
assert_redirect_url '/'
assert @wiki.file_yard(@web).has_file?('instiki-e2e.txt')
assert_equal(file, File.read("#{RAILS_ROOT}/storage/test/wiki1/instiki-e2e.txt"))
# this should refresh the page display content (cached)
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
r = process 'file', 'web' => 'wiki1', 'id' => 'filename'
assert_success
@web.allow_uploads = false
r = process 'file', 'web' => 'wiki1', 'id' => 'filename'
assert_equal '403 Forbidden', r.headers['Status']
end
end
#!/bin/env ruby -w
require File.dirname(__FILE__) + '/../test_helper'
require 'file_controller'
require 'fileutils'
# Raise errors beyond the default web-based presentation
class FileController; def rescue_action(e) logger.error(e); raise e end; end
class FileControllerTest < Test::Unit::TestCase
FILE_AREA = RAILS_ROOT + '/storage/test/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
end
def test_file
process 'file', 'web' => 'wiki1', 'id' => 'foo.tgz'
assert_success
assert_rendered_file 'file/file'
end
def test_file_download_text_file
File.open("#{FILE_AREA}/foo.txt", 'wb') { |f| f.write "aaa\nbbb\n" }
r = process 'file', 'web' => 'wiki1', 'id' => 'foo.txt'
assert_success
assert_equal "aaa\nbbb\n", r.binary_content
assert_equal 'text/plain', r.headers['Content-Type']
end
def test_file_download_pdf_file
File.open("#{FILE_AREA}/foo.pdf", 'wb') { |f| f.write "aaa\nbbb\n" }
r = process 'file', 'web' => 'wiki1', 'id' => 'foo.pdf'
assert_success
assert_equal "aaa\nbbb\n", r.binary_content
assert_equal 'application/pdf', r.headers['Content-Type']
end
def test_pic_download_gif
FileUtils.cp("#{RAILS_ROOT}/test/fixtures/rails.gif", FILE_AREA)
r = process 'pic', 'web' => 'wiki1', 'id' => 'rails.gif'
assert_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_rendered_file 'file/file'
end
def test_pic_upload_end_to_end
# edit and re-render home page so that it has an "unknown file" link to 'rails-e2e.gif'
@wiki.revise_page('wiki1', 'HomePage', '[[rails-e2e.gif:pic]]', Time.now, 'AnonymousBrave')
assert_equal "<p><span class=\"newWikiWord\">rails-e2e.gif<a href=\"../pic/rails-e2e.gif\">" +
"?</a></span></p>",
@home.display_content
# 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_rendered_file 'file/file'
# User uploads the picture
picture = File.read("#{RAILS_ROOT}/test/fixtures/rails.gif")
r = process 'pic', 'web' => 'wiki1', 'id' => 'rails-e2e.gif', 'file' => StringIO.new(picture)
assert_redirect_url '/'
assert @wiki.file_yard(@web).has_file?('rails-e2e.gif')
assert_equal(picture, File.read("#{RAILS_ROOT}/storage/test/wiki1/rails-e2e.gif"))
# this should refresh the page display content (cached)
assert_equal "<p><img alt=\"rails-e2e.gif\" src=\"../pic/rails-e2e.gif\" /></p>",
@home.display_content
end
def test_pic_upload_end_to_end
# edit and re-render home page so that it has an "unknown file" link to 'rails-e2e.gif'
@wiki.revise_page('wiki1', 'HomePage', '[[instiki-e2e.txt:file]]', Time.now, 'AnonymousBrave')
assert_equal "<p><span class=\"newWikiWord\">instiki-e2e.txt" +
"<a href=\"../file/instiki-e2e.txt\">?</a></span></p>",
@home.display_content
# 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_rendered_file 'file/file'
# User uploads the picture
file = "abcdefgh\n123"
r = process 'file', 'web' => 'wiki1', 'id' => 'instiki-e2e.txt', 'file' => StringIO.new(file)
assert_redirect_url '/'
assert @wiki.file_yard(@web).has_file?('instiki-e2e.txt')
assert_equal(file, File.read("#{RAILS_ROOT}/storage/test/wiki1/instiki-e2e.txt"))
# this should refresh the page display content (cached)
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
r = process 'file', 'web' => 'wiki1', 'id' => 'filename'
assert_success
@web.allow_uploads = false
r = process 'file', 'web' => 'wiki1', 'id' => 'filename'
assert_equal '403 Forbidden', r.headers['Status']
end
end

File diff suppressed because it is too large Load diff

226
test/test_helper.rb Executable file → Normal file
View file

@ -1,113 +1,113 @@
ENV['RAILS_ENV'] ||= 'test'
require File.dirname(__FILE__) + '/../config/environment'
require 'application'
require 'test/unit'
require 'action_controller/test_process'
# Uncomment this variable to have assert_success check that response bodies are valid XML
$validate_xml_in_assert_success = true
# Convenient setup method for Test::Unit::TestCase
class Test::Unit::TestCase
private
def setup_controller_test(controller_class = nil, host = nil)
if controller_class
@controller = controller_class
elsif self.class.to_s =~ /^(\w+Controller)Test$/
@controller = Object::const_get($1)
else
raise "Cannot derive the name of controller under test from class name #{self.class}"
end
@request, @response = ActionController::TestRequest.new, ActionController::TestResponse.new
@request.host = host || 'localhost'
return @request, @response
end
# Wiki fixture for tests
def setup_test_wiki
@wiki = ApplicationController.wiki = WikiServiceWithNoPersistence.new
@web = @wiki.create_web('Test Wiki 1', 'wiki1')
@home = @wiki.write_page('wiki1', 'HomePage', 'First revision of the HomePage end', Time.now,
Author.new('AnAuthor', '127.0.0.1'))
end
def setup_wiki_with_three_pages
@oak = @wiki.write_page('wiki1', 'Oak',
"All about oak.\n" +
"category: trees",
5.minutes.ago, Author.new('TreeHugger', '127.0.0.2'))
@elephant = @wiki.write_page('wiki1', 'Elephant',
"All about elephants.\n" +
"category: animals",
10.minutes.ago, Author.new('Guest', '127.0.0.2'))
end
def tear_down_wiki
ApplicationController.wiki = nil
end
end
class WikiServiceWithNoPersistence
include AbstractWikiService
def initialize
init_wiki_service
end
def storage_path
RAILS_ROOT + '/storage/test/'
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
attr_reader :chunks, :content
def initialize(str)
super
@chunks = []
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
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_ovverride_by_instiki
alias :__assert_success_before_ovverride_by_instiki :assert_success
end
def assert_success
__assert_success_before_ovverride_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'
require File.dirname(__FILE__) + '/../config/environment'
require 'application'
require 'test/unit'
require 'action_controller/test_process'
# Uncomment this variable to have assert_success check that response bodies are valid XML
$validate_xml_in_assert_success = true
# Convenient setup method for Test::Unit::TestCase
class Test::Unit::TestCase
private
def setup_controller_test(controller_class = nil, host = nil)
if controller_class
@controller = controller_class
elsif self.class.to_s =~ /^(\w+Controller)Test$/
@controller = Object::const_get($1)
else
raise "Cannot derive the name of controller under test from class name #{self.class}"
end
@request, @response = ActionController::TestRequest.new, ActionController::TestResponse.new
@request.host = host || 'localhost'
return @request, @response
end
# Wiki fixture for tests
def setup_test_wiki
@wiki = ApplicationController.wiki = WikiServiceWithNoPersistence.new
@web = @wiki.create_web('Test Wiki 1', 'wiki1')
@home = @wiki.write_page('wiki1', 'HomePage', 'First revision of the HomePage end', Time.now,
Author.new('AnAuthor', '127.0.0.1'))
end
def setup_wiki_with_three_pages
@oak = @wiki.write_page('wiki1', 'Oak',
"All about oak.\n" +
"category: trees",
5.minutes.ago, Author.new('TreeHugger', '127.0.0.2'))
@elephant = @wiki.write_page('wiki1', 'Elephant',
"All about elephants.\n" +
"category: animals",
10.minutes.ago, Author.new('Guest', '127.0.0.2'))
end
def tear_down_wiki
ApplicationController.wiki = nil
end
end
class WikiServiceWithNoPersistence
include AbstractWikiService
def initialize
init_wiki_service
end
def storage_path
RAILS_ROOT + '/storage/test/'
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
attr_reader :chunks, :content
def initialize(str)
super
@chunks = []
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
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_ovverride_by_instiki
alias :__assert_success_before_ovverride_by_instiki :assert_success
end
def assert_success
__assert_success_before_ovverride_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

View file

@ -1,23 +1,23 @@
#!/bin/env ruby
require File.dirname(__FILE__) + '/../../test_helper'
require 'chunks/category'
require 'chunks/match'
class CategoryTest < Test::Unit::TestCase
include ChunkMatch
def test_single_category
match(Category, 'category: test', :list => ['test'], :hidden => nil)
match(Category, 'category : chunk test ', :list => ['chunk test'], :hidden => nil)
match(Category, ':category: test', :list => ['test'], :hidden => ':')
end
def test_multiple_categories
match(Category, 'category: test, multiple', :list => ['test', 'multiple'], :hidden => nil)
match(Category, 'category : chunk test , multi category,regression test case ',
:list => ['chunk test','multi category','regression test case'], :hidden => nil
)
end
end
#!/bin/env ruby
require File.dirname(__FILE__) + '/../../test_helper'
require 'chunks/category'
require 'chunks/match'
class CategoryTest < Test::Unit::TestCase
include ChunkMatch
def test_single_category
match(Category, 'category: test', :list => ['test'], :hidden => nil)
match(Category, 'category : chunk test ', :list => ['chunk test'], :hidden => nil)
match(Category, ':category: test', :list => ['test'], :hidden => ':')
end
def test_multiple_categories
match(Category, 'category: test, multiple', :list => ['test', 'multiple'], :hidden => nil)
match(Category, 'category : chunk test , multi category,regression test case ',
:list => ['chunk test','multi category','regression test case'], :hidden => nil
)
end
end

View file

@ -1,16 +1,16 @@
#!/bin/env ruby
require File.dirname(__FILE__) + '/../../test_helper'
require 'chunks/nowiki'
require 'chunks/match'
class NoWikiTest < Test::Unit::TestCase
include ChunkMatch
def test_simple_nowiki
match(NoWiki, 'This sentence contains <nowiki>[[raw text]]</nowiki>. Do not touch!',
:plain_text => '[[raw text]]'
)
end
end
#!/bin/env ruby
require File.dirname(__FILE__) + '/../../test_helper'
require 'chunks/nowiki'
require 'chunks/match'
class NoWikiTest < Test::Unit::TestCase
include ChunkMatch
def test_simple_nowiki
match(NoWiki, 'This sentence contains <nowiki>[[raw text]]</nowiki>. Do not touch!',
:plain_text => '[[raw text]]'
)
end
end

View file

@ -1,81 +1,81 @@
#!/bin/env ruby
require File.dirname(__FILE__) + '/../../test_helper'
require 'chunks/wiki'
class WikiTest < Test::Unit::TestCase
class ContentStub < String
def chunks
@chunks ||= []
end
end
include ChunkMatch
def test_simple
match(WikiChunk::Word, 'This is a WikiWord okay?', :page_name => 'WikiWord')
end
def test_escaped
match(WikiChunk::Word, 'Do not link to an \EscapedWord',
:page_name => 'EscapedWord', :escaped_text => 'EscapedWord'
)
end
def test_simple_brackets
match(WikiChunk::Link, 'This is a [[bracketted link]]',
:page_name => 'bracketted link', :escaped_text => nil
)
end
def test_complex_brackets
match(WikiChunk::Link, 'This is a tricky link [[Sperberg-McQueen]]',
:page_name => 'Sperberg-McQueen', :escaped_text => nil
)
end
def test_textile_link
textile_link = ContentStub.new('"Here is a special link":SpecialLink')
WikiChunk::Word.apply_to(textile_link)
assert_equal '"Here is a special link":SpecialLink', textile_link
assert textile_link.chunks.empty?
end
def test_file_types
# only link
assert_link_parsed_as 'only text', 'only text', 'show', '[[only text]]'
# link and text
assert_link_parsed_as 'page name', 'link text', 'show', '[[page name|link text]]'
# link and type (file)
assert_link_parsed_as 'foo.tar.gz', 'foo.tar.gz', 'file', '[[foo.tar.gz:file]]'
# link and type (pic)
assert_link_parsed_as 'foo.tar.gz', 'foo.tar.gz', 'pic', '[[foo.tar.gz:pic]]'
# link, text and type
assert_link_parsed_as 'foo.tar.gz', 'FooTar', 'file', '[[foo.tar.gz|FooTar:file]]'
# NEGATIVE TEST CASES
# empty page name
assert_link_parsed_as '|link text?', '|link text?', 'file', '[[|link text?:file]]'
# empty link text
assert_link_parsed_as 'page name?|', 'page name?|', 'file', '[[page name?|:file]]'
# empty link type
assert_link_parsed_as 'page name', 'link?:', 'show', '[[page name|link?:]]'
# unknown link type
assert_link_parsed_as 'page name:create_system', 'page name:create_system', 'show',
'[[page name:create_system]]'
end
def assert_link_parsed_as(expected_page_name, expected_link_text, expected_link_type, link)
link_to_file = ContentStub.new(link)
WikiChunk::Link.apply_to(link_to_file)
chunk = link_to_file.chunks.last
assert chunk
assert_equal expected_page_name, chunk.page_name
assert_equal expected_link_text, chunk.link_text
assert_equal expected_link_type, chunk.link_type
end
end
#!/bin/env ruby
require File.dirname(__FILE__) + '/../../test_helper'
require 'chunks/wiki'
class WikiTest < Test::Unit::TestCase
class ContentStub < String
def chunks
@chunks ||= []
end
end
include ChunkMatch
def test_simple
match(WikiChunk::Word, 'This is a WikiWord okay?', :page_name => 'WikiWord')
end
def test_escaped
match(WikiChunk::Word, 'Do not link to an \EscapedWord',
:page_name => 'EscapedWord', :escaped_text => 'EscapedWord'
)
end
def test_simple_brackets
match(WikiChunk::Link, 'This is a [[bracketted link]]',
:page_name => 'bracketted link', :escaped_text => nil
)
end
def test_complex_brackets
match(WikiChunk::Link, 'This is a tricky link [[Sperberg-McQueen]]',
:page_name => 'Sperberg-McQueen', :escaped_text => nil
)
end
def test_textile_link
textile_link = ContentStub.new('"Here is a special link":SpecialLink')
WikiChunk::Word.apply_to(textile_link)
assert_equal '"Here is a special link":SpecialLink', textile_link
assert textile_link.chunks.empty?
end
def test_file_types
# only link
assert_link_parsed_as 'only text', 'only text', 'show', '[[only text]]'
# link and text
assert_link_parsed_as 'page name', 'link text', 'show', '[[page name|link text]]'
# link and type (file)
assert_link_parsed_as 'foo.tar.gz', 'foo.tar.gz', 'file', '[[foo.tar.gz:file]]'
# link and type (pic)
assert_link_parsed_as 'foo.tar.gz', 'foo.tar.gz', 'pic', '[[foo.tar.gz:pic]]'
# link, text and type
assert_link_parsed_as 'foo.tar.gz', 'FooTar', 'file', '[[foo.tar.gz|FooTar:file]]'
# NEGATIVE TEST CASES
# empty page name
assert_link_parsed_as '|link text?', '|link text?', 'file', '[[|link text?:file]]'
# empty link text
assert_link_parsed_as 'page name?|', 'page name?|', 'file', '[[page name?|:file]]'
# empty link type
assert_link_parsed_as 'page name', 'link?:', 'show', '[[page name|link?:]]'
# unknown link type
assert_link_parsed_as 'page name:create_system', 'page name:create_system', 'show',
'[[page name:create_system]]'
end
def assert_link_parsed_as(expected_page_name, expected_link_text, expected_link_type, link)
link_to_file = ContentStub.new(link)
WikiChunk::Link.apply_to(link_to_file)
chunk = link_to_file.chunks.last
assert chunk
assert_equal expected_page_name, chunk.page_name
assert_equal expected_link_text, chunk.link_text
assert_equal expected_link_type, chunk.link_type
end
end

View file

@ -1,82 +1,82 @@
#!/bin/env ruby -w
require File.dirname(__FILE__) + '/../test_helper'
require 'diff'
include Diff
class DiffTest < Test::Unit::TestCase
def test_init
assert(1 == 1, "tests working")
assert_nothing_raised("object created") do
s = SequenceMatcher.new "private Thread currentThread;",
"private volatile Thread currentThread;",
proc { |x| x == ' ' }
end
end
def test_matching_blocks
s = SequenceMatcher.new "abxcd", "abcd"
assert(s.get_matching_blocks == [[0, 0, 2], [3, 2, 2], [5, 4, 0]],
"get_matching_blocks works")
end
def test_ratio
s = SequenceMatcher.new "abcd", "bcde"
assert(s.ratio == 0.75, "ratio works")
assert(s.quick_ratio == 0.75, "quick_ratio works")
assert(s.real_quick_ratio == 1.0, "real_quick_ratio works")
end
def test_longest_match
s = SequenceMatcher.new(" abcd", "abcd abcd")
assert(s.find_longest_match(0, 5, 0, 9) == [0, 4, 5],
"find_longest_match works")
s = SequenceMatcher.new()
end
def test_opcodes
s = SequenceMatcher.new("qabxcd", "abycdf")
assert(s.get_opcodes == [
[:delete, 0, 1, 0, 0],
[:equal, 1, 3, 0, 2],
[:replace, 3, 4, 2, 3],
[:equal, 4, 6, 3, 5],
[:insert, 6, 6, 5, 6]], "get_opcodes works")
end
def test_count_leading
assert(Diff.count_leading(' abc', ' ') == 3,
"count_leading works")
end
def test_html2list
a = "here is the original text"
#p HTMLDiff.html2list(a)
end
def test_html_diff
a = "this was the original string"
b = "this is the super string"
assert_equal 'this <del class="diffmod">was </del>' +
'<ins class="diffmod">is </ins>the ' +
'<del class="diffmod">original </del>' +
'<ins class="diffmod">super </ins>string',
HTMLDiff.diff(a, b)
end
def test_html_diff_with_multiple_paragraphs
a = "<p>this was the original string</p>"
b = "<p>this is</p>\r\n<p>the super string</p>\r\n<p>around the world</p>"
assert_equal(
"<p>this <del class=\"diffmod\">was </del>" +
"<ins class=\"diffmod\">is</ins></p>\r\n<p>the " +
"<del class=\"diffmod\">original </del>" +
"<ins class=\"diffmod\">super </ins>string</p>\r\n" +
"<p><ins class=\"diffins\">around the world</ins></p>",
HTMLDiff.diff(a, b)
)
end
#!/bin/env ruby -w
require File.dirname(__FILE__) + '/../test_helper'
require 'diff'
include Diff
class DiffTest < Test::Unit::TestCase
def test_init
assert(1 == 1, "tests working")
assert_nothing_raised("object created") do
s = SequenceMatcher.new "private Thread currentThread;",
"private volatile Thread currentThread;",
proc { |x| x == ' ' }
end
end
def test_matching_blocks
s = SequenceMatcher.new "abxcd", "abcd"
assert(s.get_matching_blocks == [[0, 0, 2], [3, 2, 2], [5, 4, 0]],
"get_matching_blocks works")
end
def test_ratio
s = SequenceMatcher.new "abcd", "bcde"
assert(s.ratio == 0.75, "ratio works")
assert(s.quick_ratio == 0.75, "quick_ratio works")
assert(s.real_quick_ratio == 1.0, "real_quick_ratio works")
end
def test_longest_match
s = SequenceMatcher.new(" abcd", "abcd abcd")
assert(s.find_longest_match(0, 5, 0, 9) == [0, 4, 5],
"find_longest_match works")
s = SequenceMatcher.new()
end
def test_opcodes
s = SequenceMatcher.new("qabxcd", "abycdf")
assert(s.get_opcodes == [
[:delete, 0, 1, 0, 0],
[:equal, 1, 3, 0, 2],
[:replace, 3, 4, 2, 3],
[:equal, 4, 6, 3, 5],
[:insert, 6, 6, 5, 6]], "get_opcodes works")
end
def test_count_leading
assert(Diff.count_leading(' abc', ' ') == 3,
"count_leading works")
end
def test_html2list
a = "here is the original text"
#p HTMLDiff.html2list(a)
end
def test_html_diff
a = "this was the original string"
b = "this is the super string"
assert_equal 'this <del class="diffmod">was </del>' +
'<ins class="diffmod">is </ins>the ' +
'<del class="diffmod">original </del>' +
'<ins class="diffmod">super </ins>string',
HTMLDiff.diff(a, b)
end
def test_html_diff_with_multiple_paragraphs
a = "<p>this was the original string</p>"
b = "<p>this is</p>\r\n<p>the super string</p>\r\n<p>around the world</p>"
assert_equal(
"<p>this <del class=\"diffmod\">was </del>" +
"<ins class=\"diffmod\">is</ins></p>\r\n<p>the " +
"<del class=\"diffmod\">original </del>" +
"<ins class=\"diffmod\">super </ins>string</p>\r\n" +
"<p><ins class=\"diffins\">around the world</ins></p>",
HTMLDiff.diff(a, b)
)
end
end

68
test/unit/file_yard_test.rb Normal file → Executable file
View file

@ -1,35 +1,35 @@
#!/bin/env ruby -w
require File.dirname(__FILE__) + '/../test_helper'
require 'fileutils'
require 'file_yard'
require 'stringio'
class FileYardTest < Test::Unit::TestCase
def setup
FileUtils.mkdir_p(file_path)
FileUtils.rm(Dir["#{file_path}/*"])
@yard = FileYard.new(file_path)
end
def test_files
assert_equal [], @yard.files
# FileYard gets the list of files from directory in the constructor
@yard.upload_file('aaa', StringIO.new('file contents'))
assert_equal ["#{file_path}/aaa"], Dir["#{file_path}/*"]
assert_equal ['aaa'], @yard.files
assert @yard.has_file?('aaa')
assert_equal 'file contents', File.read(@yard.file_path('aaa'))
end
def test_file_path
assert_equal "#{file_path}/abcd", @yard.file_path('abcd')
end
def file_path
"#{RAILS_ROOT}/storage/test/instiki"
end
#!/bin/env ruby -w
require File.dirname(__FILE__) + '/../test_helper'
require 'fileutils'
require 'file_yard'
require 'stringio'
class FileYardTest < Test::Unit::TestCase
def setup
FileUtils.mkdir_p(file_path)
FileUtils.rm(Dir["#{file_path}/*"])
@yard = FileYard.new(file_path)
end
def test_files
assert_equal [], @yard.files
# FileYard gets the list of files from directory in the constructor
@yard.upload_file('aaa', StringIO.new('file contents'))
assert_equal ["#{file_path}/aaa"], Dir["#{file_path}/*"]
assert_equal ['aaa'], @yard.files
assert @yard.has_file?('aaa')
assert_equal 'file contents', File.read(@yard.file_path('aaa'))
end
def test_file_path
assert_equal "#{file_path}/abcd", @yard.file_path('abcd')
end
def file_path
"#{RAILS_ROOT}/storage/test/instiki"
end
end

View file

@ -1,91 +1,91 @@
#!/bin/env ruby -w
require File.dirname(__FILE__) + '/../test_helper'
require 'web'
require 'page'
class PageTest < Test::Unit::TestCase
class MockWeb < Web
def initialize() super(nil, 'test','test') end
def [](wiki_word) %w( MyWay ThatWay SmartEngine ).include?(wiki_word) end
def refresh_pages_with_references(name) end
end
def setup
@page = Page.new(
MockWeb.new,
"FirstPage",
"HisWay would be MyWay in kinda ThatWay in HisWay though MyWay \\OverThere -- see SmartEngine in that SmartEngineGUI",
Time.local(2004, 4, 4, 16, 50),
"DavidHeinemeierHansson")
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.length, 'Should have two revisions'
assert_equal 'MarianneSyhler', @page.author, 'Mary should be the author now'
assert_equal 'DavidHeinemeierHansson', @page.revisions.first.author, '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.length
@page.revise('HisWay would be MyWay in kinda update', Time.local(2004, 4, 4, 16, 57), 'MarianneSyhler')
assert_equal 2, @page.revisions.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.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.length
end
def test_revise_content_unchanged
last_revision_before = @page.revisions.last
revisions_number_before = @page.revisions.size
assert_raises(Instiki::ValidationError) {
@page.revise(@page.revisions.last.content.dup, Time.now, 'AlexeyVerkhovsky')
}
assert_same last_revision_before, @page.revisions.last
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.length, "Should have three revisions"
@page.rollback(1, Time.now)
assert_equal "spot two", @page.content
end
end
#!/bin/env ruby -w
require File.dirname(__FILE__) + '/../test_helper'
require 'web'
require 'page'
class PageTest < Test::Unit::TestCase
class MockWeb < Web
def initialize() super(nil, 'test','test') end
def [](wiki_word) %w( MyWay ThatWay SmartEngine ).include?(wiki_word) end
def refresh_pages_with_references(name) end
end
def setup
@page = Page.new(
MockWeb.new,
"FirstPage",
"HisWay would be MyWay in kinda ThatWay in HisWay though MyWay \\OverThere -- see SmartEngine in that SmartEngineGUI",
Time.local(2004, 4, 4, 16, 50),
"DavidHeinemeierHansson")
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.length, 'Should have two revisions'
assert_equal 'MarianneSyhler', @page.author, 'Mary should be the author now'
assert_equal 'DavidHeinemeierHansson', @page.revisions.first.author, '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.length
@page.revise('HisWay would be MyWay in kinda update', Time.local(2004, 4, 4, 16, 57), 'MarianneSyhler')
assert_equal 2, @page.revisions.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.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.length
end
def test_revise_content_unchanged
last_revision_before = @page.revisions.last
revisions_number_before = @page.revisions.size
assert_raises(Instiki::ValidationError) {
@page.revise(@page.revisions.last.content.dup, Time.now, 'AlexeyVerkhovsky')
}
assert_same last_revision_before, @page.revisions.last
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.length, "Should have three revisions"
@page.rollback(1, Time.now)
assert_equal "spot two", @page.content
end
end

View file

@ -1,69 +1,69 @@
#!/bin/env ruby -w
require File.dirname(__FILE__) + '/../test_helper'
require 'redcloth_for_tex'
class RedClothForTexTest < Test::Unit::TestCase
def test_basics
assert_equal '{\bf First Page}', RedClothForTex.new("*First Page*").to_tex
assert_equal '{\em First Page}', RedClothForTex.new("_First Page_").to_tex
assert_equal "\\begin{itemize}\n\t\\item A\n\t\t\\item B\n\t\t\\item C\n\t\\end{itemize}", RedClothForTex.new("* A\n* B\n* C").to_tex
end
def test_blocks
assert_equal '\section*{hello}', RedClothForTex.new("h1. hello").to_tex
assert_equal '\subsection*{hello}', RedClothForTex.new("h2. hello").to_tex
end
def test_table_of_contents
source = <<EOL
* [[A]]
** [[B]]
** [[C]]
* D
** [[E]]
*** F
EOL
expected_result = <<EOL
\\pagebreak
\\section{A}
Abe
\\subsection{B}
Babe
\\subsection{C}
\\pagebreak
\\section{D}
\\subsection{E}
\\subsubsection{F}
EOL
expected_result.chop!
assert_equal(expected_result, table_of_contents(source, 'A' => 'Abe', 'B' => 'Babe'))
end
def test_entities
assert_equal "Beck \\& Fowler are 100\\% cool", RedClothForTex.new("Beck & Fowler are 100% cool").to_tex
end
def test_bracket_links
assert_equal "such a Horrible Day, but I won't be Made Useless", RedClothForTex.new("such a [[Horrible Day]], but I won't be [[Made Useless]]").to_tex
end
def test_footnotes_on_abbreviations
assert_equal(
"such a Horrible Day\\footnote{1}, but I won't be Made Useless",
RedClothForTex.new("such a [[Horrible Day]][1], but I won't be [[Made Useless]]").to_tex
)
end
def test_subsection_depth
assert_equal "\\subsubsection*{Hello}", RedClothForTex.new("h4. Hello").to_tex
end
#!/bin/env ruby -w
require File.dirname(__FILE__) + '/../test_helper'
require 'redcloth_for_tex'
class RedClothForTexTest < Test::Unit::TestCase
def test_basics
assert_equal '{\bf First Page}', RedClothForTex.new("*First Page*").to_tex
assert_equal '{\em First Page}', RedClothForTex.new("_First Page_").to_tex
assert_equal "\\begin{itemize}\n\t\\item A\n\t\t\\item B\n\t\t\\item C\n\t\\end{itemize}", RedClothForTex.new("* A\n* B\n* C").to_tex
end
def test_blocks
assert_equal '\section*{hello}', RedClothForTex.new("h1. hello").to_tex
assert_equal '\subsection*{hello}', RedClothForTex.new("h2. hello").to_tex
end
def test_table_of_contents
source = <<EOL
* [[A]]
** [[B]]
** [[C]]
* D
** [[E]]
*** F
EOL
expected_result = <<EOL
\\pagebreak
\\section{A}
Abe
\\subsection{B}
Babe
\\subsection{C}
\\pagebreak
\\section{D}
\\subsection{E}
\\subsubsection{F}
EOL
expected_result.chop!
assert_equal(expected_result, table_of_contents(source, 'A' => 'Abe', 'B' => 'Babe'))
end
def test_entities
assert_equal "Beck \\& Fowler are 100\\% cool", RedClothForTex.new("Beck & Fowler are 100% cool").to_tex
end
def test_bracket_links
assert_equal "such a Horrible Day, but I won't be Made Useless", RedClothForTex.new("such a [[Horrible Day]], but I won't be [[Made Useless]]").to_tex
end
def test_footnotes_on_abbreviations
assert_equal(
"such a Horrible Day\\footnote{1}, but I won't be Made Useless",
RedClothForTex.new("such a [[Horrible Day]][1], but I won't be [[Made Useless]]").to_tex
)
end
def test_subsection_depth
assert_equal "\\subsubsection*{Hello}", RedClothForTex.new("h4. Hello").to_tex
end
end

View file

@ -1,255 +1,255 @@
#!/bin/env ruby -w
require File.dirname(__FILE__) + '/../test_helper'
require 'web'
require 'revision'
require 'fileutils'
class RevisionTest < Test::Unit::TestCase
def setup
setup_test_wiki
@web.markup = :textile
@page = @wiki.read_page('wiki1', 'HomePage')
['MyWay', 'SmartEngine', 'ThatWay'].each do |page|
@wiki.write_page('wiki1', page, page, Time.now, 'Me')
end
@revision = Revision.new(@page, 1,
'HisWay would be MyWay in kinda ThatWay in HisWay though MyWay \OverThere -- ' +
'see SmartEngine in that SmartEngineGUI',
Time.local(2004, 4, 4, 16, 50), 'DavidHeinemeierHansson')
end
def test_wiki_words
assert_equal %w( HisWay MyWay SmartEngine SmartEngineGUI ThatWay ), @revision.wiki_words.sort
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&#8212;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_bluecloth
@web.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\n that 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_rdoc
@web.markup = :rdoc
@revision = Revision.new(@page, 1, '+hello+ that SmartEngineGUI',
Time.local(2004, 4, 4, 16, 50), '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(
'A <code>class SmartEngine end</code> would not mark up <pre>CodeBlocks</pre>',
'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_nowiki_text
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_content_with_bracketted_wiki_word
@web.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&#8212;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\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 />\n<span class=\"newWikiWord\">Version History" +
"<a href=\"../show/VersionHistory\">?</a></span></p>\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
@page.revisions = [
Revision.new(@page, 0, 'What a blue and lovely morning',
Time.local(2004, 4, 4, 16, 50), 'DavidHeinemeierHansson'),
Revision.new(@page, 1, 'What a red and lovely morning today',
Time.local(2004, 4, 4, 16, 50), '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
@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
# 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(
"<li><a href=\"~b\">a</a></li>\n" +
"<li>c~ d</li>\n",
list_with_tildas)
end
def assert_markup_parsed_as(expected_output, input)
revision = Revision.new(@page, 1, input, Time.local(2004, 4, 4, 16, 50), 'AnAuthor')
assert_equal expected_output, revision.display_content, 'Textile output not as expected'
end
end
#!/bin/env ruby -w
require File.dirname(__FILE__) + '/../test_helper'
require 'web'
require 'revision'
require 'fileutils'
class RevisionTest < Test::Unit::TestCase
def setup
setup_test_wiki
@web.markup = :textile
@page = @wiki.read_page('wiki1', 'HomePage')
['MyWay', 'SmartEngine', 'ThatWay'].each do |page|
@wiki.write_page('wiki1', page, page, Time.now, 'Me')
end
@revision = Revision.new(@page, 1,
'HisWay would be MyWay in kinda ThatWay in HisWay though MyWay \OverThere -- ' +
'see SmartEngine in that SmartEngineGUI',
Time.local(2004, 4, 4, 16, 50), 'DavidHeinemeierHansson')
end
def test_wiki_words
assert_equal %w( HisWay MyWay SmartEngine SmartEngineGUI ThatWay ), @revision.wiki_words.sort
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&#8212;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_bluecloth
@web.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\n that 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_rdoc
@web.markup = :rdoc
@revision = Revision.new(@page, 1, '+hello+ that SmartEngineGUI',
Time.local(2004, 4, 4, 16, 50), '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(
'A <code>class SmartEngine end</code> would not mark up <pre>CodeBlocks</pre>',
'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_nowiki_text
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_content_with_bracketted_wiki_word
@web.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&#8212;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\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 />\n<span class=\"newWikiWord\">Version History" +
"<a href=\"../show/VersionHistory\">?</a></span></p>\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
@page.revisions = [
Revision.new(@page, 0, 'What a blue and lovely morning',
Time.local(2004, 4, 4, 16, 50), 'DavidHeinemeierHansson'),
Revision.new(@page, 1, 'What a red and lovely morning today',
Time.local(2004, 4, 4, 16, 50), '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
@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
# 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(
"<li><a href=\"~b\">a</a></li>\n" +
"<li>c~ d</li>\n",
list_with_tildas)
end
def assert_markup_parsed_as(expected_output, input)
revision = Revision.new(@page, 1, input, Time.local(2004, 4, 4, 16, 50), 'AnAuthor')
assert_equal expected_output, revision.display_content, 'Textile output not as expected'
end
end

View file

@ -1,179 +1,179 @@
#!/bin/env ruby -w
require File.dirname(__FILE__) + '/../test_helper'
require 'chunks/uri'
class URITest < Test::Unit::TestCase
include ChunkMatch
def test_non_matches
assert_conversion_does_not_apply(URIChunk, 'There is no URI here')
assert_conversion_does_not_apply(URIChunk,
'One gemstone is the garnet:reddish in colour, like ruby')
end
def test_simple_uri
# Simplest case
match(URIChunk, 'http://www.example.com',
:scheme =>'http', :host =>'www.example.com', :path => nil,
:link_text => 'http://www.example.com'
)
# With trailing slash
match(URIChunk, 'http://www.example.com/',
:scheme =>'http', :host =>'www.example.com', :path => '/',
:link_text => 'http://www.example.com/'
)
# Without http://
match(URIChunk, 'www.example.com',
:scheme =>'http', :host =>'www.example.com', :link_text => 'www.example.com'
)
# two parts
match(URIChunk, 'example.com',
:scheme =>'http',:host =>'example.com', :link_text => 'example.com'
)
# "unusual" base domain (was a bug in an early version)
match(URIChunk, 'http://example.com.au/',
:scheme =>'http', :host =>'example.com.au', :link_text => 'http://example.com.au/'
)
# "unusual" base domain without http://
match(URIChunk, 'example.com.au',
:scheme =>'http', :host =>'example.com.au', :link_text => 'example.com.au'
)
# Another "unusual" base domain
match(URIChunk, 'http://www.example.co.uk/',
:scheme =>'http', :host =>'www.example.co.uk',
:link_text => 'http://www.example.co.uk/'
)
match(URIChunk, 'example.co.uk',
:scheme =>'http', :host =>'example.co.uk', :link_text => 'example.co.uk'
)
# With some path at the end
match(URIChunk, 'http://moinmoin.wikiwikiweb.de/HelpOnNavigation',
:scheme => 'http', :host => 'moinmoin.wikiwikiweb.de', :path => '/HelpOnNavigation',
:link_text => 'http://moinmoin.wikiwikiweb.de/HelpOnNavigation'
)
# With some path at the end, and withot http:// prefix
match(URIChunk, 'moinmoin.wikiwikiweb.de/HelpOnNavigation',
:scheme => 'http', :host => 'moinmoin.wikiwikiweb.de', :path => '/HelpOnNavigation',
:link_text => 'moinmoin.wikiwikiweb.de/HelpOnNavigation'
)
# With a port number
match(URIChunk, 'http://www.example.com:80',
:scheme =>'http', :host =>'www.example.com', :port => '80', :path => nil,
:link_text => 'http://www.example.com:80')
# With a port number and a path
match(URIChunk, 'http://www.example.com.tw:80/HelpOnNavigation',
:scheme =>'http', :host =>'www.example.com.tw', :port => '80', :path => '/HelpOnNavigation',
:link_text => 'http://www.example.com.tw:80/HelpOnNavigation')
# With a query
match(URIChunk, 'http://www.example.com.tw:80/HelpOnNavigation?arg=val',
:scheme =>'http', :host =>'www.example.com.tw', :port => '80', :path => '/HelpOnNavigation',
:query => 'arg=val',
:link_text => 'http://www.example.com.tw:80/HelpOnNavigation?arg=val')
# Query with two arguments
match(URIChunk, 'http://www.example.com.tw:80/HelpOnNavigation?arg=val&arg2=val2',
:scheme =>'http', :host =>'www.example.com.tw', :port => '80', :path => '/HelpOnNavigation',
:query => 'arg=val&arg2=val2',
:link_text => 'http://www.example.com.tw:80/HelpOnNavigation?arg=val&arg2=val2')
# HTTPS
match(URIChunk, 'https://www.example.com',
:scheme =>'https', :host =>'www.example.com', :port => nil, :path => nil, :query => nil,
:link_text => 'https://www.example.com')
# FTP
match(URIChunk, 'ftp://www.example.com',
:scheme =>'ftp', :host =>'www.example.com', :port => nil, :path => nil, :query => nil,
:link_text => 'ftp://www.example.com')
# mailto
match(URIChunk, 'mailto:jdoe123@example.com',
:scheme =>'mailto', :host =>'example.com', :port => nil, :path => nil, :query => nil,
:user => 'jdoe123', :link_text => 'mailto:jdoe123@example.com')
# something nonexistant
match(URIChunk, 'foobar://www.example.com',
:scheme =>'foobar', :host =>'www.example.com', :port => nil, :path => nil, :query => nil,
:link_text => 'foobar://www.example.com')
# Soap opera (the most complex case imaginable... well, not really, there should be more evil)
match(URIChunk, 'http://www.example.com.tw:80/~jdoe123/Help%20Me%20?arg=val&arg2=val2',
:scheme =>'http', :host =>'www.example.com.tw', :port => '80',
:path => '/~jdoe123/Help%20Me%20', :query => 'arg=val&arg2=val2',
:link_text => 'http://www.example.com.tw:80/~jdoe123/Help%20Me%20?arg=val&arg2=val2')
end
def test_email_uri
match(URIChunk, 'mail@example.com',
:user => 'mail', :host => 'example.com', :link_text => 'mail@example.com'
)
end
def test_non_email
# The @ is part of the normal text, but 'example.com' is marked up.
match(URIChunk, 'Not an email: @example.com', :user => nil, :uri => 'http://example.com')
end
def test_non_uri
assert_conversion_does_not_apply URIChunk, 'httpd.conf'
assert_conversion_does_not_apply URIChunk, 'libproxy.so'
assert_conversion_does_not_apply URIChunk, 'ld.so.conf'
end
def test_uri_in_text
match(URIChunk, 'Go to: http://www.example.com/', :host => 'www.example.com', :path =>'/')
match(URIChunk, 'http://www.example.com/ is a link.', :host => 'www.example.com')
match(URIChunk,
'Email david@loudthinking.com',
:scheme =>'mailto', :user =>'david', :host =>'loudthinking.com')
# check that trailing punctuation is not included in the hostname
match(URIChunk, '"link":http://fake.link.com.', :scheme => 'http', :host => 'fake.link.com')
end
def test_uri_in_parentheses
match(URIChunk, 'URI (http://brackets.com.de) in brackets', :host => 'brackets.com.de')
match(URIChunk, 'because (as shown at research.net) the results', :host => 'research.net')
match(URIChunk,
'A wiki (http://wiki.org/wiki.cgi?WhatIsWiki) page',
:scheme => 'http', :host => 'wiki.org', :path => '/wiki.cgi', :query => 'WhatIsWiki'
)
end
def test_uri_list_item
match(
URIChunk,
'* http://www.btinternet.com/~mail2minh/SonyEricssonP80xPlatform.sis',
:path => '/~mail2minh/SonyEricssonP80xPlatform.sis'
)
end
def test_interesting_uri_with__comma
# Counter-intuitively, this URL matches, but the query part includes the trailing comma.
# It has no way to know that the query does not include the comma.
match(
URIChunk,
"This text contains a URL http://someplace.org:8080/~person/stuff.cgi?arg=val, doesn't it?",
:scheme => 'http', :host => 'someplace.org', :port => '8080', :path => '/~person/stuff.cgi',
:query => 'arg=val,')
end
def test_local_urls
# normal
match(LocalURIChunk, 'http://perforce:8001/toto.html',
:scheme => 'http', :host => 'perforce',
:port => '8001', :link_text => 'http://perforce:8001/toto.html')
# in parentheses
match(LocalURIChunk, 'URI (http://localhost:2500) in brackets',
:host => 'localhost', :port => '2500')
match(LocalURIChunk, 'because (as shown at http://perforce:8001) the results',
:host => 'perforce', :port => '8001')
match(LocalURIChunk,
'A wiki (http://localhost:2500/wiki.cgi?WhatIsWiki) page',
:scheme => 'http', :host => 'localhost', :path => '/wiki.cgi',
:port => '2500', :query => 'WhatIsWiki')
end
def assert_conversion_does_not_apply(chunk_type, str)
processed_str = str.dup
URIChunk.apply_to(processed_str)
assert_equal(str, processed_str)
end
end
#!/bin/env ruby -w
require File.dirname(__FILE__) + '/../test_helper'
require 'chunks/uri'
class URITest < Test::Unit::TestCase
include ChunkMatch
def test_non_matches
assert_conversion_does_not_apply(URIChunk, 'There is no URI here')
assert_conversion_does_not_apply(URIChunk,
'One gemstone is the garnet:reddish in colour, like ruby')
end
def test_simple_uri
# Simplest case
match(URIChunk, 'http://www.example.com',
:scheme =>'http', :host =>'www.example.com', :path => nil,
:link_text => 'http://www.example.com'
)
# With trailing slash
match(URIChunk, 'http://www.example.com/',
:scheme =>'http', :host =>'www.example.com', :path => '/',
:link_text => 'http://www.example.com/'
)
# Without http://
match(URIChunk, 'www.example.com',
:scheme =>'http', :host =>'www.example.com', :link_text => 'www.example.com'
)
# two parts
match(URIChunk, 'example.com',
:scheme =>'http',:host =>'example.com', :link_text => 'example.com'
)
# "unusual" base domain (was a bug in an early version)
match(URIChunk, 'http://example.com.au/',
:scheme =>'http', :host =>'example.com.au', :link_text => 'http://example.com.au/'
)
# "unusual" base domain without http://
match(URIChunk, 'example.com.au',
:scheme =>'http', :host =>'example.com.au', :link_text => 'example.com.au'
)
# Another "unusual" base domain
match(URIChunk, 'http://www.example.co.uk/',
:scheme =>'http', :host =>'www.example.co.uk',
:link_text => 'http://www.example.co.uk/'
)
match(URIChunk, 'example.co.uk',
:scheme =>'http', :host =>'example.co.uk', :link_text => 'example.co.uk'
)
# With some path at the end
match(URIChunk, 'http://moinmoin.wikiwikiweb.de/HelpOnNavigation',
:scheme => 'http', :host => 'moinmoin.wikiwikiweb.de', :path => '/HelpOnNavigation',
:link_text => 'http://moinmoin.wikiwikiweb.de/HelpOnNavigation'
)
# With some path at the end, and withot http:// prefix
match(URIChunk, 'moinmoin.wikiwikiweb.de/HelpOnNavigation',
:scheme => 'http', :host => 'moinmoin.wikiwikiweb.de', :path => '/HelpOnNavigation',
:link_text => 'moinmoin.wikiwikiweb.de/HelpOnNavigation'
)
# With a port number
match(URIChunk, 'http://www.example.com:80',
:scheme =>'http', :host =>'www.example.com', :port => '80', :path => nil,
:link_text => 'http://www.example.com:80')
# With a port number and a path
match(URIChunk, 'http://www.example.com.tw:80/HelpOnNavigation',
:scheme =>'http', :host =>'www.example.com.tw', :port => '80', :path => '/HelpOnNavigation',
:link_text => 'http://www.example.com.tw:80/HelpOnNavigation')
# With a query
match(URIChunk, 'http://www.example.com.tw:80/HelpOnNavigation?arg=val',
:scheme =>'http', :host =>'www.example.com.tw', :port => '80', :path => '/HelpOnNavigation',
:query => 'arg=val',
:link_text => 'http://www.example.com.tw:80/HelpOnNavigation?arg=val')
# Query with two arguments
match(URIChunk, 'http://www.example.com.tw:80/HelpOnNavigation?arg=val&arg2=val2',
:scheme =>'http', :host =>'www.example.com.tw', :port => '80', :path => '/HelpOnNavigation',
:query => 'arg=val&arg2=val2',
:link_text => 'http://www.example.com.tw:80/HelpOnNavigation?arg=val&arg2=val2')
# HTTPS
match(URIChunk, 'https://www.example.com',
:scheme =>'https', :host =>'www.example.com', :port => nil, :path => nil, :query => nil,
:link_text => 'https://www.example.com')
# FTP
match(URIChunk, 'ftp://www.example.com',
:scheme =>'ftp', :host =>'www.example.com', :port => nil, :path => nil, :query => nil,
:link_text => 'ftp://www.example.com')
# mailto
match(URIChunk, 'mailto:jdoe123@example.com',
:scheme =>'mailto', :host =>'example.com', :port => nil, :path => nil, :query => nil,
:user => 'jdoe123', :link_text => 'mailto:jdoe123@example.com')
# something nonexistant
match(URIChunk, 'foobar://www.example.com',
:scheme =>'foobar', :host =>'www.example.com', :port => nil, :path => nil, :query => nil,
:link_text => 'foobar://www.example.com')
# Soap opera (the most complex case imaginable... well, not really, there should be more evil)
match(URIChunk, 'http://www.example.com.tw:80/~jdoe123/Help%20Me%20?arg=val&arg2=val2',
:scheme =>'http', :host =>'www.example.com.tw', :port => '80',
:path => '/~jdoe123/Help%20Me%20', :query => 'arg=val&arg2=val2',
:link_text => 'http://www.example.com.tw:80/~jdoe123/Help%20Me%20?arg=val&arg2=val2')
end
def test_email_uri
match(URIChunk, 'mail@example.com',
:user => 'mail', :host => 'example.com', :link_text => 'mail@example.com'
)
end
def test_non_email
# The @ is part of the normal text, but 'example.com' is marked up.
match(URIChunk, 'Not an email: @example.com', :user => nil, :uri => 'http://example.com')
end
def test_non_uri
assert_conversion_does_not_apply URIChunk, 'httpd.conf'
assert_conversion_does_not_apply URIChunk, 'libproxy.so'
assert_conversion_does_not_apply URIChunk, 'ld.so.conf'
end
def test_uri_in_text
match(URIChunk, 'Go to: http://www.example.com/', :host => 'www.example.com', :path =>'/')
match(URIChunk, 'http://www.example.com/ is a link.', :host => 'www.example.com')
match(URIChunk,
'Email david@loudthinking.com',
:scheme =>'mailto', :user =>'david', :host =>'loudthinking.com')
# check that trailing punctuation is not included in the hostname
match(URIChunk, '"link":http://fake.link.com.', :scheme => 'http', :host => 'fake.link.com')
end
def test_uri_in_parentheses
match(URIChunk, 'URI (http://brackets.com.de) in brackets', :host => 'brackets.com.de')
match(URIChunk, 'because (as shown at research.net) the results', :host => 'research.net')
match(URIChunk,
'A wiki (http://wiki.org/wiki.cgi?WhatIsWiki) page',
:scheme => 'http', :host => 'wiki.org', :path => '/wiki.cgi', :query => 'WhatIsWiki'
)
end
def test_uri_list_item
match(
URIChunk,
'* http://www.btinternet.com/~mail2minh/SonyEricssonP80xPlatform.sis',
:path => '/~mail2minh/SonyEricssonP80xPlatform.sis'
)
end
def test_interesting_uri_with__comma
# Counter-intuitively, this URL matches, but the query part includes the trailing comma.
# It has no way to know that the query does not include the comma.
match(
URIChunk,
"This text contains a URL http://someplace.org:8080/~person/stuff.cgi?arg=val, doesn't it?",
:scheme => 'http', :host => 'someplace.org', :port => '8080', :path => '/~person/stuff.cgi',
:query => 'arg=val,')
end
def test_local_urls
# normal
match(LocalURIChunk, 'http://perforce:8001/toto.html',
:scheme => 'http', :host => 'perforce',
:port => '8001', :link_text => 'http://perforce:8001/toto.html')
# in parentheses
match(LocalURIChunk, 'URI (http://localhost:2500) in brackets',
:host => 'localhost', :port => '2500')
match(LocalURIChunk, 'because (as shown at http://perforce:8001) the results',
:host => 'perforce', :port => '8001')
match(LocalURIChunk,
'A wiki (http://localhost:2500/wiki.cgi?WhatIsWiki) page',
:scheme => 'http', :host => 'localhost', :path => '/wiki.cgi',
:port => '2500', :query => 'WhatIsWiki')
end
def assert_conversion_does_not_apply(chunk_type, str)
processed_str = str.dup
URIChunk.apply_to(processed_str)
assert_equal(str, processed_str)
end
end

View file

@ -1,92 +1,92 @@
#!/bin/env ruby -w
require File.dirname(__FILE__) + '/../test_helper'
require 'url_rewriting_hack'
class UrlRewritingHackTest < Test::Unit::TestCase
def test_parse_uri
assert_equal({:controller => 'wiki', :action => 'x', :web => nil},
DispatchServlet.parse_uri('/x/'))
assert_equal({:web => 'x', :controller => 'wiki', :action => 'y'},
DispatchServlet.parse_uri('/x/y'))
assert_equal({:web => 'x', :controller => 'wiki', :action => 'y'},
DispatchServlet.parse_uri('/x/y/'))
assert_equal({:web => 'x', :controller => 'wiki', :action => 'y', :id => 'z'},
DispatchServlet.parse_uri('/x/y/z'))
assert_equal({:web => 'x', :controller => 'wiki', :action => 'y', :id => 'z'},
DispatchServlet.parse_uri('/x/y/z/'))
end
def test_parse_uri_approot
assert_equal({:controller => 'wiki', :action => 'index', :web => nil},
DispatchServlet.parse_uri('/wiki/'))
end
def test_parse_uri_interestng_cases
assert_equal({:web => '_veeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeery-long_web_',
:controller => 'wiki',
:action => 'an_action', :id => 'HomePage'
},
DispatchServlet.parse_uri(
'/_veeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeery-long_web_/an_action/HomePage')
)
assert_equal false, DispatchServlet.parse_uri('')
assert_equal false, DispatchServlet.parse_uri('//')
assert_equal false, DispatchServlet.parse_uri('web')
end
def test_parse_uri_liberal_with_pagenames
assert_equal({:controller => 'wiki', :web => 'web', :action => 'show', :id => '$HOME_PAGE'},
DispatchServlet.parse_uri('/web/show/$HOME_PAGE'))
assert_equal({:controller => 'wiki', :web => 'web', :action => 'show',
:id => 'HomePage/something_else'},
DispatchServlet.parse_uri('/web/show/HomePage/something_else'))
assert_equal({:controller => 'wiki', :web => 'web', :action => 'show',
:id => 'HomePage?arg1=value1&arg2=value2'},
DispatchServlet.parse_uri('/web/show/HomePage?arg1=value1&arg2=value2'))
assert_equal({:controller => 'wiki', :web => 'web', :action => 'show',
:id => 'Page+With+Spaces'},
DispatchServlet.parse_uri('/web/show/Page+With+Spaces'))
end
def test_url_rewriting
request = ActionController::TestRequest.new
ur = ActionController::UrlRewriter.new(request, 'wiki', 'show')
assert_equal 'http://test.host/myweb/myaction',
ur.rewrite(:web => 'myweb', :controller => 'wiki', :action => 'myaction')
assert_equal 'http://test.host/myOtherWeb/',
ur.rewrite(:web => 'myOtherWeb', :controller => 'wiki')
assert_equal 'http://test.host/myaction',
ur.rewrite(:controller => 'wiki', :action => 'myaction')
assert_equal 'http://test.host/',
ur.rewrite(:controller => 'wiki')
end
def test_controller_mapping
request = ActionController::TestRequest.new
ur = ActionController::UrlRewriter.new(request, 'wiki', 'show')
assert_equal 'http://test.host/file',
ur.rewrite(:controller => 'file', :action => 'file')
assert_equal 'http://test.host/pic/abc.jpg',
ur.rewrite(:controller => 'file', :action => 'pic', :id => 'abc.jpg')
assert_equal 'http://test.host/web/pic/abc.jpg',
ur.rewrite(:web => 'web', :controller => 'file', :action => 'pic', :id => 'abc.jpg')
# default option is wiki
assert_equal 'http://test.host/unknown_action',
ur.rewrite(:controller => 'wiki', :action => 'unknown_action')
end
#!/bin/env ruby -w
require File.dirname(__FILE__) + '/../test_helper'
require 'url_rewriting_hack'
class UrlRewritingHackTest < Test::Unit::TestCase
def test_parse_uri
assert_equal({:controller => 'wiki', :action => 'x', :web => nil},
DispatchServlet.parse_uri('/x/'))
assert_equal({:web => 'x', :controller => 'wiki', :action => 'y'},
DispatchServlet.parse_uri('/x/y'))
assert_equal({:web => 'x', :controller => 'wiki', :action => 'y'},
DispatchServlet.parse_uri('/x/y/'))
assert_equal({:web => 'x', :controller => 'wiki', :action => 'y', :id => 'z'},
DispatchServlet.parse_uri('/x/y/z'))
assert_equal({:web => 'x', :controller => 'wiki', :action => 'y', :id => 'z'},
DispatchServlet.parse_uri('/x/y/z/'))
end
def test_parse_uri_approot
assert_equal({:controller => 'wiki', :action => 'index', :web => nil},
DispatchServlet.parse_uri('/wiki/'))
end
def test_parse_uri_interestng_cases
assert_equal({:web => '_veeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeery-long_web_',
:controller => 'wiki',
:action => 'an_action', :id => 'HomePage'
},
DispatchServlet.parse_uri(
'/_veeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeery-long_web_/an_action/HomePage')
)
assert_equal false, DispatchServlet.parse_uri('')
assert_equal false, DispatchServlet.parse_uri('//')
assert_equal false, DispatchServlet.parse_uri('web')
end
def test_parse_uri_liberal_with_pagenames
assert_equal({:controller => 'wiki', :web => 'web', :action => 'show', :id => '$HOME_PAGE'},
DispatchServlet.parse_uri('/web/show/$HOME_PAGE'))
assert_equal({:controller => 'wiki', :web => 'web', :action => 'show',
:id => 'HomePage/something_else'},
DispatchServlet.parse_uri('/web/show/HomePage/something_else'))
assert_equal({:controller => 'wiki', :web => 'web', :action => 'show',
:id => 'HomePage?arg1=value1&arg2=value2'},
DispatchServlet.parse_uri('/web/show/HomePage?arg1=value1&arg2=value2'))
assert_equal({:controller => 'wiki', :web => 'web', :action => 'show',
:id => 'Page+With+Spaces'},
DispatchServlet.parse_uri('/web/show/Page+With+Spaces'))
end
def test_url_rewriting
request = ActionController::TestRequest.new
ur = ActionController::UrlRewriter.new(request, 'wiki', 'show')
assert_equal 'http://test.host/myweb/myaction',
ur.rewrite(:web => 'myweb', :controller => 'wiki', :action => 'myaction')
assert_equal 'http://test.host/myOtherWeb/',
ur.rewrite(:web => 'myOtherWeb', :controller => 'wiki')
assert_equal 'http://test.host/myaction',
ur.rewrite(:controller => 'wiki', :action => 'myaction')
assert_equal 'http://test.host/',
ur.rewrite(:controller => 'wiki')
end
def test_controller_mapping
request = ActionController::TestRequest.new
ur = ActionController::UrlRewriter.new(request, 'wiki', 'show')
assert_equal 'http://test.host/file',
ur.rewrite(:controller => 'file', :action => 'file')
assert_equal 'http://test.host/pic/abc.jpg',
ur.rewrite(:controller => 'file', :action => 'pic', :id => 'abc.jpg')
assert_equal 'http://test.host/web/pic/abc.jpg',
ur.rewrite(:web => 'web', :controller => 'file', :action => 'pic', :id => 'abc.jpg')
# default option is wiki
assert_equal 'http://test.host/unknown_action',
ur.rewrite(:controller => 'wiki', :action => 'unknown_action')
end
end

View file

@ -1,130 +1,130 @@
#!/bin/env ruby -w
require File.dirname(__FILE__) + '/../test_helper'
require 'wiki_service'
class WebTest < Test::Unit::TestCase
def setup
@web = Web.new nil, 'Instiki', 'instiki'
end
def test_wiki_word_linking
@web.add_page(Page.new(@web, '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.pages["SecondPage"].display_content)
@web.add_page(Page.new(@web, '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.pages['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.pages['EverBeenInLove'] ])
assert_equal 1, @web.pages.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 &amp; 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
wiki_stub = Object.new
web = Web.new(wiki_stub, 'Wiki2', 'wiki2', '123')
assert_equal wiki_stub, web.wiki
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_equal @wiki, web.parent_wiki
assert_nil web.additional_style
assert !web.published
assert !web.brackets_only
assert !web.count_pages
assert web.allow_uploads
end
private
def add_sample_pages
@web.add_page(Page.new(@web, 'EverBeenInLove', 'Who am I me',
Time.local(2004, 4, 4, 16, 50), 'DavidHeinemeierHansson'))
@web.add_page(Page.new(@web, 'EverBeenHated', 'I am me EverBeenHated',
Time.local(2004, 4, 4, 16, 51), 'DavidHeinemeierHansson'))
end
#!/bin/env ruby -w
require File.dirname(__FILE__) + '/../test_helper'
require 'wiki_service'
class WebTest < Test::Unit::TestCase
def setup
@web = Web.new nil, 'Instiki', 'instiki'
end
def test_wiki_word_linking
@web.add_page(Page.new(@web, '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.pages["SecondPage"].display_content)
@web.add_page(Page.new(@web, '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.pages['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.pages['EverBeenInLove'] ])
assert_equal 1, @web.pages.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 &amp; 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
wiki_stub = Object.new
web = Web.new(wiki_stub, 'Wiki2', 'wiki2', '123')
assert_equal wiki_stub, web.wiki
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_equal @wiki, web.parent_wiki
assert_nil web.additional_style
assert !web.published
assert !web.brackets_only
assert !web.count_pages
assert web.allow_uploads
end
private
def add_sample_pages
@web.add_page(Page.new(@web, 'EverBeenInLove', 'Who am I me',
Time.local(2004, 4, 4, 16, 50), 'DavidHeinemeierHansson'))
@web.add_page(Page.new(@web, 'EverBeenHated', 'I am me EverBeenHated',
Time.local(2004, 4, 4, 16, 51), 'DavidHeinemeierHansson'))
end
end

View file

@ -1,116 +1,116 @@
#!/bin/env ruby -w
require File.dirname(__FILE__) + '/../test_helper'
require 'wiki_service'
require 'fileutils'
class WikiServiceTest < Test::Unit::TestCase
# Clean the test storage directory before the run
unless defined? @@storage_cleaned
FileUtils.rm(Dir[RAILS_ROOT + '/storage/test/*.command_log'])
FileUtils.rm(Dir[RAILS_ROOT + '/storage/test/*.snapshot'])
FileUtils.rm(Dir[RAILS_ROOT + '/storage/test/*.tex'])
FileUtils.rm(Dir[RAILS_ROOT + '/storage/test/*.zip'])
FileUtils.rm(Dir[RAILS_ROOT + '/storage/test/*.pdf'])
FileUtils.rm(Dir[RAILS_ROOT + '/storage/test/instiki/*'])
@@cleaned_storage = true
WikiService.instance.setup('pswd', 'Wiki', 'wiki')
end
def setup
@s = WikiService.instance
@s.create_web 'Instiki', 'instiki'
@web = @s.webs['instiki']
end
def teardown
@s.delete_web 'instiki'
end
def test_read_write_page
@s.write_page 'instiki', 'FirstPage', "Electric shocks, I love 'em",
Time.now, 'DavidHeinemeierHansson'
assert_equal "Electric shocks, I love 'em", @s.read_page('instiki', 'FirstPage').content
end
def test_read_only_operations
@s.write_page 'instiki', 'TestReadOnlyOperations', 'Read only operations dont change the' +
'state of any object, and therefore should not be logged by Madeleine!',
Time.now, 'AlexeyVerkhovsky'
assert_doesnt_change_state_or_log :authenticate, 'pswd'
assert_doesnt_change_state_or_log :read_page, 'instiki', 'TestReadOnlyOperations'
assert_doesnt_change_state_or_log :setup?
assert_doesnt_change_state_or_log :webs
@s.write_page 'instiki', 'FirstPage', "Electric shocks, I love 'em",
Time.now, 'DavidHeinemeierHansson'
assert_equal "Electric shocks, I love 'em", @s.read_page('instiki', 'FirstPage').content
end
def test_aborted_transaction
@s.write_page 'instiki', 'FirstPage', "Electric shocks, I love 'em",
10.minutes.ago, 'DavidHeinemeierHansson'
assert_doesnt_change_state('revise_page with unchanged content') {
begin
@s.revise_page 'instiki', 'FirstPage', "Electric shocks, I love 'em",
Time.now, 'DavidHeinemeierHansson'
fail 'Expected Instiki::ValidationError not raised'
rescue Instiki::ValidationError
end
}
end
def test_file_yard
file_yard = @s.file_yard(@web)
assert_equal FileYard, file_yard.class
assert_equal(@s.storage_path + '/instiki', file_yard.files_path)
end
# Checks that a method call or a block doesn;t change the persisted state of the wiki
# Usage:
# assert_doesnt_change_state :read_page, 'instiki', 'TestReadOnlyOperations'
# or
# assert_doesnt_change_state {|wiki| wiki.webs}
def assert_doesnt_change_state(method, *args, &block)
_assert_doesnt_change_state(including_command_log = false, method, *args, &block)
end
# Same as assert_doesnt_change_state, but also asserts that no vommand log is generated
def assert_doesnt_change_state_or_log(method, *args, &block)
_assert_doesnt_change_state(including_command_log = true, method, *args, &block)
end
private
def _assert_doesnt_change_state(including_log, method, *args)
WikiService.snapshot
last_snapshot_before = last_snapshot
if block_given?
yield @s
else
@s.send(method, *args)
end
if including_log
command_logs = Dir[RAILS_ROOT + 'storage/test/*.command_log']
assert command_logs.empty?, "Calls to #{method} should not be logged"
end
last_snapshot_after = last_snapshot
assert last_snapshot_before == last_snapshot_after,
'Calls to #{method} should not change the state of any persisted object'
end
def last_snapshot
snapshots = Dir[RAILS_ROOT + '/storage/test/*.snapshot']
assert !snapshots.empty?, "No snapshots found at #{RAILS_ROOT}/storage/test/"
File.read(snapshots.last)
end
end
#!/bin/env ruby -w
require File.dirname(__FILE__) + '/../test_helper'
require 'wiki_service'
require 'fileutils'
class WikiServiceTest < Test::Unit::TestCase
# Clean the test storage directory before the run
unless defined? @@storage_cleaned
FileUtils.rm(Dir[RAILS_ROOT + '/storage/test/*.command_log'])
FileUtils.rm(Dir[RAILS_ROOT + '/storage/test/*.snapshot'])
FileUtils.rm(Dir[RAILS_ROOT + '/storage/test/*.tex'])
FileUtils.rm(Dir[RAILS_ROOT + '/storage/test/*.zip'])
FileUtils.rm(Dir[RAILS_ROOT + '/storage/test/*.pdf'])
FileUtils.rm(Dir[RAILS_ROOT + '/storage/test/instiki/*'])
@@cleaned_storage = true
WikiService.instance.setup('pswd', 'Wiki', 'wiki')
end
def setup
@s = WikiService.instance
@s.create_web 'Instiki', 'instiki'
@web = @s.webs['instiki']
end
def teardown
@s.delete_web 'instiki'
end
def test_read_write_page
@s.write_page 'instiki', 'FirstPage', "Electric shocks, I love 'em",
Time.now, 'DavidHeinemeierHansson'
assert_equal "Electric shocks, I love 'em", @s.read_page('instiki', 'FirstPage').content
end
def test_read_only_operations
@s.write_page 'instiki', 'TestReadOnlyOperations', 'Read only operations dont change the' +
'state of any object, and therefore should not be logged by Madeleine!',
Time.now, 'AlexeyVerkhovsky'
assert_doesnt_change_state_or_log :authenticate, 'pswd'
assert_doesnt_change_state_or_log :read_page, 'instiki', 'TestReadOnlyOperations'
assert_doesnt_change_state_or_log :setup?
assert_doesnt_change_state_or_log :webs
@s.write_page 'instiki', 'FirstPage', "Electric shocks, I love 'em",
Time.now, 'DavidHeinemeierHansson'
assert_equal "Electric shocks, I love 'em", @s.read_page('instiki', 'FirstPage').content
end
def test_aborted_transaction
@s.write_page 'instiki', 'FirstPage', "Electric shocks, I love 'em",
10.minutes.ago, 'DavidHeinemeierHansson'
assert_doesnt_change_state('revise_page with unchanged content') {
begin
@s.revise_page 'instiki', 'FirstPage', "Electric shocks, I love 'em",
Time.now, 'DavidHeinemeierHansson'
fail 'Expected Instiki::ValidationError not raised'
rescue Instiki::ValidationError
end
}
end
def test_file_yard
file_yard = @s.file_yard(@web)
assert_equal FileYard, file_yard.class
assert_equal(@s.storage_path + '/instiki', file_yard.files_path)
end
# Checks that a method call or a block doesn;t change the persisted state of the wiki
# Usage:
# assert_doesnt_change_state :read_page, 'instiki', 'TestReadOnlyOperations'
# or
# assert_doesnt_change_state {|wiki| wiki.webs}
def assert_doesnt_change_state(method, *args, &block)
_assert_doesnt_change_state(including_command_log = false, method, *args, &block)
end
# Same as assert_doesnt_change_state, but also asserts that no vommand log is generated
def assert_doesnt_change_state_or_log(method, *args, &block)
_assert_doesnt_change_state(including_command_log = true, method, *args, &block)
end
private
def _assert_doesnt_change_state(including_log, method, *args)
WikiService.snapshot
last_snapshot_before = last_snapshot
if block_given?
yield @s
else
@s.send(method, *args)
end
if including_log
command_logs = Dir[RAILS_ROOT + 'storage/test/*.command_log']
assert command_logs.empty?, "Calls to #{method} should not be logged"
end
last_snapshot_after = last_snapshot
assert last_snapshot_before == last_snapshot_after,
'Calls to #{method} should not change the state of any persisted object'
end
def last_snapshot
snapshots = Dir[RAILS_ROOT + '/storage/test/*.snapshot']
assert !snapshots.empty?, "No snapshots found at #{RAILS_ROOT}/storage/test/"
File.read(snapshots.last)
end
end

View file

@ -1,14 +1,14 @@
#!/bin/env ruby -w
require File.dirname(__FILE__) + '/../test_helper'
require 'wiki_words'
class WikiWordsTest < Test::Unit::TestCase
def test_utf8_characters_in_wiki_word
assert_equal "Æåle Øen", WikiWords.separate("ÆåleØen")
assert_equal "ÆÅØle Øen", WikiWords.separate("ÆÅØleØen")
assert_equal "Æe ÅØle Øen", WikiWords.separate("ÆeÅØleØen")
assert_equal "Legetøj", WikiWords.separate("Legetøj")
end
end
#!/bin/env ruby -w
require File.dirname(__FILE__) + '/../test_helper'
require 'wiki_words'
class WikiWordsTest < Test::Unit::TestCase
def test_utf8_characters_in_wiki_word
assert_equal "Æåle Øen", WikiWords.separate("ÆåleØen")
assert_equal "ÆÅØle Øen", WikiWords.separate("ÆÅØleØen")
assert_equal "Æe ÅØle Øen", WikiWords.separate("ÆeÅØleØen")
assert_equal "Legetøj", WikiWords.separate("Legetøj")
end
end