To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / test / unit / lib / redmine / .svn / text-base / i18n_test.rb.svn-base @ 442:753f1380d6bc

History | View | Annotate | Download (5.14 KB)

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