comparison test/unit/helpers/application_helper_test.rb @ 1464:261b3d9a4903 redmine-2.4

Update to Redmine 2.4 branch rev 12663
author Chris Cannam
date Tue, 14 Jan 2014 14:37:42 +0000
parents 3e4c3460b6ca
children e248c7af89ec
comparison
equal deleted inserted replaced
1296:038ba2d95de8 1464:261b3d9a4903
1 # encoding: utf-8 1 # encoding: utf-8
2 # 2 #
3 # Redmine - project management software 3 # Redmine - project management software
4 # Copyright (C) 2006-2012 Jean-Philippe Lang 4 # Copyright (C) 2006-2013 Jean-Philippe Lang
5 # 5 #
6 # This program is free software; you can redistribute it and/or 6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License 7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; either version 2 8 # as published by the Free Software Foundation; either version 2
9 # of the License, or (at your option) any later version. 9 # of the License, or (at your option) any later version.
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 19
20 require File.expand_path('../../../test_helper', __FILE__) 20 require File.expand_path('../../../test_helper', __FILE__)
21 21
22 class ApplicationHelperTest < ActionView::TestCase 22 class ApplicationHelperTest < ActionView::TestCase
23 include Redmine::I18n
23 include ERB::Util 24 include ERB::Util
25 include Rails.application.routes.url_helpers
24 26
25 fixtures :projects, :roles, :enabled_modules, :users, 27 fixtures :projects, :roles, :enabled_modules, :users,
26 :repositories, :changesets, 28 :repositories, :changesets,
27 :trackers, :issue_statuses, :issues, :versions, :documents, 29 :trackers, :issue_statuses, :issues, :versions, :documents,
28 :wikis, :wiki_pages, :wiki_contents, 30 :wikis, :wiki_pages, :wiki_contents,
30 :attachments, :enumerations 32 :attachments, :enumerations
31 33
32 def setup 34 def setup
33 super 35 super
34 set_tmp_attachments_directory 36 set_tmp_attachments_directory
35 end 37 @russian_test = "\xd1\x82\xd0\xb5\xd1\x81\xd1\x82"
36 38 if @russian_test.respond_to?(:force_encoding)
37 context "#link_to_if_authorized" do 39 @russian_test.force_encoding('UTF-8')
38 context "authorized user" do
39 should "be tested"
40 end 40 end
41 41 end
42 context "unauthorized user" do 42
43 should "be tested" 43 test "#link_to_if_authorized for authorized user should allow using the :controller and :action for the target link" do
44 end 44 User.current = User.find_by_login('admin')
45 45
46 should "allow using the :controller and :action for the target link" do 46 @project = Issue.first.project # Used by helper
47 User.current = User.find_by_login('admin') 47 response = link_to_if_authorized('By controller/actionr',
48 48 {:controller => 'issues', :action => 'edit', :id => Issue.first.id})
49 @project = Issue.first.project # Used by helper 49 assert_match /href/, response
50 response = link_to_if_authorized("By controller/action", 50 end
51 {:controller => 'issues', :action => 'edit', :id => Issue.first.id}) 51
52 assert_match /href/, response 52 test "#link_to_if_authorized for unauthorized user should display nothing if user isn't authorized" do
53 end 53 User.current = User.find_by_login('dlopper')
54 54 @project = Project.find('private-child')
55 issue = @project.issues.first
56 assert !issue.visible?
57
58 response = link_to_if_authorized('Never displayed',
59 {:controller => 'issues', :action => 'show', :id => issue})
60 assert_nil response
55 end 61 end
56 62
57 def test_auto_links 63 def test_auto_links
58 to_test = { 64 to_test = {
59 'http://foo.bar' => '<a class="external" href="http://foo.bar">http://foo.bar</a>', 65 'http://foo.bar' => '<a class="external" href="http://foo.bar">http://foo.bar</a>',
81 # two exclamation marks 87 # two exclamation marks
82 'http://example.net/path!602815048C7B5C20!302.html' => '<a class="external" href="http://example.net/path!602815048C7B5C20!302.html">http://example.net/path!602815048C7B5C20!302.html</a>', 88 'http://example.net/path!602815048C7B5C20!302.html' => '<a class="external" href="http://example.net/path!602815048C7B5C20!302.html">http://example.net/path!602815048C7B5C20!302.html</a>',
83 # escaping 89 # escaping
84 'http://foo"bar' => '<a class="external" href="http://foo&quot;bar">http://foo&quot;bar</a>', 90 'http://foo"bar' => '<a class="external" href="http://foo&quot;bar">http://foo&quot;bar</a>',
85 # wrap in angle brackets 91 # wrap in angle brackets
86 '<http://foo.bar>' => '&lt;<a class="external" href="http://foo.bar">http://foo.bar</a>&gt;' 92 '<http://foo.bar>' => '&lt;<a class="external" href="http://foo.bar">http://foo.bar</a>&gt;',
93 # invalid urls
94 'http://' => 'http://',
95 'www.' => 'www.',
96 'test-www.bar.com' => 'test-www.bar.com',
87 } 97 }
88 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) } 98 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
89 end 99 end
90 100
91 if 'ruby'.respond_to?(:encoding) 101 if 'ruby'.respond_to?(:encoding)
92 def test_auto_links_with_non_ascii_characters 102 def test_auto_links_with_non_ascii_characters
93 to_test = { 103 to_test = {
94 'http://foo.bar/тест' => '<a class="external" href="http://foo.bar/тест">http://foo.bar/тест</a>' 104 "http://foo.bar/#{@russian_test}" =>
105 %|<a class="external" href="http://foo.bar/#{@russian_test}">http://foo.bar/#{@russian_test}</a>|
95 } 106 }
96 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) } 107 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
97 end 108 end
98 else 109 else
99 puts 'Skipping test_auto_links_with_non_ascii_characters, unsupported ruby version' 110 puts 'Skipping test_auto_links_with_non_ascii_characters, unsupported ruby version'
100 end 111 end
101 112
102 def test_auto_mailto 113 def test_auto_mailto
103 assert_equal '<p><a class="email" href="mailto:test@foo.bar">test@foo.bar</a></p>', 114 to_test = {
104 textilizable('test@foo.bar') 115 'test@foo.bar' => '<a class="email" href="mailto:test@foo.bar">test@foo.bar</a>',
116 'test@www.foo.bar' => '<a class="email" href="mailto:test@www.foo.bar">test@www.foo.bar</a>',
117 }
118 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
105 end 119 end
106 120
107 def test_inline_images 121 def test_inline_images
108 to_test = { 122 to_test = {
109 '!http://foo.bar/image.jpg!' => '<img src="http://foo.bar/image.jpg" alt="" />', 123 '!http://foo.bar/image.jpg!' => '<img src="http://foo.bar/image.jpg" alt="" />',
129 assert textilizable(raw).include?('<img src="bar.gif" alt="" />') 143 assert textilizable(raw).include?('<img src="bar.gif" alt="" />')
130 end 144 end
131 145
132 def test_attached_images 146 def test_attached_images
133 to_test = { 147 to_test = {
134 'Inline image: !logo.gif!' => 'Inline image: <img src="/attachments/download/3" title="This is a logo" alt="This is a logo" />', 148 'Inline image: !logo.gif!' => 'Inline image: <img src="/attachments/download/3/logo.gif" title="This is a logo" alt="This is a logo" />',
135 'Inline image: !logo.GIF!' => 'Inline image: <img src="/attachments/download/3" title="This is a logo" alt="This is a logo" />', 149 'Inline image: !logo.GIF!' => 'Inline image: <img src="/attachments/download/3/logo.gif" title="This is a logo" alt="This is a logo" />',
136 'No match: !ogo.gif!' => 'No match: <img src="ogo.gif" alt="" />', 150 'No match: !ogo.gif!' => 'No match: <img src="ogo.gif" alt="" />',
137 'No match: !ogo.GIF!' => 'No match: <img src="ogo.GIF" alt="" />', 151 'No match: !ogo.GIF!' => 'No match: <img src="ogo.GIF" alt="" />',
138 # link image 152 # link image
139 '!logo.gif!:http://foo.bar/' => '<a href="http://foo.bar/"><img src="/attachments/download/3" title="This is a logo" alt="This is a logo" /></a>', 153 '!logo.gif!:http://foo.bar/' => '<a href="http://foo.bar/"><img src="/attachments/download/3/logo.gif" title="This is a logo" alt="This is a logo" /></a>',
140 } 154 }
141 attachments = Attachment.find(:all) 155 attachments = Attachment.all
142 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text, :attachments => attachments) } 156 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text, :attachments => attachments) }
143 end 157 end
144 158
145 def test_attached_images_filename_extension 159 def test_attached_images_filename_extension
146 set_tmp_attachments_directory 160 set_tmp_attachments_directory
180 assert_equal "image/x-ms-bmp", a4.content_type 194 assert_equal "image/x-ms-bmp", a4.content_type
181 assert a4.image? 195 assert a4.image?
182 196
183 to_test = { 197 to_test = {
184 'Inline image: !testtest.jpg!' => 198 'Inline image: !testtest.jpg!' =>
185 'Inline image: <img src="/attachments/download/' + a1.id.to_s + '" alt="" />', 199 'Inline image: <img src="/attachments/download/' + a1.id.to_s + '/testtest.JPG" alt="" />',
186 'Inline image: !testtest.jpeg!' => 200 'Inline image: !testtest.jpeg!' =>
187 'Inline image: <img src="/attachments/download/' + a2.id.to_s + '" alt="" />', 201 'Inline image: <img src="/attachments/download/' + a2.id.to_s + '/testtest.jpeg" alt="" />',
188 'Inline image: !testtest.jpe!' => 202 'Inline image: !testtest.jpe!' =>
189 'Inline image: <img src="/attachments/download/' + a3.id.to_s + '" alt="" />', 203 'Inline image: <img src="/attachments/download/' + a3.id.to_s + '/testtest.JPE" alt="" />',
190 'Inline image: !testtest.bmp!' => 204 'Inline image: !testtest.bmp!' =>
191 'Inline image: <img src="/attachments/download/' + a4.id.to_s + '" alt="" />', 205 'Inline image: <img src="/attachments/download/' + a4.id.to_s + '/Testtest.BMP" alt="" />',
192 } 206 }
193 207
194 attachments = [a1, a2, a3, a4] 208 attachments = [a1, a2, a3, a4]
195 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text, :attachments => attachments) } 209 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text, :attachments => attachments) }
196 end 210 end
209 assert a2.visible?(User.find(2)) 223 assert a2.visible?(User.find(2))
210 assert a1.created_on < a2.created_on 224 assert a1.created_on < a2.created_on
211 225
212 to_test = { 226 to_test = {
213 'Inline image: !testfile.png!' => 227 'Inline image: !testfile.png!' =>
214 'Inline image: <img src="/attachments/download/' + a2.id.to_s + '" alt="" />', 228 'Inline image: <img src="/attachments/download/' + a2.id.to_s + '/testfile.PNG" alt="" />',
215 'Inline image: !Testfile.PNG!' => 229 'Inline image: !Testfile.PNG!' =>
216 'Inline image: <img src="/attachments/download/' + a2.id.to_s + '" alt="" />', 230 'Inline image: <img src="/attachments/download/' + a2.id.to_s + '/testfile.PNG" alt="" />',
217 } 231 }
218 attachments = [a1, a2] 232 attachments = [a1, a2]
219 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text, :attachments => attachments) } 233 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text, :attachments => attachments) }
220 set_tmp_attachments_directory 234 set_tmp_attachments_directory
221 end 235 end
240 end 254 end
241 255
242 if 'ruby'.respond_to?(:encoding) 256 if 'ruby'.respond_to?(:encoding)
243 def test_textile_external_links_with_non_ascii_characters 257 def test_textile_external_links_with_non_ascii_characters
244 to_test = { 258 to_test = {
245 'This is a "link":http://foo.bar/тест' => 'This is a <a href="http://foo.bar/тест" class="external">link</a>' 259 %|This is a "link":http://foo.bar/#{@russian_test}| =>
260 %|This is a <a href="http://foo.bar/#{@russian_test}" class="external">link</a>|
246 } 261 }
247 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) } 262 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
248 end 263 end
249 else 264 else
250 puts 'Skipping test_textile_external_links_with_non_ascii_characters, unsupported ruby version' 265 puts 'Skipping test_textile_external_links_with_non_ascii_characters, unsupported ruby version'
251 end 266 end
252 267
253 def test_redmine_links 268 def test_redmine_links
254 issue_link = link_to('#3', {:controller => 'issues', :action => 'show', :id => 3}, 269 issue_link = link_to('#3', {:controller => 'issues', :action => 'show', :id => 3},
255 :class => 'issue status-1 priority-4 priority-lowest overdue', :title => 'Error 281 when updating a recipe (New)') 270 :class => Issue.find(3).css_classes, :title => 'Error 281 when updating a recipe (New)')
256 note_link = link_to('#3', {:controller => 'issues', :action => 'show', :id => 3, :anchor => 'note-14'}, 271 note_link = link_to('#3-14', {:controller => 'issues', :action => 'show', :id => 3, :anchor => 'note-14'},
257 :class => 'issue status-1 priority-4 priority-lowest overdue', :title => 'Error 281 when updating a recipe (New)') 272 :class => Issue.find(3).css_classes, :title => 'Error 281 when updating a recipe (New)')
258 273 note_link2 = link_to('#3#note-14', {:controller => 'issues', :action => 'show', :id => 3, :anchor => 'note-14'},
259 changeset_link = link_to('r1', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 1}, 274 :class => Issue.find(3).css_classes, :title => 'Error 281 when updating a recipe (New)')
260 :class => 'changeset', :title => 'My very first commit') 275
261 changeset_link2 = link_to('r2', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 2}, 276 revision_link = link_to('r1', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 1},
277 :class => 'changeset', :title => 'My very first commit do not escaping #<>&')
278 revision_link2 = link_to('r2', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 2},
262 :class => 'changeset', :title => 'This commit fixes #1, #2 and references #1 & #3') 279 :class => 'changeset', :title => 'This commit fixes #1, #2 and references #1 & #3')
280
281 changeset_link2 = link_to('691322a8eb01e11fd7',
282 {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 1},
283 :class => 'changeset', :title => 'My very first commit do not escaping #<>&')
263 284
264 document_link = link_to('Test document', {:controller => 'documents', :action => 'show', :id => 1}, 285 document_link = link_to('Test document', {:controller => 'documents', :action => 'show', :id => 1},
265 :class => 'document') 286 :class => 'document')
266 287
267 version_link = link_to('1.0', {:controller => 'versions', :action => 'show', :id => 2}, 288 version_link = link_to('1.0', {:controller => 'versions', :action => 'show', :id => 2},
277 298
278 source_url = '/projects/ecookbook/repository/entry/some/file' 299 source_url = '/projects/ecookbook/repository/entry/some/file'
279 source_url_with_rev = '/projects/ecookbook/repository/revisions/52/entry/some/file' 300 source_url_with_rev = '/projects/ecookbook/repository/revisions/52/entry/some/file'
280 source_url_with_ext = '/projects/ecookbook/repository/entry/some/file.ext' 301 source_url_with_ext = '/projects/ecookbook/repository/entry/some/file.ext'
281 source_url_with_rev_and_ext = '/projects/ecookbook/repository/revisions/52/entry/some/file.ext' 302 source_url_with_rev_and_ext = '/projects/ecookbook/repository/revisions/52/entry/some/file.ext'
303 source_url_with_branch = '/projects/ecookbook/repository/revisions/branch/entry/some/file'
282 304
283 export_url = '/projects/ecookbook/repository/raw/some/file' 305 export_url = '/projects/ecookbook/repository/raw/some/file'
284 export_url_with_rev = '/projects/ecookbook/repository/revisions/52/raw/some/file' 306 export_url_with_rev = '/projects/ecookbook/repository/revisions/52/raw/some/file'
285 export_url_with_ext = '/projects/ecookbook/repository/raw/some/file.ext' 307 export_url_with_ext = '/projects/ecookbook/repository/raw/some/file.ext'
286 export_url_with_rev_and_ext = '/projects/ecookbook/repository/revisions/52/raw/some/file.ext' 308 export_url_with_rev_and_ext = '/projects/ecookbook/repository/revisions/52/raw/some/file.ext'
309 export_url_with_branch = '/projects/ecookbook/repository/revisions/branch/raw/some/file'
287 310
288 to_test = { 311 to_test = {
289 # tickets 312 # tickets
290 '#3, [#3], (#3) and #3.' => "#{issue_link}, [#{issue_link}], (#{issue_link}) and #{issue_link}.", 313 '#3, [#3], (#3) and #3.' => "#{issue_link}, [#{issue_link}], (#{issue_link}) and #{issue_link}.",
291 # ticket notes 314 # ticket notes
292 '#3-14' => note_link, 315 '#3-14' => note_link,
293 '#3#note-14' => note_link, 316 '#3#note-14' => note_link2,
294 # should not ignore leading zero 317 # should not ignore leading zero
295 '#03' => '#03', 318 '#03' => '#03',
296 # changesets 319 # changesets
297 'r1' => changeset_link, 320 'r1' => revision_link,
298 'r1.' => "#{changeset_link}.", 321 'r1.' => "#{revision_link}.",
299 'r1, r2' => "#{changeset_link}, #{changeset_link2}", 322 'r1, r2' => "#{revision_link}, #{revision_link2}",
300 'r1,r2' => "#{changeset_link},#{changeset_link2}", 323 'r1,r2' => "#{revision_link},#{revision_link2}",
324 'commit:691322a8eb01e11fd7' => changeset_link2,
301 # documents 325 # documents
302 'document#1' => document_link, 326 'document#1' => document_link,
303 'document:"Test document"' => document_link, 327 'document:"Test document"' => document_link,
304 # versions 328 # versions
305 'version#2' => version_link, 329 'version#2' => version_link,
312 'source:/some/file.ext.' => link_to('source:/some/file.ext', source_url_with_ext, :class => 'source') + ".", 336 'source:/some/file.ext.' => link_to('source:/some/file.ext', source_url_with_ext, :class => 'source') + ".",
313 'source:/some/file. ' => link_to('source:/some/file', source_url, :class => 'source') + ".", 337 'source:/some/file. ' => link_to('source:/some/file', source_url, :class => 'source') + ".",
314 'source:/some/file.ext. ' => link_to('source:/some/file.ext', source_url_with_ext, :class => 'source') + ".", 338 'source:/some/file.ext. ' => link_to('source:/some/file.ext', source_url_with_ext, :class => 'source') + ".",
315 'source:/some/file, ' => link_to('source:/some/file', source_url, :class => 'source') + ",", 339 'source:/some/file, ' => link_to('source:/some/file', source_url, :class => 'source') + ",",
316 'source:/some/file@52' => link_to('source:/some/file@52', source_url_with_rev, :class => 'source'), 340 'source:/some/file@52' => link_to('source:/some/file@52', source_url_with_rev, :class => 'source'),
341 'source:/some/file@branch' => link_to('source:/some/file@branch', source_url_with_branch, :class => 'source'),
317 'source:/some/file.ext@52' => link_to('source:/some/file.ext@52', source_url_with_rev_and_ext, :class => 'source'), 342 'source:/some/file.ext@52' => link_to('source:/some/file.ext@52', source_url_with_rev_and_ext, :class => 'source'),
318 'source:/some/file#L110' => link_to('source:/some/file#L110', source_url + "#L110", :class => 'source'), 343 'source:/some/file#L110' => link_to('source:/some/file#L110', source_url + "#L110", :class => 'source'),
319 'source:/some/file.ext#L110' => link_to('source:/some/file.ext#L110', source_url_with_ext + "#L110", :class => 'source'), 344 'source:/some/file.ext#L110' => link_to('source:/some/file.ext#L110', source_url_with_ext + "#L110", :class => 'source'),
320 'source:/some/file@52#L110' => link_to('source:/some/file@52#L110', source_url_with_rev + "#L110", :class => 'source'), 345 'source:/some/file@52#L110' => link_to('source:/some/file@52#L110', source_url_with_rev + "#L110", :class => 'source'),
321 # export 346 # export
322 'export:/some/file' => link_to('export:/some/file', export_url, :class => 'source download'), 347 'export:/some/file' => link_to('export:/some/file', export_url, :class => 'source download'),
323 'export:/some/file.ext' => link_to('export:/some/file.ext', export_url_with_ext, :class => 'source download'), 348 'export:/some/file.ext' => link_to('export:/some/file.ext', export_url_with_ext, :class => 'source download'),
324 'export:/some/file@52' => link_to('export:/some/file@52', export_url_with_rev, :class => 'source download'), 349 'export:/some/file@52' => link_to('export:/some/file@52', export_url_with_rev, :class => 'source download'),
325 'export:/some/file.ext@52' => link_to('export:/some/file.ext@52', export_url_with_rev_and_ext, :class => 'source download'), 350 'export:/some/file.ext@52' => link_to('export:/some/file.ext@52', export_url_with_rev_and_ext, :class => 'source download'),
351 'export:/some/file@branch' => link_to('export:/some/file@branch', export_url_with_branch, :class => 'source download'),
326 # forum 352 # forum
327 'forum#2' => link_to('Discussion', board_url, :class => 'board'), 353 'forum#2' => link_to('Discussion', board_url, :class => 'board'),
328 'forum:Discussion' => link_to('Discussion', board_url, :class => 'board'), 354 'forum:Discussion' => link_to('Discussion', board_url, :class => 'board'),
329 # message 355 # message
330 'message#4' => link_to('Post 2', message_url, :class => 'message'), 356 'message#4' => link_to('Post 2', message_url, :class => 'message'),
551 assert( c.save ) 577 assert( c.save )
552 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) } 578 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
553 end 579 end
554 580
555 def test_attachment_links 581 def test_attachment_links
556 attachment_link = link_to('error281.txt', {:controller => 'attachments', :action => 'download', :id => '1'}, :class => 'attachment') 582 to_test = {
557 to_test = { 583 'attachment:error281.txt' => '<a href="/attachments/download/1/error281.txt" class="attachment">error281.txt</a>'
558 'attachment:error281.txt' => attachment_link
559 } 584 }
560 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text, :attachments => Issue.find(3).attachments), "#{text} failed" } 585 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text, :attachments => Issue.find(3).attachments), "#{text} failed" }
561 end 586 end
562 587
563 def test_attachment_link_should_link_to_latest_attachment 588 def test_attachment_link_should_link_to_latest_attachment
564 set_tmp_attachments_directory 589 set_tmp_attachments_directory
565 a1 = Attachment.generate!(:filename => "test.txt", :created_on => 1.hour.ago) 590 a1 = Attachment.generate!(:filename => "test.txt", :created_on => 1.hour.ago)
566 a2 = Attachment.generate!(:filename => "test.txt") 591 a2 = Attachment.generate!(:filename => "test.txt")
567 592
568 assert_equal %(<p><a href="/attachments/download/#{a2.id}" class="attachment">test.txt</a></p>), 593 assert_equal %(<p><a href="/attachments/download/#{a2.id}/test.txt" class="attachment">test.txt</a></p>),
569 textilizable('attachment:test.txt', :attachments => [a1, a2]) 594 textilizable('attachment:test.txt', :attachments => [a1, a2])
570 end 595 end
571 596
572 def test_wiki_links 597 def test_wiki_links
598 russian_eacape = CGI.escape(@russian_test)
573 to_test = { 599 to_test = {
574 '[[CookBook documentation]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation" class="wiki-page">CookBook documentation</a>', 600 '[[CookBook documentation]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation" class="wiki-page">CookBook documentation</a>',
575 '[[Another page|Page]]' => '<a href="/projects/ecookbook/wiki/Another_page" class="wiki-page">Page</a>', 601 '[[Another page|Page]]' => '<a href="/projects/ecookbook/wiki/Another_page" class="wiki-page">Page</a>',
576 # title content should be formatted 602 # title content should be formatted
577 '[[Another page|With _styled_ *title*]]' => '<a href="/projects/ecookbook/wiki/Another_page" class="wiki-page">With <em>styled</em> <strong>title</strong></a>', 603 '[[Another page|With _styled_ *title*]]' => '<a href="/projects/ecookbook/wiki/Another_page" class="wiki-page">With <em>styled</em> <strong>title</strong></a>',
578 '[[Another page|With title containing <strong>HTML entities &amp; markups</strong>]]' => '<a href="/projects/ecookbook/wiki/Another_page" class="wiki-page">With title containing &lt;strong&gt;HTML entities &amp; markups&lt;/strong&gt;</a>', 604 '[[Another page|With title containing <strong>HTML entities &amp; markups</strong>]]' => '<a href="/projects/ecookbook/wiki/Another_page" class="wiki-page">With title containing &lt;strong&gt;HTML entities &amp; markups&lt;/strong&gt;</a>',
579 # link with anchor 605 # link with anchor
580 '[[CookBook documentation#One-section]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation#One-section" class="wiki-page">CookBook documentation</a>', 606 '[[CookBook documentation#One-section]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation#One-section" class="wiki-page">CookBook documentation</a>',
581 '[[Another page#anchor|Page]]' => '<a href="/projects/ecookbook/wiki/Another_page#anchor" class="wiki-page">Page</a>', 607 '[[Another page#anchor|Page]]' => '<a href="/projects/ecookbook/wiki/Another_page#anchor" class="wiki-page">Page</a>',
582 # UTF8 anchor 608 # UTF8 anchor
583 '[[Another_page#Тест|Тест]]' => %|<a href="/projects/ecookbook/wiki/Another_page##{CGI.escape 'Тест'}" class="wiki-page">Тест</a>|, 609 "[[Another_page##{@russian_test}|#{@russian_test}]]" =>
610 %|<a href="/projects/ecookbook/wiki/Another_page##{russian_eacape}" class="wiki-page">#{@russian_test}</a>|,
584 # page that doesn't exist 611 # page that doesn't exist
585 '[[Unknown page]]' => '<a href="/projects/ecookbook/wiki/Unknown_page" class="wiki-page new">Unknown page</a>', 612 '[[Unknown page]]' => '<a href="/projects/ecookbook/wiki/Unknown_page" class="wiki-page new">Unknown page</a>',
586 '[[Unknown page|404]]' => '<a href="/projects/ecookbook/wiki/Unknown_page" class="wiki-page new">404</a>', 613 '[[Unknown page|404]]' => '<a href="/projects/ecookbook/wiki/Unknown_page" class="wiki-page new">404</a>',
587 # link to another project wiki 614 # link to another project wiki
588 '[[onlinestore:]]' => '<a href="/projects/onlinestore/wiki" class="wiki-page">onlinestore</a>', 615 '[[onlinestore:]]' => '<a href="/projects/onlinestore/wiki" class="wiki-page">onlinestore</a>',
739 </pre> 766 </pre>
740 RAW 767 RAW
741 768
742 expected = <<-EXPECTED 769 expected = <<-EXPECTED
743 <p><a href="/projects/ecookbook/wiki/CookBook_documentation" class="wiki-page">CookBook documentation</a></p> 770 <p><a href="/projects/ecookbook/wiki/CookBook_documentation" class="wiki-page">CookBook documentation</a></p>
744 <p><a href="/issues/1" class="issue status-1 priority-4 priority-lowest" title="Can&#x27;t print recipes (New)">#1</a></p> 771 <p><a href="/issues/1" class="#{Issue.find(1).css_classes}" title="Can&#x27;t print recipes (New)">#1</a></p>
745 <pre> 772 <pre>
746 [[CookBook documentation]] 773 [[CookBook documentation]]
747 774
748 #1 775 #1
749 </pre> 776 </pre>
987 @project = Project.find(1) 1014 @project = Project.find(1)
988 set_language_if_valid 'en' 1015 set_language_if_valid 'en'
989 result = textilizable(raw, :edit_section_links => {:controller => 'wiki', :action => 'edit', :project_id => '1', :id => 'Test'}).gsub("\n", "") 1016 result = textilizable(raw, :edit_section_links => {:controller => 'wiki', :action => 'edit', :project_id => '1', :id => 'Test'}).gsub("\n", "")
990 1017
991 # heading that contains inline code 1018 # heading that contains inline code
992 assert_match Regexp.new('<div class="contextual" title="Edit this section">' + 1019 assert_match Regexp.new('<div class="contextual" id="section-4" title="Edit this section">' +
993 '<a href="/projects/1/wiki/Test/edit\?section=4"><img alt="Edit" src="/images/edit.png(\?\d+)?" /></a></div>' + 1020 '<a href="/projects/1/wiki/Test/edit\?section=4"><img alt="Edit" src="/images/edit.png(\?\d+)?" /></a></div>' +
994 '<a name="Subtitle-with-inline-code"></a>' + 1021 '<a name="Subtitle-with-inline-code"></a>' +
995 '<h2 >Subtitle with <code>inline code</code><a href="#Subtitle-with-inline-code" class="wiki-anchor">&para;</a></h2>'), 1022 '<h2 >Subtitle with <code>inline code</code><a href="#Subtitle-with-inline-code" class="wiki-anchor">&para;</a></h2>'),
996 result 1023 result
997 1024
998 # last heading 1025 # last heading
999 assert_match Regexp.new('<div class="contextual" title="Edit this section">' + 1026 assert_match Regexp.new('<div class="contextual" id="section-5" title="Edit this section">' +
1000 '<a href="/projects/1/wiki/Test/edit\?section=5"><img alt="Edit" src="/images/edit.png(\?\d+)?" /></a></div>' + 1027 '<a href="/projects/1/wiki/Test/edit\?section=5"><img alt="Edit" src="/images/edit.png(\?\d+)?" /></a></div>' +
1001 '<a name="Subtitle-after-pre-tag"></a>' + 1028 '<a name="Subtitle-after-pre-tag"></a>' +
1002 '<h2 >Subtitle after pre tag<a href="#Subtitle-after-pre-tag" class="wiki-anchor">&para;</a></h2>'), 1029 '<h2 >Subtitle after pre tag<a href="#Subtitle-after-pre-tag" class="wiki-anchor">&para;</a></h2>'),
1003 result 1030 result
1004 end 1031 end
1074 assert user.anonymous? 1101 assert user.anonymous?
1075 t = link_to_user(user) 1102 t = link_to_user(user)
1076 assert_equal ::I18n.t(:label_user_anonymous), t 1103 assert_equal ::I18n.t(:label_user_anonymous), t
1077 end 1104 end
1078 1105
1106 def test_link_to_attachment
1107 a = Attachment.find(3)
1108 assert_equal '<a href="/attachments/3/logo.gif">logo.gif</a>',
1109 link_to_attachment(a)
1110 assert_equal '<a href="/attachments/3/logo.gif">Text</a>',
1111 link_to_attachment(a, :text => 'Text')
1112 assert_equal '<a href="/attachments/3/logo.gif" class="foo">logo.gif</a>',
1113 link_to_attachment(a, :class => 'foo')
1114 assert_equal '<a href="/attachments/download/3/logo.gif">logo.gif</a>',
1115 link_to_attachment(a, :download => true)
1116 assert_equal '<a href="http://test.host/attachments/3/logo.gif">logo.gif</a>',
1117 link_to_attachment(a, :only_path => false)
1118 end
1119
1120 def test_thumbnail_tag
1121 a = Attachment.find(3)
1122 assert_equal '<a href="/attachments/3/logo.gif" title="logo.gif"><img alt="3" src="/attachments/thumbnail/3" /></a>',
1123 thumbnail_tag(a)
1124 end
1125
1079 def test_link_to_project 1126 def test_link_to_project
1080 project = Project.find(1) 1127 project = Project.find(1)
1081 assert_equal %(<a href="/projects/ecookbook">eCookbook</a>), 1128 assert_equal %(<a href="/projects/ecookbook">eCookbook</a>),
1082 link_to_project(project) 1129 link_to_project(project)
1083 assert_equal %(<a href="/projects/ecookbook/settings">eCookbook</a>), 1130 assert_equal %(<a href="/projects/ecookbook/settings">eCookbook</a>),
1086 link_to_project(project, {:only_path => false, :jump => 'blah'}) 1133 link_to_project(project, {:only_path => false, :jump => 'blah'})
1087 assert_equal %(<a href="/projects/ecookbook/settings" class="project">eCookbook</a>), 1134 assert_equal %(<a href="/projects/ecookbook/settings" class="project">eCookbook</a>),
1088 link_to_project(project, {:action => 'settings'}, :class => "project") 1135 link_to_project(project, {:action => 'settings'}, :class => "project")
1089 end 1136 end
1090 1137
1138 def test_link_to_project_settings
1139 project = Project.find(1)
1140 assert_equal '<a href="/projects/ecookbook/settings">eCookbook</a>', link_to_project_settings(project)
1141
1142 project.status = Project::STATUS_CLOSED
1143 assert_equal '<a href="/projects/ecookbook">eCookbook</a>', link_to_project_settings(project)
1144
1145 project.status = Project::STATUS_ARCHIVED
1146 assert_equal 'eCookbook', link_to_project_settings(project)
1147 end
1148
1091 def test_link_to_legacy_project_with_numerical_identifier_should_use_id 1149 def test_link_to_legacy_project_with_numerical_identifier_should_use_id
1092 # numeric identifier are no longer allowed 1150 # numeric identifier are no longer allowed
1093 Project.update_all "identifier=25", "id=1" 1151 Project.update_all "identifier=25", "id=1"
1094 1152
1095 assert_equal '<a href="/projects/1">eCookbook</a>', 1153 assert_equal '<a href="/projects/1">eCookbook</a>',
1162 1220
1163 def test_javascript_include_tag_for_plugin_should_pick_the_plugin_javascript 1221 def test_javascript_include_tag_for_plugin_should_pick_the_plugin_javascript
1164 assert_match 'src="/plugin_assets/foo/javascripts/scripts.js"', javascript_include_tag("scripts", :plugin => :foo) 1222 assert_match 'src="/plugin_assets/foo/javascripts/scripts.js"', javascript_include_tag("scripts", :plugin => :foo)
1165 end 1223 end
1166 1224
1167 def test_per_page_links_should_show_usefull_values 1225 def test_raw_json_should_escape_closing_tags
1168 set_language_if_valid 'en' 1226 s = raw_json(["<foo>bar</foo>"])
1169 stubs(:link_to).returns("[link]") 1227 assert_equal '["<foo>bar<\/foo>"]', s
1170 1228 end
1171 with_settings :per_page_options => '10, 25, 50, 100' do 1229
1172 assert_nil per_page_links(10, 3) 1230 def test_raw_json_should_be_html_safe
1173 assert_nil per_page_links(25, 3) 1231 s = raw_json(["foo"])
1174 assert_equal "Per page: 10, [link]", per_page_links(10, 22) 1232 assert s.html_safe?
1175 assert_equal "Per page: [link], 25", per_page_links(25, 22) 1233 end
1176 assert_equal "Per page: [link], [link], 50", per_page_links(50, 22) 1234
1177 assert_equal "Per page: [link], 25, [link]", per_page_links(25, 26) 1235 def test_html_title_should_app_title_if_not_set
1178 assert_equal "Per page: [link], 25, [link], [link]", per_page_links(25, 120) 1236 assert_equal 'Redmine', html_title
1179 end 1237 end
1238
1239 def test_html_title_should_join_items
1240 html_title 'Foo', 'Bar'
1241 assert_equal 'Foo - Bar - Redmine', html_title
1242 end
1243
1244 def test_html_title_should_append_current_project_name
1245 @project = Project.find(1)
1246 html_title 'Foo', 'Bar'
1247 assert_equal 'Foo - Bar - eCookbook - Redmine', html_title
1248 end
1249
1250 def test_title_should_return_a_h2_tag
1251 assert_equal '<h2>Foo</h2>', title('Foo')
1252 end
1253
1254 def test_title_should_set_html_title
1255 title('Foo')
1256 assert_equal 'Foo - Redmine', html_title
1257 end
1258
1259 def test_title_should_turn_arrays_into_links
1260 assert_equal '<h2><a href="/foo">Foo</a></h2>', title(['Foo', '/foo'])
1261 assert_equal 'Foo - Redmine', html_title
1262 end
1263
1264 def test_title_should_join_items
1265 assert_equal '<h2>Foo &#187; Bar</h2>', title('Foo', 'Bar')
1266 assert_equal 'Bar - Foo - Redmine', html_title
1180 end 1267 end
1181 end 1268 end