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