comparison .svn/pristine/15/1562dffbb640b06caf248c7277e18410c01feded.svn-base @ 1296:038ba2d95de8 redmine-2.2

Fix redmine-2.2 branch update (add missing svn files)
author Chris Cannam
date Fri, 14 Jun 2013 09:05:06 +0100
parents
children
comparison
equal deleted inserted replaced
1294:3e4c3460b6ca 1296:038ba2d95de8
1 # Redmine - project management software
2 # Copyright (C) 2006-2012 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.expand_path('../../../../test_helper', __FILE__)
19
20 class Redmine::CodesetUtilTest < ActiveSupport::TestCase
21
22 def test_to_utf8_by_setting_from_latin1
23 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
24 s1 = "Texte encod\xc3\xa9"
25 s2 = "Texte encod\xe9"
26 s3 = s2.dup
27 if s1.respond_to?(:force_encoding)
28 s1.force_encoding("UTF-8")
29 s2.force_encoding("ASCII-8BIT")
30 s3.force_encoding("UTF-8")
31 end
32 assert_equal s1, Redmine::CodesetUtil.to_utf8_by_setting(s2)
33 assert_equal s1, Redmine::CodesetUtil.to_utf8_by_setting(s3)
34 end
35 end
36
37 def test_to_utf8_by_setting_from_euc_jp
38 with_settings :repositories_encodings => 'UTF-8,EUC-JP' do
39 s1 = "\xe3\x83\xac\xe3\x83\x83\xe3\x83\x89\xe3\x83\x9e\xe3\x82\xa4\xe3\x83\xb3"
40 s2 = "\xa5\xec\xa5\xc3\xa5\xc9\xa5\xde\xa5\xa4\xa5\xf3"
41 s3 = s2.dup
42 if s1.respond_to?(:force_encoding)
43 s1.force_encoding("UTF-8")
44 s2.force_encoding("ASCII-8BIT")
45 s3.force_encoding("UTF-8")
46 end
47 assert_equal s1, Redmine::CodesetUtil.to_utf8_by_setting(s2)
48 assert_equal s1, Redmine::CodesetUtil.to_utf8_by_setting(s3)
49 end
50 end
51
52 def test_to_utf8_by_setting_should_be_converted_all_latin1
53 with_settings :repositories_encodings => 'ISO-8859-1' do
54 s1 = "\xc3\x82\xc2\x80"
55 s2 = "\xC2\x80"
56 s3 = s2.dup
57 if s1.respond_to?(:force_encoding)
58 s1.force_encoding("UTF-8")
59 s2.force_encoding("ASCII-8BIT")
60 s3.force_encoding("UTF-8")
61 end
62 assert_equal s1, Redmine::CodesetUtil.to_utf8_by_setting(s2)
63 assert_equal s1, Redmine::CodesetUtil.to_utf8_by_setting(s3)
64 end
65 end
66
67 def test_to_utf8_by_setting_blank_string
68 assert_equal "", Redmine::CodesetUtil.to_utf8_by_setting("")
69 assert_equal nil, Redmine::CodesetUtil.to_utf8_by_setting(nil)
70 end
71
72 def test_to_utf8_by_setting_returns_ascii_as_utf8
73 s1 = "ASCII"
74 s2 = s1.dup
75 if s1.respond_to?(:force_encoding)
76 s1.force_encoding("UTF-8")
77 s2.force_encoding("ISO-8859-1")
78 end
79 str1 = Redmine::CodesetUtil.to_utf8_by_setting(s1)
80 str2 = Redmine::CodesetUtil.to_utf8_by_setting(s2)
81 assert_equal s1, str1
82 assert_equal s1, str2
83 if s1.respond_to?(:force_encoding)
84 assert_equal "UTF-8", str1.encoding.to_s
85 assert_equal "UTF-8", str2.encoding.to_s
86 end
87 end
88
89 def test_to_utf8_by_setting_invalid_utf8_sequences_should_be_stripped
90 with_settings :repositories_encodings => '' do
91 # s1 = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt")
92 s1 = "Texte encod\xe9 en ISO-8859-1."
93 s1.force_encoding("ASCII-8BIT") if s1.respond_to?(:force_encoding)
94 str = Redmine::CodesetUtil.to_utf8_by_setting(s1)
95 if str.respond_to?(:force_encoding)
96 assert str.valid_encoding?
97 assert_equal "UTF-8", str.encoding.to_s
98 end
99 assert_equal "Texte encod? en ISO-8859-1.", str
100 end
101 end
102
103 def test_to_utf8_by_setting_invalid_utf8_sequences_should_be_stripped_ja_jis
104 with_settings :repositories_encodings => 'ISO-2022-JP' do
105 s1 = "test\xb5\xfetest\xb5\xfe"
106 s1.force_encoding("ASCII-8BIT") if s1.respond_to?(:force_encoding)
107 str = Redmine::CodesetUtil.to_utf8_by_setting(s1)
108 if str.respond_to?(:force_encoding)
109 assert str.valid_encoding?
110 assert_equal "UTF-8", str.encoding.to_s
111 end
112 assert_equal "test??test??", str
113 end
114 end
115 end