comparison test/unit/lib/redmine/.svn/text-base/i18n_test.rb.svn-base @ 0:513646585e45

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