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