comparison test/unit/helpers/application_helper_test.rb @ 1337:077b8890835a cannam

Merge from live branch
author Chris Cannam
date Thu, 20 Jun 2013 13:14:02 +0100
parents 0a574315af3e
children 4f746d8966dd fb9a13467253
comparison
equal deleted inserted replaced
1304:6137548ba453 1337:077b8890835a
1 # encoding: utf-8
2 #
1 # Redmine - project management software 3 # Redmine - project management software
2 # Copyright (C) 2006-2011 Jean-Philippe Lang 4 # Copyright (C) 2006-2012 Jean-Philippe Lang
3 # 5 #
4 # This program is free software; you can redistribute it and/or 6 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License 7 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2 8 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version. 9 # of the License, or (at your option) any later version.
16 # 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.
17 19
18 require File.expand_path('../../../test_helper', __FILE__) 20 require File.expand_path('../../../test_helper', __FILE__)
19 21
20 class ApplicationHelperTest < ActionView::TestCase 22 class ApplicationHelperTest < ActionView::TestCase
23 include ERB::Util
24
21 fixtures :projects, :roles, :enabled_modules, :users, 25 fixtures :projects, :roles, :enabled_modules, :users,
22 :repositories, :changesets, 26 :repositories, :changesets,
23 :trackers, :issue_statuses, :issues, :versions, :documents, 27 :trackers, :issue_statuses, :issues, :versions, :documents,
24 :wikis, :wiki_pages, :wiki_contents, 28 :wikis, :wiki_pages, :wiki_contents,
25 :boards, :messages, :news, 29 :boards, :messages, :news,
75 'ftps://foo.bar' => '<a class="external" href="ftps://foo.bar">ftps://foo.bar</a>', 79 'ftps://foo.bar' => '<a class="external" href="ftps://foo.bar">ftps://foo.bar</a>',
76 'sftp://foo.bar' => '<a class="external" href="sftp://foo.bar">sftp://foo.bar</a>', 80 'sftp://foo.bar' => '<a class="external" href="sftp://foo.bar">sftp://foo.bar</a>',
77 # two exclamation marks 81 # two exclamation marks
78 '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>', 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>',
79 # escaping 83 # escaping
80 'http://foo"bar' => '<a class="external" href="http://foo&quot;bar">http://foo"bar</a>', 84 'http://foo"bar' => '<a class="external" href="http://foo&quot;bar">http://foo&quot;bar</a>',
81 # wrap in angle brackets 85 # wrap in angle brackets
82 '<http://foo.bar>' => '&lt;<a class="external" href="http://foo.bar">http://foo.bar</a>&gt;' 86 '<http://foo.bar>' => '&lt;<a class="external" href="http://foo.bar">http://foo.bar</a>&gt;'
83 } 87 }
84 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) } 88 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
89 end
90
91 if 'ruby'.respond_to?(:encoding)
92 def test_auto_links_with_non_ascii_characters
93 to_test = {
94 'http://foo.bar/тест' => '<a class="external" href="http://foo.bar/тест">http://foo.bar/тест</a>'
95 }
96 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
97 end
98 else
99 puts 'Skipping test_auto_links_with_non_ascii_characters, unsupported ruby version'
85 end 100 end
86 101
87 def test_auto_mailto 102 def test_auto_mailto
88 assert_equal '<p><a class="email" href="mailto:test@foo.bar">test@foo.bar</a></p>', 103 assert_equal '<p><a class="email" href="mailto:test@foo.bar">test@foo.bar</a></p>',
89 textilizable('test@foo.bar') 104 textilizable('test@foo.bar')
92 def test_inline_images 107 def test_inline_images
93 to_test = { 108 to_test = {
94 '!http://foo.bar/image.jpg!' => '<img src="http://foo.bar/image.jpg" alt="" />', 109 '!http://foo.bar/image.jpg!' => '<img src="http://foo.bar/image.jpg" alt="" />',
95 'floating !>http://foo.bar/image.jpg!' => 'floating <div style="float:right"><img src="http://foo.bar/image.jpg" alt="" /></div>', 110 'floating !>http://foo.bar/image.jpg!' => 'floating <div style="float:right"><img src="http://foo.bar/image.jpg" alt="" /></div>',
96 'with class !(some-class)http://foo.bar/image.jpg!' => 'with class <img src="http://foo.bar/image.jpg" class="some-class" alt="" />', 111 'with class !(some-class)http://foo.bar/image.jpg!' => 'with class <img src="http://foo.bar/image.jpg" class="some-class" alt="" />',
97 # inline styles should be stripped 112 'with style !{width:100px;height:100px}http://foo.bar/image.jpg!' => 'with style <img src="http://foo.bar/image.jpg" style="width:100px;height:100px;" alt="" />',
98 'with style !{width:100px;height100px}http://foo.bar/image.jpg!' => 'with style <img src="http://foo.bar/image.jpg" alt="" />',
99 'with title !http://foo.bar/image.jpg(This is a title)!' => 'with title <img src="http://foo.bar/image.jpg" title="This is a title" alt="This is a title" />', 113 'with title !http://foo.bar/image.jpg(This is a title)!' => 'with title <img src="http://foo.bar/image.jpg" title="This is a title" alt="This is a title" />',
100 'with title !http://foo.bar/image.jpg(This is a double-quoted "title")!' => 'with title <img src="http://foo.bar/image.jpg" title="This is a double-quoted &quot;title&quot;" alt="This is a double-quoted &quot;title&quot;" />', 114 'with title !http://foo.bar/image.jpg(This is a double-quoted "title")!' => 'with title <img src="http://foo.bar/image.jpg" title="This is a double-quoted &quot;title&quot;" alt="This is a double-quoted &quot;title&quot;" />',
101 } 115 }
102 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) } 116 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
103 end 117 end
180 attachments = [a1, a2, a3, a4] 194 attachments = [a1, a2, a3, a4]
181 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text, :attachments => attachments) } 195 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text, :attachments => attachments) }
182 end 196 end
183 197
184 def test_attached_images_should_read_later 198 def test_attached_images_should_read_later
185 Attachment.storage_path = "#{Rails.root}/test/fixtures/files" 199 set_fixtures_attachments_directory
186 a1 = Attachment.find(16) 200 a1 = Attachment.find(16)
187 assert_equal "testfile.png", a1.filename 201 assert_equal "testfile.png", a1.filename
188 assert a1.readable? 202 assert a1.readable?
189 assert (! a1.visible?(User.anonymous)) 203 assert (! a1.visible?(User.anonymous))
190 assert a1.visible?(User.find(2)) 204 assert a1.visible?(User.find(2))
223 '"test":http://foo"bar' => '<a href="http://foo&quot;bar" class="external">test</a>', 237 '"test":http://foo"bar' => '<a href="http://foo&quot;bar" class="external">test</a>',
224 } 238 }
225 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) } 239 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
226 end 240 end
227 241
242 if 'ruby'.respond_to?(:encoding)
243 def test_textile_external_links_with_non_ascii_characters
244 to_test = {
245 'This is a "link":http://foo.bar/тест' => 'This is a <a href="http://foo.bar/тест" class="external">link</a>'
246 }
247 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
248 end
249 else
250 puts 'Skipping test_textile_external_links_with_non_ascii_characters, unsupported ruby version'
251 end
252
228 def test_redmine_links 253 def test_redmine_links
229 issue_link = link_to('#3', {:controller => 'issues', :action => 'show', :id => 3}, 254 issue_link = link_to('#3', {:controller => 'issues', :action => 'show', :id => 3},
230 :class => 'issue status-1 priority-1 overdue', :title => 'Error 281 when updating a recipe (New)') 255 :class => 'issue status-1 priority-4 priority-lowest overdue', :title => 'Error 281 when updating a recipe (New)')
256 note_link = link_to('#3', {: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)')
231 258
232 changeset_link = link_to('r1', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 1}, 259 changeset_link = link_to('r1', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 1},
233 :class => 'changeset', :title => 'My very first commit') 260 :class => 'changeset', :title => 'My very first commit')
234 changeset_link2 = link_to('r2', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 2}, 261 changeset_link2 = link_to('r2', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 2},
235 :class => 'changeset', :title => 'This commit fixes #1, #2 and references #1 & #3') 262 :class => 'changeset', :title => 'This commit fixes #1, #2 and references #1 & #3')
246 273
247 news_url = {:controller => 'news', :action => 'show', :id => 1} 274 news_url = {:controller => 'news', :action => 'show', :id => 1}
248 275
249 project_url = {:controller => 'projects', :action => 'show', :id => 'subproject1'} 276 project_url = {:controller => 'projects', :action => 'show', :id => 'subproject1'}
250 277
251 source_url = {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :path => ['some', 'file']} 278 source_url = '/projects/ecookbook/repository/entry/some/file'
252 source_url_with_ext = {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :path => ['some', 'file.ext']} 279 source_url_with_rev = '/projects/ecookbook/repository/revisions/52/entry/some/file'
280 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'
282
283 export_url = '/projects/ecookbook/repository/raw/some/file'
284 export_url_with_rev = '/projects/ecookbook/repository/revisions/52/raw/some/file'
285 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'
253 287
254 to_test = { 288 to_test = {
255 # tickets 289 # tickets
256 '#3, [#3], (#3) and #3.' => "#{issue_link}, [#{issue_link}], (#{issue_link}) and #{issue_link}.", 290 '#3, [#3], (#3) and #3.' => "#{issue_link}, [#{issue_link}], (#{issue_link}) and #{issue_link}.",
291 # ticket notes
292 '#3-14' => note_link,
293 '#3#note-14' => note_link,
294 # should not ignore leading zero
295 '#03' => '#03',
257 # changesets 296 # changesets
258 'r1' => changeset_link, 297 'r1' => changeset_link,
259 'r1.' => "#{changeset_link}.", 298 'r1.' => "#{changeset_link}.",
260 'r1, r2' => "#{changeset_link}, #{changeset_link2}", 299 'r1, r2' => "#{changeset_link}, #{changeset_link2}",
261 'r1,r2' => "#{changeset_link},#{changeset_link2}", 300 'r1,r2' => "#{changeset_link},#{changeset_link2}",
265 # versions 304 # versions
266 'version#2' => version_link, 305 'version#2' => version_link,
267 'version:1.0' => version_link, 306 'version:1.0' => version_link,
268 'version:"1.0"' => version_link, 307 'version:"1.0"' => version_link,
269 # source 308 # source
309 'source:some/file' => link_to('source:some/file', source_url, :class => 'source'),
270 'source:/some/file' => link_to('source:/some/file', source_url, :class => 'source'), 310 'source:/some/file' => link_to('source:/some/file', source_url, :class => 'source'),
271 'source:/some/file.' => link_to('source:/some/file', source_url, :class => 'source') + ".", 311 'source:/some/file.' => link_to('source:/some/file', source_url, :class => 'source') + ".",
272 'source:/some/file.ext.' => link_to('source:/some/file.ext', source_url_with_ext, :class => 'source') + ".", 312 'source:/some/file.ext.' => link_to('source:/some/file.ext', source_url_with_ext, :class => 'source') + ".",
273 'source:/some/file. ' => link_to('source:/some/file', source_url, :class => 'source') + ".", 313 'source:/some/file. ' => link_to('source:/some/file', source_url, :class => 'source') + ".",
274 'source:/some/file.ext. ' => link_to('source:/some/file.ext', source_url_with_ext, :class => 'source') + ".", 314 'source:/some/file.ext. ' => link_to('source:/some/file.ext', source_url_with_ext, :class => 'source') + ".",
275 'source:/some/file, ' => link_to('source:/some/file', source_url, :class => 'source') + ",", 315 'source:/some/file, ' => link_to('source:/some/file', source_url, :class => 'source') + ",",
276 'source:/some/file@52' => link_to('source:/some/file@52', source_url.merge(:rev => 52), :class => 'source'), 316 'source:/some/file@52' => link_to('source:/some/file@52', source_url_with_rev, :class => 'source'),
277 'source:/some/file.ext@52' => link_to('source:/some/file.ext@52', source_url_with_ext.merge(:rev => 52), :class => 'source'), 317 'source:/some/file.ext@52' => link_to('source:/some/file.ext@52', source_url_with_rev_and_ext, :class => 'source'),
278 'source:/some/file#L110' => link_to('source:/some/file#L110', source_url.merge(:anchor => 'L110'), :class => 'source'), 318 'source:/some/file#L110' => link_to('source:/some/file#L110', source_url + "#L110", :class => 'source'),
279 'source:/some/file.ext#L110' => link_to('source:/some/file.ext#L110', source_url_with_ext.merge(:anchor => 'L110'), :class => 'source'), 319 'source:/some/file.ext#L110' => link_to('source:/some/file.ext#L110', source_url_with_ext + "#L110", :class => 'source'),
280 'source:/some/file@52#L110' => link_to('source:/some/file@52#L110', source_url.merge(:rev => 52, :anchor => 'L110'), :class => 'source'), 320 'source:/some/file@52#L110' => link_to('source:/some/file@52#L110', source_url_with_rev + "#L110", :class => 'source'),
281 'export:/some/file' => link_to('export:/some/file', source_url.merge(:format => 'raw'), :class => 'source download'), 321 # export
322 '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'),
324 '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'),
282 # forum 326 # forum
283 'forum#2' => link_to('Discussion', board_url, :class => 'board'), 327 'forum#2' => link_to('Discussion', board_url, :class => 'board'),
284 'forum:Discussion' => link_to('Discussion', board_url, :class => 'board'), 328 'forum:Discussion' => link_to('Discussion', board_url, :class => 'board'),
285 # message 329 # message
286 'message#4' => link_to('Post 2', message_url, :class => 'message'), 330 'message#4' => link_to('Post 2', message_url, :class => 'message'),
290 'news:"eCookbook first release !"' => link_to('eCookbook first release !', news_url, :class => 'news'), 334 'news:"eCookbook first release !"' => link_to('eCookbook first release !', news_url, :class => 'news'),
291 # project 335 # project
292 'project#3' => link_to('eCookbook Subproject 1', project_url, :class => 'project'), 336 'project#3' => link_to('eCookbook Subproject 1', project_url, :class => 'project'),
293 'project:subproject1' => link_to('eCookbook Subproject 1', project_url, :class => 'project'), 337 'project:subproject1' => link_to('eCookbook Subproject 1', project_url, :class => 'project'),
294 'project:"eCookbook subProject 1"' => link_to('eCookbook Subproject 1', project_url, :class => 'project'), 338 'project:"eCookbook subProject 1"' => link_to('eCookbook Subproject 1', project_url, :class => 'project'),
295 # escaping
296 '!#3.' => '#3.',
297 '!r1' => 'r1',
298 '!document#1' => 'document#1',
299 '!document:"Test document"' => 'document:"Test document"',
300 '!version#2' => 'version#2',
301 '!version:1.0' => 'version:1.0',
302 '!version:"1.0"' => 'version:"1.0"',
303 '!source:/some/file' => 'source:/some/file',
304 # not found 339 # not found
305 '#0123456789' => '#0123456789', 340 '#0123456789' => '#0123456789',
306 # invalid expressions 341 # invalid expressions
307 'source:' => 'source:', 342 'source:' => 'source:',
308 # url hash 343 # url hash
309 "http://foo.bar/FAQ#3" => '<a class="external" href="http://foo.bar/FAQ#3">http://foo.bar/FAQ#3</a>', 344 "http://foo.bar/FAQ#3" => '<a class="external" href="http://foo.bar/FAQ#3">http://foo.bar/FAQ#3</a>',
310 } 345 }
311 @project = Project.find(1) 346 @project = Project.find(1)
312 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text), "#{text} failed" } 347 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text), "#{text} failed" }
348 end
349
350 def test_redmine_links_with_a_different_project_before_current_project
351 vp1 = Version.generate!(:project_id => 1, :name => '1.4.4')
352 vp3 = Version.generate!(:project_id => 3, :name => '1.4.4')
353
354 @project = Project.find(3)
355 assert_equal %(<p><a href="/versions/#{vp1.id}" class="version">1.4.4</a> <a href="/versions/#{vp3.id}" class="version">1.4.4</a></p>),
356 textilizable("ecookbook:version:1.4.4 version:1.4.4")
357 end
358
359 def test_escaped_redmine_links_should_not_be_parsed
360 to_test = [
361 '#3.',
362 '#3-14.',
363 '#3#-note14.',
364 'r1',
365 'document#1',
366 'document:"Test document"',
367 'version#2',
368 'version:1.0',
369 'version:"1.0"',
370 'source:/some/file'
371 ]
372 @project = Project.find(1)
373 to_test.each { |text| assert_equal "<p>#{text}</p>", textilizable("!" + text), "#{text} failed" }
313 end 374 end
314 375
315 def test_cross_project_redmine_links 376 def test_cross_project_redmine_links
316 source_link = link_to('ecookbook:source:/some/file', {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :path => ['some', 'file']}, 377 source_link = link_to('ecookbook:source:/some/file', {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :path => ['some', 'file']},
317 :class => 'source') 378 :class => 'source')
335 # source 396 # source
336 'source:/some/file' => 'source:/some/file', 397 'source:/some/file' => 'source:/some/file',
337 'ecookbook:source:/some/file' => source_link, 398 'ecookbook:source:/some/file' => source_link,
338 'invalid:source:/some/file' => 'invalid:source:/some/file', 399 'invalid:source:/some/file' => 'invalid:source:/some/file',
339 } 400 }
401 @project = Project.find(3)
402 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text), "#{text} failed" }
403 end
404
405 def test_multiple_repositories_redmine_links
406 svn = Repository::Subversion.create!(:project_id => 1, :identifier => 'svn_repo-1', :url => 'file:///foo/hg')
407 Changeset.create!(:repository => svn, :committed_on => Time.now, :revision => '123')
408 hg = Repository::Mercurial.create!(:project_id => 1, :identifier => 'hg1', :url => '/foo/hg')
409 Changeset.create!(:repository => hg, :committed_on => Time.now, :revision => '123', :scmid => 'abcd')
410
411 changeset_link = link_to('r2', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 2},
412 :class => 'changeset', :title => 'This commit fixes #1, #2 and references #1 & #3')
413 svn_changeset_link = link_to('svn_repo-1|r123', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :repository_id => 'svn_repo-1', :rev => 123},
414 :class => 'changeset', :title => '')
415 hg_changeset_link = link_to('hg1|abcd', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :repository_id => 'hg1', :rev => 'abcd'},
416 :class => 'changeset', :title => '')
417
418 source_link = link_to('source:some/file', {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :path => ['some', 'file']}, :class => 'source')
419 hg_source_link = link_to('source:hg1|some/file', {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :repository_id => 'hg1', :path => ['some', 'file']}, :class => 'source')
420
421 to_test = {
422 'r2' => changeset_link,
423 'svn_repo-1|r123' => svn_changeset_link,
424 'invalid|r123' => 'invalid|r123',
425 'commit:hg1|abcd' => hg_changeset_link,
426 'commit:invalid|abcd' => 'commit:invalid|abcd',
427 # source
428 'source:some/file' => source_link,
429 'source:hg1|some/file' => hg_source_link,
430 'source:invalid|some/file' => 'source:invalid|some/file',
431 }
432
433 @project = Project.find(1)
434 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text), "#{text} failed" }
435 end
436
437 def test_cross_project_multiple_repositories_redmine_links
438 svn = Repository::Subversion.create!(:project_id => 1, :identifier => 'svn1', :url => 'file:///foo/hg')
439 Changeset.create!(:repository => svn, :committed_on => Time.now, :revision => '123')
440 hg = Repository::Mercurial.create!(:project_id => 1, :identifier => 'hg1', :url => '/foo/hg')
441 Changeset.create!(:repository => hg, :committed_on => Time.now, :revision => '123', :scmid => 'abcd')
442
443 changeset_link = link_to('ecookbook:r2', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 2},
444 :class => 'changeset', :title => 'This commit fixes #1, #2 and references #1 & #3')
445 svn_changeset_link = link_to('ecookbook:svn1|r123', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :repository_id => 'svn1', :rev => 123},
446 :class => 'changeset', :title => '')
447 hg_changeset_link = link_to('ecookbook:hg1|abcd', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :repository_id => 'hg1', :rev => 'abcd'},
448 :class => 'changeset', :title => '')
449
450 source_link = link_to('ecookbook:source:some/file', {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :path => ['some', 'file']}, :class => 'source')
451 hg_source_link = link_to('ecookbook:source:hg1|some/file', {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :repository_id => 'hg1', :path => ['some', 'file']}, :class => 'source')
452
453 to_test = {
454 'ecookbook:r2' => changeset_link,
455 'ecookbook:svn1|r123' => svn_changeset_link,
456 'ecookbook:invalid|r123' => 'ecookbook:invalid|r123',
457 'ecookbook:commit:hg1|abcd' => hg_changeset_link,
458 'ecookbook:commit:invalid|abcd' => 'ecookbook:commit:invalid|abcd',
459 'invalid:commit:invalid|abcd' => 'invalid:commit:invalid|abcd',
460 # source
461 'ecookbook:source:some/file' => source_link,
462 'ecookbook:source:hg1|some/file' => hg_source_link,
463 'ecookbook:source:invalid|some/file' => 'ecookbook:source:invalid|some/file',
464 'invalid:source:invalid|some/file' => 'invalid:source:invalid|some/file',
465 }
466
340 @project = Project.find(3) 467 @project = Project.find(3)
341 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text), "#{text} failed" } 468 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text), "#{text} failed" }
342 end 469 end
343 470
344 def test_redmine_links_git_commit 471 def test_redmine_links_git_commit
431 'attachment:error281.txt' => attachment_link 558 'attachment:error281.txt' => attachment_link
432 } 559 }
433 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text, :attachments => Issue.find(3).attachments), "#{text} failed" } 560 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text, :attachments => Issue.find(3).attachments), "#{text} failed" }
434 end 561 end
435 562
563 def test_attachment_link_should_link_to_latest_attachment
564 set_tmp_attachments_directory
565 a1 = Attachment.generate!(:filename => "test.txt", :created_on => 1.hour.ago)
566 a2 = Attachment.generate!(:filename => "test.txt")
567
568 assert_equal %(<p><a href="/attachments/download/#{a2.id}" class="attachment">test.txt</a></p>),
569 textilizable('attachment:test.txt', :attachments => [a1, a2])
570 end
571
436 def test_wiki_links 572 def test_wiki_links
437 to_test = { 573 to_test = {
438 '[[CookBook documentation]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation" class="wiki-page">CookBook documentation</a>', 574 '[[CookBook documentation]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation" class="wiki-page">CookBook documentation</a>',
439 '[[Another page|Page]]' => '<a href="/projects/ecookbook/wiki/Another_page" class="wiki-page">Page</a>', 575 '[[Another page|Page]]' => '<a href="/projects/ecookbook/wiki/Another_page" class="wiki-page">Page</a>',
440 # title content should be formatted 576 # title content should be formatted
441 '[[Another page|With _styled_ *title*]]' => '<a href="/projects/ecookbook/wiki/Another_page" class="wiki-page">With <em>styled</em> <strong>title</strong></a>', 577 '[[Another page|With _styled_ *title*]]' => '<a href="/projects/ecookbook/wiki/Another_page" class="wiki-page">With <em>styled</em> <strong>title</strong></a>',
442 '[[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>', 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>',
443 # link with anchor 579 # link with anchor
444 '[[CookBook documentation#One-section]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation#One-section" class="wiki-page">CookBook documentation</a>', 580 '[[CookBook documentation#One-section]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation#One-section" class="wiki-page">CookBook documentation</a>',
445 '[[Another page#anchor|Page]]' => '<a href="/projects/ecookbook/wiki/Another_page#anchor" class="wiki-page">Page</a>', 581 '[[Another page#anchor|Page]]' => '<a href="/projects/ecookbook/wiki/Another_page#anchor" class="wiki-page">Page</a>',
582 # UTF8 anchor
583 '[[Another_page#Тест|Тест]]' => %|<a href="/projects/ecookbook/wiki/Another_page##{CGI.escape 'Тест'}" class="wiki-page">Тест</a>|,
446 # page that doesn't exist 584 # page that doesn't exist
447 '[[Unknown page]]' => '<a href="/projects/ecookbook/wiki/Unknown_page" class="wiki-page new">Unknown page</a>', 585 '[[Unknown page]]' => '<a href="/projects/ecookbook/wiki/Unknown_page" class="wiki-page new">Unknown page</a>',
448 '[[Unknown page|404]]' => '<a href="/projects/ecookbook/wiki/Unknown_page" class="wiki-page new">404</a>', 586 '[[Unknown page|404]]' => '<a href="/projects/ecookbook/wiki/Unknown_page" class="wiki-page new">404</a>',
449 # link to another project wiki 587 # link to another project wiki
450 '[[onlinestore:]]' => '<a href="/projects/onlinestore/wiki" class="wiki-page">onlinestore</a>', 588 '[[onlinestore:]]' => '<a href="/projects/onlinestore/wiki" class="wiki-page">onlinestore</a>',
482 } 620 }
483 621
484 @project = Project.find(1) 622 @project = Project.find(1)
485 623
486 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text, :wiki_links => :local) } 624 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text, :wiki_links => :local) }
625 end
626
627 def test_wiki_links_within_wiki_page_context
628
629 page = WikiPage.find_by_title('Another_page' )
630
631 to_test = {
632 # link to another page
633 '[[CookBook documentation]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation" class="wiki-page">CookBook documentation</a>',
634 '[[CookBook documentation|documentation]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation" class="wiki-page">documentation</a>',
635 '[[CookBook documentation#One-section]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation#One-section" class="wiki-page">CookBook documentation</a>',
636 '[[CookBook documentation#One-section|documentation]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation#One-section" class="wiki-page">documentation</a>',
637 # link to the current page
638 '[[Another page]]' => '<a href="/projects/ecookbook/wiki/Another_page" class="wiki-page">Another page</a>',
639 '[[Another page|Page]]' => '<a href="/projects/ecookbook/wiki/Another_page" class="wiki-page">Page</a>',
640 '[[Another page#anchor]]' => '<a href="#anchor" class="wiki-page">Another page</a>',
641 '[[Another page#anchor|Page]]' => '<a href="#anchor" class="wiki-page">Page</a>',
642 # page that doesn't exist
643 '[[Unknown page]]' => '<a href="/projects/ecookbook/wiki/Unknown_page?parent=Another_page" class="wiki-page new">Unknown page</a>',
644 '[[Unknown page|404]]' => '<a href="/projects/ecookbook/wiki/Unknown_page?parent=Another_page" class="wiki-page new">404</a>',
645 '[[Unknown page#anchor]]' => '<a href="/projects/ecookbook/wiki/Unknown_page?parent=Another_page#anchor" class="wiki-page new">Unknown page</a>',
646 '[[Unknown page#anchor|404]]' => '<a href="/projects/ecookbook/wiki/Unknown_page?parent=Another_page#anchor" class="wiki-page new">404</a>',
647 }
648
649 @project = Project.find(1)
650
651 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(WikiContent.new( :text => text, :page => page ), :text) }
652 end
653
654 def test_wiki_links_anchor_option_should_prepend_page_title_to_href
655
656 to_test = {
657 # link to a page
658 '[[CookBook documentation]]' => '<a href="#CookBook_documentation" class="wiki-page">CookBook documentation</a>',
659 '[[CookBook documentation|documentation]]' => '<a href="#CookBook_documentation" class="wiki-page">documentation</a>',
660 '[[CookBook documentation#One-section]]' => '<a href="#CookBook_documentation_One-section" class="wiki-page">CookBook documentation</a>',
661 '[[CookBook documentation#One-section|documentation]]' => '<a href="#CookBook_documentation_One-section" class="wiki-page">documentation</a>',
662 # page that doesn't exist
663 '[[Unknown page]]' => '<a href="#Unknown_page" class="wiki-page new">Unknown page</a>',
664 '[[Unknown page|404]]' => '<a href="#Unknown_page" class="wiki-page new">404</a>',
665 '[[Unknown page#anchor]]' => '<a href="#Unknown_page_anchor" class="wiki-page new">Unknown page</a>',
666 '[[Unknown page#anchor|404]]' => '<a href="#Unknown_page_anchor" class="wiki-page new">404</a>',
667 }
668
669 @project = Project.find(1)
670
671 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text, :wiki_links => :anchor) }
487 end 672 end
488 673
489 def test_html_tags 674 def test_html_tags
490 to_test = { 675 to_test = {
491 "<div>content</div>" => "<p>&lt;div&gt;content&lt;/div&gt;</p>", 676 "<div>content</div>" => "<p>&lt;div&gt;content&lt;/div&gt;</p>",
554 </pre> 739 </pre>
555 RAW 740 RAW
556 741
557 expected = <<-EXPECTED 742 expected = <<-EXPECTED
558 <p><a href="/projects/ecookbook/wiki/CookBook_documentation" class="wiki-page">CookBook documentation</a></p> 743 <p><a href="/projects/ecookbook/wiki/CookBook_documentation" class="wiki-page">CookBook documentation</a></p>
559 <p><a href="/issues/1" class="issue status-1 priority-1" title="Can't print recipes (New)">#1</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>
560 <pre> 745 <pre>
561 [[CookBook documentation]] 746 [[CookBook documentation]]
562 747
563 #1 748 #1
564 </pre> 749 </pre>
588 # Some ruby code here 773 # Some ruby code here
589 </code></pre> 774 </code></pre>
590 RAW 775 RAW
591 776
592 expected = <<-EXPECTED 777 expected = <<-EXPECTED
593 <pre><code class="ruby syntaxhl"><span class=\"CodeRay\"><span class="line-numbers">1</span><span class="comment"># Some ruby code here</span></span> 778 <pre><code class="ruby syntaxhl"><span class=\"CodeRay\"><span class="comment"># Some ruby code here</span></span>
594 </code></pre> 779 </code></pre>
595 EXPECTED 780 EXPECTED
596 781
597 assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '') 782 assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '')
783 end
784
785 def test_to_path_param
786 assert_equal 'test1/test2', to_path_param('test1/test2')
787 assert_equal 'test1/test2', to_path_param('/test1/test2/')
788 assert_equal 'test1/test2', to_path_param('//test1/test2/')
789 assert_equal nil, to_path_param('/')
598 end 790 end
599 791
600 def test_wiki_links_in_tables 792 def test_wiki_links_in_tables
601 to_test = {"|[[Page|Link title]]|[[Other Page|Other title]]|\n|Cell 21|[[Last page]]|" => 793 to_test = {"|[[Page|Link title]]|[[Other Page|Other title]]|\n|Cell 21|[[Last page]]|" =>
602 '<tr><td><a href="/projects/ecookbook/wiki/Page" class="wiki-page new">Link title</a></td>' + 794 '<tr><td><a href="/projects/ecookbook/wiki/Page" class="wiki-page new">Link title</a></td>' +
652 expected = %|<a name="#{anchor}"></a>\n<h1 >Some heading related to version 0.5<a href="##{anchor}" class="wiki-anchor">&para;</a></h1>| 844 expected = %|<a name="#{anchor}"></a>\n<h1 >Some heading related to version 0.5<a href="##{anchor}" class="wiki-anchor">&para;</a></h1>|
653 845
654 assert_equal expected, textilizable(raw) 846 assert_equal expected, textilizable(raw)
655 end 847 end
656 848
657 def test_wiki_links_within_wiki_page_context
658
659 page = WikiPage.find_by_title('Another_page' )
660
661 to_test = {
662 # link to another page
663 '[[CookBook documentation]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation" class="wiki-page">CookBook documentation</a>',
664 '[[CookBook documentation|documentation]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation" class="wiki-page">documentation</a>',
665 '[[CookBook documentation#One-section]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation#One-section" class="wiki-page">CookBook documentation</a>',
666 '[[CookBook documentation#One-section|documentation]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation#One-section" class="wiki-page">documentation</a>',
667 # link to the current page
668 '[[Another page]]' => '<a href="/projects/ecookbook/wiki/Another_page" class="wiki-page">Another page</a>',
669 '[[Another page|Page]]' => '<a href="/projects/ecookbook/wiki/Another_page" class="wiki-page">Page</a>',
670 '[[Another page#anchor]]' => '<a href="#anchor" class="wiki-page">Another page</a>',
671 '[[Another page#anchor|Page]]' => '<a href="#anchor" class="wiki-page">Page</a>',
672 # page that doesn't exist
673 '[[Unknown page]]' => '<a href="/projects/ecookbook/wiki/Unknown_page" class="wiki-page new">Unknown page</a>',
674 '[[Unknown page|404]]' => '<a href="/projects/ecookbook/wiki/Unknown_page" class="wiki-page new">404</a>',
675 '[[Unknown page#anchor]]' => '<a href="/projects/ecookbook/wiki/Unknown_page#anchor" class="wiki-page new">Unknown page</a>',
676 '[[Unknown page#anchor|404]]' => '<a href="/projects/ecookbook/wiki/Unknown_page#anchor" class="wiki-page new">404</a>',
677 }
678
679 @project = Project.find(1)
680
681 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(WikiContent.generate!( :text => text, :page => page ), :text) }
682 end
683
684 def test_wiki_links_anchor_option_should_prepend_page_title_to_href
685
686 to_test = {
687 # link to a page
688 '[[CookBook documentation]]' => '<a href="#CookBook_documentation" class="wiki-page">CookBook documentation</a>',
689 '[[CookBook documentation|documentation]]' => '<a href="#CookBook_documentation" class="wiki-page">documentation</a>',
690 '[[CookBook documentation#One-section]]' => '<a href="#CookBook_documentation_One-section" class="wiki-page">CookBook documentation</a>',
691 '[[CookBook documentation#One-section|documentation]]' => '<a href="#CookBook_documentation_One-section" class="wiki-page">documentation</a>',
692 # page that doesn't exist
693 '[[Unknown page]]' => '<a href="#Unknown_page" class="wiki-page new">Unknown page</a>',
694 '[[Unknown page|404]]' => '<a href="#Unknown_page" class="wiki-page new">404</a>',
695 '[[Unknown page#anchor]]' => '<a href="#Unknown_page_anchor" class="wiki-page new">Unknown page</a>',
696 '[[Unknown page#anchor|404]]' => '<a href="#Unknown_page_anchor" class="wiki-page new">404</a>',
697 }
698
699 @project = Project.find(1)
700
701 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text, :wiki_links => :anchor) }
702 end
703
704 def test_headings_in_wiki_single_page_export_should_be_prepended_with_page_title 849 def test_headings_in_wiki_single_page_export_should_be_prepended_with_page_title
705 page = WikiPage.generate!( :title => 'Page Title' ) 850 page = WikiPage.new( :title => 'Page Title', :wiki_id => 1 )
706 content = WikiContent.generate!( :text => 'h1. Some heading', :page => page ) 851 content = WikiContent.new( :text => 'h1. Some heading', :page => page )
707 852
708 expected = %|<a name="Page_Title_Some-heading"></a>\n<h1 >Some heading<a href="#Page_Title_Some-heading" class="wiki-anchor">&para;</a></h1>| 853 expected = %|<a name="Page_Title_Some-heading"></a>\n<h1 >Some heading<a href="#Page_Title_Some-heading" class="wiki-anchor">&para;</a></h1>|
709 854
710 assert_equal expected, textilizable(content, :text, :wiki_links => :anchor ) 855 assert_equal expected, textilizable(content, :text, :wiki_links => :anchor )
711 end 856 end
857 '<h2 >Subtitle after pre tag<a href="#Subtitle-after-pre-tag" class="wiki-anchor">&para;</a></h2>'), 1002 '<h2 >Subtitle after pre tag<a href="#Subtitle-after-pre-tag" class="wiki-anchor">&para;</a></h2>'),
858 result 1003 result
859 end 1004 end
860 1005
861 def test_default_formatter 1006 def test_default_formatter
862 Setting.text_formatting = 'unknown' 1007 with_settings :text_formatting => 'unknown' do
863 text = 'a *link*: http://www.example.net/' 1008 text = 'a *link*: http://www.example.net/'
864 assert_equal '<p>a *link*: <a href="http://www.example.net/">http://www.example.net/</a></p>', textilizable(text) 1009 assert_equal '<p>a *link*: <a class="external" href="http://www.example.net/">http://www.example.net/</a></p>', textilizable(text)
865 Setting.text_formatting = 'textile' 1010 end
866 end 1011 end
867 1012
868 def test_due_date_distance_in_words 1013 def test_due_date_distance_in_words
869 to_test = { Date.today => 'Due in 0 days', 1014 to_test = { Date.today => 'Due in 0 days',
870 Date.today + 1 => 'Due in 1 day', 1015 Date.today + 1 => 'Due in 1 day',
878 to_test.each do |date, expected| 1023 to_test.each do |date, expected|
879 assert_equal expected, due_date_distance_in_words(date) 1024 assert_equal expected, due_date_distance_in_words(date)
880 end 1025 end
881 end 1026 end
882 1027
883 def test_avatar 1028 def test_avatar_enabled
884 # turn on avatars 1029 with_settings :gravatar_enabled => '1' do
885 Setting.gravatar_enabled = '1' 1030 assert avatar(User.find_by_mail('jsmith@somenet.foo')).include?(Digest::MD5.hexdigest('jsmith@somenet.foo'))
886 assert avatar(User.find_by_mail('jsmith@somenet.foo')).include?(Digest::MD5.hexdigest('jsmith@somenet.foo')) 1031 assert avatar('jsmith <jsmith@somenet.foo>').include?(Digest::MD5.hexdigest('jsmith@somenet.foo'))
887 assert avatar('jsmith <jsmith@somenet.foo>').include?(Digest::MD5.hexdigest('jsmith@somenet.foo')) 1032 # Default size is 50
888 assert_nil avatar('jsmith') 1033 assert avatar('jsmith <jsmith@somenet.foo>').include?('size=50')
889 assert_nil avatar(nil) 1034 assert avatar('jsmith <jsmith@somenet.foo>', :size => 24).include?('size=24')
890 1035 # Non-avatar options should be considered html options
891 # turn off avatars 1036 assert avatar('jsmith <jsmith@somenet.foo>', :title => 'John Smith').include?('title="John Smith"')
892 Setting.gravatar_enabled = '0' 1037 # The default class of the img tag should be gravatar
893 assert_equal '', avatar(User.find_by_mail('jsmith@somenet.foo')) 1038 assert avatar('jsmith <jsmith@somenet.foo>').include?('class="gravatar"')
1039 assert !avatar('jsmith <jsmith@somenet.foo>', :class => 'picture').include?('class="gravatar"')
1040 assert_nil avatar('jsmith')
1041 assert_nil avatar(nil)
1042 end
1043 end
1044
1045 def test_avatar_disabled
1046 with_settings :gravatar_enabled => '0' do
1047 assert_equal '', avatar(User.find_by_mail('jsmith@somenet.foo'))
1048 end
894 end 1049 end
895 1050
896 def test_link_to_user 1051 def test_link_to_user
897 user = User.find(2) 1052 user = User.find(2)
898 t = link_to_user(user) 1053 assert_equal '<a href="/users/2" class="user active">John Smith</a>', link_to_user(user)
899 assert_equal "<a href=\"/users/2\">#{ user.name }</a>", t
900 end 1054 end
901 1055
902 def test_link_to_user_should_not_link_to_locked_user 1056 def test_link_to_user_should_not_link_to_locked_user
903 user = User.find(5) 1057 with_current_user nil do
904 assert user.locked? 1058 user = User.find(5)
905 t = link_to_user(user) 1059 assert user.locked?
906 assert_equal user.name, t 1060 assert_equal 'Dave2 Lopper2', link_to_user(user)
1061 end
1062 end
1063
1064 def test_link_to_user_should_link_to_locked_user_if_current_user_is_admin
1065 with_current_user User.find(1) do
1066 user = User.find(5)
1067 assert user.locked?
1068 assert_equal '<a href="/users/5" class="user locked">Dave2 Lopper2</a>', link_to_user(user)
1069 end
907 end 1070 end
908 1071
909 def test_link_to_user_should_not_link_to_anonymous 1072 def test_link_to_user_should_not_link_to_anonymous
910 user = User.anonymous 1073 user = User.anonymous
911 assert user.anonymous? 1074 assert user.anonymous?
932 assert_equal '<a href="/projects/1">eCookbook</a>', 1095 assert_equal '<a href="/projects/1">eCookbook</a>',
933 link_to_project(Project.find(1)) 1096 link_to_project(Project.find(1))
934 end 1097 end
935 1098
936 def test_principals_options_for_select_with_users 1099 def test_principals_options_for_select_with_users
1100 User.current = nil
937 users = [User.find(2), User.find(4)] 1101 users = [User.find(2), User.find(4)]
938 assert_equal %(<option value="2">John Smith</option><option value="4">Robert Hill</option>), 1102 assert_equal %(<option value="2">John Smith</option><option value="4">Robert Hill</option>),
939 principals_options_for_select(users) 1103 principals_options_for_select(users)
940 end 1104 end
941 1105
942 def test_principals_options_for_select_with_selected 1106 def test_principals_options_for_select_with_selected
1107 User.current = nil
943 users = [User.find(2), User.find(4)] 1108 users = [User.find(2), User.find(4)]
944 assert_equal %(<option value="2">John Smith</option><option value="4" selected="selected">Robert Hill</option>), 1109 assert_equal %(<option value="2">John Smith</option><option value="4" selected="selected">Robert Hill</option>),
945 principals_options_for_select(users, User.find(4)) 1110 principals_options_for_select(users, User.find(4))
946 end 1111 end
947 1112
948 def test_principals_options_for_select_with_users_and_groups 1113 def test_principals_options_for_select_with_users_and_groups
1114 User.current = nil
949 users = [User.find(2), Group.find(11), User.find(4), Group.find(10)] 1115 users = [User.find(2), Group.find(11), User.find(4), Group.find(10)]
950 assert_equal %(<option value="2">John Smith</option><option value="4">Robert Hill</option>) + 1116 assert_equal %(<option value="2">John Smith</option><option value="4">Robert Hill</option>) +
951 %(<optgroup label="Groups"><option value="10">A Team</option><option value="11">B Team</option></optgroup>), 1117 %(<optgroup label="Groups"><option value="10">A Team</option><option value="11">B Team</option></optgroup>),
952 principals_options_for_select(users) 1118 principals_options_for_select(users)
953 end 1119 end
954 1120
955 def test_principals_options_for_select_with_empty_collection 1121 def test_principals_options_for_select_with_empty_collection
956 assert_equal '', principals_options_for_select([]) 1122 assert_equal '', principals_options_for_select([])
957 end 1123 end
1124
1125 def test_principals_options_for_select_should_include_me_option_when_current_user_is_in_collection
1126 users = [User.find(2), User.find(4)]
1127 User.current = User.find(4)
1128 assert_include '<option value="4">&lt;&lt; me &gt;&gt;</option>', principals_options_for_select(users)
1129 end
1130
1131 def test_stylesheet_link_tag_should_pick_the_default_stylesheet
1132 assert_match 'href="/stylesheets/styles.css"', stylesheet_link_tag("styles")
1133 end
1134
1135 def test_stylesheet_link_tag_for_plugin_should_pick_the_plugin_stylesheet
1136 assert_match 'href="/plugin_assets/foo/stylesheets/styles.css"', stylesheet_link_tag("styles", :plugin => :foo)
1137 end
1138
1139 def test_image_tag_should_pick_the_default_image
1140 assert_match 'src="/images/image.png"', image_tag("image.png")
1141 end
1142
1143 def test_image_tag_should_pick_the_theme_image_if_it_exists
1144 theme = Redmine::Themes.themes.last
1145 theme.images << 'image.png'
1146
1147 with_settings :ui_theme => theme.id do
1148 assert_match %|src="/themes/#{theme.dir}/images/image.png"|, image_tag("image.png")
1149 assert_match %|src="/images/other.png"|, image_tag("other.png")
1150 end
1151 ensure
1152 theme.images.delete 'image.png'
1153 end
1154
1155 def test_image_tag_sfor_plugin_should_pick_the_plugin_image
1156 assert_match 'src="/plugin_assets/foo/images/image.png"', image_tag("image.png", :plugin => :foo)
1157 end
1158
1159 def test_javascript_include_tag_should_pick_the_default_javascript
1160 assert_match 'src="/javascripts/scripts.js"', javascript_include_tag("scripts")
1161 end
1162
1163 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)
1165 end
1166
1167 def test_per_page_links_should_show_usefull_values
1168 set_language_if_valid 'en'
1169 stubs(:link_to).returns("[link]")
1170
1171 with_settings :per_page_options => '10, 25, 50, 100' do
1172 assert_nil per_page_links(10, 3)
1173 assert_nil per_page_links(25, 3)
1174 assert_equal "Per page: 10, [link]", per_page_links(10, 22)
1175 assert_equal "Per page: [link], 25", per_page_links(25, 22)
1176 assert_equal "Per page: [link], [link], 50", per_page_links(50, 22)
1177 assert_equal "Per page: [link], 25, [link]", per_page_links(25, 26)
1178 assert_equal "Per page: [link], 25, [link], [link]", per_page_links(25, 120)
1179 end
1180 end
958 end 1181 end