require 'fileutils' require 'test/unit' INSTIKI_ROOT = File.expand_path(File.dirname(__FILE__) + "/../..") require(File.expand_path(File.dirname(__FILE__) + "/../../config/environment")) # Use instiki/../watir, if such a directory exists; This can be a CVS HEAD. # Otherwise Watir has to be installed in ruby/lib. $:.unshift INSTIKI_ROOT + '/../watir' if File.exists?(INSTIKI_ROOT + '/../watir/watir.rb') require 'watir' INSTIKI_PORT = 2501 HOME = "http://localhost:#{INSTIKI_PORT}" class E2EInstikiTest < Test::Unit::TestCase def startup @@instiki = InstikiController.start sleep 5 @@ie = Watir::IE.start(HOME) setup_web setup_home_page @@ie end def self.shutdown @@ie.close if defined? @@ie @@instiki.stop end def ie if defined? @@ie @@ie else startup end end def setup ie.goto HOME ie end # 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 enter_markup('HomePage', '[[Another Wiki Page]]') assert_equal '?', ie.link(:url, url(:show, 'Another+Wiki+Page')).text # Edit the first revision of a page enter_markup('Another+Wiki+Page', 'First revision of Another Wiki Page, linked from HomePage') # Check contents of the new page assert_equal url(:show, 'Another+Wiki+Page'), ie.url assert_match /First revision of Another Wiki Page, linked from Home Page/, ie.text assert_match /Linked from: HomePage/, ie.text # 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 } # Check also the "created on ... by ..." footnote assert_match Regexp.new('Created on ' + date_pattern + ' by Anonymous Coward\?'), ie.text end 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 enter_markup('TestEditPage', 'Test Edit Page, revision 1, altered') assert_match /Test Edit Page, revision 1, altered/, ie.text assert_match Regexp.new('Created on ' + date_pattern + ' by Anonymous Coward\?'), ie.text # revision by a named author enter_markup('TestEditPage', 'Test Edit Page, revision 2', 'Author') assert_match /Test Edit Page, revision 2/, ie.text assert_match Regexp.new('Revised on ' + date_pattern + ' by Author\?'), ie.text link_to_previous_revision = ie.link(:name, 'to_previous_revision') assert_equal url(:revision, 'TestEditPage', 0), link_to_previous_revision.href assert_equal 'Back in time', link_to_previous_revision.text assert_match /Edit \| Back in time \(1 revisions\) \| See changes/, ie.text # 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 end def test_0060_see_changes ie.goto url(:show, 'TestEditPage') assert ie.html.include?('
Test Edit Page, revision 22, rolled back