moved old test stuff
This commit is contained in:
parent
64b9a5c747
commit
8c331d1019
13 changed files with 0 additions and 856 deletions
BIN
test/fixtures/rails.gif
vendored
Executable file
BIN
test/fixtures/rails.gif
vendored
Executable file
Binary file not shown.
After Width: | Height: | Size: 8.3 KiB |
228
test/functional/admin_controller_test.rb
Normal file
228
test/functional/admin_controller_test.rb
Normal file
|
@ -0,0 +1,228 @@
|
|||
#!/bin/env ruby -w
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
require 'admin_controller'
|
||||
|
||||
# Raise errors beyond the default web-based presentation
|
||||
class AdminController; def rescue_action(e) logger.error(e); raise e end; end
|
||||
|
||||
class AdminControllerTest < Test::Unit::TestCase
|
||||
|
||||
def setup
|
||||
setup_test_wiki
|
||||
setup_controller_test
|
||||
end
|
||||
|
||||
def tear_down
|
||||
tear_down_wiki
|
||||
end
|
||||
|
||||
|
||||
def test_create_system_form_displayed
|
||||
ApplicationController.wiki = WikiServiceWithNoPersistence.new
|
||||
process('create_system')
|
||||
assert_success
|
||||
end
|
||||
|
||||
def test_create_system_form_submitted
|
||||
ApplicationController.wiki = WikiServiceWithNoPersistence.new
|
||||
assert !ApplicationController.wiki.setup?
|
||||
|
||||
process('create_system', 'password' => 'a_password', 'web_name' => 'My Wiki',
|
||||
'web_address' => 'my_wiki')
|
||||
|
||||
assert_redirected_to :web => 'my_wiki', :controller => 'wiki', :action => 'new',
|
||||
:id => 'HomePage'
|
||||
assert ApplicationController.wiki.setup?
|
||||
assert_equal 'a_password', ApplicationController.wiki.system[:password]
|
||||
assert_equal 1, ApplicationController.wiki.webs.size
|
||||
new_web = ApplicationController.wiki.webs['my_wiki']
|
||||
assert_equal 'My Wiki', new_web.name
|
||||
assert_equal 'my_wiki', new_web.address
|
||||
end
|
||||
|
||||
def test_create_system_form_submitted_and_wiki_already_initialized
|
||||
wiki_before = ApplicationController.wiki
|
||||
assert ApplicationController.wiki.setup?
|
||||
|
||||
process 'create_system', 'password' => 'a_password', 'web_name' => 'My Wiki',
|
||||
'web_address' => 'my_wiki'
|
||||
|
||||
assert_redirected_to :web => 'wiki1', :action => 'show', :id => 'HomePage'
|
||||
assert_equal wiki_before, ApplicationController.wiki
|
||||
# and no new web should be created either
|
||||
assert_equal 1, ApplicationController.wiki.webs.size
|
||||
assert_flash_has :error
|
||||
end
|
||||
|
||||
def test_create_system_no_form_and_wiki_already_initialized
|
||||
assert @wiki.setup?
|
||||
process('create_system')
|
||||
assert_redirected_to :web => 'wiki1', :action => 'show', :id => 'HomePage'
|
||||
assert_flash_has :error
|
||||
end
|
||||
|
||||
|
||||
def test_create_web
|
||||
@wiki.system[:password] = 'pswd'
|
||||
|
||||
process 'create_web', 'system_password' => 'pswd', 'name' => 'Wiki Two', 'address' => 'wiki2'
|
||||
|
||||
assert_redirected_to :web => 'wiki2', :action => 'new', :id => 'HomePage'
|
||||
wiki2 = @wiki.webs['wiki2']
|
||||
assert wiki2
|
||||
assert_equal 'Wiki Two', wiki2.name
|
||||
assert_equal 'wiki2', wiki2.address
|
||||
end
|
||||
|
||||
def test_create_web_default_password
|
||||
@wiki.system[:password] = nil
|
||||
|
||||
process 'create_web', 'system_password' => 'instiki', 'name' => 'Wiki Two', 'address' => 'wiki2'
|
||||
|
||||
assert_redirected_to :web => 'wiki2', :action => 'new', :id => 'HomePage'
|
||||
end
|
||||
|
||||
def test_create_web_failed_authentication
|
||||
@wiki.system[:password] = 'pswd'
|
||||
|
||||
process 'create_web', 'system_password' => 'wrong', 'name' => 'Wiki Two', 'address' => 'wiki2'
|
||||
|
||||
assert_redirected_to :web => nil, :action => 'index'
|
||||
assert_nil @wiki.webs['wiki2']
|
||||
end
|
||||
|
||||
def test_create_web_no_form_submitted
|
||||
@wiki.system[:password] = 'pswd'
|
||||
process 'create_web'
|
||||
assert_success
|
||||
end
|
||||
|
||||
|
||||
def test_edit_web_no_form
|
||||
process 'edit_web', 'web' => 'wiki1'
|
||||
# this action simply renders a form
|
||||
assert_success
|
||||
end
|
||||
|
||||
def test_edit_web_form_submitted
|
||||
@wiki.system[:password] = 'pswd'
|
||||
|
||||
process('edit_web', 'system_password' => 'pswd',
|
||||
'web' => 'wiki1', 'address' => 'renamed_wiki1', 'name' => 'Renamed Wiki1',
|
||||
'markup' => 'markdown', 'color' => 'blue', 'additional_style' => 'whatever',
|
||||
'safe_mode' => 'on', 'password' => 'new_password', 'published' => 'on',
|
||||
'brackets_only' => 'on', 'count_pages' => 'on', 'allow_uploads' => 'on',
|
||||
'max_upload_size' => '300')
|
||||
|
||||
assert_redirected_to :web => 'renamed_wiki1', :action => 'show', :id => 'HomePage'
|
||||
assert_equal 'renamed_wiki1', @web.address
|
||||
assert_equal 'Renamed Wiki1', @web.name
|
||||
assert_equal :markdown, @web.markup
|
||||
assert_equal 'blue', @web.color
|
||||
assert @web.safe_mode
|
||||
assert_equal 'new_password', @web.password
|
||||
assert @web.published
|
||||
assert @web.brackets_only
|
||||
assert @web.count_pages
|
||||
assert @web.allow_uploads
|
||||
assert_equal 300, @web.max_upload_size
|
||||
end
|
||||
|
||||
def test_edit_web_opposite_values
|
||||
@wiki.system[:password] = 'pswd'
|
||||
|
||||
process('edit_web', 'system_password' => 'pswd',
|
||||
'web' => 'wiki1', 'address' => 'renamed_wiki1', 'name' => 'Renamed Wiki1',
|
||||
'markup' => 'markdown', 'color' => 'blue', 'additional_style' => 'whatever',
|
||||
'password' => 'new_password')
|
||||
# safe_mode, published, brackets_only, count_pages, allow_uploads not set
|
||||
# and should become false
|
||||
|
||||
assert_redirected_to :web => 'renamed_wiki1', :action => 'show', :id => 'HomePage'
|
||||
assert !@web.safe_mode
|
||||
assert !@web.published
|
||||
assert !@web.brackets_only
|
||||
assert !@web.count_pages
|
||||
assert !@web.allow_uploads
|
||||
end
|
||||
|
||||
def test_edit_web_wrong_password
|
||||
process('edit_web', 'system_password' => 'wrong',
|
||||
'web' => 'wiki1', 'address' => 'renamed_wiki1', 'name' => 'Renamed Wiki1',
|
||||
'markup' => 'markdown', 'color' => 'blue', 'additional_style' => 'whatever',
|
||||
'password' => 'new_password')
|
||||
|
||||
#returns to the same form
|
||||
assert_success
|
||||
assert @response.has_template_object?('error')
|
||||
end
|
||||
|
||||
def test_edit_web_rename_to_already_existing_web_name
|
||||
@wiki.system[:password] = 'pswd'
|
||||
|
||||
@wiki.create_web('Another', 'another')
|
||||
process('edit_web', 'system_password' => 'pswd',
|
||||
'web' => 'wiki1', 'address' => 'another', 'name' => 'Renamed Wiki1',
|
||||
'markup' => 'markdown', 'color' => 'blue', 'additional_style' => 'whatever',
|
||||
'password' => 'new_password')
|
||||
|
||||
#returns to the same form
|
||||
assert_success
|
||||
assert @response.has_template_object?('error')
|
||||
end
|
||||
|
||||
def test_edit_web_empty_password
|
||||
process('edit_web', 'system_password' => '',
|
||||
'web' => 'wiki1', 'address' => 'renamed_wiki1', 'name' => 'Renamed Wiki1',
|
||||
'markup' => 'markdown', 'color' => 'blue', 'additional_style' => 'whatever',
|
||||
'password' => 'new_password')
|
||||
|
||||
#returns to the same form
|
||||
assert_success
|
||||
assert @response.has_template_object?('error')
|
||||
end
|
||||
|
||||
|
||||
def test_remove_orphaned_pages
|
||||
setup_wiki_with_three_pages
|
||||
@wiki.system[:password] = 'pswd'
|
||||
orhan_page_linking_to_oak = @wiki.write_page('wiki1', 'Pine',
|
||||
"Refers to [[Oak]].\n" +
|
||||
"category: trees",
|
||||
Time.now, Author.new('TreeHugger', '127.0.0.2'))
|
||||
|
||||
r = process('remove_orphaned_pages', 'web' => 'wiki1', 'system_password_orphaned' => 'pswd')
|
||||
|
||||
assert_redirected_to :controller => 'wiki', :web => 'wiki1', :action => 'list'
|
||||
assert_equal [@home, @oak], @web.select.sort,
|
||||
"Pages are not as expected: #{@web.select.sort.map {|p| p.name}.inspect}"
|
||||
|
||||
|
||||
# Oak is now orphan, second pass should remove it
|
||||
r = process('remove_orphaned_pages', 'web' => 'wiki1', 'system_password_orphaned' => 'pswd')
|
||||
assert_redirected_to :controller => 'wiki', :web => 'wiki1', :action => 'list'
|
||||
assert_equal [@home], @web.select.sort,
|
||||
"Pages are not as expected: #{@web.select.sort.map {|p| p.name}.inspect}"
|
||||
|
||||
# third pass does not destroy HomePage
|
||||
r = process('remove_orphaned_pages', 'web' => 'wiki1', 'system_password_orphaned' => 'pswd')
|
||||
assert_redirected_to :action => 'list'
|
||||
assert_equal [@home], @web.select.sort,
|
||||
"Pages are not as expected: #{@web.select.sort.map {|p| p.name}.inspect}"
|
||||
end
|
||||
|
||||
def test_remove_orphaned_pages_empty_or_wrong_password
|
||||
setup_wiki_with_three_pages
|
||||
@wiki.system[:password] = 'pswd'
|
||||
|
||||
process('remove_orphaned_pages', 'web' => 'wiki1')
|
||||
assert_redirected_to(:controller => 'admin', :action => 'edit_web', :web => 'wiki1')
|
||||
assert @response.flash[:error]
|
||||
|
||||
process('remove_orphaned_pages', 'web' => 'wiki1', 'system_password_orphaned' => 'wrong')
|
||||
assert_redirected_to(:controller => 'admin', :action => 'edit_web', :web => 'wiki1')
|
||||
assert @response.flash[:error]
|
||||
end
|
||||
|
||||
end
|
31
test/functional/application_test.rb
Executable file
31
test/functional/application_test.rb
Executable file
|
@ -0,0 +1,31 @@
|
|||
# Unit tests for ApplicationController (the abstract controller class)
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
require 'wiki_controller'
|
||||
require 'rexml/document'
|
||||
|
||||
# Need some concrete class to test the abstract class features
|
||||
class WikiController; def rescue_action(e) logger.error(e); raise e end; end
|
||||
|
||||
class ApplicationTest < Test::Unit::TestCase
|
||||
|
||||
def setup
|
||||
setup_test_wiki
|
||||
setup_controller_test(WikiController)
|
||||
end
|
||||
|
||||
def tear_down
|
||||
tear_down_wiki
|
||||
end
|
||||
|
||||
def test_utf8_header
|
||||
r = process('show', 'web' => 'wiki1', 'id' => 'HomePage')
|
||||
assert_equal 'text/html; charset=UTF-8', r.headers['Content-Type']
|
||||
end
|
||||
|
||||
def test_connect_to_model_unknown_wiki
|
||||
r = process('show', 'web' => 'unknown_wiki', 'id' => 'HomePage')
|
||||
assert_equal 404, r.response_code
|
||||
end
|
||||
|
||||
end
|
127
test/functional/file_controller_test.rb
Executable file
127
test/functional/file_controller_test.rb
Executable file
|
@ -0,0 +1,127 @@
|
|||
#!/bin/env ruby -w
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
require 'file_controller'
|
||||
require 'fileutils'
|
||||
|
||||
# Raise errors beyond the default web-based presentation
|
||||
class FileController; def rescue_action(e) logger.error(e); raise e end; end
|
||||
|
||||
class FileControllerTest < Test::Unit::TestCase
|
||||
|
||||
FILE_AREA = RAILS_ROOT + '/storage/test/wiki1'
|
||||
FileUtils.mkdir_p(FILE_AREA) unless File.directory?(FILE_AREA)
|
||||
FileUtils.rm(Dir["#{FILE_AREA}/*"])
|
||||
|
||||
def setup
|
||||
setup_test_wiki
|
||||
setup_controller_test
|
||||
end
|
||||
|
||||
def tear_down
|
||||
tear_down_wiki
|
||||
end
|
||||
|
||||
def test_file
|
||||
process 'file', 'web' => 'wiki1', 'id' => 'foo.tgz'
|
||||
|
||||
assert_success
|
||||
assert_rendered_file 'file/file'
|
||||
end
|
||||
|
||||
def test_file_download_text_file
|
||||
File.open("#{FILE_AREA}/foo.txt", 'wb') { |f| f.write "aaa\nbbb\n" }
|
||||
|
||||
r = process 'file', 'web' => 'wiki1', 'id' => 'foo.txt'
|
||||
|
||||
assert_success
|
||||
assert_equal "aaa\nbbb\n", r.binary_content
|
||||
assert_equal 'text/plain', r.headers['Content-Type']
|
||||
end
|
||||
|
||||
def test_file_download_pdf_file
|
||||
File.open("#{FILE_AREA}/foo.pdf", 'wb') { |f| f.write "aaa\nbbb\n" }
|
||||
|
||||
r = process 'file', 'web' => 'wiki1', 'id' => 'foo.pdf'
|
||||
|
||||
assert_success
|
||||
assert_equal "aaa\nbbb\n", r.binary_content
|
||||
assert_equal 'application/pdf', r.headers['Content-Type']
|
||||
end
|
||||
|
||||
def test_pic_download_gif
|
||||
FileUtils.cp("#{RAILS_ROOT}/test/fixtures/rails.gif", FILE_AREA)
|
||||
|
||||
r = process 'pic', 'web' => 'wiki1', 'id' => 'rails.gif'
|
||||
|
||||
assert_success
|
||||
assert_equal File.size("#{FILE_AREA}/rails.gif"), r.binary_content.size
|
||||
end
|
||||
|
||||
def test_pic_unknown_pic
|
||||
r = process 'pic', 'web' => 'wiki1', 'id' => 'non-existant.gif'
|
||||
|
||||
assert_success
|
||||
assert_rendered_file 'file/file'
|
||||
end
|
||||
|
||||
def test_pic_upload_end_to_end
|
||||
# edit and re-render home page so that it has an "unknown file" link to 'rails-e2e.gif'
|
||||
@wiki.revise_page('wiki1', 'HomePage', '[[rails-e2e.gif:pic]]', Time.now, 'AnonymousBrave')
|
||||
assert_equal "<p><span class=\"newWikiWord\">rails-e2e.gif<a href=\"../pic/rails-e2e.gif\">" +
|
||||
"?</a></span></p>",
|
||||
@home.display_content
|
||||
|
||||
# rails-e2e.gif is unknown to the system, so pic action goes to the file [upload] form
|
||||
r = process 'pic', 'web' => 'wiki1', 'id' => 'rails-e2e.gif'
|
||||
assert_success
|
||||
assert_rendered_file 'file/file'
|
||||
|
||||
# User uploads the picture
|
||||
picture = File.read("#{RAILS_ROOT}/test/fixtures/rails.gif")
|
||||
r = process 'pic', 'web' => 'wiki1', 'id' => 'rails-e2e.gif', 'file' => StringIO.new(picture)
|
||||
assert_redirect_url '/'
|
||||
assert @wiki.file_yard(@web).has_file?('rails-e2e.gif')
|
||||
assert_equal(picture, File.read("#{RAILS_ROOT}/storage/test/wiki1/rails-e2e.gif"))
|
||||
|
||||
# this should refresh the page display content (cached)
|
||||
assert_equal "<p><img alt=\"rails-e2e.gif\" src=\"../pic/rails-e2e.gif\" /></p>",
|
||||
@home.display_content
|
||||
end
|
||||
|
||||
def test_pic_upload_end_to_end
|
||||
# edit and re-render home page so that it has an "unknown file" link to 'rails-e2e.gif'
|
||||
@wiki.revise_page('wiki1', 'HomePage', '[[instiki-e2e.txt:file]]', Time.now, 'AnonymousBrave')
|
||||
assert_equal "<p><span class=\"newWikiWord\">instiki-e2e.txt" +
|
||||
"<a href=\"../file/instiki-e2e.txt\">?</a></span></p>",
|
||||
@home.display_content
|
||||
|
||||
# rails-e2e.gif is unknown to the system, so pic action goes to the file [upload] form
|
||||
r = process 'file', 'web' => 'wiki1', 'id' => 'instiki-e2e.txt'
|
||||
assert_success
|
||||
assert_rendered_file 'file/file'
|
||||
|
||||
# User uploads the picture
|
||||
file = "abcdefgh\n123"
|
||||
r = process 'file', 'web' => 'wiki1', 'id' => 'instiki-e2e.txt', 'file' => StringIO.new(file)
|
||||
assert_redirected_to :controller => 'wiki', :action => 'show', :web => 'wiki1', :id => 'HomePage'
|
||||
assert @wiki.file_yard(@web).has_file?('instiki-e2e.txt')
|
||||
assert_equal(file, File.read("#{RAILS_ROOT}/storage/test/wiki1/instiki-e2e.txt"))
|
||||
|
||||
# this should refresh the page display content (cached)
|
||||
assert_equal "<p><a class=\"existingWikiWord\" href=\"../file/instiki-e2e.txt\">" +
|
||||
"instiki-e2e.txt</a></p>",
|
||||
@home.display_content
|
||||
end
|
||||
|
||||
def test_uploads_blocking
|
||||
@web.allow_uploads = true
|
||||
r = process 'file', 'web' => 'wiki1', 'id' => 'filename'
|
||||
assert_success
|
||||
|
||||
@web.allow_uploads = false
|
||||
r = process 'file', 'web' => 'wiki1', 'id' => 'filename'
|
||||
assert_equal '403 Forbidden', r.headers['Status']
|
||||
end
|
||||
|
||||
end
|
666
test/functional/wiki_controller_test.rb
Executable file
666
test/functional/wiki_controller_test.rb
Executable file
|
@ -0,0 +1,666 @@
|
|||
#!/bin/env ruby -w
|
||||
|
||||
# Uncomment the line below to enable pdflatex tests; don't forget to comment them again
|
||||
# commiting to SVN
|
||||
# $INSTIKI_TEST_PDFLATEX = true
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
require 'wiki_controller'
|
||||
require 'rexml/document'
|
||||
require 'tempfile'
|
||||
require 'zip/zipfilesystem'
|
||||
|
||||
# Raise errors beyond the default web-based presentation
|
||||
class WikiController; def rescue_action(e) logger.error(e); raise e end; end
|
||||
|
||||
class WikiControllerTest < Test::Unit::TestCase
|
||||
|
||||
def setup
|
||||
setup_test_wiki
|
||||
setup_controller_test
|
||||
end
|
||||
|
||||
def tear_down
|
||||
tear_down_wiki
|
||||
end
|
||||
|
||||
|
||||
def test_authenticate
|
||||
@web.password = 'pswd'
|
||||
|
||||
r = process('authenticate', 'web' => 'wiki1', 'password' => 'pswd')
|
||||
assert_redirected_to :web => 'wiki1', :action => 'show', :id => 'HomePage'
|
||||
assert_equal ['pswd'], r.cookies['web_address']
|
||||
end
|
||||
|
||||
def test_authenticate_wrong_password
|
||||
@web.password = 'pswd'
|
||||
|
||||
r = process('authenticate', 'web' => 'wiki1', 'password' => 'wrong password')
|
||||
assert_redirected_to :action => 'login', :web => 'wiki1'
|
||||
assert_nil r.cookies['web_address']
|
||||
end
|
||||
|
||||
|
||||
def test_authors
|
||||
setup_wiki_with_three_pages
|
||||
@wiki.write_page('wiki1', 'BreakSortingOrder',
|
||||
"This page breaks the accidentally correct sorting order of authors",
|
||||
Time.now, Author.new('BreakingTheOrder', '127.0.0.2'))
|
||||
|
||||
r = process('authors', 'web' => 'wiki1')
|
||||
|
||||
assert_success
|
||||
assert_equal ['AnAuthor', 'BreakingTheOrder', 'Guest', 'TreeHugger'],
|
||||
r.template_objects['authors']
|
||||
end
|
||||
|
||||
|
||||
def test_cancel_edit
|
||||
setup_wiki_with_three_pages
|
||||
@oak.lock(Time.now, 'Locky')
|
||||
assert @oak.locked?(Time.now)
|
||||
|
||||
r = process('cancel_edit', 'web' => 'wiki1', 'id' => 'Oak')
|
||||
|
||||
assert_redirected_to :action => 'show', :id => 'Oak'
|
||||
assert !@oak.locked?(Time.now)
|
||||
end
|
||||
|
||||
|
||||
def test_edit
|
||||
r = process 'edit', 'web' => 'wiki1', 'id' => 'HomePage'
|
||||
assert_success
|
||||
assert_equal @wiki.read_page('wiki1', 'HomePage'), r.template_objects['page']
|
||||
end
|
||||
|
||||
def test_edit_page_locked_page
|
||||
@home.lock(Time.now, 'Locky')
|
||||
process 'edit', 'web' => 'wiki1', 'id' => 'HomePage'
|
||||
assert_redirected_to :action => 'locked'
|
||||
end
|
||||
|
||||
def test_edit_page_break_lock
|
||||
@home.lock(Time.now, 'Locky')
|
||||
process 'edit', 'web' => 'wiki1', 'id' => 'HomePage', 'break_lock' => 'y'
|
||||
assert_success
|
||||
assert @home.locked?(Time.now)
|
||||
end
|
||||
|
||||
def test_edit_unknown_page
|
||||
process 'edit', 'web' => 'wiki1', 'id' => 'UnknownPage', 'break_lock' => 'y'
|
||||
assert_redirected_to :controller => 'wiki', :action => 'show', :web => 'wiki1',
|
||||
:id => 'HomePage'
|
||||
end
|
||||
|
||||
def test_edit_page_with_special_symbols
|
||||
@wiki.write_page('wiki1', 'With : Special /> symbols',
|
||||
'This page has special symbols in the name',
|
||||
Time.now, Author.new('Special', '127.0.0.3'))
|
||||
|
||||
r = process 'edit', 'web' => 'wiki1', 'id' => 'With : Special /> symbols'
|
||||
assert_success
|
||||
xml = REXML::Document.new(r.body)
|
||||
form = REXML::XPath.first(xml, '//form')
|
||||
assert_equal '/wiki1/save/With+%3A+Special+%2F%3E+symbols', form.attributes['action']
|
||||
end
|
||||
|
||||
|
||||
def test_export_html
|
||||
setup_wiki_with_three_pages
|
||||
|
||||
r = process 'export_html', 'web' => 'wiki1'
|
||||
|
||||
assert_success
|
||||
assert_equal 'application/zip', r.headers['Content-Type']
|
||||
assert_match /attachment; filename="wiki1-html-\d\d\d\d-\d\d-\d\d-\d\d-\d\d-\d\d.zip"/,
|
||||
r.headers['Content-Disposition']
|
||||
content = r.binary_content
|
||||
assert_equal 'PK', content[0..1], 'Content is not a zip file'
|
||||
assert_equal :export, r.template_objects['link_mode']
|
||||
|
||||
# Tempfile doesn't know how to open files with binary flag, hence the two-step process
|
||||
Tempfile.open('instiki_export_file') { |f| @tempfile_path = f.path }
|
||||
begin
|
||||
File.open(@tempfile_path, 'wb') { |f| f.write(content); @exported_file = f.path }
|
||||
Zip::ZipFile.open(@exported_file) do |zip|
|
||||
assert_equal %w(Elephant.html HomePage.html Oak.html index.html), zip.dir.entries('.').sort
|
||||
assert_match /.*<html .*All about elephants.*<\/html>/,
|
||||
zip.file.read('Elephant.html').gsub(/\s+/, ' ')
|
||||
assert_match /.*<html .*All about oak.*<\/html>/,
|
||||
zip.file.read('Oak.html').gsub(/\s+/, ' ')
|
||||
assert_match /.*<html .*First revision of the.*HomePage.*end.*<\/html>/,
|
||||
zip.file.read('HomePage.html').gsub(/\s+/, ' ')
|
||||
assert_equal '<html><head><META HTTP-EQUIV="Refresh" CONTENT="0;URL=HomePage.html"></head></html> ', zip.file.read('index.html').gsub(/\s+/, ' ')
|
||||
end
|
||||
ensure
|
||||
File.delete(@tempfile_path) if File.exist?(@tempfile_path)
|
||||
end
|
||||
end
|
||||
|
||||
def test_export_html_no_layout
|
||||
setup_wiki_with_three_pages
|
||||
|
||||
r = process 'export_html', 'web' => 'wiki1', 'layout' => 'no'
|
||||
|
||||
assert_success
|
||||
assert_equal 'application/zip', r.headers['Content-Type']
|
||||
assert_match /attachment; filename="wiki1-html-\d\d\d\d-\d\d-\d\d-\d\d-\d\d-\d\d.zip"/,
|
||||
r.headers['Content-Disposition']
|
||||
content = r.binary_content
|
||||
assert_equal 'PK', content[0..1], 'Content is not a zip file'
|
||||
assert_equal :export, r.template_objects['link_mode']
|
||||
end
|
||||
|
||||
def test_export_markup
|
||||
r = process 'export_markup', 'web' => 'wiki1'
|
||||
|
||||
assert_success
|
||||
assert_equal 'application/zip', r.headers['Content-Type']
|
||||
assert_match /attachment; filename="wiki1-textile-\d\d\d\d-\d\d-\d\d-\d\d-\d\d-\d\d.zip"/,
|
||||
r.headers['Content-Disposition']
|
||||
content = r.binary_content
|
||||
assert_equal 'PK', content[0..1], 'Content is not a zip file'
|
||||
end
|
||||
|
||||
|
||||
if ENV['INSTIKI_TEST_LATEX'] or defined? $INSTIKI_TEST_PDFLATEX
|
||||
|
||||
def test_export_pdf
|
||||
r = process 'export_pdf', 'web' => 'wiki1'
|
||||
assert_success
|
||||
assert_equal 'application/pdf', r.headers['Content-Type']
|
||||
assert_match /attachment; filename="wiki1-tex-\d\d\d\d-\d\d-\d\d-\d\d-\d\d-\d\d.pdf"/,
|
||||
r.headers['Content-Disposition']
|
||||
content = r.binary_content
|
||||
assert_equal '%PDF', content[0..3]
|
||||
assert_equal "EOF\n", content[-4..-1]
|
||||
end
|
||||
|
||||
else
|
||||
puts 'Warning: tests involving pdflatex are very slow, therefore they are disabled by default.'
|
||||
puts ' Set environment variable INSTIKI_TEST_PDFLATEX or global Ruby variable'
|
||||
puts ' $INSTIKI_TEST_PDFLATEX to enable them.'
|
||||
end
|
||||
|
||||
|
||||
def test_export_tex
|
||||
setup_wiki_with_three_pages
|
||||
|
||||
r = process 'export_tex', 'web' => 'wiki1'
|
||||
|
||||
assert_success
|
||||
assert_equal 'application/octet-stream', r.headers['Content-Type']
|
||||
assert_match /attachment; filename="wiki1-tex-\d\d\d\d-\d\d-\d\d-\d\d-\d\d-\d\d.tex"/,
|
||||
r.headers['Content-Disposition']
|
||||
content = r.binary_content
|
||||
assert_equal '\documentclass', content[0..13], 'Content is not a TeX file'
|
||||
end
|
||||
|
||||
def test_feeds
|
||||
process('feeds', 'web' => 'wiki1')
|
||||
end
|
||||
|
||||
def test_index
|
||||
process('index')
|
||||
assert_redirected_to :web => 'wiki1', :action => 'show', :id => 'HomePage'
|
||||
end
|
||||
|
||||
def test_index_multiple_webs
|
||||
@wiki.create_web('Test Wiki 2', 'wiki2')
|
||||
process('index')
|
||||
assert_redirected_to :action => 'web_list'
|
||||
end
|
||||
|
||||
def test_index_multiple_webs_web_explicit
|
||||
@wiki.create_web('Test Wiki 2', 'wiki2')
|
||||
process('index', 'web' => 'wiki2')
|
||||
assert_redirected_to :web => 'wiki2', :action => 'show', :id => 'HomePage'
|
||||
end
|
||||
|
||||
def test_index_wiki_not_initialized
|
||||
ApplicationController.wiki = WikiServiceWithNoPersistence.new
|
||||
process('index')
|
||||
assert_redirected_to :controller => 'admin', :action => 'create_system'
|
||||
end
|
||||
|
||||
|
||||
def test_list
|
||||
setup_wiki_with_three_pages
|
||||
|
||||
r = process('list', 'web' => 'wiki1')
|
||||
|
||||
assert_equal ['animals', 'trees'], r.template_objects['categories']
|
||||
assert_nil r.template_objects['category']
|
||||
assert_equal [@elephant, @home, @oak], r.template_objects['pages_in_category']
|
||||
end
|
||||
|
||||
|
||||
def test_locked
|
||||
@home.lock(Time.now, 'Locky')
|
||||
r = process('locked', 'web' => 'wiki1', 'id' => 'HomePage')
|
||||
assert_success
|
||||
assert_equal @home, r.template_objects['page']
|
||||
end
|
||||
|
||||
|
||||
def test_login
|
||||
r = process 'login', 'web' => 'wiki1'
|
||||
assert_success
|
||||
# this action goes straight to the templates
|
||||
end
|
||||
|
||||
|
||||
def test_new
|
||||
r = process('new', 'id' => 'NewPage', 'web' => 'wiki1')
|
||||
assert_success
|
||||
assert_equal 'AnonymousCoward', r.template_objects['author']
|
||||
assert_equal 'NewPage', r.template_objects['page_name']
|
||||
end
|
||||
|
||||
|
||||
if ENV['INSTIKI_TEST_LATEX'] or defined? $INSTIKI_TEST_PDFLATEX
|
||||
|
||||
def test_pdf
|
||||
assert RedClothForTex.available?, 'Cannot do test_pdf when pdflatex is not available'
|
||||
r = process('pdf', 'web' => 'wiki1', 'id' => 'HomePage')
|
||||
assert_success
|
||||
|
||||
content = r.binary_content
|
||||
|
||||
assert_equal '%PDF', content[0..3]
|
||||
assert_equal "EOF\n", content[-4..-1]
|
||||
|
||||
assert_equal 'application/pdf', r.headers['Content-Type']
|
||||
assert_match /attachment; filename="HomePage-wiki1-\d\d\d\d-\d\d-\d\d-\d\d-\d\d-\d\d.pdf"/,
|
||||
r.headers['Content-Disposition']
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
def test_print
|
||||
r = process('print', 'web' => 'wiki1', 'id' => 'HomePage')
|
||||
|
||||
assert_success
|
||||
assert_equal :show, r.template_objects['link_mode']
|
||||
end
|
||||
|
||||
|
||||
def test_published
|
||||
@web.published = true
|
||||
|
||||
r = process('published', 'web' => 'wiki1', 'id' => 'HomePage')
|
||||
|
||||
assert_success
|
||||
assert_equal @home, r.template_objects['page']
|
||||
end
|
||||
|
||||
|
||||
def test_published_web_not_published
|
||||
@web.published = false
|
||||
|
||||
r = process('published', 'web' => 'wiki1', 'id' => 'HomePage')
|
||||
|
||||
assert_redirected_to :action => 'show', :id => 'HomePage'
|
||||
end
|
||||
|
||||
|
||||
def test_recently_revised
|
||||
r = process('recently_revised', 'web' => 'wiki1')
|
||||
assert_success
|
||||
|
||||
assert_equal [], r.template_objects['categories']
|
||||
assert_nil r.template_objects['category']
|
||||
assert_equal [@home], r.template_objects['pages_in_category']
|
||||
assert_equal 'the web', r.template_objects['set_name']
|
||||
end
|
||||
|
||||
def test_recently_revised_with_categorized_page
|
||||
page2 = @wiki.write_page('wiki1', 'Page2',
|
||||
"Page2 contents.\n" +
|
||||
"category: categorized",
|
||||
Time.now, Author.new('AnotherAuthor', '127.0.0.2'))
|
||||
|
||||
r = process('recently_revised', 'web' => 'wiki1')
|
||||
assert_success
|
||||
|
||||
assert_equal ['categorized'], r.template_objects['categories']
|
||||
# no category is specified in params
|
||||
assert_nil r.template_objects['category']
|
||||
assert_equal [@home, page2], r.template_objects['pages_in_category'],
|
||||
"Pages are not as expected: " +
|
||||
r.template_objects['pages_in_category'].map {|p| p.name}.inspect
|
||||
assert_equal 'the web', r.template_objects['set_name']
|
||||
end
|
||||
|
||||
def test_recently_revised_with_categorized_page_multiple_categories
|
||||
setup_wiki_with_three_pages
|
||||
|
||||
r = process('recently_revised', 'web' => 'wiki1')
|
||||
assert_success
|
||||
|
||||
assert_equal ['animals', 'trees'], r.template_objects['categories']
|
||||
# no category is specified in params
|
||||
assert_nil r.template_objects['category']
|
||||
assert_equal [@elephant, @home, @oak], r.template_objects['pages_in_category'],
|
||||
"Pages are not as expected: " +
|
||||
r.template_objects['pages_in_category'].map {|p| p.name}.inspect
|
||||
assert_equal 'the web', r.template_objects['set_name']
|
||||
end
|
||||
|
||||
def test_recently_revised_with_specified_category
|
||||
setup_wiki_with_three_pages
|
||||
|
||||
r = process('recently_revised', 'web' => 'wiki1', 'category' => 'animals')
|
||||
assert_success
|
||||
|
||||
assert_equal ['animals', 'trees'], r.template_objects['categories']
|
||||
# no category is specified in params
|
||||
assert_equal 'animals', r.template_objects['category']
|
||||
assert_equal [@elephant], r.template_objects['pages_in_category']
|
||||
assert_equal "category 'animals'", r.template_objects['set_name']
|
||||
end
|
||||
|
||||
|
||||
def test_revision
|
||||
r = process 'revision', 'web' => 'wiki1', 'id' => 'HomePage', 'rev' => '0'
|
||||
|
||||
assert_success
|
||||
assert_equal @home, r.template_objects['page']
|
||||
assert_equal @home.revisions[0], r.template_objects['revision']
|
||||
end
|
||||
|
||||
|
||||
def test_rollback
|
||||
# rollback shows a form where a revision can be edited.
|
||||
# its assigns the same as or revision
|
||||
r = process 'rollback', 'web' => 'wiki1', 'id' => 'HomePage', 'rev' => '0'
|
||||
|
||||
assert_success
|
||||
assert_equal @home, r.template_objects['page']
|
||||
assert_equal @home.revisions[0], r.template_objects['revision']
|
||||
end
|
||||
|
||||
def test_rss_with_content
|
||||
setup_wiki_with_three_pages
|
||||
|
||||
r = process 'rss_with_content', 'web' => 'wiki1'
|
||||
|
||||
assert_success
|
||||
pages = r.template_objects['pages_by_revision']
|
||||
assert_equal [@home, @oak, @elephant], pages,
|
||||
"Pages are not as expected: #{pages.map {|p| p.name}.inspect}"
|
||||
assert !r.template_objects['hide_description']
|
||||
end
|
||||
|
||||
def test_rss_with_content_when_blocked
|
||||
setup_wiki_with_three_pages
|
||||
@web.password = 'aaa'
|
||||
@web.published = false
|
||||
|
||||
r = process 'rss_with_content', 'web' => 'wiki1'
|
||||
|
||||
assert_equal 403, r.response_code
|
||||
end
|
||||
|
||||
|
||||
def test_rss_with_headlines
|
||||
setup_wiki_with_three_pages
|
||||
@title_with_spaces = @wiki.write_page('wiki1', 'Title With Spaces',
|
||||
'About spaces', 1.hour.ago, Author.new('TreeHugger', '127.0.0.2'))
|
||||
|
||||
@request.host = 'localhost'
|
||||
@request.port = 8080
|
||||
|
||||
r = process 'rss_with_headlines', 'web' => 'wiki1'
|
||||
|
||||
assert_success
|
||||
pages = r.template_objects['pages_by_revision']
|
||||
assert_equal [@home, @oak, @elephant, @title_with_spaces], pages,
|
||||
"Pages are not as expected: #{pages.map {|p| p.name}.inspect}"
|
||||
assert r.template_objects['hide_description']
|
||||
|
||||
xml = REXML::Document.new(r.body)
|
||||
|
||||
expected_page_links =
|
||||
['http://localhost:8080/wiki1/show/HomePage',
|
||||
'http://localhost:8080/wiki1/show/Oak',
|
||||
'http://localhost:8080/wiki1/show/Elephant',
|
||||
'http://localhost:8080/wiki1/show/Title+With+Spaces']
|
||||
|
||||
assert_template_xpath_match '/rss/channel/link',
|
||||
'http://localhost:8080/wiki1/show/HomePage'
|
||||
assert_template_xpath_match '/rss/channel/item/guid', expected_page_links
|
||||
assert_template_xpath_match '/rss/channel/item/link', expected_page_links
|
||||
end
|
||||
|
||||
def test_rss_switch_links_to_published
|
||||
setup_wiki_with_three_pages
|
||||
@web.password = 'aaa'
|
||||
@web.published = true
|
||||
|
||||
@request.host = 'foo.bar.info'
|
||||
@request.port = 80
|
||||
|
||||
r = process 'rss_with_headlines', 'web' => 'wiki1'
|
||||
|
||||
assert_success
|
||||
xml = REXML::Document.new(r.body)
|
||||
|
||||
expected_page_links =
|
||||
['http://foo.bar.info/wiki1/published/HomePage',
|
||||
'http://foo.bar.info/wiki1/published/Oak',
|
||||
'http://foo.bar.info/wiki1/published/Elephant']
|
||||
|
||||
assert_template_xpath_match '/rss/channel/link',
|
||||
'http://foo.bar.info/wiki1/published/HomePage'
|
||||
assert_template_xpath_match '/rss/channel/item/guid', expected_page_links
|
||||
assert_template_xpath_match '/rss/channel/item/link', expected_page_links
|
||||
end
|
||||
|
||||
def test_rss_with_params
|
||||
setup_wiki_with_30_pages
|
||||
|
||||
r = process 'rss_with_headlines', 'web' => 'wiki1'
|
||||
assert_success
|
||||
pages = r.template_objects['pages_by_revision']
|
||||
assert_equal 15, pages.size, 15
|
||||
|
||||
r = process 'rss_with_headlines', 'web' => 'wiki1', 'limit' => '5'
|
||||
assert_success
|
||||
pages = r.template_objects['pages_by_revision']
|
||||
assert_equal 5, pages.size
|
||||
|
||||
r = process 'rss_with_headlines', 'web' => 'wiki1', 'limit' => '25'
|
||||
assert_success
|
||||
pages = r.template_objects['pages_by_revision']
|
||||
assert_equal 25, pages.size
|
||||
|
||||
r = process 'rss_with_headlines', 'web' => 'wiki1', 'limit' => 'all'
|
||||
assert_success
|
||||
pages = r.template_objects['pages_by_revision']
|
||||
assert_equal 31, pages.size
|
||||
|
||||
r = process 'rss_with_headlines', 'web' => 'wiki1', 'start' => '1976-10-16'
|
||||
assert_success
|
||||
pages = r.template_objects['pages_by_revision']
|
||||
assert_equal 16, pages.size
|
||||
|
||||
r = process 'rss_with_headlines', 'web' => 'wiki1', 'end' => '1976-10-16'
|
||||
assert_success
|
||||
pages = r.template_objects['pages_by_revision']
|
||||
assert_equal 15, pages.size
|
||||
|
||||
r = process 'rss_with_headlines', 'web' => 'wiki1', 'start' => '1976-10-01', 'end' => '1976-10-06'
|
||||
assert_success
|
||||
pages = r.template_objects['pages_by_revision']
|
||||
assert_equal 5, pages.size
|
||||
end
|
||||
|
||||
def test_rss_title_with_ampersand
|
||||
# was ticket:143
|
||||
setup_wiki_with_three_pages
|
||||
|
||||
@wiki.write_page('wiki1', 'Title&With&Ampersands',
|
||||
'About spaces', 1.hour.ago, Author.new('NitPicker', '127.0.0.3'))
|
||||
|
||||
r = process 'rss_with_headlines', 'web' => 'wiki1'
|
||||
|
||||
assert r.body.include?('<title>Home Page</title>')
|
||||
assert r.body.include?('<title>Title&With&Ampersands</title>')
|
||||
end
|
||||
|
||||
def test_rss_timestamp
|
||||
setup_wiki_with_three_pages
|
||||
|
||||
new_page = @wiki.write_page('wiki1', 'PageCreatedAtTheBeginningOfCtime',
|
||||
'Created on 1 Jan 1970 at 0:00:00 Z', Time.at(0), Author.new('NitPicker', '127.0.0.3'))
|
||||
|
||||
r = process 'rss_with_headlines', 'web' => 'wiki1'
|
||||
|
||||
assert_template_xpath_match '/rss/channel/item/pubDate[4]', "Thu, 01 Jan 1970 00:00:00 Z"
|
||||
end
|
||||
|
||||
def test_save
|
||||
r = process 'save', 'web' => 'wiki1', 'id' => 'NewPage', 'content' => 'Contents of a new page',
|
||||
'author' => 'AuthorOfNewPage'
|
||||
|
||||
assert_redirected_to :web => 'wiki1', :action => 'show', :id => 'NewPage'
|
||||
assert_equal ['AuthorOfNewPage'], r.cookies['author'].value
|
||||
new_page = @wiki.read_page('wiki1', 'NewPage')
|
||||
assert_equal 'Contents of a new page', new_page.content
|
||||
assert_equal 'AuthorOfNewPage', new_page.author
|
||||
end
|
||||
|
||||
def test_save_new_revision_of_existing_page
|
||||
@home.lock(Time.now, 'Batman')
|
||||
|
||||
r = process 'save', 'web' => 'wiki1', 'id' => 'HomePage', 'content' => 'Revised HomePage',
|
||||
'author' => 'Batman'
|
||||
|
||||
assert_redirected_to :web => 'wiki1', :action => 'show', :id => 'HomePage'
|
||||
assert_equal ['Batman'], r.cookies['author'].value
|
||||
home_page = @wiki.read_page('wiki1', 'HomePage')
|
||||
assert_equal [home_page], @web.pages.values
|
||||
assert_equal 2, home_page.revisions.size
|
||||
assert_equal 'Revised HomePage', home_page.content
|
||||
assert_equal 'Batman', home_page.author
|
||||
assert !home_page.locked?(Time.now)
|
||||
end
|
||||
|
||||
def test_save_new_revision_identical_to_last
|
||||
revisions_before = @home.revisions.size
|
||||
@home.lock(Time.now, 'AnAuthor')
|
||||
|
||||
r = process 'save', {'web' => 'wiki1', 'id' => 'HomePage',
|
||||
'content' => @home.revisions.last.content.dup,
|
||||
'author' => 'SomeOtherAuthor'}, {:return_to => '/wiki1/show/HomePage'}
|
||||
|
||||
assert_redirected_to :action => 'edit', :web => 'wiki1', :id => 'HomePage'
|
||||
assert_flash_has :error
|
||||
assert r.flash[:error].kind_of?(Instiki::ValidationError)
|
||||
|
||||
revisions_after = @home.revisions.size
|
||||
assert_equal revisions_before, revisions_after
|
||||
assert !@home.locked?(Time.now), 'HomePage should be unlocked if an edit was unsuccessful'
|
||||
end
|
||||
|
||||
|
||||
def test_search
|
||||
setup_wiki_with_three_pages
|
||||
|
||||
r = process 'search', 'web' => 'wiki1', 'query' => '\s[A-Z]ak'
|
||||
|
||||
assert_redirected_to :action => 'show', :id => 'Oak'
|
||||
end
|
||||
|
||||
def test_search_multiple_results
|
||||
setup_wiki_with_three_pages
|
||||
|
||||
r = process 'search', 'web' => 'wiki1', 'query' => 'All about'
|
||||
|
||||
assert_success
|
||||
assert_equal 'All about', r.template_objects['query']
|
||||
assert_equal [@elephant, @oak], r.template_objects['results']
|
||||
assert_equal [], r.template_objects['title_results']
|
||||
end
|
||||
|
||||
def test_search_by_content_and_title
|
||||
setup_wiki_with_three_pages
|
||||
|
||||
r = process 'search', 'web' => 'wiki1', 'query' => '(Oak|Elephant)'
|
||||
|
||||
assert_success
|
||||
assert_equal '(Oak|Elephant)', r.template_objects['query']
|
||||
assert_equal [@elephant, @oak], r.template_objects['results']
|
||||
assert_equal [@elephant, @oak], r.template_objects['title_results']
|
||||
end
|
||||
|
||||
def test_search_zero_results
|
||||
setup_wiki_with_three_pages
|
||||
|
||||
r = process 'search', 'web' => 'wiki1', 'query' => 'non-existant text'
|
||||
|
||||
assert_success
|
||||
assert_equal [], r.template_objects['results']
|
||||
assert_equal [], r.template_objects['title_results']
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
def test_show_page
|
||||
r = process('show', 'id' => 'HomePage', 'web' => 'wiki1')
|
||||
assert_success
|
||||
assert_match /First revision of the <a.*HomePage.*<\/a> end/, r.body
|
||||
end
|
||||
|
||||
def test_show_page_with_multiple_revisions
|
||||
@wiki.write_page('wiki1', 'HomePage', 'Second revision of the HomePage end', Time.now,
|
||||
Author.new('AnotherAuthor', '127.0.0.2'))
|
||||
|
||||
r = process('show', 'id' => 'HomePage', 'web' => 'wiki1')
|
||||
|
||||
assert_success
|
||||
assert_match /Second revision of the <a.*HomePage.*<\/a> end/, r.body
|
||||
end
|
||||
|
||||
def test_show_page_nonexistant_page
|
||||
process('show', 'id' => 'UnknownPage', 'web' => 'wiki1')
|
||||
assert_redirected_to :web => 'wiki1', :action => 'new', :id => 'UnknownPage'
|
||||
end
|
||||
|
||||
def test_show_no_page
|
||||
r = process('show', 'id' => '', 'web' => 'wiki1')
|
||||
assert_equal 404, r.response_code
|
||||
|
||||
r = process('show', 'web' => 'wiki1')
|
||||
assert_equal 404, r.response_code
|
||||
end
|
||||
|
||||
|
||||
def test_tex
|
||||
r = process('tex', 'web' => 'wiki1', 'id' => 'HomePage')
|
||||
assert_success
|
||||
|
||||
assert_equal "\\documentclass[12pt,titlepage]{article}\n\n\\usepackage[danish]{babel} " +
|
||||
"%danske tekster\n\\usepackage[OT1]{fontenc} %rigtige danske bogstaver...\n" +
|
||||
"\\usepackage{a4}\n\\usepackage{graphicx}\n\\usepackage{ucs}\n\\usepackage[utf8x]" +
|
||||
"{inputenc}\n\\input epsf \n\n%----------------------------------------------------" +
|
||||
"---------------\n\n\\begin{document}\n\n\\sloppy\n\n%-----------------------------" +
|
||||
"--------------------------------------\n\n\\section*{HomePage}\n\nFirst revision of " +
|
||||
"the HomePage end\n\n\\end{document}", r.body
|
||||
end
|
||||
|
||||
|
||||
def test_web_list
|
||||
another_wiki = @wiki.create_web('Another Wiki', 'another_wiki')
|
||||
|
||||
r = process('web_list')
|
||||
|
||||
assert_success
|
||||
assert_equal [another_wiki, @web], r.template_objects['webs']
|
||||
end
|
||||
|
||||
end
|
361
test/watir/e2e.rb
Normal file
361
test/watir/e2e.rb
Normal file
|
@ -0,0 +1,361 @@
|
|||
require 'fileutils'
|
||||
require 'cgi'
|
||||
require 'test/unit'
|
||||
require 'rexml/document'
|
||||
|
||||
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 version of Watir.
|
||||
# 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: Home Page/, 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?('<P>Test Edit Page, revision <DEL class=diffmod>2</DEL>' +
|
||||
'<INS class=diffmod>2, rolled back</INS></P>')
|
||||
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
|
||||
|
||||
ie.link(:text, 'Hide changes').click
|
||||
|
||||
assert_match /Test Edit Page, revision 2, rolled back/, ie.text
|
||||
end
|
||||
|
||||
def test_0070_all_pages
|
||||
# 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')
|
||||
|
||||
ie.link(:text, 'All Pages').click
|
||||
|
||||
page_links = ie.links.map { |l| l.text }
|
||||
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
|
||||
# and before that, we have the tail of the main menu
|
||||
assert_equal 'Export', page_links[-7]
|
||||
end
|
||||
|
||||
def test_0080_recently_revised
|
||||
ie.link(:text, 'Recently Revised').click
|
||||
|
||||
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
|
||||
|
||||
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 =
|
||||
'Anonymous Coward\? co- or authored: Another Wiki Page, Home Page, Test Edit Page.*' +
|
||||
'Another Author co- or authored: Another Author, Test Edit Page.*' +
|
||||
'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
|
||||
ie.back
|
||||
ie.link(:text, 'Test Edit Page').click
|
||||
assert_equal url(:show, 'TestEditPage'), ie.url
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
private
|
||||
|
||||
def bp
|
||||
require 'breakpoint'
|
||||
breakpoint
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
assert_equal url(:print, 'HomePage'), ie.link(:text, 'Print').href
|
||||
end
|
||||
|
||||
def check_footnote
|
||||
assert_match /This site is running on Instiki/, ie.text
|
||||
assert_equal 'http://instiki.org/', ie.link(:text, 'Instiki').href
|
||||
assert_match /Powered by Ruby on Rails/, ie.text
|
||||
assert_equal 'http://rubyonrails.com/', ie.link(:text, 'Ruby on Rails').href
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
assert_equal url(:new, 'HomePage'), ie.url
|
||||
end
|
||||
|
||||
def setup_home_page
|
||||
ie.textField(:name, 'content').set('Homepage of a test wiki')
|
||||
ie.button(:value, 'Submit').click
|
||||
assert_equal url(:show, 'HomePage'), ie.url
|
||||
end
|
||||
|
||||
def url(operation, page_name = nil, revision = nil)
|
||||
page_name = CGI.escape(page_name) if page_name
|
||||
case operation
|
||||
when :edit, :new, :show, :print, :revision, :rollback
|
||||
"#{HOME}/wiki/#{operation}/#{page_name}" + (revision ? "?rev=#{revision}" : '')
|
||||
when :rss_with_content, :rss_with_headlines
|
||||
"#{HOME}/wiki/#{operation}"
|
||||
else
|
||||
raise "Unsupported operation: '#{operation}"
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class InstikiController
|
||||
|
||||
attr_reader :process_id
|
||||
|
||||
def self.start
|
||||
startup_info = [68].pack('lx64')
|
||||
process_info = [0, 0, 0, 0].pack('llll')
|
||||
|
||||
startup_command =
|
||||
"ruby #{RAILS_ROOT}/instiki.rb --storage #{prepare_storage} " +
|
||||
" --port #{INSTIKI_PORT} --environment development"
|
||||
|
||||
result = Win32API.new('kernel32.dll', 'CreateProcess', 'pplllllppp', 'L').call(
|
||||
nil,
|
||||
startup_command,
|
||||
0, 0, 1, 0, 0, '.', startup_info, process_info)
|
||||
|
||||
# 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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
end
|
||||
|
||||
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
|
Loading…
Add table
Add a link
Reference in a new issue