summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorGo MAEDA <maeda@farend.jp>2018-05-07 01:13:12 +0000
committerGo MAEDA <maeda@farend.jp>2018-05-07 01:13:12 +0000
commitca2875fab2c3c3d96dcdbad5c3eb1068887dadd4 (patch)
tree5cc6aa92db02475ea06e2be225b91cb985d9f027 /test
parent43d9bea7c5da32a99c3ebdb828e23d6a02c31c12 (diff)
downloadredmine-ca2875fab2c3c3d96dcdbad5c3eb1068887dadd4.tar.gz
redmine-ca2875fab2c3c3d96dcdbad5c3eb1068887dadd4.zip
Allow switching the encoding to UTF-8 when exporting to CSV (#26279).
Patch by Mizuki ISHIKAWA. git-svn-id: http://svn.redmine.org/redmine/trunk@17328 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'test')
-rw-r--r--test/helpers/application_helper_test.rb16
-rw-r--r--test/unit/lib/redmine/export/csv_test.rb17
2 files changed, 32 insertions, 1 deletions
diff --git a/test/helpers/application_helper_test.rb b/test/helpers/application_helper_test.rb
index 78a4822f1..692c6c6bb 100644
--- a/test/helpers/application_helper_test.rb
+++ b/test/helpers/application_helper_test.rb
@@ -1607,4 +1607,20 @@ RAW
assert_equal '<span class="hours hours-int">0</span><span class="hours hours-dec">:45</span>', html_hours('0:45')
assert_equal '<span class="hours hours-int">0</span><span class="hours hours-dec">.75</span>', html_hours('0.75')
end
+
+ def test_export_csv_encoding_select_tag_should_return_nil_when_general_csv_encoding_is_UTF8
+ with_locale 'az' do
+ assert_equal l(:general_csv_encoding), 'UTF-8'
+ assert_nil export_csv_encoding_select_tag
+ end
+ end
+
+ def test_export_csv_encoding_select_tag_should_have_two_option_when_general_csv_encoding_is_not_UTF8
+ with_locale 'en' do
+ assert_not_equal l(:general_csv_encoding), 'UTF-8'
+ result = export_csv_encoding_select_tag
+ assert_select_in result, "option[selected='selected'][value=#{l(:general_csv_encoding)}]", :text => l(:general_csv_encoding)
+ assert_select_in result, "option[value='UTF-8']", :text => 'UTF-8'
+ end
+ end
end
diff --git a/test/unit/lib/redmine/export/csv_test.rb b/test/unit/lib/redmine/export/csv_test.rb
index 52e930c14..d3727b620 100644
--- a/test/unit/lib/redmine/export/csv_test.rb
+++ b/test/unit/lib/redmine/export/csv_test.rb
@@ -18,7 +18,7 @@
require File.expand_path('../../../../../test_helper', __FILE__)
class CsvTest < ActiveSupport::TestCase
-
+ include Redmine::I18n
BOM = "\xEF\xBB\xBF".force_encoding('UTF-8')
def test_should_include_bom_when_utf8_encoded
@@ -28,4 +28,19 @@ class CsvTest < ActiveSupport::TestCase
assert string.starts_with?(BOM)
end
end
+
+ def test_generate_should_return_strings_with_given_encoding
+ with_locale 'en' do
+ string = Redmine::Export::CSV.generate({encoding: 'ISO-8859-3'}) {|csv| csv << %w(Foo Bar)}
+ assert_equal 'ISO-8859-3', string.encoding.name
+ assert_not_equal l(:general_csv_encoding), string.encoding.name
+ end
+ end
+
+ def test_generate_should_return_strings_with_general_csv_encoding_if_invalid_encoding_is_given
+ with_locale 'en' do
+ string = Redmine::Export::CSV.generate({encoding: 'invalid-encoding-name'}) {|csv| csv << %w(Foo Bar)}
+ assert_equal l(:general_csv_encoding), string.encoding.name
+ end
+ end
end