summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/functional/application_controller_test.rb8
-rw-r--r--test/functional/attachments_controller_test.rb2
-rw-r--r--test/functional/custom_fields_controller_test.rb2
-rw-r--r--test/functional/issues_controller_test.rb2
-rw-r--r--test/functional/messages_controller_test.rb8
-rw-r--r--test/functional/news_controller_test.rb6
-rw-r--r--test/functional/projects_controller_test.rb8
-rw-r--r--test/functional/repositories_controller_test.rb2
-rw-r--r--test/functional/search_controller_test.rb2
-rw-r--r--test/functional/timelog_controller_test.rb2
-rw-r--r--test/functional/welcome_controller_test.rb2
-rw-r--r--test/functional/wikis_controller_test.rb2
-rw-r--r--test/integration/account_test.rb14
-rw-r--r--test/integration/admin_test.rb4
-rw-r--r--test/integration/application_test.rb6
-rw-r--r--test/integration/issues_test.rb2
-rw-r--r--test/test_helper.rb5
-rw-r--r--test/unit/default_data_test.rb3
-rw-r--r--test/unit/helpers/application_helper_test.rb50
-rw-r--r--test/unit/issue_test.rb6
-rw-r--r--test/unit/lib/redmine/i18n_test.rb100
-rw-r--r--test/unit/mailer_test.rb19
-rw-r--r--test/unit/project_test.rb4
-rw-r--r--test/unit/repository_test.rb2
-rw-r--r--test/unit/user_test.rb2
-rw-r--r--test/unit/version_test.rb2
-rw-r--r--test/unit/wiki_page_test.rb6
27 files changed, 172 insertions, 99 deletions
diff --git a/test/functional/application_controller_test.rb b/test/functional/application_controller_test.rb
index 7d1cc8391..0232b6a4d 100644
--- a/test/functional/application_controller_test.rb
+++ b/test/functional/application_controller_test.rb
@@ -22,6 +22,8 @@ require 'application'
class ApplicationController; def rescue_action(e) raise e end; end
class ApplicationControllerTest < Test::Unit::TestCase
+ include Redmine::I18n
+
def setup
@controller = ApplicationController.new
@request = ActionController::TestRequest.new
@@ -30,9 +32,9 @@ class ApplicationControllerTest < Test::Unit::TestCase
# check that all language files are valid
def test_localization
- lang_files_count = Dir["#{RAILS_ROOT}/lang/*.yml"].size
- assert_equal lang_files_count, GLoc.valid_languages.size
- GLoc.valid_languages.each do |lang|
+ lang_files_count = Dir["#{RAILS_ROOT}/config/locales/*.yml"].size
+ assert_equal lang_files_count, valid_languages.size
+ valid_languages.each do |lang|
assert set_language_if_valid(lang)
end
set_language_if_valid('en')
diff --git a/test/functional/attachments_controller_test.rb b/test/functional/attachments_controller_test.rb
index 634d4279b..43650bdfd 100644
--- a/test/functional/attachments_controller_test.rb
+++ b/test/functional/attachments_controller_test.rb
@@ -86,7 +86,7 @@ class AttachmentsControllerTest < Test::Unit::TestCase
post :destroy, :id => 1
end
# no referrer
- assert_redirected_to 'projects/show/ecookbook'
+ assert_redirected_to 'projects/ecookbook'
assert_nil Attachment.find_by_id(1)
j = issue.journals.find(:first, :order => 'created_on DESC')
assert_equal 'attachment', j.details.first.property
diff --git a/test/functional/custom_fields_controller_test.rb b/test/functional/custom_fields_controller_test.rb
index 42dedb3c1..10af23563 100644
--- a/test/functional/custom_fields_controller_test.rb
+++ b/test/functional/custom_fields_controller_test.rb
@@ -47,7 +47,7 @@ class CustomFieldsControllerTest < Test::Unit::TestCase
:field_format => "list",
:tracker_ids => ["1", ""]}
end
- assert_redirected_to '/custom_fields'
+ assert_redirected_to '/custom_fields?tab=IssueCustomField'
field = IssueCustomField.find_by_name('test_post_new_list')
assert_not_nil field
assert_equal ["0.1", "0.2"], field.possible_values
diff --git a/test/functional/issues_controller_test.rb b/test/functional/issues_controller_test.rb
index 25100f9a0..ebc2aa8b8 100644
--- a/test/functional/issues_controller_test.rb
+++ b/test/functional/issues_controller_test.rb
@@ -445,7 +445,7 @@ class IssuesControllerTest < Test::Unit::TestCase
assert_template 'new'
issue = assigns(:issue)
assert_not_nil issue
- assert_equal 'activerecord_error_invalid', issue.errors.on(:custom_values)
+ assert_equal I18n.translate('activerecord.errors.messages.invalid'), issue.errors.on(:custom_values)
end
def test_post_new_with_watchers
diff --git a/test/functional/messages_controller_test.rb b/test/functional/messages_controller_test.rb
index d19249c06..94062b402 100644
--- a/test/functional/messages_controller_test.rb
+++ b/test/functional/messages_controller_test.rb
@@ -87,9 +87,9 @@ class MessagesControllerTest < Test::Unit::TestCase
post :new, :board_id => 1,
:message => { :subject => 'Test created message',
:content => 'Message body'}
- assert_redirected_to 'messages/show'
message = Message.find_by_subject('Test created message')
assert_not_nil message
+ assert_redirected_to "boards/1/topics/#{message.to_param}"
assert_equal 'Message body', message.content
assert_equal 2, message.author_id
assert_equal 1, message.board_id
@@ -127,7 +127,7 @@ class MessagesControllerTest < Test::Unit::TestCase
post :edit, :board_id => 1, :id => 1,
:message => { :subject => 'New subject',
:content => 'New body'}
- assert_redirected_to 'messages/show'
+ assert_redirected_to 'boards/1/topics/1'
message = Message.find(1)
assert_equal 'New subject', message.subject
assert_equal 'New body', message.content
@@ -143,7 +143,7 @@ class MessagesControllerTest < Test::Unit::TestCase
def test_reply
@request.session[:user_id] = 2
post :reply, :board_id => 1, :id => 1, :reply => { :content => 'This is a test reply', :subject => 'Test reply' }
- assert_redirected_to 'messages/show'
+ assert_redirected_to 'boards/1/topics/1'
assert Message.find_by_subject('Test reply')
end
@@ -157,7 +157,7 @@ class MessagesControllerTest < Test::Unit::TestCase
def test_destroy_topic
@request.session[:user_id] = 2
post :destroy, :board_id => 1, :id => 1
- assert_redirected_to 'boards/show'
+ assert_redirected_to 'projects/ecookbook/boards/1'
assert_nil Message.find_by_id(1)
end
diff --git a/test/functional/news_controller_test.rb b/test/functional/news_controller_test.rb
index 651471b66..009e58c73 100644
--- a/test/functional/news_controller_test.rb
+++ b/test/functional/news_controller_test.rb
@@ -146,7 +146,7 @@ class NewsControllerTest < Test::Unit::TestCase
def test_post_edit
@request.session[:user_id] = 2
post :edit, :id => 1, :news => { :description => 'Description changed by test_post_edit' }
- assert_redirected_to 'news/show/1'
+ assert_redirected_to 'news/1'
news = News.find(1)
assert_equal 'Description changed by test_post_edit', news.description
end
@@ -167,7 +167,7 @@ class NewsControllerTest < Test::Unit::TestCase
def test_add_comment
@request.session[:user_id] = 2
post :add_comment, :id => 1, :comment => { :comments => 'This is a NewsControllerTest comment' }
- assert_redirected_to 'news/show/1'
+ assert_redirected_to 'news/1'
comment = News.find(1).comments.find(:first, :order => 'created_on DESC')
assert_not_nil comment
@@ -179,7 +179,7 @@ class NewsControllerTest < Test::Unit::TestCase
comments_count = News.find(1).comments.size
@request.session[:user_id] = 2
post :destroy_comment, :id => 1, :comment_id => 2
- assert_redirected_to 'news/show/1'
+ assert_redirected_to 'news/1'
assert_nil Comment.find_by_id(2)
assert_equal comments_count - 1, News.find(1).comments.size
end
diff --git a/test/functional/projects_controller_test.rb b/test/functional/projects_controller_test.rb
index ec5d40a77..371e28424 100644
--- a/test/functional/projects_controller_test.rb
+++ b/test/functional/projects_controller_test.rb
@@ -148,7 +148,7 @@ class ProjectsControllerTest < Test::Unit::TestCase
@request.session[:user_id] = 2 # manager
post :edit, :id => 1, :project => {:name => 'Test changed name',
:issue_custom_field_ids => ['']}
- assert_redirected_to 'projects/settings/ecookbook'
+ assert_redirected_to 'projects/ecookbook/settings'
project = Project.find(1)
assert_equal 'Test changed name', project.name
end
@@ -214,7 +214,7 @@ class ProjectsControllerTest < Test::Unit::TestCase
post :add_file, :id => 1, :version_id => '',
:attachments => {'1' => {'file' => test_uploaded_file('testfile.txt', 'text/plain')}}
end
- assert_redirected_to 'projects/list_files/ecookbook'
+ assert_redirected_to 'projects/ecookbook/files'
a = Attachment.find(:first, :order => 'created_on DESC')
assert_equal 'testfile.txt', a.filename
assert_equal Project.find(1), a.container
@@ -245,7 +245,7 @@ class ProjectsControllerTest < Test::Unit::TestCase
post :add_file, :id => 1, :version_id => '2',
:attachments => {'1' => {'file' => test_uploaded_file('testfile.txt', 'text/plain')}}
end
- assert_redirected_to 'projects/list_files/ecookbook'
+ assert_redirected_to 'projects/ecookbook/files'
a = Attachment.find(:first, :order => 'created_on DESC')
assert_equal 'testfile.txt', a.filename
assert_equal Version.find(2), a.container
@@ -483,7 +483,7 @@ class ProjectsControllerTest < Test::Unit::TestCase
def test_project_menu
assert_no_difference 'Redmine::MenuManager.items(:project_menu).size' do
Redmine::MenuManager.map :project_menu do |menu|
- menu.push :foo, { :controller => 'projects', :action => 'show' }, :cation => 'Foo'
+ menu.push :foo, { :controller => 'projects', :action => 'show' }, :caption => 'Foo'
menu.push :bar, { :controller => 'projects', :action => 'show' }, :before => :activity
menu.push :hello, { :controller => 'projects', :action => 'show' }, :caption => Proc.new {|p| p.name.upcase }, :after => :bar
end
diff --git a/test/functional/repositories_controller_test.rb b/test/functional/repositories_controller_test.rb
index ccf5e77ba..ceb7341b0 100644
--- a/test/functional/repositories_controller_test.rb
+++ b/test/functional/repositories_controller_test.rb
@@ -200,7 +200,7 @@ class RepositoriesControllerTest < Test::Unit::TestCase
assert_no_difference "Changeset.count(:conditions => 'user_id = 3')" do
post :committers, :id => 1, :committers => { '0' => ['foo', '2'], '1' => ['dlopper', '3']}
- assert_redirected_to '/repositories/committers/ecookbook'
+ assert_redirected_to 'projects/ecookbook/repository/committers'
assert_equal User.find(2), c.reload.user
end
end
diff --git a/test/functional/search_controller_test.rb b/test/functional/search_controller_test.rb
index b804bbd28..ec81e417f 100644
--- a/test/functional/search_controller_test.rb
+++ b/test/functional/search_controller_test.rb
@@ -126,7 +126,7 @@ class SearchControllerTest < Test::Unit::TestCase
def test_quick_jump_to_issue
# issue of a public project
get :index, :q => "3"
- assert_redirected_to 'issues/show/3'
+ assert_redirected_to 'issues/3'
# issue of a private project
get :index, :q => "4"
diff --git a/test/functional/timelog_controller_test.rb b/test/functional/timelog_controller_test.rb
index 46c3f3ef8..a69a70ec0 100644
--- a/test/functional/timelog_controller_test.rb
+++ b/test/functional/timelog_controller_test.rb
@@ -377,6 +377,7 @@ class TimelogControllerTest < Test::Unit::TestCase
end
def test_details_all_projects_csv_export
+ Setting.date_format = '%m/%d/%Y'
get :details, :format => 'csv'
assert_response :success
assert_equal 'text/csv', @response.content_type
@@ -385,6 +386,7 @@ class TimelogControllerTest < Test::Unit::TestCase
end
def test_details_csv_export
+ Setting.date_format = '%m/%d/%Y'
get :details, :project_id => 1, :format => 'csv'
assert_response :success
assert_equal 'text/csv', @response.content_type
diff --git a/test/functional/welcome_controller_test.rb b/test/functional/welcome_controller_test.rb
index b45cb97c8..0376fd857 100644
--- a/test/functional/welcome_controller_test.rb
+++ b/test/functional/welcome_controller_test.rb
@@ -51,7 +51,7 @@ class WelcomeControllerTest < Test::Unit::TestCase
Setting.default_language = 'en'
@request.env['HTTP_ACCEPT_LANGUAGE'] = 'zh-TW'
get :index
- assert_equal :"zh-tw", @controller.current_language
+ assert_equal :"zh-TW", @controller.current_language
end
def test_browser_language_alternate_not_valid
diff --git a/test/functional/wikis_controller_test.rb b/test/functional/wikis_controller_test.rb
index 4000b1128..c558db0cb 100644
--- a/test/functional/wikis_controller_test.rb
+++ b/test/functional/wikis_controller_test.rb
@@ -63,7 +63,7 @@ class WikisControllerTest < Test::Unit::TestCase
def test_destroy
@request.session[:user_id] = 1
post :destroy, :id => 1, :confirm => 1
- assert_redirected_to :action => 'settings', :id => 'ecookbook', :tab => 'wiki'
+ assert_redirected_to :controller => 'projects', :action => 'settings', :id => 'ecookbook', :tab => 'wiki'
assert_nil Project.find(1).wiki
end
diff --git a/test/integration/account_test.rb b/test/integration/account_test.rb
index c6cfd080e..5c6f1cebd 100644
--- a/test/integration/account_test.rb
+++ b/test/integration/account_test.rb
@@ -29,7 +29,7 @@ class AccountTest < ActionController::IntegrationTest
# Replace this with your real tests.
def test_login
get "my/page"
- assert_redirected_to "account/login"
+ assert_redirected_to "/login?back_url=http%3A%2F%2Fwww.example.com%2Fmy%2Fpage"
log_user('jsmith', 'jsmith')
get "my/account"
@@ -45,7 +45,7 @@ class AccountTest < ActionController::IntegrationTest
assert_template "account/lost_password"
post "account/lost_password", :mail => 'jSmith@somenet.foo'
- assert_redirected_to "account/login"
+ assert_redirected_to "/login"
token = Token.find(:first)
assert_equal 'recovery', token.action
@@ -57,7 +57,7 @@ class AccountTest < ActionController::IntegrationTest
assert_template "account/password_recovery"
post "account/lost_password", :token => token.value, :new_password => 'newpass', :new_password_confirmation => 'newpass'
- assert_redirected_to "account/login"
+ assert_redirected_to "/login"
assert_equal 'Password was successfully updated.', flash[:notice]
log_user('jsmith', 'newpass')
@@ -86,7 +86,7 @@ class AccountTest < ActionController::IntegrationTest
post 'account/register', :user => {:login => "newuser", :language => "en", :firstname => "New", :lastname => "User", :mail => "newuser@foo.bar"},
:password => "newpass", :password_confirmation => "newpass"
- assert_redirected_to 'account/login'
+ assert_redirected_to '/login'
assert !User.find_by_login('newuser').active?
end
@@ -96,7 +96,7 @@ class AccountTest < ActionController::IntegrationTest
post 'account/register', :user => {:login => "newuser", :language => "en", :firstname => "New", :lastname => "User", :mail => "newuser@foo.bar"},
:password => "newpass", :password_confirmation => "newpass"
- assert_redirected_to 'account/login'
+ assert_redirected_to '/login'
assert !User.find_by_login('newuser').active?
token = Token.find(:first)
@@ -105,7 +105,7 @@ class AccountTest < ActionController::IntegrationTest
assert !token.expired?
get 'account/activate', :token => token.value
- assert_redirected_to 'account/login'
+ assert_redirected_to '/login'
log_user('newuser', 'newpass')
end
@@ -139,7 +139,7 @@ class AccountTest < ActionController::IntegrationTest
assert_no_tag :input, :attributes => { :name => 'user[password]' }
post 'account/register', :user => {:firstname => 'Foo', :lastname => 'Smith', :mail => 'foo@bar.com'}
- assert_redirected_to 'my/account'
+ assert_redirected_to '/my/account'
user = User.find_by_login('foo')
assert user.is_a?(User)
diff --git a/test/integration/admin_test.rb b/test/integration/admin_test.rb
index 5182c9abd..6c1db7503 100644
--- a/test/integration/admin_test.rb
+++ b/test/integration/admin_test.rb
@@ -26,7 +26,7 @@ class AdminTest < ActionController::IntegrationTest
assert_response :success
assert_template "users/add"
post "/users/add", :user => { :login => "psmith", :firstname => "Paul", :lastname => "Smith", :mail => "psmith@somenet.foo", :language => "en" }, :password => "psmith09", :password_confirmation => "psmith09"
- assert_redirected_to "users/list"
+ assert_redirected_to "/users"
user = User.find_by_login("psmith")
assert_kind_of User, user
@@ -35,7 +35,7 @@ class AdminTest < ActionController::IntegrationTest
assert_equal "Paul", logged_user.firstname
post "users/edit", :id => user.id, :user => { :status => User::STATUS_LOCKED }
- assert_redirected_to "users/list"
+ assert_redirected_to "/users"
locked_user = User.try_to_login("psmith", "psmith09")
assert_equal nil, locked_user
end
diff --git a/test/integration/application_test.rb b/test/integration/application_test.rb
index 18f4891c2..dc6fdf392 100644
--- a/test/integration/application_test.rb
+++ b/test/integration/application_test.rb
@@ -18,6 +18,8 @@
require "#{File.dirname(__FILE__)}/../test_helper"
class ApplicationTest < ActionController::IntegrationTest
+ include Redmine::I18n
+
fixtures :users
def test_set_localization
@@ -27,13 +29,13 @@ class ApplicationTest < ActionController::IntegrationTest
get 'projects', { }, 'Accept-Language' => 'fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3'
assert_response :success
assert_tag :tag => 'h2', :content => 'Projets'
- assert_equal 'fr', User.current.language
+ assert_equal :fr, current_language
# then an italien user
get 'projects', { }, 'Accept-Language' => 'it;q=0.8,en-us;q=0.5,en;q=0.3'
assert_response :success
assert_tag :tag => 'h2', :content => 'Progetti'
- assert_equal 'it', User.current.language
+ assert_equal :it, current_language
# not a supported language: default language should be used
get 'projects', { }, 'Accept-Language' => 'zz'
diff --git a/test/integration/issues_test.rb b/test/integration/issues_test.rb
index 61bbbce34..9f3c07f18 100644
--- a/test/integration/issues_test.rb
+++ b/test/integration/issues_test.rb
@@ -54,7 +54,7 @@ class IssuesTest < ActionController::IntegrationTest
assert_kind_of Issue, issue
# check redirection
- assert_redirected_to :controller => 'issues', :action => 'show'
+ assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
follow_redirect!
assert_equal issue, assigns(:issue)
diff --git a/test/test_helper.rb b/test/test_helper.rb
index ebc9bae46..7d817fb19 100644
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -46,12 +46,11 @@ class Test::Unit::TestCase
# Add more helper methods to be used by all tests here...
def log_user(login, password)
- get "/account/login"
+ get "/login"
assert_equal nil, session[:user_id]
assert_response :success
assert_template "account/login"
- post "/account/login", :username => login, :password => password
- assert_redirected_to "my/page"
+ post "/login", :username => login, :password => password
assert_equal login, User.find(session[:user_id]).login
end
diff --git a/test/unit/default_data_test.rb b/test/unit/default_data_test.rb
index 39616135e..ae637ba39 100644
--- a/test/unit/default_data_test.rb
+++ b/test/unit/default_data_test.rb
@@ -18,6 +18,7 @@
require File.dirname(__FILE__) + '/../test_helper'
class DefaultDataTest < Test::Unit::TestCase
+ include Redmine::I18n
fixtures :roles
def test_no_data
@@ -30,7 +31,7 @@ class DefaultDataTest < Test::Unit::TestCase
end
def test_load
- GLoc.valid_languages.each do |lang|
+ valid_languages.each do |lang|
begin
Role.delete_all("builtin = 0")
Tracker.delete_all
diff --git a/test/unit/helpers/application_helper_test.rb b/test/unit/helpers/application_helper_test.rb
index c72ab1706..c1b30c5f0 100644
--- a/test/unit/helpers/application_helper_test.rb
+++ b/test/unit/helpers/application_helper_test.rb
@@ -1,5 +1,5 @@
-# redMine - project management software
-# Copyright (C) 2006-2007 Jean-Philippe Lang
+# Redmine - project management software
+# Copyright (C) 2006-2009 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@@ -20,6 +20,8 @@ require File.dirname(__FILE__) + '/../../test_helper'
class ApplicationHelperTest < HelperTestCase
include ApplicationHelper
include ActionView::Helpers::TextHelper
+ include ActionView::Helpers::DateHelper
+
fixtures :projects, :roles, :enabled_modules, :users,
:repositories, :changesets,
:trackers, :issue_statuses, :issues, :versions, :documents,
@@ -390,50 +392,14 @@ EXPECTED
Setting.text_formatting = 'textile'
end
- def test_date_format_default
- today = Date.today
- Setting.date_format = ''
- assert_equal l_date(today), format_date(today)
- end
-
- def test_date_format
- today = Date.today
- Setting.date_format = '%d %m %Y'
- assert_equal today.strftime('%d %m %Y'), format_date(today)
- end
-
- def test_time_format_default
- now = Time.now
- Setting.date_format = ''
- Setting.time_format = ''
- assert_equal l_datetime(now), format_time(now)
- assert_equal l_time(now), format_time(now, false)
- end
-
- def test_time_format
- now = Time.now
- Setting.date_format = '%d %m %Y'
- Setting.time_format = '%H %M'
- assert_equal now.strftime('%d %m %Y %H %M'), format_time(now)
- assert_equal now.strftime('%H %M'), format_time(now, false)
- end
-
- def test_utc_time_format
- now = Time.now.utc
- Setting.date_format = '%d %m %Y'
- Setting.time_format = '%H %M'
- assert_equal Time.now.strftime('%d %m %Y %H %M'), format_time(now)
- assert_equal Time.now.strftime('%H %M'), format_time(now, false)
- end
-
def test_due_date_distance_in_words
to_test = { Date.today => 'Due in 0 days',
Date.today + 1 => 'Due in 1 day',
- Date.today + 100 => 'Due in 100 days',
- Date.today + 20000 => 'Due in 20000 days',
+ Date.today + 100 => 'Due in about 3 months',
+ Date.today + 20000 => 'Due in over 55 years',
Date.today - 1 => '1 day late',
- Date.today - 100 => '100 days late',
- Date.today - 20000 => '20000 days late',
+ Date.today - 100 => 'about 3 months late',
+ Date.today - 20000 => 'over 55 years late',
}
to_test.each do |date, expected|
assert_equal expected, due_date_distance_in_words(date)
diff --git a/test/unit/issue_test.rb b/test/unit/issue_test.rb
index bfe29f552..7013d2c0d 100644
--- a/test/unit/issue_test.rb
+++ b/test/unit/issue_test.rb
@@ -47,15 +47,15 @@ class IssueTest < Test::Unit::TestCase
assert issue.available_custom_fields.include?(field)
# No value for the custom field
assert !issue.save
- assert_equal 'activerecord_error_invalid', issue.errors.on(:custom_values)
+ assert_equal I18n.translate('activerecord.errors.messages.invalid'), issue.errors.on(:custom_values)
# Blank value
issue.custom_field_values = { field.id => '' }
assert !issue.save
- assert_equal 'activerecord_error_invalid', issue.errors.on(:custom_values)
+ assert_equal I18n.translate('activerecord.errors.messages.invalid'), issue.errors.on(:custom_values)
# Invalid value
issue.custom_field_values = { field.id => 'SQLServer' }
assert !issue.save
- assert_equal 'activerecord_error_invalid', issue.errors.on(:custom_values)
+ assert_equal I18n.translate('activerecord.errors.messages.invalid'), issue.errors.on(:custom_values)
# Valid value
issue.custom_field_values = { field.id => 'PostgreSQL' }
assert issue.save
diff --git a/test/unit/lib/redmine/i18n_test.rb b/test/unit/lib/redmine/i18n_test.rb
new file mode 100644
index 000000000..0335d78b1
--- /dev/null
+++ b/test/unit/lib/redmine/i18n_test.rb
@@ -0,0 +1,100 @@
+# Redmine - project management software
+# Copyright (C) 2006-2009 Jean-Philippe Lang
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+require File.dirname(__FILE__) + '/../../../test_helper'
+
+class Redmine::I18nTest < Test::Unit::TestCase
+ include Redmine::I18n
+
+ def setup
+ @hook_module = Redmine::Hook
+ end
+
+ def test_date_format_default
+ set_language_if_valid 'en'
+ today = Date.today
+ Setting.date_format = ''
+ assert_equal I18n.l(today), format_date(today)
+ end
+
+ def test_date_format
+ set_language_if_valid 'en'
+ today = Date.today
+ Setting.date_format = '%d %m %Y'
+ assert_equal today.strftime('%d %m %Y'), format_date(today)
+ end
+
+ def test_date_and_time_for_each_language
+ Setting.date_format = ''
+ valid_languages.each do |lang|
+ set_language_if_valid lang
+ assert_nothing_raised "#{lang} failure" do
+ format_date(Date.today)
+ format_time(Time.now)
+ format_time(Time.now, false)
+ end
+ assert l('date.day_names').is_a?(Array)
+ assert_equal 7, l('date.day_names').size
+
+ assert l('date.month_names').is_a?(Array)
+ assert_equal 13, l('date.month_names').size
+ end
+ end
+
+ def test_time_format_default
+ set_language_if_valid 'en'
+ now = Time.now
+ Setting.date_format = ''
+ Setting.time_format = ''
+ assert_equal I18n.l(now), format_time(now)
+ assert_equal I18n.l(now, :format => :time), format_time(now, false)
+ end
+
+ def test_time_format
+ set_language_if_valid 'en'
+ now = Time.now
+ Setting.date_format = '%d %m %Y'
+ Setting.time_format = '%H %M'
+ assert_equal now.strftime('%d %m %Y %H %M'), format_time(now)
+ assert_equal now.strftime('%H %M'), format_time(now, false)
+ end
+
+ def test_utc_time_format
+ set_language_if_valid 'en'
+ now = Time.now.utc
+ Setting.date_format = '%d %m %Y'
+ Setting.time_format = '%H %M'
+ assert_equal Time.now.strftime('%d %m %Y %H %M'), format_time(now)
+ assert_equal Time.now.strftime('%H %M'), format_time(now, false)
+ end
+
+ def test_valid_languages
+ assert valid_languages.is_a?(Array)
+ assert valid_languages.first.is_a?(Symbol)
+ end
+
+ def test_valid_language
+ to_test = {'fr' => :fr,
+ 'Fr' => :fr,
+ 'zh' => :zh,
+ 'zh-tw' => :"zh-TW",
+ 'zh-TW' => :"zh-TW",
+ 'zh-ZZ' => nil }
+
+ to_test.each {|lang, expected| assert_equal expected, find_language(lang)}
+ end
+end
diff --git a/test/unit/mailer_test.rb b/test/unit/mailer_test.rb
index 141ff40b9..156938963 100644
--- a/test/unit/mailer_test.rb
+++ b/test/unit/mailer_test.rb
@@ -18,6 +18,7 @@
require File.dirname(__FILE__) + '/../test_helper'
class MailerTest < Test::Unit::TestCase
+ include Redmine::I18n
fixtures :projects, :issues, :users, :members, :documents, :attachments, :news, :tokens, :journals, :journal_details, :changesets, :trackers, :issue_statuses, :enumerations, :messages, :boards, :repositories
def test_generated_links_in_emails
@@ -138,7 +139,7 @@ class MailerTest < Test::Unit::TestCase
# test mailer methods for each language
def test_issue_add
issue = Issue.find(1)
- GLoc.valid_languages.each do |lang|
+ valid_languages.each do |lang|
Setting.default_language = lang.to_s
assert Mailer.deliver_issue_add(issue)
end
@@ -146,7 +147,7 @@ class MailerTest < Test::Unit::TestCase
def test_issue_edit
journal = Journal.find(1)
- GLoc.valid_languages.each do |lang|
+ valid_languages.each do |lang|
Setting.default_language = lang.to_s
assert Mailer.deliver_issue_edit(journal)
end
@@ -154,7 +155,7 @@ class MailerTest < Test::Unit::TestCase
def test_document_added
document = Document.find(1)
- GLoc.valid_languages.each do |lang|
+ valid_languages.each do |lang|
Setting.default_language = lang.to_s
assert Mailer.deliver_document_added(document)
end
@@ -162,7 +163,7 @@ class MailerTest < Test::Unit::TestCase
def test_attachments_added
attachements = [ Attachment.find_by_container_type('Document') ]
- GLoc.valid_languages.each do |lang|
+ valid_languages.each do |lang|
Setting.default_language = lang.to_s
assert Mailer.deliver_attachments_added(attachements)
end
@@ -170,7 +171,7 @@ class MailerTest < Test::Unit::TestCase
def test_news_added
news = News.find(:first)
- GLoc.valid_languages.each do |lang|
+ valid_languages.each do |lang|
Setting.default_language = lang.to_s
assert Mailer.deliver_news_added(news)
end
@@ -180,7 +181,7 @@ class MailerTest < Test::Unit::TestCase
message = Message.find(:first)
recipients = ([message.root] + message.root.children).collect {|m| m.author.mail if m.author}
recipients = recipients.compact.uniq
- GLoc.valid_languages.each do |lang|
+ valid_languages.each do |lang|
Setting.default_language = lang.to_s
assert Mailer.deliver_message_posted(message, recipients)
end
@@ -188,7 +189,7 @@ class MailerTest < Test::Unit::TestCase
def test_account_information
user = User.find(:first)
- GLoc.valid_languages.each do |lang|
+ valid_languages.each do |lang|
user.update_attribute :language, lang.to_s
user.reload
assert Mailer.deliver_account_information(user, 'pAsswORd')
@@ -197,7 +198,7 @@ class MailerTest < Test::Unit::TestCase
def test_lost_password
token = Token.find(2)
- GLoc.valid_languages.each do |lang|
+ valid_languages.each do |lang|
token.user.update_attribute :language, lang.to_s
token.reload
assert Mailer.deliver_lost_password(token)
@@ -206,7 +207,7 @@ class MailerTest < Test::Unit::TestCase
def test_register
token = Token.find(1)
- GLoc.valid_languages.each do |lang|
+ valid_languages.each do |lang|
token.user.update_attribute :language, lang.to_s
token.reload
assert Mailer.deliver_register(token)
diff --git a/test/unit/project_test.rb b/test/unit/project_test.rb
index 27cff13d6..f579e14ff 100644
--- a/test/unit/project_test.rb
+++ b/test/unit/project_test.rb
@@ -44,7 +44,7 @@ class ProjectTest < Test::Unit::TestCase
@ecookbook.name = ""
assert !@ecookbook.save
assert_equal 1, @ecookbook.errors.count
- assert_equal "activerecord_error_blank", @ecookbook.errors.on(:name)
+ assert_equal I18n.translate('activerecord.errors.messages.blank'), @ecookbook.errors.on(:name)
end
def test_archive
@@ -191,7 +191,7 @@ class ProjectTest < Test::Unit::TestCase
child = parent.children.find(3)
assert_equal [1, 2], parent.tracker_ids
- assert_equal [2, 3], child.tracker_ids
+ assert_equal [2, 3], child.trackers.collect(&:id)
assert_kind_of Tracker, parent.rolled_up_trackers.first
assert_equal Tracker.find(1), parent.rolled_up_trackers.first
diff --git a/test/unit/repository_test.rb b/test/unit/repository_test.rb
index 6d4073c79..497eeabfd 100644
--- a/test/unit/repository_test.rb
+++ b/test/unit/repository_test.rb
@@ -60,7 +60,7 @@ class RepositoryTest < Test::Unit::TestCase
Setting.enabled_scm = ['Darcs', 'Git']
repository = Repository::Subversion.new(:project => Project.find(3), :url => "svn://localhost")
assert !repository.save
- assert_equal :activerecord_error_invalid, repository.errors.on(:type)
+ assert_equal I18n.translate('activerecord.errors.messages.invalid'), repository.errors.on(:type)
# re-enable Subversion for following tests
Setting.delete_all
end
diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb
index fd3403709..f6d270410 100644
--- a/test/unit/user_test.rb
+++ b/test/unit/user_test.rb
@@ -59,7 +59,7 @@ class UserTest < Test::Unit::TestCase
u.login = 'newuser2'
u.password, u.password_confirmation = "password", "password"
assert !u.save
- assert_equal 'activerecord_error_taken', u.errors.on(:mail)
+ assert_equal I18n.translate('activerecord.errors.messages.taken'), u.errors.on(:mail)
end
def test_update
diff --git a/test/unit/version_test.rb b/test/unit/version_test.rb
index 72f049335..6c5297fc4 100644
--- a/test/unit/version_test.rb
+++ b/test/unit/version_test.rb
@@ -31,7 +31,7 @@ class VersionTest < Test::Unit::TestCase
def test_invalid_effective_date_validation
v = Version.new(:project => Project.find(1), :name => '1.1', :effective_date => '99999-01-01')
assert !v.save
- assert_equal 'activerecord_error_not_a_date', v.errors.on(:effective_date)
+ assert_equal I18n.translate('activerecord.errors.messages.not_a_date'), v.errors.on(:effective_date)
end
def test_progress_should_be_0_with_no_assigned_issues
diff --git a/test/unit/wiki_page_test.rb b/test/unit/wiki_page_test.rb
index e5ebeeea6..f7f62aec4 100644
--- a/test/unit/wiki_page_test.rb
+++ b/test/unit/wiki_page_test.rb
@@ -78,15 +78,15 @@ class WikiPageTest < Test::Unit::TestCase
# A page that doesn't exist
page.parent_title = 'Unknown title'
assert !page.save
- assert_equal :activerecord_error_invalid, page.errors.on(:parent_title)
+ assert_equal I18n.translate('activerecord.errors.messages.invalid'), page.errors.on(:parent_title)
# A child page
page.parent_title = 'Page_with_an_inline_image'
assert !page.save
- assert_equal :activerecord_error_circular_dependency, page.errors.on(:parent_title)
+ assert_equal I18n.translate('activerecord.errors.messages.circular_dependency'), page.errors.on(:parent_title)
# The page itself
page.parent_title = 'CookBook_documentation'
assert !page.save
- assert_equal :activerecord_error_circular_dependency, page.errors.on(:parent_title)
+ assert_equal I18n.translate('activerecord.errors.messages.circular_dependency'), page.errors.on(:parent_title)
page.parent_title = 'Another_page'
assert page.save