diff options
author | Toshi MARUYAMA <marutosijp2@yahoo.co.jp> | 2011-11-24 09:43:01 +0000 |
---|---|---|
committer | Toshi MARUYAMA <marutosijp2@yahoo.co.jp> | 2011-11-24 09:43:01 +0000 |
commit | f936b7b5a4ecd335f0464adb07d629d7c4f6b081 (patch) | |
tree | 70837876ecff9a57b291caec9a3c74fdb15f4e6c /test | |
parent | be29227c12da043996cf05a489fa6b7ef26bea81 (diff) | |
download | redmine-f936b7b5a4ecd335f0464adb07d629d7c4f6b081.tar.gz redmine-f936b7b5a4ecd335f0464adb07d629d7c4f6b081.zip |
pdf: lib: add the method to return attachment from filename and encoding (#3261)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@7912 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'test')
-rw-r--r-- | test/fixtures/attachments.yml | 26 | ||||
-rw-r--r-- | test/unit/lib/redmine/export/pdf_test.rb | 37 |
2 files changed, 63 insertions, 0 deletions
diff --git a/test/fixtures/attachments.yml b/test/fixtures/attachments.yml index 57bd23822..32d7cabc1 100644 --- a/test/fixtures/attachments.yml +++ b/test/fixtures/attachments.yml @@ -208,3 +208,29 @@ attachments_017: filename: testfile.PNG filesize: 3582 author_id: 2 +attachments_018: + content_type: image/png + downloads: 0 + created_on: 2011-01-23 16:14:50 +09:00 + disk_filename: 101123161450_testfile_1.png + container_id: 14 + digest: 8e0294de2441577c529f170b6fb8f638 + id: 18 + container_type: Issue + description: "" + filename: testテスト.png + filesize: 2654 + author_id: 2 +attachments_019: + content_type: image/png + downloads: 0 + created_on: 2011-02-23 16:14:50 +09:00 + disk_filename: 101223161450_testfile_2.png + container_id: 14 + digest: 6bc2963e8d7ea0d3e68d12d1fba3d6ca + id: 19 + container_type: Issue + description: "" + filename: Testテスト.PNG + filesize: 3582 + author_id: 2 diff --git a/test/unit/lib/redmine/export/pdf_test.rb b/test/unit/lib/redmine/export/pdf_test.rb index d80741cdd..9b89958b8 100644 --- a/test/unit/lib/redmine/export/pdf_test.rb +++ b/test/unit/lib/redmine/export/pdf_test.rb @@ -19,6 +19,8 @@ require File.expand_path('../../../../../test_helper', __FILE__) require 'iconv' class PdfTest < ActiveSupport::TestCase + fixtures :users, :projects, :roles, :members, :member_roles, + :enabled_modules, :issues, :trackers, :attachments def test_fix_text_encoding_nil assert_equal '', Redmine::Export::PDF::RDMPdfEncoding::rdm_from_utf8(nil, "UTF-8") @@ -87,4 +89,39 @@ class PdfTest < ActiveSupport::TestCase assert_equal "Texte encod? en ISO-8859-1", txt_1 assert_equal "?a?b?c?d?e test", txt_2 end + + def test_attach + Attachment.storage_path = "#{Rails.root}/test/fixtures/files" + + str2 = "\x83e\x83X\x83g" + str2.force_encoding("ASCII-8BIT") if str2.respond_to?(:force_encoding) + encoding = ( RUBY_PLATFORM == 'java' ? "SJIS" : "CP932" ) + + a1 = Attachment.find(17) + a2 = Attachment.find(19) + + User.current = User.find(1) + assert a1.readable? + assert a1.visible? + assert a2.readable? + assert a2.visible? + + aa1 = Redmine::Export::PDF::RDMPdfEncoding::attach(Attachment.all, "Testfile.PNG", "UTF-8") + assert_equal 17, aa1.id + aa2 = Redmine::Export::PDF::RDMPdfEncoding::attach(Attachment.all, "test#{str2}.png", encoding) + assert_equal 19, aa2.id + + User.current = nil + assert a1.readable? + assert (! a1.visible?) + assert a2.readable? + assert (! a2.visible?) + + aa1 = Redmine::Export::PDF::RDMPdfEncoding::attach(Attachment.all, "Testfile.PNG", "UTF-8") + assert_equal nil, aa1 + aa2 = Redmine::Export::PDF::RDMPdfEncoding::attach(Attachment.all, "test#{str2}.png", encoding) + assert_equal nil, aa2 + + set_tmp_attachments_directory + end end |