annotate .svn/pristine/6c/6c1bc2cf6fdcda95eb68095dcabf8689b24d2903.svn-base @ 1628:9c5f8e24dadc live tip

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