2007-01-22 14:43:50 +01:00
|
|
|
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.
|
2010-01-03 20:19:47 +01:00
|
|
|
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'config', 'environment'))
|
2007-01-22 14:43:50 +01:00
|
|
|
|
2009-02-04 21:26:08 +01:00
|
|
|
require 'test_help'
|
2007-01-22 14:43:50 +01:00
|
|
|
require 'wiki_content'
|
|
|
|
require 'url_generator'
|
2008-01-21 18:59:55 +01:00
|
|
|
require 'digest/sha1'
|
|
|
|
|
|
|
|
# simulates cookie session store
|
|
|
|
class FakeSessionDbMan
|
|
|
|
def self.generate_digest(data)
|
|
|
|
Digest::SHA1.hexdigest("secure")
|
|
|
|
end
|
|
|
|
end
|
2007-01-22 14:43:50 +01:00
|
|
|
|
2009-02-04 21:26:08 +01:00
|
|
|
class ActiveSupport::TestCase
|
|
|
|
self.pre_loaded_fixtures = false
|
|
|
|
self.use_transactional_fixtures = true
|
|
|
|
self.use_instantiated_fixtures = false
|
2010-01-03 20:19:47 +01:00
|
|
|
self.fixture_path = Rails.root.join('test', 'fixtures', '')
|
2009-02-04 21:26:08 +01:00
|
|
|
end
|
2007-01-22 14:43:50 +01:00
|
|
|
|
|
|
|
# activate PageObserver
|
|
|
|
PageObserver.instance
|
|
|
|
|
|
|
|
class Test::Unit::TestCase
|
|
|
|
def create_fixtures(*table_names)
|
2010-01-03 20:19:47 +01:00
|
|
|
Fixtures.create_fixtures(Rails.root.join('test', 'fixtures'), table_names)
|
2007-01-22 14:43:50 +01:00
|
|
|
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'),
|
2009-12-01 02:38:34 +01:00
|
|
|
x_test_renderer)
|
2007-01-22 14:43:50 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
@web = Web.find(@web.id)
|
|
|
|
end
|
|
|
|
|
2009-12-01 02:38:34 +01:00
|
|
|
def x_test_renderer(revision = nil)
|
2007-01-22 14:43:50 +01:00
|
|
|
PageRenderer.setup_url_generator(StubUrlGenerator.new)
|
|
|
|
PageRenderer.new(revision)
|
|
|
|
end
|
|
|
|
|
|
|
|
def use_blank_wiki
|
|
|
|
Revision.destroy_all
|
|
|
|
Page.destroy_all
|
|
|
|
Web.destroy_all
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# This module is to be included in unit tests that involve matching chunks.
|
|
|
|
# It provides a easy way to test whether a chunk matches a particular string
|
|
|
|
# and any the values of any fields that should be set after a match.
|
|
|
|
class ContentStub < String
|
2010-05-27 07:27:49 +02:00
|
|
|
|
|
|
|
attr_reader :web
|
|
|
|
|
2007-01-22 14:43:50 +01:00
|
|
|
include ChunkManager
|
|
|
|
def initialize(str)
|
|
|
|
super
|
|
|
|
init_chunk_manager
|
2010-05-27 07:27:49 +02:00
|
|
|
@web = Object.new
|
|
|
|
class << @web
|
|
|
|
def address
|
|
|
|
'wiki1'
|
|
|
|
end
|
|
|
|
end
|
2007-01-22 14:43:50 +01:00
|
|
|
end
|
2010-05-27 07:27:49 +02:00
|
|
|
|
|
|
|
def url_generator
|
|
|
|
StubUrlGenerator.new
|
|
|
|
end
|
|
|
|
|
2007-01-22 14:43:50 +01:00
|
|
|
def page_link(*); end
|
|
|
|
end
|
|
|
|
|
|
|
|
module ChunkMatch
|
|
|
|
|
|
|
|
# Asserts a number of tests for the given type and text.
|
|
|
|
def match(chunk_type, test_text, expected_chunk_state)
|
|
|
|
if chunk_type.respond_to? :pattern
|
|
|
|
assert_match(chunk_type.pattern, test_text)
|
|
|
|
end
|
|
|
|
|
|
|
|
content = ContentStub.new(test_text)
|
|
|
|
chunk_type.apply_to(content)
|
|
|
|
|
|
|
|
# Test if requested parts are correct.
|
|
|
|
expected_chunk_state.each_pair do |a_method, expected_value|
|
|
|
|
assert content.chunks.last.kind_of?(chunk_type)
|
|
|
|
assert_respond_to(content.chunks.last, a_method)
|
|
|
|
assert_equal(expected_value, content.chunks.last.send(a_method.to_sym),
|
|
|
|
"Wrong #{a_method} value")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Asserts that test_text doesn't match the chunk_type
|
|
|
|
def no_match(chunk_type, test_text)
|
|
|
|
if chunk_type.respond_to? :pattern
|
|
|
|
assert_no_match(chunk_type.pattern, test_text)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class StubUrlGenerator < AbstractUrlGenerator
|
|
|
|
|
|
|
|
def initialize
|
2010-01-26 05:01:10 +01:00
|
|
|
super(:doesnt_need_controller)
|
2007-01-22 14:43:50 +01:00
|
|
|
end
|
2010-01-26 05:01:10 +01:00
|
|
|
|
|
|
|
def url_for(hash = {})
|
2010-05-27 07:27:49 +02:00
|
|
|
if(hash[:action] == 'list')
|
2010-05-27 08:17:24 +02:00
|
|
|
"/#{hash[:web]}/list"
|
2010-05-27 07:27:49 +02:00
|
|
|
else
|
|
|
|
'../files/pngs'
|
|
|
|
end
|
2010-01-26 05:01:10 +01:00
|
|
|
end
|
|
|
|
|
2007-10-10 06:56:55 +02:00
|
|
|
def file_link(mode, name, text, web_name, known_file, description)
|
2007-01-22 14:43:50 +01:00
|
|
|
link = CGI.escape(name)
|
|
|
|
case mode
|
|
|
|
when :export
|
2007-10-10 06:56:55 +02:00
|
|
|
if known_file then %{<a class="existingWikiWord" title="#{description}" href="#{link}.html">#{text}</a>}
|
2007-01-22 14:43:50 +01:00
|
|
|
else %{<span class="newWikiWord">#{text}</span>} end
|
|
|
|
when :publish
|
2007-10-10 06:56:55 +02:00
|
|
|
if known_file then %{<a class="existingWikiWord" title="#{description}" href="../published/#{link}">#{text}</a>}
|
2007-01-22 14:43:50 +01:00
|
|
|
else %{<span class=\"newWikiWord\">#{text}</span>} end
|
|
|
|
else
|
|
|
|
if known_file
|
2007-10-10 06:56:55 +02:00
|
|
|
%{<a class=\"existingWikiWord\" title="#{description}" href=\"../file/#{link}\">#{text}</a>}
|
2007-01-22 14:43:50 +01:00
|
|
|
else
|
|
|
|
%{<span class=\"newWikiWord\">#{text}<a href=\"../file/#{link}\">?</a></span>}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def page_link(mode, name, text, web_address, known_page)
|
|
|
|
link = CGI.escape(name)
|
2010-01-03 20:19:47 +01:00
|
|
|
title = web_address == 'wiki1' ? '' : " title='#{web_address}'"
|
2009-06-07 04:08:08 +02:00
|
|
|
case mode
|
2007-01-22 14:43:50 +01:00
|
|
|
when :export
|
|
|
|
if known_page then %{<a class="existingWikiWord" href="#{link}.html">#{text}</a>}
|
|
|
|
else %{<span class="newWikiWord">#{text}</span>} end
|
|
|
|
when :publish
|
2010-01-03 20:19:47 +01:00
|
|
|
if known_page then %{<a class="existingWikiWord" href="../published/#{link}"#{title}>#{text}</a>}
|
2007-01-22 14:43:50 +01:00
|
|
|
else %{<span class="newWikiWord">#{text}</span>} end
|
|
|
|
else
|
|
|
|
if known_page
|
2010-01-03 20:19:47 +01:00
|
|
|
if web_address == 'instiki'
|
|
|
|
%{<a class="existingWikiWord" href="../../#{web_address}/show/#{link}"#{title}>#{text}</a>}
|
|
|
|
else
|
|
|
|
%{<a class="existingWikiWord" href="../show/#{link}"#{title}>#{text}</a>}
|
|
|
|
end
|
2007-01-22 14:43:50 +01:00
|
|
|
else
|
2007-10-06 23:04:11 +02:00
|
|
|
if web_address == 'instiki'
|
|
|
|
%{<span class="newWikiWord">#{text}<a href="../../#{web_address}/show/#{link}">?</a></span>}
|
|
|
|
else
|
|
|
|
%{<span class="newWikiWord">#{text}<a href="../show/#{link}">?</a></span>}
|
|
|
|
end
|
2007-01-22 14:43:50 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2007-10-09 18:02:44 +02:00
|
|
|
def pic_link(mode, name, text, web_name, known_pic)
|
2007-01-22 14:43:50 +01:00
|
|
|
link = CGI.escape(name)
|
2007-10-09 18:02:44 +02:00
|
|
|
text = CGI.escapeHTML(CGI.unescapeHTML(text || :description))
|
2007-01-22 14:43:50 +01:00
|
|
|
case mode.to_sym
|
|
|
|
when :export
|
2007-10-09 18:02:44 +02:00
|
|
|
if known_pic then %{<img alt="#{text}" src="#{link}" />}
|
2007-01-22 14:43:50 +01:00
|
|
|
else %{<img alt="#{text}" src="no image" />} end
|
|
|
|
when :publish
|
2008-12-20 20:56:50 +01:00
|
|
|
if known_pic then %{<img alt="#{text}" src="../file/#{link}" />}
|
2007-01-22 14:43:50 +01:00
|
|
|
else %{<span class="newWikiWord">#{text}</span>} end
|
|
|
|
else
|
2007-10-09 18:02:44 +02:00
|
|
|
if known_pic then %{<img alt="#{text}" src="../file/#{link}" />}
|
2007-01-22 14:43:50 +01:00
|
|
|
else %{<span class="newWikiWord">#{text}<a href="../file/#{link}">?</a></span>} end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-03-04 05:27:26 +01:00
|
|
|
def media_link(mode, name, text, web_address, known_media, media_type)
|
|
|
|
link = CGI.escape(name)
|
|
|
|
text = CGI.escapeHTML(CGI.unescapeHTML(text || :description))
|
|
|
|
case mode.to_sym
|
|
|
|
when :export
|
|
|
|
if known_media
|
|
|
|
%{<#{media_type} src="#{CGI.escape(name)}" controls="controls">#{text}</#{media_type}>}
|
|
|
|
else
|
|
|
|
text
|
|
|
|
end
|
|
|
|
when :publish
|
|
|
|
if known_media
|
|
|
|
%{<#{media_type} src="../file/#{link}" controls="controls">#{text}</#{media_type}>}
|
|
|
|
else
|
|
|
|
%{<span class="newWikiWord">#{text}</span>}
|
|
|
|
end
|
|
|
|
else
|
|
|
|
if known_media
|
|
|
|
%{<#{media_type} src="../file/#{link}" controls="controls">#{text}</#{media_type}>}
|
|
|
|
else
|
|
|
|
%{<span class="newWikiWord">#{text}<a href="../file/#{link}">?</a></span>}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2007-01-22 14:43:50 +01:00
|
|
|
module Test
|
|
|
|
module Unit
|
|
|
|
module Assertions
|
|
|
|
def assert_success(bypass_body_parsing = false)
|
|
|
|
assert_response :success
|
|
|
|
unless bypass_body_parsing
|
|
|
|
assert_nothing_raised(@response.body) { REXML::Document.new(@response.body) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|