2005-08-15 21:17:32 +02:00
|
|
|
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
|
|
|
|
|
|
|
class WebTest < Test::Unit::TestCase
|
2005-09-11 10:05:19 +02:00
|
|
|
fixtures :webs, :pages, :revisions, :system, :wiki_references
|
2005-08-15 21:17:32 +02:00
|
|
|
|
|
|
|
def setup
|
|
|
|
@web = webs(:instiki)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_pages_by_revision
|
|
|
|
add_sample_pages
|
|
|
|
assert_equal 'EverBeenHated', @web.select.by_revision.first.name
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_pages_by_match
|
|
|
|
add_sample_pages
|
|
|
|
assert_equal 2, @web.select { |page| page.content =~ /me/i }.length
|
|
|
|
assert_equal 1, @web.select { |page| page.content =~ /Who/i }.length
|
|
|
|
assert_equal 0, @web.select { |page| page.content =~ /none/i }.length
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_references
|
|
|
|
add_sample_pages
|
|
|
|
assert_equal 1, @web.select.pages_that_reference('EverBeenHated').length
|
|
|
|
assert_equal 0, @web.select.pages_that_reference('EverBeenInLove').length
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_delete
|
|
|
|
add_sample_pages
|
|
|
|
assert_equal 2, @web.pages.length
|
|
|
|
@web.remove_pages([ @web.page('EverBeenInLove') ])
|
|
|
|
assert_equal 1, @web.pages(true).length
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_initialize
|
|
|
|
web = Web.new(:name => 'Wiki2', :address => 'wiki2', :password => '123')
|
|
|
|
|
|
|
|
assert_equal 'Wiki2', web.name
|
|
|
|
assert_equal 'wiki2', web.address
|
|
|
|
assert_equal '123', web.password
|
|
|
|
|
|
|
|
# new web should be set for maximum features enabled
|
|
|
|
assert_equal :textile, web.markup
|
|
|
|
assert_equal '008B26', web.color
|
|
|
|
assert !web.safe_mode?
|
|
|
|
assert_equal([], web.pages)
|
|
|
|
assert web.allow_uploads?
|
|
|
|
assert_nil web.additional_style
|
|
|
|
assert !web.published?
|
|
|
|
assert !web.brackets_only?
|
|
|
|
assert !web.count_pages?
|
|
|
|
assert_equal 100, web.max_upload_size
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_initialize_invalid_name
|
|
|
|
assert_raises(Instiki::ValidationError) {
|
|
|
|
Web.create(:name => 'Wiki2', :address => "wiki\234", :password => '123')
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_new_page_linked_from_mother_page
|
|
|
|
# this was a bug in revision 204
|
|
|
|
home = @web.add_page('HomePage', 'This page refers to AnotherPage',
|
2005-09-10 08:12:57 +02:00
|
|
|
Time.local(2004, 4, 4, 16, 50), 'Alexey Verkhovsky', test_renderer)
|
2005-08-15 21:17:32 +02:00
|
|
|
@web.add_page('AnotherPage', 'This is \AnotherPage',
|
2005-09-10 08:12:57 +02:00
|
|
|
Time.local(2004, 4, 4, 16, 51), 'Alexey Verkhovsky', test_renderer)
|
2005-08-15 21:17:32 +02:00
|
|
|
|
|
|
|
@web.pages(true)
|
|
|
|
assert_equal [home], @web.select.pages_that_link_to('AnotherPage')
|
|
|
|
end
|
2005-09-09 07:31:27 +02:00
|
|
|
|
2005-08-15 21:17:32 +02:00
|
|
|
def test_orphaned_pages
|
|
|
|
add_sample_pages
|
|
|
|
home = @web.add_page('HomePage',
|
|
|
|
'This is a home page, it should not be an orphan',
|
2005-09-10 08:12:57 +02:00
|
|
|
Time.local(2004, 4, 4, 16, 50), 'AlexeyVerkhovsky', test_renderer)
|
2005-08-15 21:17:32 +02:00
|
|
|
author = @web.add_page('AlexeyVerkhovsky',
|
|
|
|
'This is an author page, it should not be an orphan',
|
2005-09-10 08:12:57 +02:00
|
|
|
Time.local(2004, 4, 4, 16, 50), 'AlexeyVerkhovsky', test_renderer)
|
2005-08-15 21:17:32 +02:00
|
|
|
self_linked = @web.add_page('SelfLinked',
|
2005-09-11 10:05:19 +02:00
|
|
|
'I am SelfLinked and link to EverBeenInLove',
|
2005-09-10 08:12:57 +02:00
|
|
|
Time.local(2004, 4, 4, 16, 50), 'AnonymousCoward', test_renderer)
|
2005-08-15 21:17:32 +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
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def add_sample_pages
|
|
|
|
@in_love = @web.add_page('EverBeenInLove', 'Who am I me',
|
2005-09-10 08:12:57 +02:00
|
|
|
Time.local(2004, 4, 4, 16, 50), 'DavidHeinemeierHansson', test_renderer)
|
2005-08-15 21:17:32 +02:00
|
|
|
@hated = @web.add_page('EverBeenHated', 'I am me EverBeenHated',
|
2005-09-10 08:12:57 +02:00
|
|
|
Time.local(2004, 4, 4, 16, 51), 'DavidHeinemeierHansson', test_renderer)
|
2005-08-15 21:17:32 +02:00
|
|
|
end
|
|
|
|
end
|