From b38dc9a301c3ab0fafc5dd824ad57059ec58fc91 Mon Sep 17 00:00:00 2001 From: Toshi MARUYAMA Date: Fri, 18 Nov 2011 14:57:58 +0000 Subject: [PATCH] move repositories helper to_utf8 tests to new CodesetUtilTest (#2371) git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@7828 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- .../redmine/codeset_util_test.rb} | 43 +++++++++---------- 1 file changed, 21 insertions(+), 22 deletions(-) rename test/unit/{helpers/repository_helper_test.rb => lib/redmine/codeset_util_test.rb} (70%) diff --git a/test/unit/helpers/repository_helper_test.rb b/test/unit/lib/redmine/codeset_util_test.rb similarity index 70% rename from test/unit/helpers/repository_helper_test.rb rename to test/unit/lib/redmine/codeset_util_test.rb index c4297c5e9..681591d59 100644 --- a/test/unit/helpers/repository_helper_test.rb +++ b/test/unit/lib/redmine/codeset_util_test.rb @@ -15,12 +15,11 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -require File.expand_path('../../../test_helper', __FILE__) +require File.expand_path('../../../../test_helper', __FILE__) -class RepositoryHelperTest < ActionView::TestCase - include RepositoriesHelper +class Redmine::CodesetUtilTest < ActiveSupport::TestCase - def test_from_latin1_to_utf8 + def test_to_utf8_by_setting_from_latin1 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do s1 = "Texte encod\xc3\xa9" s2 = "Texte encod\xe9" @@ -30,12 +29,12 @@ class RepositoryHelperTest < ActionView::TestCase s2.force_encoding("ASCII-8BIT") s3.force_encoding("UTF-8") end - assert_equal s1, to_utf8(s2) - assert_equal s1, to_utf8(s3) + assert_equal s1, Redmine::CodesetUtil.to_utf8_by_setting(s2) + assert_equal s1, Redmine::CodesetUtil.to_utf8_by_setting(s3) end end - def test_from_euc_jp_to_utf8 + def test_to_utf8_by_setting_from_euc_jp 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" @@ -45,12 +44,12 @@ class RepositoryHelperTest < ActionView::TestCase s2.force_encoding("ASCII-8BIT") s3.force_encoding("UTF-8") end - assert_equal s1, to_utf8(s2) - assert_equal s1, to_utf8(s3) + assert_equal s1, Redmine::CodesetUtil.to_utf8_by_setting(s2) + assert_equal s1, Redmine::CodesetUtil.to_utf8_by_setting(s3) end end - def test_to_utf8_should_be_converted_all_latin1_to_utf8 + def test_to_utf8_by_setting_should_be_converted_all_latin1 with_settings :repositories_encodings => 'ISO-8859-1' do s1 = "\xc3\x82\xc2\x80" s2 = "\xC2\x80" @@ -60,25 +59,25 @@ class RepositoryHelperTest < ActionView::TestCase s2.force_encoding("ASCII-8BIT") s3.force_encoding("UTF-8") end - assert_equal s1, to_utf8(s2) - assert_equal s1, to_utf8(s3) + assert_equal s1, Redmine::CodesetUtil.to_utf8_by_setting(s2) + assert_equal s1, Redmine::CodesetUtil.to_utf8_by_setting(s3) end end - def test_to_utf8_blank_string - assert_equal "", to_utf8("") - assert_equal nil, to_utf8(nil) + def test_to_utf8_by_setting_blank_string + assert_equal "", Redmine::CodesetUtil.to_utf8_by_setting("") + assert_equal nil, Redmine::CodesetUtil.to_utf8_by_setting(nil) end - def test_to_utf8_returns_ascii_as_utf8 + def test_to_utf8_by_setting_returns_ascii_as_utf8 s1 = "ASCII" s2 = s1.dup if s1.respond_to?(:force_encoding) s1.force_encoding("UTF-8") s2.force_encoding("ISO-8859-1") end - str1 = to_utf8(s1) - str2 = to_utf8(s2) + str1 = Redmine::CodesetUtil.to_utf8_by_setting(s1) + str2 = Redmine::CodesetUtil.to_utf8_by_setting(s2) assert_equal s1, str1 assert_equal s1, str2 if s1.respond_to?(:force_encoding) @@ -87,12 +86,12 @@ class RepositoryHelperTest < ActionView::TestCase end end - def test_to_utf8_invalid_utf8_sequences_should_be_stripped + def test_to_utf8_by_setting_invalid_utf8_sequences_should_be_stripped with_settings :repositories_encodings => '' do # s1 = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt") s1 = "Texte encod\xe9 en ISO-8859-1." s1.force_encoding("ASCII-8BIT") if s1.respond_to?(:force_encoding) - str = to_utf8(s1) + str = Redmine::CodesetUtil.to_utf8_by_setting(s1) if str.respond_to?(:force_encoding) assert str.valid_encoding? assert_equal "UTF-8", str.encoding.to_s @@ -101,11 +100,11 @@ class RepositoryHelperTest < ActionView::TestCase end end - def test_to_utf8_invalid_utf8_sequences_should_be_stripped_ja_jis + def test_to_utf8_by_setting_invalid_utf8_sequences_should_be_stripped_ja_jis with_settings :repositories_encodings => 'ISO-2022-JP' do s1 = "test\xb5\xfetest\xb5\xfe" s1.force_encoding("ASCII-8BIT") if s1.respond_to?(:force_encoding) - str = to_utf8(s1) + str = Redmine::CodesetUtil.to_utf8_by_setting(s1) if str.respond_to?(:force_encoding) assert str.valid_encoding? assert_equal "UTF-8", str.encoding.to_s -- 2.39.5