blob: f3cb0c3360dcd626221cf535e0a610c2e00971ba [file] [log] [blame]
ENV["RAILS_ENV"] = "test"
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
require 'test_help'
#--######################################################################
# Copyright (c) 2006 LogicaCMG
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v10.html
#
# Contributors:
#
# Onno van der Straaten:: initial implementation
#++######################################################################
# {Copyright (c) 2006 LogicaCMG}[link:files/COPYRIGHT.html]
class Test::Unit::TestCase
# Turn off transactional fixtures if you're working with MyISAM tables in MySQL
# TODO: comment that unit tests depend on each other
self.use_transactional_fixtures = false
# Instantiated fixtures are slow, but give you @david where you otherwise would need people(:david)
self.use_instantiated_fixtures = false
# Add more helper methods to be used by all tests here...
def create_openup0825
site = Site.new_baseline_process(:folder => openup0825_folder, :title => 'openup0825', :user_id => User.find_central_admin.id, :baseline_baseline => 'OUP_20060825')
site.unzip_upload
# TODO: without second call below, the site cannot be saved because of a missing baseline
site = Site.new_baseline_process(:folder => openup0825_folder, :title => 'openup0825', :user_id => User.find_central_admin.id, :baseline_baseline => 'OUP_20060825')
if site.save
return site
else
raise "Failed to create openup0825"
end
end
# Special assert created for researching the mistery of disappearing associations
# when running unit tests.
def assert_openup0721
openup0721 = Site.find_by_title('openup0721')
if !openup0721.nil?
assert_equal 8, openup0721.pages.size
end
end
def openup0825_folder
return "OpenUP-Basic_published_20060825#{ENV['EPFWIKI_TESTDATA']}"
end
def openup0721_folder
return "OpenUP-Basic_published_20060721#{ENV['EPFWIKI_TESTDATA']}"
end
def openup0728_folder
return "OpenUP-Basic_published_20060728#{ENV['EPFWIKI_TESTDATA']}"
end
def assert_field(name)
assert_tag :tag => "input", :attributes => {:id => name}
end
def assert_no_field(name)
assert_no_tag :tag => "input", :attributes => {:id => name}
end
def assert_errors(object = nil)
if object
object.errors.full_messages.each do |message|
assert_tag :content => message
end
else
assert_tag error_message_field
end
end
def assert_no_errors(object = nil)
if object
object.errors.full_messages.each do |message|
assert_no_tag :content => message
end
else
assert_no_tag error_message_field
end
end
def assert_pattern(pat, html, result)
html =~ pat
assert_equal result, $&
end
def error_message_field
{:tag => 'div', :attributes => { :class => 'errorExplanation', :id => 'errorExplanation' }}
end
def assert_save(object)
if !object.save
assert_equal '', object.errors.full_messages.join(", ")
end
end
def assert_enhanced_file(path)
html = IO.readlines(path).join
assert_not_nil html.index('<!-- epfwiki iframe start -->')
assert_not_nil html.index('onload')
assert_equal nil, html.index('<!-- treebrowser tag -->')
assert_equal nil, html.index('<!-- copyright statement -->')
end
def assert_version_file(path)
html = IO.readlines(path).join
assert_equal nil, html.index('<!-- epfwiki iframe start -->')
assert_not_nil html.index('<body>')
assert_not_nil html.index('<!-- treebrowser tag -->')
#assert_not_nil html.index('<!-- copyright statement -->')
end
def assert_kind_of_checkout(checkout)
assert_kind_of Checkout, checkout
assert File.exists?(checkout.version.path)
end
def create_cadmin
cadmin = User.new_cadmin(:id => 5, :name => 'onno', :email => 'Onno@noneExistingDomain.Com', :password => 'xyz', :password_confirmation => 'xyz')
return cadmin
end
def logonUser
get :index
session['user'] = User.find(4)
end
def logonUser3
get :index
session['user'] = User.find(3)
end
def logonUser4
get :index
session['user'] = User.find(3)
end
def logonUser5
get :index
session['user'] = User.find(5)
end
def logonCentralAdmin
get :index
session['user'] = User.find_central_admin
end
def logonAdmin
get :index
session['user'] = User.find(2)
end
def assert_tologin
#assert_equal ::MSG_LOGIN, flash['notice']
assert_equal @request.request_uri, session["return_to"]
assert_redirected_to :controller => 'login'
end
def assert_unot_admin_message
assert_equal LoginController::FLASH_UNOT_ADMIN, flash['error']
assert_redirected_to :controller => "other", :action => "error"
end
def assert_unot_cadmin_message
assert_equal LoginController::FLASH_UNOT_CADMIN, flash['error']
assert_redirected_to :controller => "other", :action => "error"
end
def assert_illegal_get
assert_redirected_to :controller => 'other', :action => 'error'
assert ::FLASH_USE_POST_NOT_GET, flash['error']
end
end