annotate .svn/pristine/e0/e0b53700ab5620cb5201c4583b4e265634c8fe72.svn-base @ 1519:afce8026aaeb redmine-2.4-integration

Merge from branch "live"
author Chris Cannam
date Tue, 09 Sep 2014 09:34:53 +0100
parents e248c7af89ec
children
rev   line source
Chris@1494 1 # Redmine - project management software
Chris@1494 2 # Copyright (C) 2006-2014 Jean-Philippe Lang
Chris@1494 3 #
Chris@1494 4 # This program is free software; you can redistribute it and/or
Chris@1494 5 # modify it under the terms of the GNU General Public License
Chris@1494 6 # as published by the Free Software Foundation; either version 2
Chris@1494 7 # of the License, or (at your option) any later version.
Chris@1494 8 #
Chris@1494 9 # This program is distributed in the hope that it will be useful,
Chris@1494 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1494 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1494 12 # GNU General Public License for more details.
Chris@1494 13 #
Chris@1494 14 # You should have received a copy of the GNU General Public License
Chris@1494 15 # along with this program; if not, write to the Free Software
Chris@1494 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1494 17
Chris@1494 18 require File.expand_path('../../../../../test_helper', __FILE__)
Chris@1494 19
Chris@1494 20 class PdfTest < ActiveSupport::TestCase
Chris@1494 21 fixtures :users, :projects, :roles, :members, :member_roles,
Chris@1494 22 :enabled_modules, :issues, :trackers, :attachments
Chris@1494 23
Chris@1494 24 def test_fix_text_encoding_nil
Chris@1494 25 assert_equal '', Redmine::Export::PDF::RDMPdfEncoding::rdm_from_utf8(nil, "UTF-8")
Chris@1494 26 assert_equal '', Redmine::Export::PDF::RDMPdfEncoding::rdm_from_utf8(nil, "ISO-8859-1")
Chris@1494 27 end
Chris@1494 28
Chris@1494 29 def test_rdm_pdf_iconv_cannot_convert_ja_cp932
Chris@1494 30 encoding = ( RUBY_PLATFORM == 'java' ? "SJIS" : "CP932" )
Chris@1494 31 utf8_txt_1 = "\xe7\x8b\x80\xe6\x85\x8b"
Chris@1494 32 utf8_txt_2 = "\xe7\x8b\x80\xe6\x85\x8b\xe7\x8b\x80"
Chris@1494 33 utf8_txt_3 = "\xe7\x8b\x80\xe7\x8b\x80\xe6\x85\x8b\xe7\x8b\x80"
Chris@1494 34 if utf8_txt_1.respond_to?(:force_encoding)
Chris@1494 35 txt_1 = Redmine::Export::PDF::RDMPdfEncoding::rdm_from_utf8(utf8_txt_1, encoding)
Chris@1494 36 txt_2 = Redmine::Export::PDF::RDMPdfEncoding::rdm_from_utf8(utf8_txt_2, encoding)
Chris@1494 37 txt_3 = Redmine::Export::PDF::RDMPdfEncoding::rdm_from_utf8(utf8_txt_3, encoding)
Chris@1494 38 assert_equal "?\x91\xd4".force_encoding("ASCII-8BIT"), txt_1
Chris@1494 39 assert_equal "?\x91\xd4?".force_encoding("ASCII-8BIT"), txt_2
Chris@1494 40 assert_equal "??\x91\xd4?".force_encoding("ASCII-8BIT"), txt_3
Chris@1494 41 assert_equal "ASCII-8BIT", txt_1.encoding.to_s
Chris@1494 42 assert_equal "ASCII-8BIT", txt_2.encoding.to_s
Chris@1494 43 assert_equal "ASCII-8BIT", txt_3.encoding.to_s
Chris@1494 44 elsif RUBY_PLATFORM == 'java'
Chris@1494 45 assert_equal "??",
Chris@1494 46 Redmine::Export::PDF::RDMPdfEncoding::rdm_from_utf8(utf8_txt_1, encoding)
Chris@1494 47 assert_equal "???",
Chris@1494 48 Redmine::Export::PDF::RDMPdfEncoding::rdm_from_utf8(utf8_txt_2, encoding)
Chris@1494 49 assert_equal "????",
Chris@1494 50 Redmine::Export::PDF::RDMPdfEncoding::rdm_from_utf8(utf8_txt_3, encoding)
Chris@1494 51 else
Chris@1494 52 assert_equal "???\x91\xd4",
Chris@1494 53 Redmine::Export::PDF::RDMPdfEncoding::rdm_from_utf8(utf8_txt_1, encoding)
Chris@1494 54 assert_equal "???\x91\xd4???",
Chris@1494 55 Redmine::Export::PDF::RDMPdfEncoding::rdm_from_utf8(utf8_txt_2, encoding)
Chris@1494 56 assert_equal "??????\x91\xd4???",
Chris@1494 57 Redmine::Export::PDF::RDMPdfEncoding::rdm_from_utf8(utf8_txt_3, encoding)
Chris@1494 58 end
Chris@1494 59 end
Chris@1494 60
Chris@1494 61 def test_rdm_pdf_iconv_invalid_utf8_should_be_replaced_en
Chris@1494 62 str1 = "Texte encod\xe9 en ISO-8859-1"
Chris@1494 63 str2 = "\xe9a\xe9b\xe9c\xe9d\xe9e test"
Chris@1494 64 str1.force_encoding("UTF-8") if str1.respond_to?(:force_encoding)
Chris@1494 65 str2.force_encoding("ASCII-8BIT") if str2.respond_to?(:force_encoding)
Chris@1494 66 txt_1 = Redmine::Export::PDF::RDMPdfEncoding::rdm_from_utf8(str1, 'UTF-8')
Chris@1494 67 txt_2 = Redmine::Export::PDF::RDMPdfEncoding::rdm_from_utf8(str2, 'UTF-8')
Chris@1494 68 if txt_1.respond_to?(:force_encoding)
Chris@1494 69 assert_equal "ASCII-8BIT", txt_1.encoding.to_s
Chris@1494 70 assert_equal "ASCII-8BIT", txt_2.encoding.to_s
Chris@1494 71 end
Chris@1494 72 assert_equal "Texte encod? en ISO-8859-1", txt_1
Chris@1494 73 assert_equal "?a?b?c?d?e test", txt_2
Chris@1494 74 end
Chris@1494 75
Chris@1494 76 def test_rdm_pdf_iconv_invalid_utf8_should_be_replaced_ja
Chris@1494 77 str1 = "Texte encod\xe9 en ISO-8859-1"
Chris@1494 78 str2 = "\xe9a\xe9b\xe9c\xe9d\xe9e test"
Chris@1494 79 str1.force_encoding("UTF-8") if str1.respond_to?(:force_encoding)
Chris@1494 80 str2.force_encoding("ASCII-8BIT") if str2.respond_to?(:force_encoding)
Chris@1494 81 encoding = ( RUBY_PLATFORM == 'java' ? "SJIS" : "CP932" )
Chris@1494 82 txt_1 = Redmine::Export::PDF::RDMPdfEncoding::rdm_from_utf8(str1, encoding)
Chris@1494 83 txt_2 = Redmine::Export::PDF::RDMPdfEncoding::rdm_from_utf8(str2, encoding)
Chris@1494 84 if txt_1.respond_to?(:force_encoding)
Chris@1494 85 assert_equal "ASCII-8BIT", txt_1.encoding.to_s
Chris@1494 86 assert_equal "ASCII-8BIT", txt_2.encoding.to_s
Chris@1494 87 end
Chris@1494 88 assert_equal "Texte encod? en ISO-8859-1", txt_1
Chris@1494 89 assert_equal "?a?b?c?d?e test", txt_2
Chris@1494 90 end
Chris@1494 91
Chris@1494 92 def test_attach
Chris@1494 93 set_fixtures_attachments_directory
Chris@1494 94
Chris@1494 95 str2 = "\x83e\x83X\x83g"
Chris@1494 96 str2.force_encoding("ASCII-8BIT") if str2.respond_to?(:force_encoding)
Chris@1494 97 encoding = ( RUBY_PLATFORM == 'java' ? "SJIS" : "CP932" )
Chris@1494 98
Chris@1494 99 a1 = Attachment.find(17)
Chris@1494 100 a2 = Attachment.find(19)
Chris@1494 101
Chris@1494 102 User.current = User.find(1)
Chris@1494 103 assert a1.readable?
Chris@1494 104 assert a1.visible?
Chris@1494 105 assert a2.readable?
Chris@1494 106 assert a2.visible?
Chris@1494 107
Chris@1494 108 aa1 = Redmine::Export::PDF::RDMPdfEncoding::attach(Attachment.all, "Testfile.PNG", "UTF-8")
Chris@1494 109 assert_not_nil aa1
Chris@1494 110 assert_equal 17, aa1.id
Chris@1494 111 aa2 = Redmine::Export::PDF::RDMPdfEncoding::attach(Attachment.all, "test#{str2}.png", encoding)
Chris@1494 112 assert_not_nil aa2
Chris@1494 113 assert_equal 19, aa2.id
Chris@1494 114
Chris@1494 115 User.current = nil
Chris@1494 116 assert a1.readable?
Chris@1494 117 assert (! a1.visible?)
Chris@1494 118 assert a2.readable?
Chris@1494 119 assert (! a2.visible?)
Chris@1494 120
Chris@1494 121 aa1 = Redmine::Export::PDF::RDMPdfEncoding::attach(Attachment.all, "Testfile.PNG", "UTF-8")
Chris@1494 122 assert_equal nil, aa1
Chris@1494 123 aa2 = Redmine::Export::PDF::RDMPdfEncoding::attach(Attachment.all, "test#{str2}.png", encoding)
Chris@1494 124 assert_equal nil, aa2
Chris@1494 125
Chris@1494 126 set_tmp_attachments_directory
Chris@1494 127 end
Chris@1494 128 end