2011-10-29 16:19:11 +04:00
|
|
|
#-- encoding: UTF-8
|
2011-05-30 00:11:52 +04:00
|
|
|
#-- copyright
|
|
|
|
# ChiliProject is a project management system.
|
2011-05-30 22:52:25 +04:00
|
|
|
#
|
2013-01-07 17:14:21 +04:00
|
|
|
# Copyright (C) 2010-2013 the ChiliProject Team
|
2011-05-30 22:52:25 +04:00
|
|
|
#
|
2011-02-23 10:04:52 +03:00
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
2011-05-30 22:52:25 +04:00
|
|
|
#
|
2011-05-30 00:11:52 +04:00
|
|
|
# See doc/COPYRIGHT.rdoc for more details.
|
|
|
|
#++
|
2011-02-23 10:04:52 +03:00
|
|
|
require File.expand_path('../../../test_helper', __FILE__)
|
|
|
|
|
|
|
|
class RepositoryHelperTest < HelperTestCase
|
|
|
|
include RepositoriesHelper
|
|
|
|
|
2011-05-07 03:38:13 +04:00
|
|
|
def test_from_latin1_to_utf8_for_repositories
|
2011-02-23 10:04:52 +03:00
|
|
|
with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
|
|
|
|
s1 = "Texte encod\xc3\xa9"
|
|
|
|
s2 = "Texte encod\xe9"
|
2011-03-17 06:51:46 +03:00
|
|
|
s3 = s2.dup
|
2011-02-23 10:04:52 +03:00
|
|
|
if s1.respond_to?(:force_encoding)
|
|
|
|
s1.force_encoding("UTF-8")
|
|
|
|
s2.force_encoding("ASCII-8BIT")
|
|
|
|
s3.force_encoding("UTF-8")
|
|
|
|
end
|
2011-05-07 03:38:13 +04:00
|
|
|
assert_equal s1, to_utf8_for_repositories(s2)
|
|
|
|
assert_equal s1, to_utf8_for_repositories(s3)
|
2011-02-23 10:04:52 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-05-07 03:38:13 +04:00
|
|
|
def test_from_euc_jp_to_utf8_for_repositories
|
2011-02-23 10:04:52 +03:00
|
|
|
with_settings :repositories_encodings => 'UTF-8,EUC-JP' do
|
|
|
|
s1 = "\xe3\x83\xac\xe3\x83\x83\xe3\x83\x89\xe3\x83\x9e\xe3\x82\xa4\xe3\x83\xb3"
|
|
|
|
s2 = "\xa5\xec\xa5\xc3\xa5\xc9\xa5\xde\xa5\xa4\xa5\xf3"
|
2011-03-17 06:51:46 +03:00
|
|
|
s3 = s2.dup
|
2011-02-23 10:04:52 +03:00
|
|
|
if s1.respond_to?(:force_encoding)
|
|
|
|
s1.force_encoding("UTF-8")
|
|
|
|
s2.force_encoding("ASCII-8BIT")
|
|
|
|
s3.force_encoding("UTF-8")
|
|
|
|
end
|
2011-05-07 03:38:13 +04:00
|
|
|
assert_equal s1, to_utf8_for_repositories(s2)
|
|
|
|
assert_equal s1, to_utf8_for_repositories(s3)
|
2011-02-23 10:04:52 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-05-07 03:38:13 +04:00
|
|
|
def test_to_utf8_for_repositories_should_be_converted_all_latin1_to_utf8
|
2011-02-23 10:04:52 +03:00
|
|
|
with_settings :repositories_encodings => 'ISO-8859-1' do
|
|
|
|
s1 = "\xc3\x82\xc2\x80"
|
|
|
|
s2 = "\xC2\x80"
|
2011-03-17 06:51:46 +03:00
|
|
|
s3 = s2.dup
|
2011-02-23 10:04:52 +03:00
|
|
|
if s1.respond_to?(:force_encoding)
|
|
|
|
s1.force_encoding("UTF-8")
|
|
|
|
s2.force_encoding("ASCII-8BIT")
|
|
|
|
s3.force_encoding("UTF-8")
|
|
|
|
end
|
2011-05-07 03:38:13 +04:00
|
|
|
assert_equal s1, to_utf8_for_repositories(s2)
|
|
|
|
assert_equal s1, to_utf8_for_repositories(s3)
|
2011-02-23 10:04:52 +03:00
|
|
|
end
|
|
|
|
end
|
2011-03-17 06:51:46 +03:00
|
|
|
|
2011-05-07 03:38:13 +04:00
|
|
|
def test_to_utf8_for_repositories_blank_string
|
|
|
|
assert_equal "", to_utf8_for_repositories("")
|
|
|
|
assert_equal nil, to_utf8_for_repositories(nil)
|
2011-03-17 06:51:46 +03:00
|
|
|
end
|
2011-02-23 10:04:52 +03:00
|
|
|
|
2011-05-07 03:38:13 +04:00
|
|
|
def test_to_utf8_for_repositories_returns_ascii_as_utf8
|
2011-03-19 08:46:25 +03:00
|
|
|
s1 = "ASCII"
|
|
|
|
s2 = s1.dup
|
|
|
|
if s1.respond_to?(:force_encoding)
|
|
|
|
s1.force_encoding("UTF-8")
|
|
|
|
s2.force_encoding("ISO-8859-1")
|
|
|
|
end
|
2011-05-07 03:38:13 +04:00
|
|
|
str1 = to_utf8_for_repositories(s1)
|
|
|
|
str2 = to_utf8_for_repositories(s2)
|
2011-03-19 08:46:25 +03:00
|
|
|
assert_equal s1, str1
|
|
|
|
assert_equal s1, str2
|
|
|
|
if s1.respond_to?(:force_encoding)
|
|
|
|
assert_equal "UTF-8", str1.encoding.to_s
|
|
|
|
assert_equal "UTF-8", str2.encoding.to_s
|
|
|
|
end
|
|
|
|
end
|
2011-03-19 08:46:47 +03:00
|
|
|
|
2011-05-07 03:38:13 +04:00
|
|
|
def test_to_utf8_for_repositories_invalid_utf8_sequences_should_be_stripped
|
2011-03-19 08:46:47 +03:00
|
|
|
with_settings :repositories_encodings => '' do
|
|
|
|
s1 = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt")
|
2011-05-07 03:38:13 +04:00
|
|
|
str = to_utf8_for_repositories(s1)
|
2011-03-19 08:46:47 +03:00
|
|
|
if str.respond_to?(:force_encoding)
|
|
|
|
assert_equal "Texte encod? en ISO-8859-1.", str
|
|
|
|
assert str.valid_encoding?
|
|
|
|
assert_equal "UTF-8", str.encoding.to_s
|
|
|
|
else
|
|
|
|
assert_equal "Texte encod en ISO-8859-1.", str
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2011-03-19 08:46:25 +03:00
|
|
|
end
|