annotate .svn/pristine/e2/e2e7de446428cc9a38224f2be0a8f285b69b66af.svn-base @ 1524:82fac3dcf466 redmine-2.5-integration

Fix failure to interpret Javascript when autocompleting members for project
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Thu, 11 Sep 2014 10:24:38 +0100
parents e248c7af89ec
children
rev   line source
Chris@1494 1 # Redmine - project management software
Chris@1494 2 # Copyright (C) 2006-2014 Jean-Philippe Lang
Chris@1494 3 #
Chris@1494 4 # This program is free software; you can redistribute it and/or
Chris@1494 5 # modify it under the terms of the GNU General Public License
Chris@1494 6 # as published by the Free Software Foundation; either version 2
Chris@1494 7 # of the License, or (at your option) any later version.
Chris@1494 8 #
Chris@1494 9 # This program is distributed in the hope that it will be useful,
Chris@1494 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1494 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1494 12 # GNU General Public License for more details.
Chris@1494 13 #
Chris@1494 14 # You should have received a copy of the GNU General Public License
Chris@1494 15 # along with this program; if not, write to the Free Software
Chris@1494 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1494 17
Chris@1494 18 require File.expand_path('../../../../test_helper', __FILE__)
Chris@1494 19
Chris@1494 20 class Redmine::CodesetUtilTest < ActiveSupport::TestCase
Chris@1494 21
Chris@1494 22 def test_to_utf8_by_setting_from_latin1
Chris@1494 23 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
Chris@1494 24 s1 = "Texte encod\xc3\xa9"
Chris@1494 25 s2 = "Texte encod\xe9"
Chris@1494 26 s3 = s2.dup
Chris@1494 27 if s1.respond_to?(:force_encoding)
Chris@1494 28 s1.force_encoding("UTF-8")
Chris@1494 29 s2.force_encoding("ASCII-8BIT")
Chris@1494 30 s3.force_encoding("UTF-8")
Chris@1494 31 end
Chris@1494 32 assert_equal s1, Redmine::CodesetUtil.to_utf8_by_setting(s2)
Chris@1494 33 assert_equal s1, Redmine::CodesetUtil.to_utf8_by_setting(s3)
Chris@1494 34 end
Chris@1494 35 end
Chris@1494 36
Chris@1494 37 def test_to_utf8_by_setting_from_euc_jp
Chris@1494 38 with_settings :repositories_encodings => 'UTF-8,EUC-JP' do
Chris@1494 39 s1 = "\xe3\x83\xac\xe3\x83\x83\xe3\x83\x89\xe3\x83\x9e\xe3\x82\xa4\xe3\x83\xb3"
Chris@1494 40 s2 = "\xa5\xec\xa5\xc3\xa5\xc9\xa5\xde\xa5\xa4\xa5\xf3"
Chris@1494 41 s3 = s2.dup
Chris@1494 42 if s1.respond_to?(:force_encoding)
Chris@1494 43 s1.force_encoding("UTF-8")
Chris@1494 44 s2.force_encoding("ASCII-8BIT")
Chris@1494 45 s3.force_encoding("UTF-8")
Chris@1494 46 end
Chris@1494 47 assert_equal s1, Redmine::CodesetUtil.to_utf8_by_setting(s2)
Chris@1494 48 assert_equal s1, Redmine::CodesetUtil.to_utf8_by_setting(s3)
Chris@1494 49 end
Chris@1494 50 end
Chris@1494 51
Chris@1494 52 def test_to_utf8_by_setting_should_be_converted_all_latin1
Chris@1494 53 with_settings :repositories_encodings => 'ISO-8859-1' do
Chris@1494 54 s1 = "\xc3\x82\xc2\x80"
Chris@1494 55 s2 = "\xC2\x80"
Chris@1494 56 s3 = s2.dup
Chris@1494 57 if s1.respond_to?(:force_encoding)
Chris@1494 58 s1.force_encoding("UTF-8")
Chris@1494 59 s2.force_encoding("ASCII-8BIT")
Chris@1494 60 s3.force_encoding("UTF-8")
Chris@1494 61 end
Chris@1494 62 assert_equal s1, Redmine::CodesetUtil.to_utf8_by_setting(s2)
Chris@1494 63 assert_equal s1, Redmine::CodesetUtil.to_utf8_by_setting(s3)
Chris@1494 64 end
Chris@1494 65 end
Chris@1494 66
Chris@1494 67 def test_to_utf8_by_setting_blank_string
Chris@1494 68 assert_equal "", Redmine::CodesetUtil.to_utf8_by_setting("")
Chris@1494 69 assert_equal nil, Redmine::CodesetUtil.to_utf8_by_setting(nil)
Chris@1494 70 end
Chris@1494 71
Chris@1494 72 def test_to_utf8_by_setting_returns_ascii_as_utf8
Chris@1494 73 s1 = "ASCII"
Chris@1494 74 s2 = s1.dup
Chris@1494 75 if s1.respond_to?(:force_encoding)
Chris@1494 76 s1.force_encoding("UTF-8")
Chris@1494 77 s2.force_encoding("ISO-8859-1")
Chris@1494 78 end
Chris@1494 79 str1 = Redmine::CodesetUtil.to_utf8_by_setting(s1)
Chris@1494 80 str2 = Redmine::CodesetUtil.to_utf8_by_setting(s2)
Chris@1494 81 assert_equal s1, str1
Chris@1494 82 assert_equal s1, str2
Chris@1494 83 if s1.respond_to?(:force_encoding)
Chris@1494 84 assert_equal "UTF-8", str1.encoding.to_s
Chris@1494 85 assert_equal "UTF-8", str2.encoding.to_s
Chris@1494 86 end
Chris@1494 87 end
Chris@1494 88
Chris@1494 89 def test_to_utf8_by_setting_invalid_utf8_sequences_should_be_stripped
Chris@1494 90 with_settings :repositories_encodings => '' do
Chris@1494 91 # s1 = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt")
Chris@1494 92 s1 = "Texte encod\xe9 en ISO-8859-1."
Chris@1494 93 s1.force_encoding("ASCII-8BIT") if s1.respond_to?(:force_encoding)
Chris@1494 94 str = Redmine::CodesetUtil.to_utf8_by_setting(s1)
Chris@1494 95 if str.respond_to?(:force_encoding)
Chris@1494 96 assert str.valid_encoding?
Chris@1494 97 assert_equal "UTF-8", str.encoding.to_s
Chris@1494 98 end
Chris@1494 99 assert_equal "Texte encod? en ISO-8859-1.", str
Chris@1494 100 end
Chris@1494 101 end
Chris@1494 102
Chris@1494 103 def test_to_utf8_by_setting_invalid_utf8_sequences_should_be_stripped_ja_jis
Chris@1494 104 with_settings :repositories_encodings => 'ISO-2022-JP' do
Chris@1494 105 s1 = "test\xb5\xfetest\xb5\xfe"
Chris@1494 106 s1.force_encoding("ASCII-8BIT") if s1.respond_to?(:force_encoding)
Chris@1494 107 str = Redmine::CodesetUtil.to_utf8_by_setting(s1)
Chris@1494 108 if str.respond_to?(:force_encoding)
Chris@1494 109 assert str.valid_encoding?
Chris@1494 110 assert_equal "UTF-8", str.encoding.to_s
Chris@1494 111 end
Chris@1494 112 assert_equal "test??test??", str
Chris@1494 113 end
Chris@1494 114 end
Chris@1494 115 end