comparison test/unit/lib/redmine/i18n_test.rb @ 1464:261b3d9a4903 redmine-2.4

Update to Redmine 2.4 branch rev 12663
author Chris Cannam
date Tue, 14 Jan 2014 14:37:42 +0000
parents 433d4f72a19b
children e248c7af89ec
comparison
equal deleted inserted replaced
1296:038ba2d95de8 1464:261b3d9a4903
1 # Redmine - project management software 1 # Redmine - project management software
2 # Copyright (C) 2006-2012 Jean-Philippe Lang 2 # Copyright (C) 2006-2013 Jean-Philippe Lang
3 # 3 #
4 # This program is free software; you can redistribute it and/or 4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License 5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2 6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version. 7 # of the License, or (at your option) any later version.
103 def test_time_format_default 103 def test_time_format_default
104 set_language_if_valid 'en' 104 set_language_if_valid 'en'
105 now = Time.parse('2011-02-20 15:45:22') 105 now = Time.parse('2011-02-20 15:45:22')
106 with_settings :time_format => '' do 106 with_settings :time_format => '' do
107 with_settings :date_format => '' do 107 with_settings :date_format => '' do
108 assert_equal '02/20/2011 03:45 pm', format_time(now) 108 assert_equal '02/20/2011 03:45 PM', format_time(now)
109 assert_equal '03:45 pm', format_time(now, false) 109 assert_equal '03:45 PM', format_time(now, false)
110 end 110 end
111 with_settings :date_format => '%Y-%m-%d' do 111 with_settings :date_format => '%Y-%m-%d' do
112 assert_equal '2011-02-20 03:45 pm', format_time(now) 112 assert_equal '2011-02-20 03:45 PM', format_time(now)
113 assert_equal '03:45 pm', format_time(now, false) 113 assert_equal '03:45 PM', format_time(now, false)
114 end 114 end
115 end 115 end
116 end 116 end
117 117
118 def test_time_format_default_with_user_locale 118 def test_time_format_default_with_user_locale
127 with_settings :date_format => '%Y-%m-%d' do 127 with_settings :date_format => '%Y-%m-%d' do
128 assert_equal '2011-02-20 15:45', format_time(now) 128 assert_equal '2011-02-20 15:45', format_time(now)
129 assert_equal '15:45', format_time(now, false) 129 assert_equal '15:45', format_time(now, false)
130 end 130 end
131 end 131 end
132 end
133
134 def test_time_format
135 set_language_if_valid 'en'
136 now = Time.now
137 Setting.date_format = '%d %m %Y'
138 Setting.time_format = '%H %M'
139 assert_equal now.strftime('%d %m %Y %H %M'), format_time(now)
140 assert_equal now.strftime('%H %M'), format_time(now, false)
141 end 132 end
142 133
143 def test_utc_time_format 134 def test_utc_time_format
144 set_language_if_valid 'en' 135 set_language_if_valid 'en'
145 now = Time.now 136 now = Time.now
194 assert valid_languages.first.is_a?(Symbol) 185 assert valid_languages.first.is_a?(Symbol)
195 end 186 end
196 187
197 def test_languages_options 188 def test_languages_options
198 options = languages_options 189 options = languages_options
199
200 assert options.is_a?(Array) 190 assert options.is_a?(Array)
201 assert_equal valid_languages.size, options.size 191 assert_equal valid_languages.size, options.size
202 assert_nil options.detect {|option| !option.is_a?(Array)} 192 assert_nil options.detect {|option| !option.is_a?(Array)}
203 assert_nil options.detect {|option| option.size != 2} 193 assert_nil options.detect {|option| option.size != 2}
204 assert_nil options.detect {|option| !option.first.is_a?(String) || !option.last.is_a?(String)} 194 assert_nil options.detect {|option| !option.first.is_a?(String) || !option.last.is_a?(String)}
205 assert_include ["English", "en"], options 195 assert_include ["English", "en"], options
196 ja = "Japanese (\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e)"
197 ja.force_encoding('UTF-8') if ja.respond_to?(:force_encoding)
198 assert_include [ja, "ja"], options
206 end 199 end
207 200
208 def test_locales_validness 201 def test_locales_validness
209 lang_files_count = Dir["#{Rails.root}/config/locales/*.yml"].size 202 lang_files_count = Dir["#{Rails.root}/config/locales/*.yml"].size
210 assert_equal lang_files_count, valid_languages.size 203 assert_equal lang_files_count, valid_languages.size