Mercurial > hg > soundsoftware-site
comparison test/unit/helpers/application_helper_test.rb @ 1115:433d4f72a19b redmine-2.2
Update to Redmine SVN revision 11137 on 2.2-stable branch
author | Chris Cannam |
---|---|
date | Mon, 07 Jan 2013 12:01:42 +0000 |
parents | 5f33065ddc4b |
children | bb32da3bea34 3e4c3460b6ca |
comparison
equal
deleted
inserted
replaced
929:5f33065ddc4b | 1115:433d4f72a19b |
---|---|
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"bar">http://foo"bar</a>', | 84 'http://foo"bar' => '<a class="external" href="http://foo"bar">http://foo"bar</a>', |
81 # wrap in angle brackets | 85 # wrap in angle brackets |
82 '<http://foo.bar>' => '<<a class="external" href="http://foo.bar">http://foo.bar</a>>' | 86 '<http://foo.bar>' => '<<a class="external" href="http://foo.bar">http://foo.bar</a>>' |
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 "title"" alt="This is a double-quoted "title"" />', | 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 "title"" alt="This is a double-quoted "title"" />', |
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"bar" class="external">test</a>', | 237 '"test":http://foo"bar' => '<a href="http://foo"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_escaped_redmine_links_should_not_be_parsed | |
351 to_test = [ | |
352 '#3.', | |
353 '#3-14.', | |
354 '#3#-note14.', | |
355 'r1', | |
356 'document#1', | |
357 'document:"Test document"', | |
358 'version#2', | |
359 'version:1.0', | |
360 'version:"1.0"', | |
361 'source:/some/file' | |
362 ] | |
363 @project = Project.find(1) | |
364 to_test.each { |text| assert_equal "<p>#{text}</p>", textilizable("!" + text), "#{text} failed" } | |
313 end | 365 end |
314 | 366 |
315 def test_cross_project_redmine_links | 367 def test_cross_project_redmine_links |
316 source_link = link_to('ecookbook:source:/some/file', {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :path => ['some', 'file']}, | 368 source_link = link_to('ecookbook:source:/some/file', {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :path => ['some', 'file']}, |
317 :class => 'source') | 369 :class => 'source') |
335 # source | 387 # source |
336 'source:/some/file' => 'source:/some/file', | 388 'source:/some/file' => 'source:/some/file', |
337 'ecookbook:source:/some/file' => source_link, | 389 'ecookbook:source:/some/file' => source_link, |
338 'invalid:source:/some/file' => 'invalid:source:/some/file', | 390 'invalid:source:/some/file' => 'invalid:source:/some/file', |
339 } | 391 } |
392 @project = Project.find(3) | |
393 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text), "#{text} failed" } | |
394 end | |
395 | |
396 def test_multiple_repositories_redmine_links | |
397 svn = Repository::Subversion.create!(:project_id => 1, :identifier => 'svn1', :url => 'file:///foo/hg') | |
398 Changeset.create!(:repository => svn, :committed_on => Time.now, :revision => '123') | |
399 hg = Repository::Mercurial.create!(:project_id => 1, :identifier => 'hg1', :url => '/foo/hg') | |
400 Changeset.create!(:repository => hg, :committed_on => Time.now, :revision => '123', :scmid => 'abcd') | |
401 | |
402 changeset_link = link_to('r2', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 2}, | |
403 :class => 'changeset', :title => 'This commit fixes #1, #2 and references #1 & #3') | |
404 svn_changeset_link = link_to('svn1|r123', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :repository_id => 'svn1', :rev => 123}, | |
405 :class => 'changeset', :title => '') | |
406 hg_changeset_link = link_to('hg1|abcd', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :repository_id => 'hg1', :rev => 'abcd'}, | |
407 :class => 'changeset', :title => '') | |
408 | |
409 source_link = link_to('source:some/file', {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :path => ['some', 'file']}, :class => 'source') | |
410 hg_source_link = link_to('source:hg1|some/file', {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :repository_id => 'hg1', :path => ['some', 'file']}, :class => 'source') | |
411 | |
412 to_test = { | |
413 'r2' => changeset_link, | |
414 'svn1|r123' => svn_changeset_link, | |
415 'invalid|r123' => 'invalid|r123', | |
416 'commit:hg1|abcd' => hg_changeset_link, | |
417 'commit:invalid|abcd' => 'commit:invalid|abcd', | |
418 # source | |
419 'source:some/file' => source_link, | |
420 'source:hg1|some/file' => hg_source_link, | |
421 'source:invalid|some/file' => 'source:invalid|some/file', | |
422 } | |
423 | |
424 @project = Project.find(1) | |
425 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text), "#{text} failed" } | |
426 end | |
427 | |
428 def test_cross_project_multiple_repositories_redmine_links | |
429 svn = Repository::Subversion.create!(:project_id => 1, :identifier => 'svn1', :url => 'file:///foo/hg') | |
430 Changeset.create!(:repository => svn, :committed_on => Time.now, :revision => '123') | |
431 hg = Repository::Mercurial.create!(:project_id => 1, :identifier => 'hg1', :url => '/foo/hg') | |
432 Changeset.create!(:repository => hg, :committed_on => Time.now, :revision => '123', :scmid => 'abcd') | |
433 | |
434 changeset_link = link_to('ecookbook:r2', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 2}, | |
435 :class => 'changeset', :title => 'This commit fixes #1, #2 and references #1 & #3') | |
436 svn_changeset_link = link_to('ecookbook:svn1|r123', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :repository_id => 'svn1', :rev => 123}, | |
437 :class => 'changeset', :title => '') | |
438 hg_changeset_link = link_to('ecookbook:hg1|abcd', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :repository_id => 'hg1', :rev => 'abcd'}, | |
439 :class => 'changeset', :title => '') | |
440 | |
441 source_link = link_to('ecookbook:source:some/file', {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :path => ['some', 'file']}, :class => 'source') | |
442 hg_source_link = link_to('ecookbook:source:hg1|some/file', {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :repository_id => 'hg1', :path => ['some', 'file']}, :class => 'source') | |
443 | |
444 to_test = { | |
445 'ecookbook:r2' => changeset_link, | |
446 'ecookbook:svn1|r123' => svn_changeset_link, | |
447 'ecookbook:invalid|r123' => 'ecookbook:invalid|r123', | |
448 'ecookbook:commit:hg1|abcd' => hg_changeset_link, | |
449 'ecookbook:commit:invalid|abcd' => 'ecookbook:commit:invalid|abcd', | |
450 'invalid:commit:invalid|abcd' => 'invalid:commit:invalid|abcd', | |
451 # source | |
452 'ecookbook:source:some/file' => source_link, | |
453 'ecookbook:source:hg1|some/file' => hg_source_link, | |
454 'ecookbook:source:invalid|some/file' => 'ecookbook:source:invalid|some/file', | |
455 'invalid:source:invalid|some/file' => 'invalid:source:invalid|some/file', | |
456 } | |
457 | |
340 @project = Project.find(3) | 458 @project = Project.find(3) |
341 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text), "#{text} failed" } | 459 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text), "#{text} failed" } |
342 end | 460 end |
343 | 461 |
344 def test_redmine_links_git_commit | 462 def test_redmine_links_git_commit |
441 '[[Another page|With _styled_ *title*]]' => '<a href="/projects/ecookbook/wiki/Another_page" class="wiki-page">With <em>styled</em> <strong>title</strong></a>', | 559 '[[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 & markups</strong>]]' => '<a href="/projects/ecookbook/wiki/Another_page" class="wiki-page">With title containing <strong>HTML entities & markups</strong></a>', | 560 '[[Another page|With title containing <strong>HTML entities & markups</strong>]]' => '<a href="/projects/ecookbook/wiki/Another_page" class="wiki-page">With title containing <strong>HTML entities & markups</strong></a>', |
443 # link with anchor | 561 # link with anchor |
444 '[[CookBook documentation#One-section]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation#One-section" class="wiki-page">CookBook documentation</a>', | 562 '[[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>', | 563 '[[Another page#anchor|Page]]' => '<a href="/projects/ecookbook/wiki/Another_page#anchor" class="wiki-page">Page</a>', |
564 # UTF8 anchor | |
565 '[[Another_page#Тест|Тест]]' => %|<a href="/projects/ecookbook/wiki/Another_page##{CGI.escape 'Тест'}" class="wiki-page">Тест</a>|, | |
446 # page that doesn't exist | 566 # page that doesn't exist |
447 '[[Unknown page]]' => '<a href="/projects/ecookbook/wiki/Unknown_page" class="wiki-page new">Unknown page</a>', | 567 '[[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>', | 568 '[[Unknown page|404]]' => '<a href="/projects/ecookbook/wiki/Unknown_page" class="wiki-page new">404</a>', |
449 # link to another project wiki | 569 # link to another project wiki |
450 '[[onlinestore:]]' => '<a href="/projects/onlinestore/wiki" class="wiki-page">onlinestore</a>', | 570 '[[onlinestore:]]' => '<a href="/projects/onlinestore/wiki" class="wiki-page">onlinestore</a>', |
482 } | 602 } |
483 | 603 |
484 @project = Project.find(1) | 604 @project = Project.find(1) |
485 | 605 |
486 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text, :wiki_links => :local) } | 606 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text, :wiki_links => :local) } |
607 end | |
608 | |
609 def test_wiki_links_within_wiki_page_context | |
610 | |
611 page = WikiPage.find_by_title('Another_page' ) | |
612 | |
613 to_test = { | |
614 # link to another page | |
615 '[[CookBook documentation]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation" class="wiki-page">CookBook documentation</a>', | |
616 '[[CookBook documentation|documentation]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation" class="wiki-page">documentation</a>', | |
617 '[[CookBook documentation#One-section]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation#One-section" class="wiki-page">CookBook documentation</a>', | |
618 '[[CookBook documentation#One-section|documentation]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation#One-section" class="wiki-page">documentation</a>', | |
619 # link to the current page | |
620 '[[Another page]]' => '<a href="/projects/ecookbook/wiki/Another_page" class="wiki-page">Another page</a>', | |
621 '[[Another page|Page]]' => '<a href="/projects/ecookbook/wiki/Another_page" class="wiki-page">Page</a>', | |
622 '[[Another page#anchor]]' => '<a href="#anchor" class="wiki-page">Another page</a>', | |
623 '[[Another page#anchor|Page]]' => '<a href="#anchor" class="wiki-page">Page</a>', | |
624 # page that doesn't exist | |
625 '[[Unknown page]]' => '<a href="/projects/ecookbook/wiki/Unknown_page?parent=Another_page" class="wiki-page new">Unknown page</a>', | |
626 '[[Unknown page|404]]' => '<a href="/projects/ecookbook/wiki/Unknown_page?parent=Another_page" class="wiki-page new">404</a>', | |
627 '[[Unknown page#anchor]]' => '<a href="/projects/ecookbook/wiki/Unknown_page?parent=Another_page#anchor" class="wiki-page new">Unknown page</a>', | |
628 '[[Unknown page#anchor|404]]' => '<a href="/projects/ecookbook/wiki/Unknown_page?parent=Another_page#anchor" class="wiki-page new">404</a>', | |
629 } | |
630 | |
631 @project = Project.find(1) | |
632 | |
633 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(WikiContent.new( :text => text, :page => page ), :text) } | |
634 end | |
635 | |
636 def test_wiki_links_anchor_option_should_prepend_page_title_to_href | |
637 | |
638 to_test = { | |
639 # link to a page | |
640 '[[CookBook documentation]]' => '<a href="#CookBook_documentation" class="wiki-page">CookBook documentation</a>', | |
641 '[[CookBook documentation|documentation]]' => '<a href="#CookBook_documentation" class="wiki-page">documentation</a>', | |
642 '[[CookBook documentation#One-section]]' => '<a href="#CookBook_documentation_One-section" class="wiki-page">CookBook documentation</a>', | |
643 '[[CookBook documentation#One-section|documentation]]' => '<a href="#CookBook_documentation_One-section" class="wiki-page">documentation</a>', | |
644 # page that doesn't exist | |
645 '[[Unknown page]]' => '<a href="#Unknown_page" class="wiki-page new">Unknown page</a>', | |
646 '[[Unknown page|404]]' => '<a href="#Unknown_page" class="wiki-page new">404</a>', | |
647 '[[Unknown page#anchor]]' => '<a href="#Unknown_page_anchor" class="wiki-page new">Unknown page</a>', | |
648 '[[Unknown page#anchor|404]]' => '<a href="#Unknown_page_anchor" class="wiki-page new">404</a>', | |
649 } | |
650 | |
651 @project = Project.find(1) | |
652 | |
653 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text, :wiki_links => :anchor) } | |
487 end | 654 end |
488 | 655 |
489 def test_html_tags | 656 def test_html_tags |
490 to_test = { | 657 to_test = { |
491 "<div>content</div>" => "<p><div>content</div></p>", | 658 "<div>content</div>" => "<p><div>content</div></p>", |
554 </pre> | 721 </pre> |
555 RAW | 722 RAW |
556 | 723 |
557 expected = <<-EXPECTED | 724 expected = <<-EXPECTED |
558 <p><a href="/projects/ecookbook/wiki/CookBook_documentation" class="wiki-page">CookBook documentation</a></p> | 725 <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> | 726 <p><a href="/issues/1" class="issue status-1 priority-4 priority-lowest" title="Can't print recipes (New)">#1</a></p> |
560 <pre> | 727 <pre> |
561 [[CookBook documentation]] | 728 [[CookBook documentation]] |
562 | 729 |
563 #1 | 730 #1 |
564 </pre> | 731 </pre> |
588 # Some ruby code here | 755 # Some ruby code here |
589 </code></pre> | 756 </code></pre> |
590 RAW | 757 RAW |
591 | 758 |
592 expected = <<-EXPECTED | 759 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> | 760 <pre><code class="ruby syntaxhl"><span class=\"CodeRay\"><span class="comment"># Some ruby code here</span></span> |
594 </code></pre> | 761 </code></pre> |
595 EXPECTED | 762 EXPECTED |
596 | 763 |
597 assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '') | 764 assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '') |
765 end | |
766 | |
767 def test_to_path_param | |
768 assert_equal 'test1/test2', to_path_param('test1/test2') | |
769 assert_equal 'test1/test2', to_path_param('/test1/test2/') | |
770 assert_equal 'test1/test2', to_path_param('//test1/test2/') | |
771 assert_equal nil, to_path_param('/') | |
598 end | 772 end |
599 | 773 |
600 def test_wiki_links_in_tables | 774 def test_wiki_links_in_tables |
601 to_test = {"|[[Page|Link title]]|[[Other Page|Other title]]|\n|Cell 21|[[Last page]]|" => | 775 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>' + | 776 '<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">¶</a></h1>| | 826 expected = %|<a name="#{anchor}"></a>\n<h1 >Some heading related to version 0.5<a href="##{anchor}" class="wiki-anchor">¶</a></h1>| |
653 | 827 |
654 assert_equal expected, textilizable(raw) | 828 assert_equal expected, textilizable(raw) |
655 end | 829 end |
656 | 830 |
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 | 831 def test_headings_in_wiki_single_page_export_should_be_prepended_with_page_title |
705 page = WikiPage.generate!( :title => 'Page Title' ) | 832 page = WikiPage.new( :title => 'Page Title', :wiki_id => 1 ) |
706 content = WikiContent.generate!( :text => 'h1. Some heading', :page => page ) | 833 content = WikiContent.new( :text => 'h1. Some heading', :page => page ) |
707 | 834 |
708 expected = %|<a name="Page_Title_Some-heading"></a>\n<h1 >Some heading<a href="#Page_Title_Some-heading" class="wiki-anchor">¶</a></h1>| | 835 expected = %|<a name="Page_Title_Some-heading"></a>\n<h1 >Some heading<a href="#Page_Title_Some-heading" class="wiki-anchor">¶</a></h1>| |
709 | 836 |
710 assert_equal expected, textilizable(content, :text, :wiki_links => :anchor ) | 837 assert_equal expected, textilizable(content, :text, :wiki_links => :anchor ) |
711 end | 838 end |
857 '<h2 >Subtitle after pre tag<a href="#Subtitle-after-pre-tag" class="wiki-anchor">¶</a></h2>'), | 984 '<h2 >Subtitle after pre tag<a href="#Subtitle-after-pre-tag" class="wiki-anchor">¶</a></h2>'), |
858 result | 985 result |
859 end | 986 end |
860 | 987 |
861 def test_default_formatter | 988 def test_default_formatter |
862 Setting.text_formatting = 'unknown' | 989 with_settings :text_formatting => 'unknown' do |
863 text = 'a *link*: http://www.example.net/' | 990 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) | 991 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' | 992 end |
866 end | 993 end |
867 | 994 |
868 def test_due_date_distance_in_words | 995 def test_due_date_distance_in_words |
869 to_test = { Date.today => 'Due in 0 days', | 996 to_test = { Date.today => 'Due in 0 days', |
870 Date.today + 1 => 'Due in 1 day', | 997 Date.today + 1 => 'Due in 1 day', |
878 to_test.each do |date, expected| | 1005 to_test.each do |date, expected| |
879 assert_equal expected, due_date_distance_in_words(date) | 1006 assert_equal expected, due_date_distance_in_words(date) |
880 end | 1007 end |
881 end | 1008 end |
882 | 1009 |
883 def test_avatar | 1010 def test_avatar_enabled |
884 # turn on avatars | 1011 with_settings :gravatar_enabled => '1' do |
885 Setting.gravatar_enabled = '1' | 1012 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')) | 1013 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')) | 1014 # Default size is 50 |
888 assert_nil avatar('jsmith') | 1015 assert avatar('jsmith <jsmith@somenet.foo>').include?('size=50') |
889 assert_nil avatar(nil) | 1016 assert avatar('jsmith <jsmith@somenet.foo>', :size => 24).include?('size=24') |
890 | 1017 # Non-avatar options should be considered html options |
891 # turn off avatars | 1018 assert avatar('jsmith <jsmith@somenet.foo>', :title => 'John Smith').include?('title="John Smith"') |
892 Setting.gravatar_enabled = '0' | 1019 # The default class of the img tag should be gravatar |
893 assert_equal '', avatar(User.find_by_mail('jsmith@somenet.foo')) | 1020 assert avatar('jsmith <jsmith@somenet.foo>').include?('class="gravatar"') |
1021 assert !avatar('jsmith <jsmith@somenet.foo>', :class => 'picture').include?('class="gravatar"') | |
1022 assert_nil avatar('jsmith') | |
1023 assert_nil avatar(nil) | |
1024 end | |
1025 end | |
1026 | |
1027 def test_avatar_disabled | |
1028 with_settings :gravatar_enabled => '0' do | |
1029 assert_equal '', avatar(User.find_by_mail('jsmith@somenet.foo')) | |
1030 end | |
894 end | 1031 end |
895 | 1032 |
896 def test_link_to_user | 1033 def test_link_to_user |
897 user = User.find(2) | 1034 user = User.find(2) |
898 t = link_to_user(user) | 1035 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 | 1036 end |
901 | 1037 |
902 def test_link_to_user_should_not_link_to_locked_user | 1038 def test_link_to_user_should_not_link_to_locked_user |
903 user = User.find(5) | 1039 with_current_user nil do |
904 assert user.locked? | 1040 user = User.find(5) |
905 t = link_to_user(user) | 1041 assert user.locked? |
906 assert_equal user.name, t | 1042 assert_equal 'Dave2 Lopper2', link_to_user(user) |
1043 end | |
1044 end | |
1045 | |
1046 def test_link_to_user_should_link_to_locked_user_if_current_user_is_admin | |
1047 with_current_user User.find(1) do | |
1048 user = User.find(5) | |
1049 assert user.locked? | |
1050 assert_equal '<a href="/users/5" class="user locked">Dave2 Lopper2</a>', link_to_user(user) | |
1051 end | |
907 end | 1052 end |
908 | 1053 |
909 def test_link_to_user_should_not_link_to_anonymous | 1054 def test_link_to_user_should_not_link_to_anonymous |
910 user = User.anonymous | 1055 user = User.anonymous |
911 assert user.anonymous? | 1056 assert user.anonymous? |
932 assert_equal '<a href="/projects/1">eCookbook</a>', | 1077 assert_equal '<a href="/projects/1">eCookbook</a>', |
933 link_to_project(Project.find(1)) | 1078 link_to_project(Project.find(1)) |
934 end | 1079 end |
935 | 1080 |
936 def test_principals_options_for_select_with_users | 1081 def test_principals_options_for_select_with_users |
1082 User.current = nil | |
937 users = [User.find(2), User.find(4)] | 1083 users = [User.find(2), User.find(4)] |
938 assert_equal %(<option value="2">John Smith</option><option value="4">Robert Hill</option>), | 1084 assert_equal %(<option value="2">John Smith</option><option value="4">Robert Hill</option>), |
939 principals_options_for_select(users) | 1085 principals_options_for_select(users) |
940 end | 1086 end |
941 | 1087 |
942 def test_principals_options_for_select_with_selected | 1088 def test_principals_options_for_select_with_selected |
1089 User.current = nil | |
943 users = [User.find(2), User.find(4)] | 1090 users = [User.find(2), User.find(4)] |
944 assert_equal %(<option value="2">John Smith</option><option value="4" selected="selected">Robert Hill</option>), | 1091 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)) | 1092 principals_options_for_select(users, User.find(4)) |
946 end | 1093 end |
947 | 1094 |
948 def test_principals_options_for_select_with_users_and_groups | 1095 def test_principals_options_for_select_with_users_and_groups |
1096 User.current = nil | |
949 users = [User.find(2), Group.find(11), User.find(4), Group.find(10)] | 1097 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>) + | 1098 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>), | 1099 %(<optgroup label="Groups"><option value="10">A Team</option><option value="11">B Team</option></optgroup>), |
952 principals_options_for_select(users) | 1100 principals_options_for_select(users) |
953 end | 1101 end |
954 | 1102 |
955 def test_principals_options_for_select_with_empty_collection | 1103 def test_principals_options_for_select_with_empty_collection |
956 assert_equal '', principals_options_for_select([]) | 1104 assert_equal '', principals_options_for_select([]) |
957 end | 1105 end |
1106 | |
1107 def test_principals_options_for_select_should_include_me_option_when_current_user_is_in_collection | |
1108 users = [User.find(2), User.find(4)] | |
1109 User.current = User.find(4) | |
1110 assert_include '<option value="4"><< me >></option>', principals_options_for_select(users) | |
1111 end | |
1112 | |
1113 def test_stylesheet_link_tag_should_pick_the_default_stylesheet | |
1114 assert_match 'href="/stylesheets/styles.css"', stylesheet_link_tag("styles") | |
1115 end | |
1116 | |
1117 def test_stylesheet_link_tag_for_plugin_should_pick_the_plugin_stylesheet | |
1118 assert_match 'href="/plugin_assets/foo/stylesheets/styles.css"', stylesheet_link_tag("styles", :plugin => :foo) | |
1119 end | |
1120 | |
1121 def test_image_tag_should_pick_the_default_image | |
1122 assert_match 'src="/images/image.png"', image_tag("image.png") | |
1123 end | |
1124 | |
1125 def test_image_tag_should_pick_the_theme_image_if_it_exists | |
1126 theme = Redmine::Themes.themes.last | |
1127 theme.images << 'image.png' | |
1128 | |
1129 with_settings :ui_theme => theme.id do | |
1130 assert_match %|src="/themes/#{theme.dir}/images/image.png"|, image_tag("image.png") | |
1131 assert_match %|src="/images/other.png"|, image_tag("other.png") | |
1132 end | |
1133 ensure | |
1134 theme.images.delete 'image.png' | |
1135 end | |
1136 | |
1137 def test_image_tag_sfor_plugin_should_pick_the_plugin_image | |
1138 assert_match 'src="/plugin_assets/foo/images/image.png"', image_tag("image.png", :plugin => :foo) | |
1139 end | |
1140 | |
1141 def test_javascript_include_tag_should_pick_the_default_javascript | |
1142 assert_match 'src="/javascripts/scripts.js"', javascript_include_tag("scripts") | |
1143 end | |
1144 | |
1145 def test_javascript_include_tag_for_plugin_should_pick_the_plugin_javascript | |
1146 assert_match 'src="/plugin_assets/foo/javascripts/scripts.js"', javascript_include_tag("scripts", :plugin => :foo) | |
1147 end | |
1148 | |
1149 def test_per_page_links_should_show_usefull_values | |
1150 set_language_if_valid 'en' | |
1151 stubs(:link_to).returns("[link]") | |
1152 | |
1153 with_settings :per_page_options => '10, 25, 50, 100' do | |
1154 assert_nil per_page_links(10, 3) | |
1155 assert_nil per_page_links(25, 3) | |
1156 assert_equal "Per page: 10, [link]", per_page_links(10, 22) | |
1157 assert_equal "Per page: [link], 25", per_page_links(25, 22) | |
1158 assert_equal "Per page: [link], [link], 50", per_page_links(50, 22) | |
1159 assert_equal "Per page: [link], 25, [link]", per_page_links(25, 26) | |
1160 assert_equal "Per page: [link], 25, [link], [link]", per_page_links(25, 120) | |
1161 end | |
1162 end | |
958 end | 1163 end |