##// END OF EJS Templates
Sets file encoding to utf-8 for ruby 1.9....
Jean-Philippe Lang -
r2796:38dc4d1cf954
parent child
Show More
@@ -1,485 +1,487
1 # encoding: utf-8
2 #
1 3 # Redmine - project management software
2 4 # Copyright (C) 2006-2009 Jean-Philippe Lang
3 5 #
4 6 # This program is free software; you can redistribute it and/or
5 7 # modify it under the terms of the GNU General Public License
6 8 # as published by the Free Software Foundation; either version 2
7 9 # of the License, or (at your option) any later version.
8 10 #
9 11 # This program is distributed in the hope that it will be useful,
10 12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 14 # GNU General Public License for more details.
13 15 #
14 16 # You should have received a copy of the GNU General Public License
15 17 # along with this program; if not, write to the Free Software
16 18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 19
18 20 require 'iconv'
19 21 require 'rfpdf/fpdf'
20 22 require 'rfpdf/chinese'
21 23
22 24 module Redmine
23 25 module Export
24 26 module PDF
25 27 include ActionView::Helpers::TextHelper
26 28 include ActionView::Helpers::NumberHelper
27 29
28 30 class IFPDF < FPDF
29 31 include Redmine::I18n
30 32 attr_accessor :footer_date
31 33
32 34 def initialize(lang)
33 35 super()
34 36 set_language_if_valid lang
35 37 case current_language.to_s.downcase
36 38 when 'ja'
37 39 extend(PDF_Japanese)
38 40 AddSJISFont()
39 41 @font_for_content = 'SJIS'
40 42 @font_for_footer = 'SJIS'
41 43 when 'zh'
42 44 extend(PDF_Chinese)
43 45 AddGBFont()
44 46 @font_for_content = 'GB'
45 47 @font_for_footer = 'GB'
46 48 when 'zh-tw'
47 49 extend(PDF_Chinese)
48 50 AddBig5Font()
49 51 @font_for_content = 'Big5'
50 52 @font_for_footer = 'Big5'
51 53 else
52 54 @font_for_content = 'Arial'
53 55 @font_for_footer = 'Helvetica'
54 56 end
55 57 SetCreator(Redmine::Info.app_name)
56 58 SetFont(@font_for_content)
57 59 end
58 60
59 61 def SetFontStyle(style, size)
60 62 SetFont(@font_for_content, style, size)
61 63 end
62 64
63 65 def SetTitle(txt)
64 66 txt = begin
65 67 utf16txt = Iconv.conv('UTF-16BE', 'UTF-8', txt)
66 68 hextxt = "<FEFF" # FEFF is BOM
67 69 hextxt << utf16txt.unpack("C*").map {|x| sprintf("%02X",x) }.join
68 70 hextxt << ">"
69 71 rescue
70 72 txt
71 73 end || ''
72 74 super(txt)
73 75 end
74 76
75 77 def textstring(s)
76 78 # Format a text string
77 79 if s =~ /^</ # This means the string is hex-dumped.
78 80 return s
79 81 else
80 82 return '('+escape(s)+')'
81 83 end
82 84 end
83 85
84 86 def Cell(w,h=0,txt='',border=0,ln=0,align='',fill=0,link='')
85 87 @ic ||= Iconv.new(l(:general_pdf_encoding), 'UTF-8')
86 88 # these quotation marks are not correctly rendered in the pdf
87 89 txt = txt.gsub(/[“�]/, '"') if txt
88 90 txt = begin
89 91 # 0x5c char handling
90 92 txtar = txt.split('\\')
91 93 txtar << '' if txt[-1] == ?\\
92 94 txtar.collect {|x| @ic.iconv(x)}.join('\\').gsub(/\\/, "\\\\\\\\")
93 95 rescue
94 96 txt
95 97 end || ''
96 98 super w,h,txt,border,ln,align,fill,link
97 99 end
98 100
99 101 def Footer
100 102 SetFont(@font_for_footer, 'I', 8)
101 103 SetY(-15)
102 104 SetX(15)
103 105 Cell(0, 5, @footer_date, 0, 0, 'L')
104 106 SetY(-15)
105 107 SetX(-30)
106 108 Cell(0, 5, PageNo().to_s + '/{nb}', 0, 0, 'C')
107 109 end
108 110 end
109 111
110 112 # Returns a PDF string of a list of issues
111 113 def issues_to_pdf(issues, project, query)
112 114 pdf = IFPDF.new(current_language)
113 115 title = query.new_record? ? l(:label_issue_plural) : query.name
114 116 title = "#{project} - #{title}" if project
115 117 pdf.SetTitle(title)
116 118 pdf.AliasNbPages
117 119 pdf.footer_date = format_date(Date.today)
118 120 pdf.AddPage("L")
119 121
120 122 row_height = 6
121 123 col_width = []
122 124 unless query.columns.empty?
123 125 col_width = query.columns.collect {|column| column.name == :subject ? 4.0 : 1.0 }
124 126 ratio = 262.0 / col_width.inject(0) {|s,w| s += w}
125 127 col_width = col_width.collect {|w| w * ratio}
126 128 end
127 129
128 130 # title
129 131 pdf.SetFontStyle('B',11)
130 132 pdf.Cell(190,10, title)
131 133 pdf.Ln
132 134
133 135 # headers
134 136 pdf.SetFontStyle('B',8)
135 137 pdf.SetFillColor(230, 230, 230)
136 138 pdf.Cell(15, row_height, "#", 1, 0, 'L', 1)
137 139 query.columns.each_with_index do |column, i|
138 140 pdf.Cell(col_width[i], row_height, column.caption, 1, 0, 'L', 1)
139 141 end
140 142 pdf.Ln
141 143
142 144 # rows
143 145 pdf.SetFontStyle('',8)
144 146 pdf.SetFillColor(255, 255, 255)
145 147 group = false
146 148 issues.each do |issue|
147 149 if query.grouped? && issue.send(query.group_by) != group
148 150 group = issue.send(query.group_by)
149 151 pdf.SetFontStyle('B',9)
150 152 pdf.Cell(277, row_height, "#{group.blank? ? 'None' : group.to_s}", 1, 1, 'L')
151 153 pdf.SetFontStyle('',8)
152 154 end
153 155 pdf.Cell(15, row_height, issue.id.to_s, 1, 0, 'L', 1)
154 156 query.columns.each_with_index do |column, i|
155 157 s = if column.is_a?(QueryCustomFieldColumn)
156 158 cv = issue.custom_values.detect {|v| v.custom_field_id == column.custom_field.id}
157 159 show_value(cv)
158 160 else
159 161 value = issue.send(column.name)
160 162 if value.is_a?(Date)
161 163 format_date(value)
162 164 elsif value.is_a?(Time)
163 165 format_time(value)
164 166 else
165 167 value
166 168 end
167 169 end
168 170 pdf.Cell(col_width[i], row_height, s.to_s, 1, 0, 'L', 1)
169 171 end
170 172 pdf.Ln
171 173 end
172 174 if issues.size == Setting.issues_export_limit.to_i
173 175 pdf.SetFontStyle('B',10)
174 176 pdf.Cell(0, row_height, '...')
175 177 end
176 178 pdf.Output
177 179 end
178 180
179 181 # Returns a PDF string of a single issue
180 182 def issue_to_pdf(issue)
181 183 pdf = IFPDF.new(current_language)
182 184 pdf.SetTitle("#{issue.project} - ##{issue.tracker} #{issue.id}")
183 185 pdf.AliasNbPages
184 186 pdf.footer_date = format_date(Date.today)
185 187 pdf.AddPage
186 188
187 189 pdf.SetFontStyle('B',11)
188 190 pdf.Cell(190,10, "#{issue.project} - #{issue.tracker} # #{issue.id}: #{issue.subject}")
189 191 pdf.Ln
190 192
191 193 y0 = pdf.GetY
192 194
193 195 pdf.SetFontStyle('B',9)
194 196 pdf.Cell(35,5, l(:field_status) + ":","LT")
195 197 pdf.SetFontStyle('',9)
196 198 pdf.Cell(60,5, issue.status.to_s,"RT")
197 199 pdf.SetFontStyle('B',9)
198 200 pdf.Cell(35,5, l(:field_priority) + ":","LT")
199 201 pdf.SetFontStyle('',9)
200 202 pdf.Cell(60,5, issue.priority.to_s,"RT")
201 203 pdf.Ln
202 204
203 205 pdf.SetFontStyle('B',9)
204 206 pdf.Cell(35,5, l(:field_author) + ":","L")
205 207 pdf.SetFontStyle('',9)
206 208 pdf.Cell(60,5, issue.author.to_s,"R")
207 209 pdf.SetFontStyle('B',9)
208 210 pdf.Cell(35,5, l(:field_category) + ":","L")
209 211 pdf.SetFontStyle('',9)
210 212 pdf.Cell(60,5, issue.category.to_s,"R")
211 213 pdf.Ln
212 214
213 215 pdf.SetFontStyle('B',9)
214 216 pdf.Cell(35,5, l(:field_created_on) + ":","L")
215 217 pdf.SetFontStyle('',9)
216 218 pdf.Cell(60,5, format_date(issue.created_on),"R")
217 219 pdf.SetFontStyle('B',9)
218 220 pdf.Cell(35,5, l(:field_assigned_to) + ":","L")
219 221 pdf.SetFontStyle('',9)
220 222 pdf.Cell(60,5, issue.assigned_to.to_s,"R")
221 223 pdf.Ln
222 224
223 225 pdf.SetFontStyle('B',9)
224 226 pdf.Cell(35,5, l(:field_updated_on) + ":","LB")
225 227 pdf.SetFontStyle('',9)
226 228 pdf.Cell(60,5, format_date(issue.updated_on),"RB")
227 229 pdf.SetFontStyle('B',9)
228 230 pdf.Cell(35,5, l(:field_due_date) + ":","LB")
229 231 pdf.SetFontStyle('',9)
230 232 pdf.Cell(60,5, format_date(issue.due_date),"RB")
231 233 pdf.Ln
232 234
233 235 for custom_value in issue.custom_field_values
234 236 pdf.SetFontStyle('B',9)
235 237 pdf.Cell(35,5, custom_value.custom_field.name + ":","L")
236 238 pdf.SetFontStyle('',9)
237 239 pdf.MultiCell(155,5, (show_value custom_value),"R")
238 240 end
239 241
240 242 pdf.SetFontStyle('B',9)
241 243 pdf.Cell(35,5, l(:field_subject) + ":","LTB")
242 244 pdf.SetFontStyle('',9)
243 245 pdf.Cell(155,5, issue.subject,"RTB")
244 246 pdf.Ln
245 247
246 248 pdf.SetFontStyle('B',9)
247 249 pdf.Cell(35,5, l(:field_description) + ":")
248 250 pdf.SetFontStyle('',9)
249 251 pdf.MultiCell(155,5, @issue.description,"BR")
250 252
251 253 pdf.Line(pdf.GetX, y0, pdf.GetX, pdf.GetY)
252 254 pdf.Line(pdf.GetX, pdf.GetY, 170, pdf.GetY)
253 255 pdf.Ln
254 256
255 257 if issue.changesets.any? && User.current.allowed_to?(:view_changesets, issue.project)
256 258 pdf.SetFontStyle('B',9)
257 259 pdf.Cell(190,5, l(:label_associated_revisions), "B")
258 260 pdf.Ln
259 261 for changeset in issue.changesets
260 262 pdf.SetFontStyle('B',8)
261 263 pdf.Cell(190,5, format_time(changeset.committed_on) + " - " + changeset.author.to_s)
262 264 pdf.Ln
263 265 unless changeset.comments.blank?
264 266 pdf.SetFontStyle('',8)
265 267 pdf.MultiCell(190,5, changeset.comments)
266 268 end
267 269 pdf.Ln
268 270 end
269 271 end
270 272
271 273 pdf.SetFontStyle('B',9)
272 274 pdf.Cell(190,5, l(:label_history), "B")
273 275 pdf.Ln
274 276 for journal in issue.journals.find(:all, :include => [:user, :details], :order => "#{Journal.table_name}.created_on ASC")
275 277 pdf.SetFontStyle('B',8)
276 278 pdf.Cell(190,5, format_time(journal.created_on) + " - " + journal.user.name)
277 279 pdf.Ln
278 280 pdf.SetFontStyle('I',8)
279 281 for detail in journal.details
280 282 pdf.Cell(190,5, "- " + show_detail(detail, true))
281 283 pdf.Ln
282 284 end
283 285 if journal.notes?
284 286 pdf.SetFontStyle('',8)
285 287 pdf.MultiCell(190,5, journal.notes)
286 288 end
287 289 pdf.Ln
288 290 end
289 291
290 292 if issue.attachments.any?
291 293 pdf.SetFontStyle('B',9)
292 294 pdf.Cell(190,5, l(:label_attachment_plural), "B")
293 295 pdf.Ln
294 296 for attachment in issue.attachments
295 297 pdf.SetFontStyle('',8)
296 298 pdf.Cell(80,5, attachment.filename)
297 299 pdf.Cell(20,5, number_to_human_size(attachment.filesize),0,0,"R")
298 300 pdf.Cell(25,5, format_date(attachment.created_on),0,0,"R")
299 301 pdf.Cell(65,5, attachment.author.name,0,0,"R")
300 302 pdf.Ln
301 303 end
302 304 end
303 305 pdf.Output
304 306 end
305 307
306 308 # Returns a PDF string of a gantt chart
307 309 def gantt_to_pdf(gantt, project)
308 310 pdf = IFPDF.new(current_language)
309 311 pdf.SetTitle("#{l(:label_gantt)} #{project}")
310 312 pdf.AliasNbPages
311 313 pdf.footer_date = format_date(Date.today)
312 314 pdf.AddPage("L")
313 315 pdf.SetFontStyle('B',12)
314 316 pdf.SetX(15)
315 317 pdf.Cell(70, 20, project.to_s)
316 318 pdf.Ln
317 319 pdf.SetFontStyle('B',9)
318 320
319 321 subject_width = 70
320 322 header_heigth = 5
321 323
322 324 headers_heigth = header_heigth
323 325 show_weeks = false
324 326 show_days = false
325 327
326 328 if gantt.months < 7
327 329 show_weeks = true
328 330 headers_heigth = 2*header_heigth
329 331 if gantt.months < 3
330 332 show_days = true
331 333 headers_heigth = 3*header_heigth
332 334 end
333 335 end
334 336
335 337 g_width = 210
336 338 zoom = (g_width) / (gantt.date_to - gantt.date_from + 1)
337 339 g_height = 120
338 340 t_height = g_height + headers_heigth
339 341
340 342 y_start = pdf.GetY
341 343
342 344 # Months headers
343 345 month_f = gantt.date_from
344 346 left = subject_width
345 347 height = header_heigth
346 348 gantt.months.times do
347 349 width = ((month_f >> 1) - month_f) * zoom
348 350 pdf.SetY(y_start)
349 351 pdf.SetX(left)
350 352 pdf.Cell(width, height, "#{month_f.year}-#{month_f.month}", "LTR", 0, "C")
351 353 left = left + width
352 354 month_f = month_f >> 1
353 355 end
354 356
355 357 # Weeks headers
356 358 if show_weeks
357 359 left = subject_width
358 360 height = header_heigth
359 361 if gantt.date_from.cwday == 1
360 362 # gantt.date_from is monday
361 363 week_f = gantt.date_from
362 364 else
363 365 # find next monday after gantt.date_from
364 366 week_f = gantt.date_from + (7 - gantt.date_from.cwday + 1)
365 367 width = (7 - gantt.date_from.cwday + 1) * zoom-1
366 368 pdf.SetY(y_start + header_heigth)
367 369 pdf.SetX(left)
368 370 pdf.Cell(width + 1, height, "", "LTR")
369 371 left = left + width+1
370 372 end
371 373 while week_f <= gantt.date_to
372 374 width = (week_f + 6 <= gantt.date_to) ? 7 * zoom : (gantt.date_to - week_f + 1) * zoom
373 375 pdf.SetY(y_start + header_heigth)
374 376 pdf.SetX(left)
375 377 pdf.Cell(width, height, (width >= 5 ? week_f.cweek.to_s : ""), "LTR", 0, "C")
376 378 left = left + width
377 379 week_f = week_f+7
378 380 end
379 381 end
380 382
381 383 # Days headers
382 384 if show_days
383 385 left = subject_width
384 386 height = header_heigth
385 387 wday = gantt.date_from.cwday
386 388 pdf.SetFontStyle('B',7)
387 389 (gantt.date_to - gantt.date_from + 1).to_i.times do
388 390 width = zoom
389 391 pdf.SetY(y_start + 2 * header_heigth)
390 392 pdf.SetX(left)
391 393 pdf.Cell(width, height, day_name(wday).first, "LTR", 0, "C")
392 394 left = left + width
393 395 wday = wday + 1
394 396 wday = 1 if wday > 7
395 397 end
396 398 end
397 399
398 400 pdf.SetY(y_start)
399 401 pdf.SetX(15)
400 402 pdf.Cell(subject_width+g_width-15, headers_heigth, "", 1)
401 403
402 404 # Tasks
403 405 top = headers_heigth + y_start
404 406 pdf.SetFontStyle('B',7)
405 407 gantt.events.each do |i|
406 408 pdf.SetY(top)
407 409 pdf.SetX(15)
408 410
409 411 if i.is_a? Issue
410 412 pdf.Cell(subject_width-15, 5, "#{i.tracker} #{i.id}: #{i.subject}".sub(/^(.{30}[^\s]*\s).*$/, '\1 (...)'), "LR")
411 413 else
412 414 pdf.Cell(subject_width-15, 5, "#{l(:label_version)}: #{i.name}", "LR")
413 415 end
414 416
415 417 pdf.SetY(top)
416 418 pdf.SetX(subject_width)
417 419 pdf.Cell(g_width, 5, "", "LR")
418 420
419 421 pdf.SetY(top+1.5)
420 422
421 423 if i.is_a? Issue
422 424 i_start_date = (i.start_date >= gantt.date_from ? i.start_date : gantt.date_from )
423 425 i_end_date = (i.due_before <= gantt.date_to ? i.due_before : gantt.date_to )
424 426
425 427 i_done_date = i.start_date + ((i.due_before - i.start_date+1)*i.done_ratio/100).floor
426 428 i_done_date = (i_done_date <= gantt.date_from ? gantt.date_from : i_done_date )
427 429 i_done_date = (i_done_date >= gantt.date_to ? gantt.date_to : i_done_date )
428 430
429 431 i_late_date = [i_end_date, Date.today].min if i_start_date < Date.today
430 432
431 433 i_left = ((i_start_date - gantt.date_from)*zoom)
432 434 i_width = ((i_end_date - i_start_date + 1)*zoom)
433 435 d_width = ((i_done_date - i_start_date)*zoom)
434 436 l_width = ((i_late_date - i_start_date+1)*zoom) if i_late_date
435 437 l_width ||= 0
436 438
437 439 pdf.SetX(subject_width + i_left)
438 440 pdf.SetFillColor(200,200,200)
439 441 pdf.Cell(i_width, 2, "", 0, 0, "", 1)
440 442
441 443 if l_width > 0
442 444 pdf.SetY(top+1.5)
443 445 pdf.SetX(subject_width + i_left)
444 446 pdf.SetFillColor(255,100,100)
445 447 pdf.Cell(l_width, 2, "", 0, 0, "", 1)
446 448 end
447 449 if d_width > 0
448 450 pdf.SetY(top+1.5)
449 451 pdf.SetX(subject_width + i_left)
450 452 pdf.SetFillColor(100,100,255)
451 453 pdf.Cell(d_width, 2, "", 0, 0, "", 1)
452 454 end
453 455
454 456 pdf.SetY(top+1.5)
455 457 pdf.SetX(subject_width + i_left + i_width)
456 458 pdf.Cell(30, 2, "#{i.status} #{i.done_ratio}%")
457 459 else
458 460 i_left = ((i.start_date - gantt.date_from)*zoom)
459 461
460 462 pdf.SetX(subject_width + i_left)
461 463 pdf.SetFillColor(50,200,50)
462 464 pdf.Cell(2, 2, "", 0, 0, "", 1)
463 465
464 466 pdf.SetY(top+1.5)
465 467 pdf.SetX(subject_width + i_left + 3)
466 468 pdf.Cell(30, 2, "#{i.name}")
467 469 end
468 470
469 471 top = top + 5
470 472 pdf.SetDrawColor(200, 200, 200)
471 473 pdf.Line(15, top, subject_width+g_width, top)
472 474 if pdf.GetY() > 180
473 475 pdf.AddPage("L")
474 476 top = 20
475 477 pdf.Line(15, top, subject_width+g_width, top)
476 478 end
477 479 pdf.SetDrawColor(0, 0, 0)
478 480 end
479 481
480 482 pdf.Line(15, top, subject_width+g_width, top)
481 483 pdf.Output
482 484 end
483 485 end
484 486 end
485 487 end
@@ -1,46 +1,48
1 # encoding: utf-8
2 #
1 3 # redMine - project management software
2 4 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 5 #
4 6 # This program is free software; you can redistribute it and/or
5 7 # modify it under the terms of the GNU General Public License
6 8 # as published by the Free Software Foundation; either version 2
7 9 # of the License, or (at your option) any later version.
8 10 #
9 11 # This program is distributed in the hope that it will be useful,
10 12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 14 # GNU General Public License for more details.
13 15 #
14 16 # You should have received a copy of the GNU General Public License
15 17 # along with this program; if not, write to the Free Software
16 18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 19
18 20 require File.dirname(__FILE__) + '/../test_helper'
19 21
20 22 class AttachmentTest < ActiveSupport::TestCase
21 23 fixtures :issues, :users
22 24
23 25 def setup
24 26 end
25 27
26 28 def test_create
27 29 a = Attachment.new(:container => Issue.find(1),
28 30 :file => uploaded_test_file("testfile.txt", "text/plain"),
29 31 :author => User.find(1))
30 32 assert a.save
31 33 assert_equal 'testfile.txt', a.filename
32 34 assert_equal 59, a.filesize
33 35 assert_equal 'text/plain', a.content_type
34 36 assert_equal 0, a.downloads
35 37 assert_equal Digest::MD5.hexdigest(uploaded_test_file("testfile.txt", "text/plain").read), a.digest
36 38 assert File.exist?(a.diskfile)
37 39 end
38 40
39 41 def test_diskfilename
40 42 assert Attachment.disk_filename("test_file.txt") =~ /^\d{12}_test_file.txt$/
41 43 assert_equal 'test_file.txt', Attachment.disk_filename("test_file.txt")[13..-1]
42 44 assert_equal '770c509475505f37c2b8fb6030434d6b.txt', Attachment.disk_filename("test_accentué.txt")[13..-1]
43 45 assert_equal 'f8139524ebb8f32e51976982cd20a85d', Attachment.disk_filename("test_accentué")[13..-1]
44 46 assert_equal 'cbb5b0f30978ba03731d61f9f6d10011', Attachment.disk_filename("test_accentué.ça")[13..-1]
45 47 end
46 48 end
@@ -1,45 +1,47
1 # encoding: utf-8
2 #
1 3 # Redmine - project management software
2 4 # Copyright (C) 2006-2009 Jean-Philippe Lang
3 5 #
4 6 # This program is free software; you can redistribute it and/or
5 7 # modify it under the terms of the GNU General Public License
6 8 # as published by the Free Software Foundation; either version 2
7 9 # of the License, or (at your option) any later version.
8 10 #
9 11 # This program is distributed in the hope that it will be useful,
10 12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 14 # GNU General Public License for more details.
13 15 #
14 16 # You should have received a copy of the GNU General Public License
15 17 # along with this program; if not, write to the Free Software
16 18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 19
18 20 require File.dirname(__FILE__) + '/../../test_helper'
19 21
20 22 class SearchHelperTest < HelperTestCase
21 23 include SearchHelper
22 24
23 25 def test_highlight_single_token
24 26 assert_equal 'This is a <span class="highlight token-0">token</span>.',
25 27 highlight_tokens('This is a token.', %w(token))
26 28 end
27 29
28 30 def test_highlight_multiple_tokens
29 31 assert_equal 'This is a <span class="highlight token-0">token</span> and <span class="highlight token-1">another</span> <span class="highlight token-0">token</span>.',
30 32 highlight_tokens('This is a token and another token.', %w(token another))
31 33 end
32 34
33 35 def test_highlight_should_not_exceed_maximum_length
34 36 s = (('1234567890' * 100) + ' token ') * 100
35 37 r = highlight_tokens(s, %w(token))
36 38 assert r.include?('<span class="highlight token-0">token</span>')
37 39 assert r.length <= 1300
38 40 end
39 41
40 42 def test_highlight_multibyte
41 43 s = ('й' * 200) + ' token ' + ('й' * 200)
42 44 r = highlight_tokens(s, %w(token))
43 45 assert_equal ('й' * 45) + ' ... ' + ('й' * 44) + ' <span class="highlight token-0">token</span> ' + ('й' * 44) + ' ... ' + ('й' * 45), r
44 46 end
45 47 end
@@ -1,44 +1,46
1 # encoding: utf-8
2 #
1 3 # redMine - project management software
2 4 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 5 #
4 6 # This program is free software; you can redistribute it and/or
5 7 # modify it under the terms of the GNU General Public License
6 8 # as published by the Free Software Foundation; either version 2
7 9 # of the License, or (at your option) any later version.
8 10 #
9 11 # This program is distributed in the hope that it will be useful,
10 12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 14 # GNU General Public License for more details.
13 15 #
14 16 # You should have received a copy of the GNU General Public License
15 17 # along with this program; if not, write to the Free Software
16 18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 19
18 20 require File.dirname(__FILE__) + '/../test_helper'
19 21
20 22 class WikiTest < ActiveSupport::TestCase
21 23 fixtures :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions
22 24
23 25 def test_create
24 26 wiki = Wiki.new(:project => Project.find(2))
25 27 assert !wiki.save
26 28 assert_equal 1, wiki.errors.count
27 29
28 30 wiki.start_page = "Start page"
29 31 assert wiki.save
30 32 end
31 33
32 34 def test_update
33 35 @wiki = Wiki.find(1)
34 36 @wiki.start_page = "Another start page"
35 37 assert @wiki.save
36 38 @wiki.reload
37 39 assert_equal "Another start page", @wiki.start_page
38 40 end
39 41
40 42 def test_titleize
41 43 assert_equal 'Page_title_with_CAPITALES', Wiki.titleize('page title with CAPITALES')
42 44 assert_equal 'テスト', Wiki.titleize('テスト')
43 45 end
44 46 end
General Comments 0
You need to be logged in to leave comments. Login now