annotate .svn/pristine/94/946610db029f9c718cdfb0d1e063ab6fbd404ac9.svn-base @ 1295:622f24f53b42 redmine-2.3

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