Chris@0: # Redmine - project management software Chris@0: # Copyright (C) 2006-2009 Jean-Philippe Lang Chris@0: # Chris@0: # This program is free software; you can redistribute it and/or Chris@0: # modify it under the terms of the GNU General Public License Chris@0: # as published by the Free Software Foundation; either version 2 Chris@0: # of the License, or (at your option) any later version. Chris@0: # Chris@0: # This program is distributed in the hope that it will be useful, Chris@0: # but WITHOUT ANY WARRANTY; without even the implied warranty of Chris@0: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Chris@0: # GNU General Public License for more details. Chris@0: # Chris@0: # You should have received a copy of the GNU General Public License Chris@0: # along with this program; if not, write to the Free Software Chris@0: # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Chris@0: Chris@0: require File.dirname(__FILE__) + '/../../../test_helper' Chris@0: Chris@0: class Redmine::I18nTest < ActiveSupport::TestCase Chris@0: include Redmine::I18n Chris@0: include ActionView::Helpers::NumberHelper Chris@0: Chris@0: def setup Chris@0: @hook_module = Redmine::Hook Chris@0: end Chris@0: Chris@0: def test_date_format_default Chris@0: set_language_if_valid 'en' Chris@0: today = Date.today Chris@0: Setting.date_format = '' Chris@0: assert_equal I18n.l(today), format_date(today) Chris@0: end Chris@0: Chris@0: def test_date_format Chris@0: set_language_if_valid 'en' Chris@0: today = Date.today Chris@0: Setting.date_format = '%d %m %Y' Chris@0: assert_equal today.strftime('%d %m %Y'), format_date(today) Chris@0: end Chris@0: Chris@0: def test_date_and_time_for_each_language Chris@0: Setting.date_format = '' Chris@0: valid_languages.each do |lang| Chris@0: set_language_if_valid lang Chris@0: assert_nothing_raised "#{lang} failure" do Chris@0: format_date(Date.today) Chris@0: format_time(Time.now) Chris@0: format_time(Time.now, false) Chris@0: assert_not_equal 'default', ::I18n.l(Date.today, :format => :default), "date.formats.default missing in #{lang}" Chris@0: assert_not_equal 'time', ::I18n.l(Time.now, :format => :time), "time.formats.time missing in #{lang}" Chris@0: end Chris@0: assert l('date.day_names').is_a?(Array) Chris@0: assert_equal 7, l('date.day_names').size Chris@0: Chris@0: assert l('date.month_names').is_a?(Array) Chris@0: assert_equal 13, l('date.month_names').size Chris@0: end Chris@0: end Chris@0: Chris@0: def test_time_format_default Chris@0: set_language_if_valid 'en' Chris@0: now = Time.now Chris@0: Setting.date_format = '' Chris@0: Setting.time_format = '' Chris@0: assert_equal I18n.l(now), format_time(now) Chris@0: assert_equal I18n.l(now, :format => :time), format_time(now, false) Chris@0: end Chris@0: Chris@0: def test_time_format Chris@0: set_language_if_valid 'en' Chris@0: now = Time.now Chris@0: Setting.date_format = '%d %m %Y' Chris@0: Setting.time_format = '%H %M' Chris@0: assert_equal now.strftime('%d %m %Y %H %M'), format_time(now) Chris@0: assert_equal now.strftime('%H %M'), format_time(now, false) Chris@0: end Chris@0: Chris@0: def test_utc_time_format Chris@0: set_language_if_valid 'en' Chris@0: now = Time.now.utc Chris@0: Setting.date_format = '%d %m %Y' Chris@0: Setting.time_format = '%H %M' Chris@0: assert_equal Time.now.strftime('%d %m %Y %H %M'), format_time(now) Chris@0: assert_equal Time.now.strftime('%H %M'), format_time(now, false) Chris@0: end Chris@0: Chris@0: def test_number_to_human_size_for_each_language Chris@0: valid_languages.each do |lang| Chris@0: set_language_if_valid lang Chris@0: assert_nothing_raised "#{lang} failure" do Chris@0: number_to_human_size(1024*1024*4) Chris@0: end Chris@0: end Chris@0: end Chris@0: Chris@0: def test_valid_languages Chris@0: assert valid_languages.is_a?(Array) Chris@0: assert valid_languages.first.is_a?(Symbol) Chris@0: end Chris@0: Chris@0: def test_valid_language Chris@0: to_test = {'fr' => :fr, Chris@0: 'Fr' => :fr, Chris@0: 'zh' => :zh, Chris@0: 'zh-tw' => :"zh-TW", Chris@0: 'zh-TW' => :"zh-TW", Chris@0: 'zh-ZZ' => nil } Chris@0: Chris@0: to_test.each {|lang, expected| assert_equal expected, find_language(lang)} Chris@0: end Chris@0: end