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