diff options
author | Go MAEDA <maeda@farend.jp> | 2022-01-07 01:29:55 +0000 |
---|---|---|
committer | Go MAEDA <maeda@farend.jp> | 2022-01-07 01:29:55 +0000 |
commit | ec0ce00b95c4d08c2c7c9bae79d16f84829349fb (patch) | |
tree | ef315418de950296aeb2c000f615417e375ad50e /test/unit | |
parent | 03cd59edc05e540ff549903170e52051bcca229b (diff) | |
download | redmine-ec0ce00b95c4d08c2c7c9bae79d16f84829349fb.tar.gz redmine-ec0ce00b95c4d08c2c7c9bae79d16f84829349fb.zip |
Auto guess file encoding when importing CSV file (#34718).
Patch by Go MAEDA.
git-svn-id: http://svn.redmine.org/redmine/trunk@21352 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'test/unit')
-rw-r--r-- | test/unit/issue_import_test.rb | 27 | ||||
-rw-r--r-- | test/unit/lib/redmine/codeset_util_test.rb | 17 |
2 files changed, 44 insertions, 0 deletions
diff --git a/test/unit/issue_import_test.rb b/test/unit/issue_import_test.rb index b08629b55..3f98f0372 100644 --- a/test/unit/issue_import_test.rb +++ b/test/unit/issue_import_test.rb @@ -411,4 +411,31 @@ class IssueImportTest < ActiveSupport::TestCase assert_empty import.mapping end + + def test_set_default_settings_should_guess_encoding + import = generate_import('import_iso8859-1.csv') + with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do + import.set_default_settings + guessed_encoding = import.settings['encoding'] + assert_equal 'ISO-8859-1', guessed_encoding + end + with_settings :repositories_encodings => 'UTF-8,iso8859-1' do + import.set_default_settings + guessed_encoding = import.settings['encoding'] + assert_equal 'ISO-8859-1', guessed_encoding + assert_includes Setting::ENCODINGS, guessed_encoding + end + end + + def test_set_default_settings_should_use_general_csv_encoding_when_cannnot_guess_encoding + import = generate_import('import_iso8859-1.csv') + user = User.generate!(:language => 'ja') + import.user = user + with_settings :repositories_encodings => 'UTF-8' do + import.set_default_settings + guessed_encoding = import.settings['encoding'] + assert_equal 'CP932', lu(user, :general_csv_encoding) + assert_equal 'CP932', guessed_encoding + end + end end diff --git a/test/unit/lib/redmine/codeset_util_test.rb b/test/unit/lib/redmine/codeset_util_test.rb index aaf664047..56094ecfa 100644 --- a/test/unit/lib/redmine/codeset_util_test.rb +++ b/test/unit/lib/redmine/codeset_util_test.rb @@ -101,4 +101,21 @@ class Redmine::CodesetUtilTest < ActiveSupport::TestCase assert_equal "UTF-8", s2.encoding.to_s assert_equal 'こんにち?', s2 end + + def test_guess_encoding_should_return_guessed_encoding + str = '日本語'.encode('Windows-31J').b + with_settings :repositories_encodings => 'UTF-8,Windows-31J' do + assert_equal 'Windows-31J', Redmine::CodesetUtil.guess_encoding(str) + end + with_settings :repositories_encodings => 'UTF-8,csWindows31J' do + assert_equal 'csWindows31J', Redmine::CodesetUtil.guess_encoding(str) + end + end + + def guess_encoding_should_return_nil_if_cannot_guess_encoding + str = '日本語'.encode('Windows-31J').b + with_settings :repositories_encodings => 'UTF-8,EUC-JP' do + assert_nil Redmine::CodesetUtil.guess_encoding(str) + end + end end |