2005-01-20 01:05:23 +01:00
|
|
|
#!/bin/env ruby -w
|
2005-01-16 23:40:44 +01:00
|
|
|
|
|
|
|
require File.dirname(__FILE__) + '/../test_helper'
|
|
|
|
require 'web'
|
|
|
|
require 'page'
|
2005-01-15 21:26:54 +01:00
|
|
|
|
|
|
|
class MockWeb < Web
|
|
|
|
def initialize() super('test','test') end
|
|
|
|
def [](wiki_word) %w( MyWay ThatWay SmartEngine ).include?(wiki_word) end
|
|
|
|
def refresh_pages_with_references(name) end
|
|
|
|
end
|
|
|
|
|
|
|
|
class PageTest < Test::Unit::TestCase
|
2005-01-17 22:27:38 +01:00
|
|
|
|
2005-01-15 21:26:54 +01:00
|
|
|
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
|
|
|
|
|
2005-01-17 22:27:38 +01:00
|
|
|
def test_lock
|
2005-01-15 21:26:54 +01:00
|
|
|
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
|
|
|
|
|
2005-01-17 22:27:38 +01:00
|
|
|
def test_lock_duration
|
2005-01-15 21:26:54 +01:00
|
|
|
@page.lock(Time.local(2004, 4, 4, 16, 30), "DavidHeinemeierHansson")
|
|
|
|
|
|
|
|
assert_equal 15, @page.lock_duration(Time.local(2004, 4, 4, 16, 45))
|
|
|
|
end
|
|
|
|
|
2005-01-17 22:27:38 +01:00
|
|
|
def test_plain_name
|
|
|
|
assert_equal "First Page", @page.plain_name
|
2005-01-15 21:26:54 +01:00
|
|
|
end
|
2005-01-17 22:27:38 +01:00
|
|
|
|
|
|
|
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'
|
2005-01-15 21:26:54 +01:00
|
|
|
end
|
|
|
|
|
2005-01-17 22:27:38 +01:00
|
|
|
def test_revise_continous_revision
|
|
|
|
@page.revise('HisWay would be MyWay in kinda lame', Time.local(2004, 4, 4, 16, 55), 'MarianneSyhler')
|
2005-01-15 21:26:54 +01:00
|
|
|
assert_equal 2, @page.revisions.length
|
|
|
|
|
2005-01-17 22:27:38 +01:00
|
|
|
@page.revise('HisWay would be MyWay in kinda update', Time.local(2004, 4, 4, 16, 57), 'MarianneSyhler')
|
2005-01-15 21:26:54 +01:00
|
|
|
assert_equal 2, @page.revisions.length
|
2005-01-17 22:27:38 +01:00
|
|
|
assert_equal 'HisWay would be MyWay in kinda update', @page.revisions.last.content
|
2005-01-16 23:27:09 +01:00
|
|
|
assert_equal Time.local(2004, 4, 4, 16, 57), @page.revisions.last.created_at
|
2005-01-15 21:26:54 +01:00
|
|
|
|
2005-01-17 22:27:38 +01:00
|
|
|
@page.revise('HisWay would be MyWay in the house', Time.local(2004, 4, 4, 16, 58), 'DavidHeinemeierHansson')
|
2005-01-15 21:26:54 +01:00
|
|
|
assert_equal 3, @page.revisions.length
|
2005-01-17 22:27:38 +01:00
|
|
|
assert_equal 'HisWay would be MyWay in the house', @page.revisions.last.content
|
2005-01-15 21:26:54 +01:00
|
|
|
|
2005-01-17 22:27:38 +01:00
|
|
|
@page.revise('HisWay would be MyWay in my way', Time.local(2004, 4, 4, 17, 30), 'DavidHeinemeierHansson')
|
2005-01-15 21:26:54 +01:00
|
|
|
assert_equal 4, @page.revisions.length
|
|
|
|
end
|
2005-01-17 22:27:38 +01:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2005-01-15 21:26:54 +01:00
|
|
|
end
|