Revision 441:cbce1fd3b1b7 test/unit/lib/redmine/.svn/text-base
| test/unit/lib/redmine/.svn/text-base/i18n_test.rb.svn-base | ||
|---|---|---|
| 1 | 1 |
# Redmine - project management software |
| 2 |
# Copyright (C) 2006-2009 Jean-Philippe Lang
|
|
| 2 |
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
|
| 3 | 3 |
# |
| 4 | 4 |
# This program is free software; you can redistribute it and/or |
| 5 | 5 |
# modify it under the terms of the GNU General Public License |
| 6 | 6 |
# as published by the Free Software Foundation; either version 2 |
| 7 | 7 |
# of the License, or (at your option) any later version. |
| 8 |
#
|
|
| 8 |
# |
|
| 9 | 9 |
# This program is distributed in the hope that it will be useful, |
| 10 | 10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | 11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | 12 |
# GNU General Public License for more details. |
| 13 |
#
|
|
| 13 |
# |
|
| 14 | 14 |
# You should have received a copy of the GNU General Public License |
| 15 | 15 |
# along with this program; if not, write to the Free Software |
| 16 | 16 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| ... | ... | |
| 20 | 20 |
class Redmine::I18nTest < ActiveSupport::TestCase |
| 21 | 21 |
include Redmine::I18n |
| 22 | 22 |
include ActionView::Helpers::NumberHelper |
| 23 |
|
|
| 23 |
|
|
| 24 | 24 |
def setup |
| 25 | 25 |
@hook_module = Redmine::Hook |
| 26 | 26 |
end |
| 27 |
|
|
| 27 |
|
|
| 28 | 28 |
def test_date_format_default |
| 29 | 29 |
set_language_if_valid 'en' |
| 30 | 30 |
today = Date.today |
| 31 |
Setting.date_format = ''
|
|
| 31 |
Setting.date_format = '' |
|
| 32 | 32 |
assert_equal I18n.l(today), format_date(today) |
| 33 | 33 |
end |
| 34 |
|
|
| 34 |
|
|
| 35 | 35 |
def test_date_format |
| 36 | 36 |
set_language_if_valid 'en' |
| 37 | 37 |
today = Date.today |
| 38 | 38 |
Setting.date_format = '%d %m %Y' |
| 39 | 39 |
assert_equal today.strftime('%d %m %Y'), format_date(today)
|
| 40 | 40 |
end |
| 41 |
|
|
| 41 |
|
|
| 42 | 42 |
def test_date_and_time_for_each_language |
| 43 | 43 |
Setting.date_format = '' |
| 44 | 44 |
valid_languages.each do |lang| |
| ... | ... | |
| 47 | 47 |
format_date(Date.today) |
| 48 | 48 |
format_time(Time.now) |
| 49 | 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}"
|
|
| 50 |
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}"
|
|
| 52 | 54 |
end |
| 53 | 55 |
assert l('date.day_names').is_a?(Array)
|
| 54 | 56 |
assert_equal 7, l('date.day_names').size
|
| 55 |
|
|
| 57 |
|
|
| 56 | 58 |
assert l('date.month_names').is_a?(Array)
|
| 57 | 59 |
assert_equal 13, l('date.month_names').size
|
| 58 | 60 |
end |
| 59 | 61 |
end |
| 60 |
|
|
| 62 |
|
|
| 61 | 63 |
def test_time_format |
| 62 | 64 |
set_language_if_valid 'en' |
| 63 | 65 |
now = Time.parse('2011-02-20 15:45:22')
|
| ... | ... | |
| 66 | 68 |
assert_equal '02/20/2011 15:45', format_time(now) |
| 67 | 69 |
assert_equal '15:45', format_time(now, false) |
| 68 | 70 |
end |
| 69 |
|
|
| 70 | 71 |
with_settings :date_format => '%Y-%m-%d' do |
| 71 | 72 |
assert_equal '2011-02-20 15:45', format_time(now) |
| 72 | 73 |
assert_equal '15:45', format_time(now, false) |
| 73 | 74 |
end |
| 74 | 75 |
end |
| 75 | 76 |
end |
| 76 |
|
|
| 77 |
|
|
| 77 | 78 |
def test_time_format_default |
| 78 | 79 |
set_language_if_valid 'en' |
| 79 | 80 |
now = Time.parse('2011-02-20 15:45:22')
|
| ... | ... | |
| 82 | 83 |
assert_equal '02/20/2011 03:45 pm', format_time(now) |
| 83 | 84 |
assert_equal '03:45 pm', format_time(now, false) |
| 84 | 85 |
end |
| 85 |
|
|
| 86 | 86 |
with_settings :date_format => '%Y-%m-%d' do |
| 87 | 87 |
assert_equal '2011-02-20 03:45 pm', format_time(now) |
| 88 | 88 |
assert_equal '03:45 pm', format_time(now, false) |
| 89 | 89 |
end |
| 90 | 90 |
end |
| 91 | 91 |
end |
| 92 |
|
|
| 92 |
|
|
| 93 | 93 |
def test_time_format |
| 94 | 94 |
set_language_if_valid 'en' |
| 95 | 95 |
now = Time.now |
| ... | ... | |
| 98 | 98 |
assert_equal now.strftime('%d %m %Y %H %M'), format_time(now)
|
| 99 | 99 |
assert_equal now.strftime('%H %M'), format_time(now, false)
|
| 100 | 100 |
end |
| 101 |
|
|
| 101 |
|
|
| 102 | 102 |
def test_utc_time_format |
| 103 | 103 |
set_language_if_valid 'en' |
| 104 |
now = Time.now.utc
|
|
| 104 |
now = Time.now |
|
| 105 | 105 |
Setting.date_format = '%d %m %Y' |
| 106 | 106 |
Setting.time_format = '%H %M' |
| 107 |
assert_equal Time.now.strftime('%d %m %Y %H %M'), format_time(now)
|
|
| 108 |
assert_equal Time.now.strftime('%H %M'), format_time(now, false)
|
|
| 107 |
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 | 109 |
end |
| 110 |
|
|
| 110 |
|
|
| 111 | 111 |
def test_number_to_human_size_for_each_language |
| 112 | 112 |
valid_languages.each do |lang| |
| 113 | 113 |
set_language_if_valid lang |
| ... | ... | |
| 116 | 116 |
end |
| 117 | 117 |
end |
| 118 | 118 |
end |
| 119 |
|
|
| 119 |
|
|
| 120 | 120 |
def test_valid_languages |
| 121 | 121 |
assert valid_languages.is_a?(Array) |
| 122 | 122 |
assert valid_languages.first.is_a?(Symbol) |
| 123 | 123 |
end |
| 124 |
|
|
| 124 |
|
|
| 125 | 125 |
def test_valid_language |
| 126 | 126 |
to_test = {'fr' => :fr,
|
| 127 | 127 |
'Fr' => :fr, |
| ... | ... | |
| 129 | 129 |
'zh-tw' => :"zh-TW", |
| 130 | 130 |
'zh-TW' => :"zh-TW", |
| 131 | 131 |
'zh-ZZ' => nil } |
| 132 |
|
|
| 133 | 132 |
to_test.each {|lang, expected| assert_equal expected, find_language(lang)}
|
| 134 | 133 |
end |
| 135 |
|
|
| 134 |
|
|
| 136 | 135 |
def test_fallback |
| 137 | 136 |
::I18n.backend.store_translations(:en, {:untranslated => "Untranslated string"})
|
| 138 | 137 |
::I18n.locale = 'en' |
| 139 | 138 |
assert_equal "Untranslated string", l(:untranslated) |
| 140 | 139 |
::I18n.locale = 'fr' |
| 141 | 140 |
assert_equal "Untranslated string", l(:untranslated) |
| 142 |
|
|
| 141 |
|
|
| 143 | 142 |
::I18n.backend.store_translations(:fr, {:untranslated => "Pas de traduction"})
|
| 144 | 143 |
::I18n.locale = 'en' |
| 145 | 144 |
assert_equal "Untranslated string", l(:untranslated) |
| 146 | 145 |
::I18n.locale = 'fr' |
| 147 | 146 |
assert_equal "Pas de traduction", l(:untranslated) |
| 148 | 147 |
end |
| 148 |
|
|
| 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 |
|
| 149 | 159 |
end |
| test/unit/lib/redmine/.svn/text-base/notifiable_test.rb.svn-base | ||
|---|---|---|
| 1 |
# redMine - project management software
|
|
| 2 |
# Copyright (C) 2006-2008 Jean-Philippe Lang
|
|
| 1 |
# Redmine - project management software
|
|
| 2 |
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
|
| 3 | 3 |
# |
| 4 | 4 |
# This program is free software; you can redistribute it and/or |
| 5 | 5 |
# modify it under the terms of the GNU General Public License |
| ... | ... | |
| 22 | 22 |
end |
| 23 | 23 |
|
| 24 | 24 |
def test_all |
| 25 |
assert_equal 11, Redmine::Notifiable.all.length
|
|
| 25 |
assert_equal 12, Redmine::Notifiable.all.length
|
|
| 26 | 26 |
|
| 27 |
%w(issue_added issue_updated issue_note_added issue_status_updated issue_priority_updated news_added document_added file_added message_posted wiki_content_added wiki_content_updated).each do |notifiable| |
|
| 27 |
%w(issue_added issue_updated issue_note_added issue_status_updated issue_priority_updated news_added news_comment_added document_added file_added message_posted wiki_content_added wiki_content_updated).each do |notifiable|
|
|
| 28 | 28 |
assert Redmine::Notifiable.all.collect(&:name).include?(notifiable), "missing #{notifiable}"
|
| 29 | 29 |
end |
| 30 | 30 |
end |
| test/unit/lib/redmine/.svn/text-base/unified_diff_test.rb.svn-base | ||
|---|---|---|
| 1 | 1 |
# Redmine - project management software |
| 2 |
# Copyright (C) 2006-2008 Jean-Philippe Lang
|
|
| 2 |
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
|
| 3 | 3 |
# |
| 4 | 4 |
# This program is free software; you can redistribute it and/or |
| 5 | 5 |
# modify it under the terms of the GNU General Public License |
| ... | ... | |
| 34 | 34 |
assert_equal 2, diff.size |
| 35 | 35 |
end |
| 36 | 36 |
|
| 37 |
def test_inline_partials |
|
| 38 |
diff = Redmine::UnifiedDiff.new(read_diff_fixture('partials.diff'))
|
|
| 39 |
assert_equal 1, diff.size |
|
| 40 |
diff = diff.first |
|
| 41 |
assert_equal 43, diff.size |
|
| 42 |
|
|
| 43 |
assert_equal [51, -1], diff[0].offsets |
|
| 44 |
assert_equal [51, -1], diff[1].offsets |
|
| 45 |
assert_equal 'Lorem ipsum dolor sit amet, consectetur adipiscing <span>elit</span>', diff[0].html_line |
|
| 46 |
assert_equal 'Lorem ipsum dolor sit amet, consectetur adipiscing <span>xx</span>', diff[1].html_line |
|
| 47 |
|
|
| 48 |
assert_nil diff[2].offsets |
|
| 49 |
assert_equal 'Praesent et sagittis dui. Vivamus ac diam diam', diff[2].html_line |
|
| 50 |
|
|
| 51 |
assert_equal [0, -14], diff[3].offsets |
|
| 52 |
assert_equal [0, -14], diff[4].offsets |
|
| 53 |
assert_equal '<span>Ut sed</span> auctor justo', diff[3].html_line |
|
| 54 |
assert_equal '<span>xxx</span> auctor justo', diff[4].html_line |
|
| 55 |
|
|
| 56 |
assert_equal [13, -19], diff[6].offsets |
|
| 57 |
assert_equal [13, -19], diff[7].offsets |
|
| 58 |
|
|
| 59 |
assert_equal [24, -8], diff[9].offsets |
|
| 60 |
assert_equal [24, -8], diff[10].offsets |
|
| 61 |
|
|
| 62 |
assert_equal [37, -1], diff[12].offsets |
|
| 63 |
assert_equal [37, -1], diff[13].offsets |
|
| 64 |
|
|
| 65 |
assert_equal [0, -38], diff[15].offsets |
|
| 66 |
assert_equal [0, -38], diff[16].offsets |
|
| 67 |
end |
|
| 68 |
|
|
| 69 |
def test_side_by_side_partials |
|
| 70 |
diff = Redmine::UnifiedDiff.new(read_diff_fixture('partials.diff'), :type => 'sbs')
|
|
| 71 |
assert_equal 1, diff.size |
|
| 72 |
diff = diff.first |
|
| 73 |
assert_equal 32, diff.size |
|
| 74 |
|
|
| 75 |
assert_equal [51, -1], diff[0].offsets |
|
| 76 |
assert_equal 'Lorem ipsum dolor sit amet, consectetur adipiscing <span>elit</span>', diff[0].html_line_left |
|
| 77 |
assert_equal 'Lorem ipsum dolor sit amet, consectetur adipiscing <span>xx</span>', diff[0].html_line_right |
|
| 78 |
|
|
| 79 |
assert_nil diff[1].offsets |
|
| 80 |
assert_equal 'Praesent et sagittis dui. Vivamus ac diam diam', diff[1].html_line_left |
|
| 81 |
assert_equal 'Praesent et sagittis dui. Vivamus ac diam diam', diff[1].html_line_right |
|
| 82 |
|
|
| 83 |
assert_equal [0, -14], diff[2].offsets |
|
| 84 |
assert_equal '<span>Ut sed</span> auctor justo', diff[2].html_line_left |
|
| 85 |
assert_equal '<span>xxx</span> auctor justo', diff[2].html_line_right |
|
| 86 |
|
|
| 87 |
assert_equal [13, -19], diff[4].offsets |
|
| 88 |
assert_equal [24, -8], diff[6].offsets |
|
| 89 |
assert_equal [37, -1], diff[8].offsets |
|
| 90 |
assert_equal [0, -38], diff[10].offsets |
|
| 91 |
|
|
| 92 |
end |
|
| 93 |
|
|
| 37 | 94 |
def test_line_starting_with_dashes |
| 38 | 95 |
diff = Redmine::UnifiedDiff.new(<<-DIFF |
| 39 | 96 |
--- old.txt Wed Nov 11 14:24:58 2009 |
Also available in: Unified diff