annotate test/unit/lib/redmine/.svn/text-base/i18n_test.rb.svn-base @ 850:e9e53db0c93a bug_213

Close obsolete branch bug_213
author Chris Cannam
date Sat, 13 Aug 2011 14:51:48 +0100
parents 753f1380d6bc
children
rev   line source
Chris@0 1 # Redmine - project management software
Chris@441 2 # Copyright (C) 2006-2011 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@441 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@441 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@119 18 require File.expand_path('../../../../test_helper', __FILE__)
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@441 23
Chris@0 24 def setup
Chris@0 25 @hook_module = Redmine::Hook
Chris@0 26 end
Chris@441 27
Chris@0 28 def test_date_format_default
Chris@0 29 set_language_if_valid 'en'
Chris@0 30 today = Date.today
Chris@441 31 Setting.date_format = ''
Chris@119 32 assert_equal I18n.l(today), format_date(today)
Chris@0 33 end
Chris@441 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@441 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@441 50 assert_not_equal 'default', ::I18n.l(Date.today, :format => :default),
Chris@441 51 "date.formats.default missing in #{lang}"
Chris@441 52 assert_not_equal 'time', ::I18n.l(Time.now, :format => :time),
Chris@441 53 "time.formats.time missing in #{lang}"
Chris@0 54 end
Chris@0 55 assert l('date.day_names').is_a?(Array)
Chris@0 56 assert_equal 7, l('date.day_names').size
Chris@441 57
Chris@0 58 assert l('date.month_names').is_a?(Array)
Chris@0 59 assert_equal 13, l('date.month_names').size
Chris@0 60 end
Chris@0 61 end
Chris@441 62
Chris@245 63 def test_time_format
Chris@245 64 set_language_if_valid 'en'
Chris@245 65 now = Time.parse('2011-02-20 15:45:22')
Chris@245 66 with_settings :time_format => '%H:%M' do
Chris@245 67 with_settings :date_format => '' do
Chris@245 68 assert_equal '02/20/2011 15:45', format_time(now)
Chris@245 69 assert_equal '15:45', format_time(now, false)
Chris@245 70 end
Chris@245 71 with_settings :date_format => '%Y-%m-%d' do
Chris@245 72 assert_equal '2011-02-20 15:45', format_time(now)
Chris@245 73 assert_equal '15:45', format_time(now, false)
Chris@245 74 end
Chris@245 75 end
Chris@245 76 end
Chris@441 77
Chris@0 78 def test_time_format_default
Chris@0 79 set_language_if_valid 'en'
Chris@245 80 now = Time.parse('2011-02-20 15:45:22')
Chris@245 81 with_settings :time_format => '' do
Chris@245 82 with_settings :date_format => '' do
Chris@245 83 assert_equal '02/20/2011 03:45 pm', format_time(now)
Chris@245 84 assert_equal '03:45 pm', format_time(now, false)
Chris@245 85 end
Chris@245 86 with_settings :date_format => '%Y-%m-%d' do
Chris@245 87 assert_equal '2011-02-20 03:45 pm', format_time(now)
Chris@245 88 assert_equal '03:45 pm', format_time(now, false)
Chris@245 89 end
Chris@245 90 end
Chris@0 91 end
Chris@441 92
Chris@0 93 def test_time_format
Chris@0 94 set_language_if_valid 'en'
Chris@0 95 now = Time.now
Chris@0 96 Setting.date_format = '%d %m %Y'
Chris@0 97 Setting.time_format = '%H %M'
Chris@0 98 assert_equal now.strftime('%d %m %Y %H %M'), format_time(now)
Chris@0 99 assert_equal now.strftime('%H %M'), format_time(now, false)
Chris@0 100 end
Chris@441 101
Chris@0 102 def test_utc_time_format
Chris@0 103 set_language_if_valid 'en'
Chris@441 104 now = Time.now
Chris@0 105 Setting.date_format = '%d %m %Y'
Chris@0 106 Setting.time_format = '%H %M'
Chris@441 107 assert_equal now.strftime('%d %m %Y %H %M'), format_time(now.utc)
Chris@441 108 assert_equal now.strftime('%H %M'), format_time(now.utc, false)
Chris@0 109 end
Chris@441 110
Chris@0 111 def test_number_to_human_size_for_each_language
Chris@0 112 valid_languages.each do |lang|
Chris@0 113 set_language_if_valid lang
Chris@0 114 assert_nothing_raised "#{lang} failure" do
Chris@0 115 number_to_human_size(1024*1024*4)
Chris@0 116 end
Chris@0 117 end
Chris@0 118 end
Chris@441 119
Chris@0 120 def test_valid_languages
Chris@0 121 assert valid_languages.is_a?(Array)
Chris@0 122 assert valid_languages.first.is_a?(Symbol)
Chris@0 123 end
Chris@441 124
Chris@0 125 def test_valid_language
Chris@0 126 to_test = {'fr' => :fr,
Chris@0 127 'Fr' => :fr,
Chris@0 128 'zh' => :zh,
Chris@0 129 'zh-tw' => :"zh-TW",
Chris@0 130 'zh-TW' => :"zh-TW",
Chris@0 131 'zh-ZZ' => nil }
Chris@0 132 to_test.each {|lang, expected| assert_equal expected, find_language(lang)}
Chris@0 133 end
Chris@441 134
Chris@119 135 def test_fallback
Chris@119 136 ::I18n.backend.store_translations(:en, {:untranslated => "Untranslated string"})
Chris@119 137 ::I18n.locale = 'en'
Chris@119 138 assert_equal "Untranslated string", l(:untranslated)
Chris@119 139 ::I18n.locale = 'fr'
Chris@119 140 assert_equal "Untranslated string", l(:untranslated)
Chris@441 141
Chris@119 142 ::I18n.backend.store_translations(:fr, {:untranslated => "Pas de traduction"})
Chris@119 143 ::I18n.locale = 'en'
Chris@119 144 assert_equal "Untranslated string", l(:untranslated)
Chris@119 145 ::I18n.locale = 'fr'
Chris@119 146 assert_equal "Pas de traduction", l(:untranslated)
Chris@119 147 end
Chris@441 148
Chris@441 149 def test_utf8
Chris@441 150 set_language_if_valid 'ja'
Chris@441 151 str_ja_yes = "\xe3\x81\xaf\xe3\x81\x84"
Chris@441 152 i18n_ja_yes = l(:general_text_Yes)
Chris@441 153 if str_ja_yes.respond_to?(:force_encoding)
Chris@441 154 str_ja_yes.force_encoding('UTF-8')
Chris@441 155 assert_equal "UTF-8", i18n_ja_yes.encoding.to_s
Chris@441 156 end
Chris@441 157 assert_equal str_ja_yes, i18n_ja_yes
Chris@441 158 end
Chris@0 159 end