annotate .svn/pristine/63/636943525457e5c4d4d0c3e654c86a8a51ed59f5.svn-base @ 1519:afce8026aaeb redmine-2.4-integration

Merge from branch "live"
author Chris Cannam
date Tue, 09 Sep 2014 09:34:53 +0100
parents cbb26bc654de
children
rev   line source
Chris@909 1 # Redmine - project management software
Chris@909 2 # Copyright (C) 2006-2011 Jean-Philippe Lang
Chris@909 3 #
Chris@909 4 # This program is free software; you can redistribute it and/or
Chris@909 5 # modify it under the terms of the GNU General Public License
Chris@909 6 # as published by the Free Software Foundation; either version 2
Chris@909 7 # of the License, or (at your option) any later version.
Chris@909 8 #
Chris@909 9 # This program is distributed in the hope that it will be useful,
Chris@909 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@909 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@909 12 # GNU General Public License for more details.
Chris@909 13 #
Chris@909 14 # You should have received a copy of the GNU General Public License
Chris@909 15 # along with this program; if not, write to the Free Software
Chris@909 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@909 17
Chris@909 18 require File.expand_path('../../../../test_helper', __FILE__)
Chris@909 19
Chris@909 20 class Redmine::I18nTest < ActiveSupport::TestCase
Chris@909 21 include Redmine::I18n
Chris@909 22 include ActionView::Helpers::NumberHelper
Chris@909 23
Chris@909 24 def setup
Chris@909 25 @hook_module = Redmine::Hook
Chris@909 26 end
Chris@909 27
Chris@909 28 def test_date_format_default
Chris@909 29 set_language_if_valid 'en'
Chris@909 30 today = Date.today
Chris@909 31 Setting.date_format = ''
Chris@909 32 assert_equal I18n.l(today), format_date(today)
Chris@909 33 end
Chris@909 34
Chris@909 35 def test_date_format
Chris@909 36 set_language_if_valid 'en'
Chris@909 37 today = Date.today
Chris@909 38 Setting.date_format = '%d %m %Y'
Chris@909 39 assert_equal today.strftime('%d %m %Y'), format_date(today)
Chris@909 40 end
Chris@909 41
Chris@909 42 def test_date_and_time_for_each_language
Chris@909 43 Setting.date_format = ''
Chris@909 44 valid_languages.each do |lang|
Chris@909 45 set_language_if_valid lang
Chris@909 46 assert_nothing_raised "#{lang} failure" do
Chris@909 47 format_date(Date.today)
Chris@909 48 format_time(Time.now)
Chris@909 49 format_time(Time.now, false)
Chris@909 50 assert_not_equal 'default', ::I18n.l(Date.today, :format => :default),
Chris@909 51 "date.formats.default missing in #{lang}"
Chris@909 52 assert_not_equal 'time', ::I18n.l(Time.now, :format => :time),
Chris@909 53 "time.formats.time missing in #{lang}"
Chris@909 54 end
Chris@909 55 assert l('date.day_names').is_a?(Array)
Chris@909 56 assert_equal 7, l('date.day_names').size
Chris@909 57
Chris@909 58 assert l('date.month_names').is_a?(Array)
Chris@909 59 assert_equal 13, l('date.month_names').size
Chris@909 60 end
Chris@909 61 end
Chris@909 62
Chris@909 63 def test_time_format
Chris@909 64 set_language_if_valid 'en'
Chris@909 65 now = Time.parse('2011-02-20 15:45:22')
Chris@909 66 with_settings :time_format => '%H:%M' do
Chris@909 67 with_settings :date_format => '' do
Chris@909 68 assert_equal '02/20/2011 15:45', format_time(now)
Chris@909 69 assert_equal '15:45', format_time(now, false)
Chris@909 70 end
Chris@909 71 with_settings :date_format => '%Y-%m-%d' do
Chris@909 72 assert_equal '2011-02-20 15:45', format_time(now)
Chris@909 73 assert_equal '15:45', format_time(now, false)
Chris@909 74 end
Chris@909 75 end
Chris@909 76 end
Chris@909 77
Chris@909 78 def test_time_format_default
Chris@909 79 set_language_if_valid 'en'
Chris@909 80 now = Time.parse('2011-02-20 15:45:22')
Chris@909 81 with_settings :time_format => '' do
Chris@909 82 with_settings :date_format => '' do
Chris@909 83 assert_equal '02/20/2011 03:45 pm', format_time(now)
Chris@909 84 assert_equal '03:45 pm', format_time(now, false)
Chris@909 85 end
Chris@909 86 with_settings :date_format => '%Y-%m-%d' do
Chris@909 87 assert_equal '2011-02-20 03:45 pm', format_time(now)
Chris@909 88 assert_equal '03:45 pm', format_time(now, false)
Chris@909 89 end
Chris@909 90 end
Chris@909 91 end
Chris@909 92
Chris@909 93 def test_time_format
Chris@909 94 set_language_if_valid 'en'
Chris@909 95 now = Time.now
Chris@909 96 Setting.date_format = '%d %m %Y'
Chris@909 97 Setting.time_format = '%H %M'
Chris@909 98 assert_equal now.strftime('%d %m %Y %H %M'), format_time(now)
Chris@909 99 assert_equal now.strftime('%H %M'), format_time(now, false)
Chris@909 100 end
Chris@909 101
Chris@909 102 def test_utc_time_format
Chris@909 103 set_language_if_valid 'en'
Chris@909 104 now = Time.now
Chris@909 105 Setting.date_format = '%d %m %Y'
Chris@909 106 Setting.time_format = '%H %M'
Chris@909 107 assert_equal now.strftime('%d %m %Y %H %M'), format_time(now.utc)
Chris@909 108 assert_equal now.strftime('%H %M'), format_time(now.utc, false)
Chris@909 109 end
Chris@909 110
Chris@909 111 def test_number_to_human_size_for_each_language
Chris@909 112 valid_languages.each do |lang|
Chris@909 113 set_language_if_valid lang
Chris@909 114 assert_nothing_raised "#{lang} failure" do
Chris@909 115 number_to_human_size(1024*1024*4)
Chris@909 116 end
Chris@909 117 end
Chris@909 118 end
Chris@909 119
Chris@909 120 def test_valid_languages
Chris@909 121 assert valid_languages.is_a?(Array)
Chris@909 122 assert valid_languages.first.is_a?(Symbol)
Chris@909 123 end
Chris@909 124
Chris@909 125 def test_valid_language
Chris@909 126 to_test = {'fr' => :fr,
Chris@909 127 'Fr' => :fr,
Chris@909 128 'zh' => :zh,
Chris@909 129 'zh-tw' => :"zh-TW",
Chris@909 130 'zh-TW' => :"zh-TW",
Chris@909 131 'zh-ZZ' => nil }
Chris@909 132 to_test.each {|lang, expected| assert_equal expected, find_language(lang)}
Chris@909 133 end
Chris@909 134
Chris@909 135 def test_fallback
Chris@909 136 ::I18n.backend.store_translations(:en, {:untranslated => "Untranslated string"})
Chris@909 137 ::I18n.locale = 'en'
Chris@909 138 assert_equal "Untranslated string", l(:untranslated)
Chris@909 139 ::I18n.locale = 'fr'
Chris@909 140 assert_equal "Untranslated string", l(:untranslated)
Chris@909 141
Chris@909 142 ::I18n.backend.store_translations(:fr, {:untranslated => "Pas de traduction"})
Chris@909 143 ::I18n.locale = 'en'
Chris@909 144 assert_equal "Untranslated string", l(:untranslated)
Chris@909 145 ::I18n.locale = 'fr'
Chris@909 146 assert_equal "Pas de traduction", l(:untranslated)
Chris@909 147 end
Chris@909 148
Chris@909 149 def test_utf8
Chris@909 150 set_language_if_valid 'ja'
Chris@909 151 str_ja_yes = "\xe3\x81\xaf\xe3\x81\x84"
Chris@909 152 i18n_ja_yes = l(:general_text_Yes)
Chris@909 153 if str_ja_yes.respond_to?(:force_encoding)
Chris@909 154 str_ja_yes.force_encoding('UTF-8')
Chris@909 155 assert_equal "UTF-8", i18n_ja_yes.encoding.to_s
Chris@909 156 end
Chris@909 157 assert_equal str_ja_yes, i18n_ja_yes
Chris@909 158 end
Chris@909 159 end