mirror of
https://github.com/redmine/redmine.git
synced 2025-11-15 09:46:02 +01:00
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
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user