annotate test/unit/lib/redmine/i18n_test.rb @ 878:30bfa805f6c8 feature_117

Close obsolete branch feature_117
author Chris Cannam
date Tue, 29 Mar 2011 17:41:07 +0100
parents 94944d00e43c
children af80e5618e9b 8661b858af72
rev   line source
Chris@0 1 # Redmine - project management software
Chris@0 2 # Copyright (C) 2006-2009 Jean-Philippe Lang
Chris@0 3 #
Chris@0 4 # This program is free software; you can redistribute it and/or
Chris@0 5 # modify it under the terms of the GNU General Public License
Chris@0 6 # as published by the Free Software Foundation; either version 2
Chris@0 7 # of the License, or (at your option) any later version.
Chris@0 8 #
Chris@0 9 # This program is distributed in the hope that it will be useful,
Chris@0 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@0 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@0 12 # GNU General Public License for more details.
Chris@0 13 #
Chris@0 14 # You should have received a copy of the GNU General Public License
Chris@0 15 # along with this program; if not, write to the Free Software
Chris@0 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@0 17
Chris@0 18 require File.dirname(__FILE__) + '/../../../test_helper'
Chris@0 19
Chris@0 20 class Redmine::I18nTest < ActiveSupport::TestCase
Chris@0 21 include Redmine::I18n
Chris@0 22 include ActionView::Helpers::NumberHelper
Chris@0 23
Chris@0 24 def setup
Chris@0 25 @hook_module = Redmine::Hook
Chris@0 26 end
Chris@0 27
Chris@0 28 def test_date_format_default
Chris@0 29 set_language_if_valid 'en'
Chris@0 30 today = Date.today
Chris@0 31 Setting.date_format = ''
chris@37 32 assert_equal I18n.l(today, :count => today.strftime('%d')), format_date(today)
Chris@0 33 end
Chris@0 34
Chris@0 35 def test_date_format
Chris@0 36 set_language_if_valid 'en'
Chris@0 37 today = Date.today
Chris@0 38 Setting.date_format = '%d %m %Y'
Chris@0 39 assert_equal today.strftime('%d %m %Y'), format_date(today)
Chris@0 40 end
Chris@0 41
Chris@0 42 def test_date_and_time_for_each_language
Chris@0 43 Setting.date_format = ''
Chris@0 44 valid_languages.each do |lang|
Chris@0 45 set_language_if_valid lang
Chris@0 46 assert_nothing_raised "#{lang} failure" do
Chris@0 47 format_date(Date.today)
Chris@0 48 format_time(Time.now)
Chris@0 49 format_time(Time.now, false)
chris@37 50 assert_not_equal 'default', ::I18n.l(Date.today, :count => Date.today.strftime('%d'), :format => :default), "date.formats.default missing in #{lang}"
Chris@0 51 assert_not_equal 'time', ::I18n.l(Time.now, :format => :time), "time.formats.time missing in #{lang}"
Chris@0 52 end
Chris@0 53 assert l('date.day_names').is_a?(Array)
Chris@0 54 assert_equal 7, l('date.day_names').size
Chris@0 55
Chris@0 56 assert l('date.month_names').is_a?(Array)
Chris@0 57 assert_equal 13, l('date.month_names').size
Chris@0 58 end
Chris@0 59 end
Chris@0 60
Chris@0 61 def test_time_format_default
Chris@0 62 set_language_if_valid 'en'
Chris@0 63 now = Time.now
Chris@0 64 Setting.date_format = ''
Chris@0 65 Setting.time_format = ''
chris@37 66 assert_equal I18n.l(now, :count => now.strftime('%d')), format_time(now)
chris@37 67 assert_equal I18n.l(now, :count => now.strftime('%d'), :format => :time), format_time(now, false)
Chris@0 68 end
Chris@0 69
Chris@0 70 def test_time_format
Chris@0 71 set_language_if_valid 'en'
Chris@0 72 now = Time.now
Chris@0 73 Setting.date_format = '%d %m %Y'
Chris@0 74 Setting.time_format = '%H %M'
Chris@0 75 assert_equal now.strftime('%d %m %Y %H %M'), format_time(now)
Chris@0 76 assert_equal now.strftime('%H %M'), format_time(now, false)
Chris@0 77 end
Chris@0 78
Chris@0 79 def test_utc_time_format
Chris@0 80 set_language_if_valid 'en'
Chris@0 81 now = Time.now.utc
Chris@0 82 Setting.date_format = '%d %m %Y'
Chris@0 83 Setting.time_format = '%H %M'
Chris@0 84 assert_equal Time.now.strftime('%d %m %Y %H %M'), format_time(now)
Chris@0 85 assert_equal Time.now.strftime('%H %M'), format_time(now, false)
Chris@0 86 end
Chris@0 87
Chris@0 88 def test_number_to_human_size_for_each_language
Chris@0 89 valid_languages.each do |lang|
Chris@0 90 set_language_if_valid lang
Chris@0 91 assert_nothing_raised "#{lang} failure" do
Chris@0 92 number_to_human_size(1024*1024*4)
Chris@0 93 end
Chris@0 94 end
Chris@0 95 end
Chris@0 96
Chris@0 97 def test_valid_languages
Chris@0 98 assert valid_languages.is_a?(Array)
Chris@0 99 assert valid_languages.first.is_a?(Symbol)
Chris@0 100 end
Chris@0 101
Chris@0 102 def test_valid_language
Chris@0 103 to_test = {'fr' => :fr,
Chris@0 104 'Fr' => :fr,
Chris@0 105 'zh' => :zh,
Chris@0 106 'zh-tw' => :"zh-TW",
Chris@0 107 'zh-TW' => :"zh-TW",
Chris@0 108 'zh-ZZ' => nil }
Chris@0 109
Chris@0 110 to_test.each {|lang, expected| assert_equal expected, find_language(lang)}
Chris@0 111 end
Chris@0 112 end