2005-01-24 19:52:04 +01:00
|
|
|
#!/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
|
2005-05-12 03:07:24 +02:00
|
|
|
@web.add_page('SecondPage', 'Yo, yo. Have you EverBeenHated',
|
|
|
|
Time.now, 'DavidHeinemeierHansson')
|
2005-01-24 19:52:04 +01:00
|
|
|
|
|
|
|
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)
|
|
|
|
|
2005-05-12 03:07:24 +02:00
|
|
|
@web.add_page('EverBeenHated', 'Yo, yo. Have you EverBeenHated', Time.now,
|
|
|
|
'DavidHeinemeierHansson')
|
2005-01-24 19:52:04 +01:00
|
|
|
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 & 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
|
2005-03-31 06:44:10 +02:00
|
|
|
assert_equal({}, web.pages)
|
2005-01-24 19:52:04 +01:00
|
|
|
assert web.allow_uploads
|
2005-03-31 06:44:10 +02:00
|
|
|
assert_equal wiki_stub, web.wiki
|
2005-01-24 19:52:04 +01:00
|
|
|
assert_nil web.additional_style
|
|
|
|
assert !web.published
|
|
|
|
assert !web.brackets_only
|
|
|
|
assert !web.count_pages
|
|
|
|
assert web.allow_uploads
|
2005-01-30 07:11:00 +01:00
|
|
|
assert_equal 100, web.max_upload_size
|
2005-01-24 19:52:04 +01:00
|
|
|
end
|
|
|
|
|
2005-03-26 01:00:49 +01:00
|
|
|
def test_initialize_invalid_name
|
|
|
|
wiki_stub = Object.new
|
|
|
|
assert_raises(Instiki::ValidationError) {
|
|
|
|
Web.new(wiki_stub, 'Wiki2', "wiki\234", '123')
|
|
|
|
}
|
|
|
|
end
|
2005-01-24 19:52:04 +01:00
|
|
|
|
2005-04-03 07:15:56 +02:00
|
|
|
def test_new_page_linked_from_mother_page
|
|
|
|
# this was a bug in revision 204
|
2005-05-12 03:07:24 +02:00
|
|
|
home = @web.add_page('HomePage', 'This page refers to AnotherPage',
|
2005-04-03 07:15:56 +02:00
|
|
|
Time.local(2004, 4, 4, 16, 50), 'Alexey Verkhovsky')
|
2005-05-12 03:07:24 +02:00
|
|
|
@web.add_page('AnotherPage', 'This is \AnotherPage',
|
2005-04-03 07:15:56 +02:00
|
|
|
Time.local(2004, 4, 4, 16, 51), 'Alexey Verkhovsky')
|
|
|
|
|
|
|
|
assert_equal [home], @web.select.pages_that_link_to('AnotherPage')
|
|
|
|
end
|
|
|
|
|
2005-04-03 08:11:37 +02:00
|
|
|
def test_orphaned_pages
|
|
|
|
add_sample_pages
|
2005-05-12 03:07:24 +02:00
|
|
|
home = @web.add_page('HomePage',
|
2005-04-03 08:11:37 +02:00
|
|
|
'This is a home page, it should not be an orphan',
|
2005-05-12 03:07:24 +02:00
|
|
|
Time.local(2004, 4, 4, 16, 50), 'AlexeyVerkhovsky')
|
|
|
|
author = @web.add_page('AlexeyVerkhovsky',
|
2005-04-03 08:11:37 +02:00
|
|
|
'This is an author page, it should not be an orphan',
|
2005-05-12 03:07:24 +02:00
|
|
|
Time.local(2004, 4, 4, 16, 50), 'AlexeyVerkhovsky')
|
|
|
|
self_linked = @web.add_page('SelfLinked',
|
2005-04-03 08:11:37 +02:00
|
|
|
'I am me SelfLinked and link to EverBeenInLove',
|
2005-05-12 03:07:24 +02:00
|
|
|
Time.local(2004, 4, 4, 16, 50), 'AnonymousCoward')
|
2005-04-03 08:11:37 +02:00
|
|
|
|
|
|
|
# page that links to itself, and nobody else links to it must be an orphan
|
|
|
|
assert_equal ['EverBeenHated', 'SelfLinked'],
|
|
|
|
@web.select.orphaned_pages.collect{ |page| page.name }.sort
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2005-01-24 19:52:04 +01:00
|
|
|
private
|
|
|
|
|
|
|
|
def add_sample_pages
|
2005-05-12 03:07:24 +02:00
|
|
|
@in_love = @web.add_page('EverBeenInLove', 'Who am I me',
|
|
|
|
Time.local(2004, 4, 4, 16, 50), 'DavidHeinemeierHansson')
|
|
|
|
@hated = @web.add_page('EverBeenHated', 'I am me EverBeenHated',
|
|
|
|
Time.local(2004, 4, 4, 16, 51), 'DavidHeinemeierHansson')
|
2005-01-24 19:52:04 +01:00
|
|
|
end
|
2005-03-27 20:13:43 +02:00
|
|
|
end
|