Chris@245: # Redmine - project management software Chris@245: # Copyright (C) 2006-2011 Jean-Philippe Lang Chris@245: # Chris@245: # This program is free software; you can redistribute it and/or Chris@245: # modify it under the terms of the GNU General Public License Chris@245: # as published by the Free Software Foundation; either version 2 Chris@245: # of the License, or (at your option) any later version. Chris@245: # Chris@245: # This program is distributed in the hope that it will be useful, Chris@245: # but WITHOUT ANY WARRANTY; without even the implied warranty of Chris@245: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Chris@245: # GNU General Public License for more details. Chris@245: # Chris@245: # You should have received a copy of the GNU General Public License Chris@245: # along with this program; if not, write to the Free Software Chris@245: # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Chris@245: Chris@245: require File.expand_path('../../../test_helper', __FILE__) Chris@245: Chris@245: class RepositoryHelperTest < HelperTestCase Chris@245: include RepositoriesHelper Chris@245: Chris@245: def test_from_latin1_to_utf8 Chris@245: with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do Chris@245: s1 = "Texte encod\xc3\xa9" Chris@245: s2 = "Texte encod\xe9" Chris@245: s3 = s2 Chris@245: if s1.respond_to?(:force_encoding) Chris@245: s1.force_encoding("UTF-8") Chris@245: s2.force_encoding("ASCII-8BIT") Chris@245: s3.force_encoding("UTF-8") Chris@245: end Chris@245: assert_equal s1, to_utf8(s2) Chris@245: assert_equal s1, to_utf8(s3) Chris@245: end Chris@245: end Chris@245: Chris@245: def test_from_euc_jp_to_utf8 Chris@245: with_settings :repositories_encodings => 'UTF-8,EUC-JP' do Chris@245: s1 = "\xe3\x83\xac\xe3\x83\x83\xe3\x83\x89\xe3\x83\x9e\xe3\x82\xa4\xe3\x83\xb3" Chris@245: s2 = "\xa5\xec\xa5\xc3\xa5\xc9\xa5\xde\xa5\xa4\xa5\xf3" Chris@245: s3 = s2 Chris@245: if s1.respond_to?(:force_encoding) Chris@245: s1.force_encoding("UTF-8") Chris@245: s2.force_encoding("ASCII-8BIT") Chris@245: s3.force_encoding("UTF-8") Chris@245: end Chris@245: assert_equal s1, to_utf8(s2) Chris@245: assert_equal s1, to_utf8(s3) Chris@245: end Chris@245: end Chris@245: Chris@245: def test_to_utf8_should_be_converted_all_latin1_to_utf8 Chris@245: with_settings :repositories_encodings => 'ISO-8859-1' do Chris@245: s1 = "\xc3\x82\xc2\x80" Chris@245: s2 = "\xC2\x80" Chris@245: s3 = s2 Chris@245: if s1.respond_to?(:force_encoding) Chris@245: s1.force_encoding("UTF-8") Chris@245: s2.force_encoding("ASCII-8BIT") Chris@245: s3.force_encoding("UTF-8") Chris@245: end Chris@245: assert_equal s1, to_utf8(s2) Chris@245: assert_equal s1, to_utf8(s3) Chris@245: end Chris@245: end Chris@245: end Chris@245: