2005-05-06 04:40:52 +02:00
|
|
|
require 'fileutils'
|
2005-05-29 02:02:54 +02:00
|
|
|
require 'cgi'
|
2005-05-06 04:40:52 +02:00
|
|
|
require 'test/unit'
|
2005-05-29 20:39:56 +02:00
|
|
|
require 'rexml/document'
|
2005-05-06 04:40:52 +02:00
|
|
|
|
|
|
|
INSTIKI_ROOT = File.expand_path(File.dirname(__FILE__) + "/../..")
|
|
|
|
require(File.expand_path(File.dirname(__FILE__) + "/../../config/environment"))
|
|
|
|
|
2005-05-29 18:46:37 +02:00
|
|
|
# Use instiki/../watir, if such a directory exists; This can be a CVS HEAD version of Watir.
|
2005-05-18 00:27:26 +02:00
|
|
|
# Otherwise Watir has to be installed in ruby/lib.
|
|
|
|
$:.unshift INSTIKI_ROOT + '/../watir' if File.exists?(INSTIKI_ROOT + '/../watir/watir.rb')
|
|
|
|
require 'watir'
|
|
|
|
|
2005-05-06 04:40:52 +02:00
|
|
|
INSTIKI_PORT = 2501
|
|
|
|
HOME = "http://localhost:#{INSTIKI_PORT}"
|
|
|
|
|
|
|
|
class E2EInstikiTest < Test::Unit::TestCase
|
|
|
|
|
|
|
|
def startup
|
2005-05-10 15:22:29 +02:00
|
|
|
@@instiki = InstikiController.start
|
2005-05-06 04:40:52 +02:00
|
|
|
|
|
|
|
sleep 5
|
2005-05-06 05:18:14 +02:00
|
|
|
@@ie = Watir::IE.start(HOME)
|
2005-05-06 04:40:52 +02:00
|
|
|
|
|
|
|
setup_web
|
|
|
|
setup_home_page
|
2005-05-18 05:11:33 +02:00
|
|
|
|
2005-05-06 04:40:52 +02:00
|
|
|
@@ie
|
|
|
|
end
|
2005-05-18 05:11:33 +02:00
|
|
|
|
2005-05-06 04:40:52 +02:00
|
|
|
def self.shutdown
|
|
|
|
@@ie.close if defined? @@ie
|
2005-05-10 15:22:29 +02:00
|
|
|
@@instiki.stop
|
2005-05-06 04:40:52 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def ie
|
|
|
|
if defined? @@ie
|
|
|
|
@@ie
|
|
|
|
else
|
|
|
|
startup
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def setup
|
2005-05-18 00:27:26 +02:00
|
|
|
ie.goto HOME
|
2005-05-06 04:40:52 +02:00
|
|
|
ie
|
|
|
|
end
|
|
|
|
|
2005-05-18 00:27:26 +02:00
|
|
|
# Numbers like _00010_ determine the sequence in which the test cases are executed by Test::Unit
|
|
|
|
# Unfortunately, this sequence is important.
|
|
|
|
|
|
|
|
def test_00010_home_page_contents
|
|
|
|
check_main_menu
|
|
|
|
check_bottom_menu
|
|
|
|
check_footnote
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_00020_add_a_page
|
|
|
|
# Add reference to a non-existant wiki page
|
2005-05-18 03:53:59 +02:00
|
|
|
enter_markup('HomePage', '[[Another Wiki Page]]')
|
2005-05-29 02:02:54 +02:00
|
|
|
assert_equal '?', ie.link(:url, url(:show, 'Another Wiki Page')).text
|
2005-05-18 00:27:26 +02:00
|
|
|
|
|
|
|
# Edit the first revision of a page
|
2005-05-29 02:02:54 +02:00
|
|
|
enter_markup('Another Wiki Page', 'First revision of Another Wiki Page, linked from HomePage')
|
2005-05-18 00:27:26 +02:00
|
|
|
|
|
|
|
# Check contents of the new page
|
2005-05-29 02:02:54 +02:00
|
|
|
assert_equal url(:show, 'Another Wiki Page'), ie.url
|
2005-05-18 00:27:26 +02:00
|
|
|
assert_match /First revision of Another Wiki Page, linked from Home Page/, ie.text
|
2005-05-29 01:37:51 +02:00
|
|
|
assert_match /Linked from: Home Page/, ie.text
|
2005-05-18 00:27:26 +02:00
|
|
|
|
|
|
|
# There must be three links to HomePage - main menu, contents of the page and navigation bar
|
|
|
|
links_to_homepage = ie.links.to_a.select { |link| link.text == 'Home Page' }
|
|
|
|
assert_equal 3, links_to_homepage.size
|
|
|
|
links_to_homepage.each { |link| assert_equal url(:show, 'HomePage'), link.href }
|
2005-05-18 02:39:26 +02:00
|
|
|
|
|
|
|
# Check also the "created on ... by ..." footnote
|
|
|
|
assert_match Regexp.new('Created on ' + date_pattern + ' by Anonymous Coward\?'), ie.text
|
2005-05-06 04:40:52 +02:00
|
|
|
end
|
2005-05-18 03:53:59 +02:00
|
|
|
|
|
|
|
def test_00030_edit_page
|
|
|
|
enter_markup('TestEditPage', 'Test Edit Page, revision 1')
|
|
|
|
assert_match /Test Edit Page, revision 1/, ie.text
|
|
|
|
|
|
|
|
# subsequent revision by the anonymous author
|
2005-05-18 05:11:33 +02:00
|
|
|
enter_markup('TestEditPage', 'Test Edit Page, revision 1, altered')
|
|
|
|
assert_match /Test Edit Page, revision 1, altered/, ie.text
|
2005-05-18 03:53:59 +02:00
|
|
|
assert_match Regexp.new('Created on ' + date_pattern + ' by Anonymous Coward\?'), ie.text
|
|
|
|
|
|
|
|
# revision by a named author
|
2005-05-18 05:11:33 +02:00
|
|
|
enter_markup('TestEditPage', 'Test Edit Page, revision 2', 'Author')
|
|
|
|
assert_match /Test Edit Page, revision 2/, ie.text
|
2005-05-18 03:53:59 +02:00
|
|
|
assert_match Regexp.new('Revised on ' + date_pattern + ' by Author\?'), ie.text
|
|
|
|
|
|
|
|
link_to_previous_revision = ie.link(:name, 'to_previous_revision')
|
2005-05-18 05:11:33 +02:00
|
|
|
assert_equal url(:revision, 'TestEditPage', 0), link_to_previous_revision.href
|
2005-05-18 03:53:59 +02:00
|
|
|
assert_equal 'Back in time', link_to_previous_revision.text
|
|
|
|
assert_match /Edit \| Back in time \(1 revisions\) \| See changes/, ie.text
|
2005-05-18 05:11:33 +02:00
|
|
|
|
|
|
|
# another anonymous revision
|
|
|
|
enter_markup('TestEditPage', 'Test Edit Page, revision 3')
|
|
|
|
assert_match /Test Edit Page, revision 3/, ie.text
|
|
|
|
assert_match /Edit \| Back in time \(2 revisions\) \| See changes \| Hide changes /, ie.text
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_00040_traversing_revisions
|
|
|
|
ie.goto url(:revision, 'TestEditPage', 1)
|
|
|
|
assert_match /Test Edit Page, revision 2/, ie.text
|
|
|
|
assert_match(Regexp.new(
|
|
|
|
'Forward in time \(1 more\) \| Back in time \(1 more\) \| ' +
|
|
|
|
'See current \| See changes \| Hide changes \| Rollback'),
|
|
|
|
ie.text)
|
|
|
|
|
|
|
|
ie.link(:name, 'to_previous_revision').click
|
|
|
|
assert_match /Test Edit Page, revision 1, altered/, ie.text
|
|
|
|
assert_match /Forward in time \(2 more\) \| See current \| Rollback/, ie.text
|
|
|
|
|
|
|
|
ie.link(:name, 'to_next_revision').click
|
|
|
|
assert_match /Test Edit Page, revision 2/, ie.text
|
|
|
|
|
|
|
|
ie.link(:name, 'to_next_revision').click
|
|
|
|
assert_match /Test Edit Page, revision 3/, ie.text
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_00050_rollback
|
|
|
|
ie.goto url(:revision, 'TestEditPage', 1)
|
|
|
|
assert_match /Test Edit Page, revision 2/, ie.text
|
|
|
|
ie.link(:name, 'rollback').click
|
|
|
|
assert_equal url(:rollback, 'TestEditPage', 1), ie.url
|
|
|
|
assert_equal 'Test Edit Page, revision 2', ie.text_field(:name, 'content').value
|
|
|
|
|
|
|
|
ie.text_field(:name, 'content').set('Test Edit Page, revision 2, rolled back')
|
|
|
|
ie.button(:value, 'Update').click
|
|
|
|
|
|
|
|
assert_equal url(:show, 'TestEditPage'), ie.url
|
|
|
|
assert_match /Test Edit Page, revision 2, rolled back/, ie.text
|
2005-05-18 03:53:59 +02:00
|
|
|
end
|
2005-05-06 04:40:52 +02:00
|
|
|
|
2005-05-29 00:54:09 +02:00
|
|
|
def test_0060_see_changes
|
|
|
|
ie.goto url(:show, 'TestEditPage')
|
2005-05-29 02:02:54 +02:00
|
|
|
assert ie.html.include?('<P>Test Edit Page, revision <DEL class=diffmod>2</DEL>' +
|
|
|
|
'<INS class=diffmod>2, rolled back</INS></P>')
|
2005-05-29 00:54:09 +02:00
|
|
|
assert_match /Test Edit Page, revision 2, rolled back/, ie.text
|
|
|
|
|
|
|
|
ie.link(:text, 'See changes').click
|
|
|
|
|
|
|
|
assert_match /Showing changes from revision #1 to #2: Added \| Removed/, ie.text
|
|
|
|
assert_match /Test Edit Page, revision 22, rolled back/, ie.text
|
2005-05-29 01:37:51 +02:00
|
|
|
|
|
|
|
ie.link(:text, 'Hide changes').click
|
|
|
|
|
|
|
|
assert_match /Test Edit Page, revision 2, rolled back/, ie.text
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_0070_all_pages
|
2005-05-29 02:02:54 +02:00
|
|
|
# create a wanted page, and unlink Another Wiki Page from Home Page
|
|
|
|
# (to see that it doesn't show up in the orphans, regardless)
|
|
|
|
enter_markup('Another Wiki Page', 'Reference to a NonExistantPage')
|
|
|
|
|
2005-05-29 01:37:51 +02:00
|
|
|
ie.link(:text, 'All Pages').click
|
2005-05-29 02:02:54 +02:00
|
|
|
|
2005-05-29 01:37:51 +02:00
|
|
|
page_links = ie.links.map { |l| l.text }
|
2005-05-29 02:02:54 +02:00
|
|
|
expected_page_links = ['Another Wiki Page', 'Home Page', 'Test Edit Page', '?',
|
|
|
|
'Another Wiki Page', 'Test Edit Page']
|
|
|
|
assert_equal expected_page_links, page_links[-6..-1]
|
|
|
|
links_sequence = 'All Pages.*Another Wiki Page.*Home Page.*Test Edit Page.*' +
|
|
|
|
'Wanted Pages.*Non Existant Page\? wanted by Another Wiki Page.*'+
|
|
|
|
'Orphaned Pages.*Test Edit Page.*'
|
|
|
|
assert_match Regexp.new(links_sequence, Regexp::MULTILINE), ie.text
|
2005-05-29 01:37:51 +02:00
|
|
|
# and before that, we have the tail of the main menu
|
2005-05-29 02:02:54 +02:00
|
|
|
assert_equal 'Export', page_links[-7]
|
2005-05-29 01:37:51 +02:00
|
|
|
end
|
2005-05-29 02:13:09 +02:00
|
|
|
|
|
|
|
def test_0080_recently_revised
|
|
|
|
ie.link(:text, 'Recently Revised').click
|
2005-05-29 01:43:28 +02:00
|
|
|
|
2005-05-29 02:13:09 +02:00
|
|
|
links = ie.links.map { |l| l.text }
|
|
|
|
assert_equal ['Another Wiki Page', '?', 'Test Edit Page', '?', 'Home Page', '?'], links[-6..-1]
|
|
|
|
|
|
|
|
expected_text =
|
|
|
|
'Another Wiki Page.*by Anonymous Coward\?.*' +
|
|
|
|
'Test Edit Page.*by Anonymous Coward\?.*' +
|
|
|
|
'Home Page.*by Anonymous Coward\?.*'
|
|
|
|
assert_match Regexp.new(expected_text, Regexp::MULTILINE), ie.text
|
|
|
|
end
|
2005-05-29 16:12:46 +02:00
|
|
|
|
|
|
|
def test_0090_authors
|
|
|
|
# create a revision of TestEditPage, and a corresponding author page
|
|
|
|
enter_markup('TestEditPage', '3rd revision of this page', 'Another Author')
|
|
|
|
ie.link(:afterText, 'Another Author').click
|
|
|
|
assert_equal url(:new, 'Another Author'), ie.url
|
|
|
|
enter_markup('Another Author', 'Email me at another_author@foo.bar.com', 'Another Author')
|
|
|
|
|
|
|
|
ie.link(:text, 'Authors').click
|
|
|
|
|
|
|
|
expected_authors =
|
2005-05-29 16:18:05 +02:00
|
|
|
'Anonymous Coward\? co- or authored: Another Wiki Page, Home Page, Test Edit Page.*' +
|
|
|
|
'Another Author co- or authored: Another Author, Test Edit Page.*' +
|
2005-05-29 16:12:46 +02:00
|
|
|
'Author\? co- or authored: Test Edit Page'
|
|
|
|
assert_match Regexp.new(expected_authors, Regexp::MULTILINE), ie.text
|
|
|
|
|
|
|
|
ie.link(:text, 'Another Author').click
|
|
|
|
assert_equal url(:show, 'Another Author'), ie.url
|
2005-05-29 16:18:05 +02:00
|
|
|
ie.back
|
|
|
|
ie.link(:text, 'Test Edit Page').click
|
|
|
|
assert_equal url(:show, 'TestEditPage'), ie.url
|
2005-05-29 16:12:46 +02:00
|
|
|
end
|
2005-05-29 02:13:09 +02:00
|
|
|
|
2005-05-29 18:46:37 +02:00
|
|
|
def test_0100_feeds
|
|
|
|
ie.link(:text, 'Feeds').click
|
|
|
|
assert_equal url(:rss_with_content), ie.link(:text, 'Full content (RSS 2.0)').href
|
|
|
|
assert_equal url(:rss_with_headlines), ie.link(:text, 'Headlines (RSS 2.0)').href
|
|
|
|
|
|
|
|
ie.link(:text, 'Full content (RSS 2.0)').click
|
|
|
|
assert_nothing_raised { REXML::Document.new ie.text }
|
|
|
|
|
|
|
|
ie.back
|
|
|
|
ie.link(:text, 'Headlines (RSS 2.0)').click
|
|
|
|
assert_nothing_raised { REXML::Document.new ie.text }
|
|
|
|
end
|
|
|
|
|
2005-05-06 04:40:52 +02:00
|
|
|
private
|
2005-05-18 05:11:33 +02:00
|
|
|
|
2005-05-18 00:27:26 +02:00
|
|
|
def bp
|
|
|
|
require 'breakpoint'
|
|
|
|
breakpoint
|
|
|
|
end
|
2005-05-18 05:11:33 +02:00
|
|
|
|
2005-05-18 00:27:26 +02:00
|
|
|
def check_main_menu
|
|
|
|
assert_equal HOME + '/wiki/list', ie.link(:text, 'All Pages').href
|
|
|
|
assert_equal HOME + '/wiki/recently_revised', ie.link(:text, 'Recently Revised').href
|
|
|
|
assert_equal HOME + '/wiki/authors', ie.link(:text, 'Authors').href
|
|
|
|
assert_equal HOME + '/wiki/feeds', ie.link(:text, 'Feeds').href
|
|
|
|
assert_equal HOME + '/wiki/export', ie.link(:text, 'Export').href
|
|
|
|
end
|
2005-05-18 05:11:33 +02:00
|
|
|
|
2005-05-18 00:27:26 +02:00
|
|
|
def check_bottom_menu
|
|
|
|
assert_equal url(:edit, 'HomePage'), ie.link(:text, 'Edit Page').href
|
|
|
|
assert_equal HOME + '/wiki/edit_web', ie.link(:text, 'Edit Web').href
|
2005-05-18 03:53:59 +02:00
|
|
|
assert_equal url(:print, 'HomePage'), ie.link(:text, 'Print').href
|
2005-05-18 00:27:26 +02:00
|
|
|
end
|
2005-05-18 05:11:33 +02:00
|
|
|
|
2005-05-18 00:27:26 +02:00
|
|
|
def check_footnote
|
2005-05-18 02:39:26 +02:00
|
|
|
assert_match /This site is running on Instiki/, ie.text
|
2005-05-18 00:27:26 +02:00
|
|
|
assert_equal 'http://instiki.org/', ie.link(:text, 'Instiki').href
|
2005-05-18 02:39:26 +02:00
|
|
|
assert_match /Powered by Ruby on Rails/, ie.text
|
2005-05-18 00:27:26 +02:00
|
|
|
assert_equal 'http://rubyonrails.com/', ie.link(:text, 'Ruby on Rails').href
|
|
|
|
end
|
2005-05-18 03:53:59 +02:00
|
|
|
|
|
|
|
def date_pattern
|
|
|
|
'(January|February|March|April|May|June|July|August|September|October|November|December) ' +
|
|
|
|
'\d\d?, \d\d\d\d \d\d:\d\d'
|
|
|
|
end
|
2005-05-18 05:11:33 +02:00
|
|
|
|
2005-05-18 03:53:59 +02:00
|
|
|
def enter_markup(page, content, author = nil)
|
|
|
|
ie.goto url(:show, page)
|
|
|
|
if ie.url == url(:show, page)
|
|
|
|
ie.link(:name, 'edit').click
|
|
|
|
assert_equal url(:edit, page), ie.url
|
|
|
|
else
|
|
|
|
assert_equal url(:new, page), ie.url
|
|
|
|
end
|
|
|
|
|
|
|
|
ie.text_field(:name, 'content').set(content)
|
|
|
|
ie.text_field(:name, 'author').set(author || '')
|
|
|
|
ie.button(:value, 'Submit').click
|
|
|
|
|
|
|
|
assert_equal url(:show, page), ie.url
|
|
|
|
end
|
2005-05-18 05:11:33 +02:00
|
|
|
|
2005-05-06 04:40:52 +02:00
|
|
|
def setup_web
|
|
|
|
assert_equal 'Wiki', ie.textField(:name, 'web_name').value
|
|
|
|
assert_equal 'wiki', ie.textField(:name, 'web_address').value
|
|
|
|
assert_equal '', ie.textField(:name, 'password').value
|
|
|
|
assert_equal '', ie.textField(:name, 'password_check').value
|
|
|
|
|
|
|
|
ie.textField(:name, 'password').set('123')
|
|
|
|
ie.textField(:name, 'password_check').set('123')
|
|
|
|
ie.button(:value, 'Setup').click
|
2005-05-18 00:27:26 +02:00
|
|
|
assert_equal url(:new, 'HomePage'), ie.url
|
2005-05-06 04:40:52 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def setup_home_page
|
|
|
|
ie.textField(:name, 'content').set('Homepage of a test wiki')
|
|
|
|
ie.button(:value, 'Submit').click
|
2005-05-18 00:27:26 +02:00
|
|
|
assert_equal url(:show, 'HomePage'), ie.url
|
2005-05-06 04:40:52 +02:00
|
|
|
end
|
|
|
|
|
2005-05-18 05:11:33 +02:00
|
|
|
def url(operation, page_name = nil, revision = nil)
|
2005-05-29 18:46:37 +02:00
|
|
|
page_name = CGI.escape(page_name) if page_name
|
2005-05-18 00:27:26 +02:00
|
|
|
case operation
|
2005-05-18 05:11:33 +02:00
|
|
|
when :edit, :new, :show, :print, :revision, :rollback
|
|
|
|
"#{HOME}/wiki/#{operation}/#{page_name}" + (revision ? "?rev=#{revision}" : '')
|
2005-05-29 18:46:37 +02:00
|
|
|
when :rss_with_content, :rss_with_headlines
|
|
|
|
"#{HOME}/wiki/#{operation}"
|
2005-05-18 00:27:26 +02:00
|
|
|
else
|
|
|
|
raise "Unsupported operation: '#{operation}"
|
|
|
|
end
|
2005-05-06 04:40:52 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2005-05-10 15:22:29 +02:00
|
|
|
class InstikiController
|
|
|
|
|
|
|
|
attr_reader :process_id
|
|
|
|
|
|
|
|
def self.start
|
|
|
|
startup_info = [68].pack('lx64')
|
|
|
|
process_info = [0, 0, 0, 0].pack('llll')
|
2005-05-18 05:11:33 +02:00
|
|
|
|
2005-05-10 15:22:29 +02:00
|
|
|
startup_command =
|
|
|
|
"ruby #{RAILS_ROOT}/instiki.rb --storage #{prepare_storage} " +
|
|
|
|
" --port #{INSTIKI_PORT} --environment development"
|
2005-05-18 05:11:33 +02:00
|
|
|
|
2005-05-10 15:22:29 +02:00
|
|
|
result = Win32API.new('kernel32.dll', 'CreateProcess', 'pplllllppp', 'L').call(
|
|
|
|
nil,
|
|
|
|
startup_command,
|
|
|
|
0, 0, 1, 0, 0, '.', startup_info, process_info)
|
2005-05-18 05:11:33 +02:00
|
|
|
|
2005-05-10 15:22:29 +02:00
|
|
|
# TODO print the error code, or better yet a text message
|
|
|
|
raise "Failed to start Instiki." if result == 0
|
|
|
|
|
|
|
|
process_id = process_info.unpack('llll')[2]
|
|
|
|
return self.new(process_id)
|
|
|
|
end
|
2005-05-18 05:11:33 +02:00
|
|
|
|
2005-05-10 15:22:29 +02:00
|
|
|
def self.prepare_storage
|
|
|
|
storage_path = INSTIKI_ROOT + '/storage/e2e'
|
|
|
|
FileUtils.rm_rf(storage_path) if File.exists? storage_path
|
|
|
|
FileUtils.mkdir_p(storage_path)
|
|
|
|
storage_path
|
|
|
|
end
|
2005-05-18 05:11:33 +02:00
|
|
|
|
2005-05-10 15:22:29 +02:00
|
|
|
def initialize(pid)
|
|
|
|
@process_id = pid
|
|
|
|
end
|
|
|
|
|
|
|
|
def stop
|
|
|
|
right_to_terminate_process = 1
|
|
|
|
handle = Win32API.new('kernel32.dll', 'OpenProcess', 'lil', 'l').call(
|
|
|
|
right_to_terminate_process, 0, @process_id)
|
|
|
|
Win32API.new('kernel32.dll', 'TerminateProcess', 'll', 'L').call(handle, 0)
|
|
|
|
end
|
2005-05-18 05:11:33 +02:00
|
|
|
|
2005-05-10 15:22:29 +02:00
|
|
|
end
|
|
|
|
|
2005-05-06 04:40:52 +02:00
|
|
|
begin
|
|
|
|
require 'test/unit/ui/console/testrunner'
|
|
|
|
Test::Unit::UI::Console::TestRunner.new(E2EInstikiTest.suite).start
|
|
|
|
rescue => e
|
|
|
|
$stderr.puts 'Unhandled error during test execution'
|
|
|
|
$stderr.puts e.message
|
|
|
|
$stderr.puts e.backtrace
|
|
|
|
ensure
|
|
|
|
begin
|
|
|
|
E2EInstikiTest::shutdown
|
|
|
|
rescue => e
|
|
|
|
$stderr.puts 'Error during shutdown'
|
|
|
|
$stderr.puts e.message
|
|
|
|
$stderr.puts e.backtrace
|
|
|
|
end
|
|
|
|
end
|