annotate test/unit/helpers/application_helper_test.rb @ 1516:b450a9d58aed redmine-2.4

Update to Redmine SVN revision 13356 on 2.4-stable branch
author Chris Cannam
date Tue, 09 Sep 2014 09:28:31 +0100
parents e248c7af89ec
children dffacf8a6908
rev   line source
Chris@1115 1 # encoding: utf-8
Chris@1115 2 #
Chris@0 3 # Redmine - project management software
Chris@1494 4 # Copyright (C) 2006-2014 Jean-Philippe Lang
Chris@0 5 #
Chris@0 6 # This program is free software; you can redistribute it and/or
Chris@0 7 # modify it under the terms of the GNU General Public License
Chris@0 8 # as published by the Free Software Foundation; either version 2
Chris@0 9 # of the License, or (at your option) any later version.
Chris@441 10 #
Chris@0 11 # This program is distributed in the hope that it will be useful,
Chris@0 12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@0 13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@0 14 # GNU General Public License for more details.
Chris@441 15 #
Chris@0 16 # You should have received a copy of the GNU General Public License
Chris@0 17 # along with this program; if not, write to the Free Software
Chris@0 18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@0 19
Chris@119 20 require File.expand_path('../../../test_helper', __FILE__)
Chris@0 21
chris@22 22 class ApplicationHelperTest < ActionView::TestCase
Chris@1464 23 include Redmine::I18n
Chris@1115 24 include ERB::Util
Chris@1464 25 include Rails.application.routes.url_helpers
Chris@1115 26
Chris@0 27 fixtures :projects, :roles, :enabled_modules, :users,
Chris@909 28 :repositories, :changesets,
Chris@909 29 :trackers, :issue_statuses, :issues, :versions, :documents,
Chris@909 30 :wikis, :wiki_pages, :wiki_contents,
Chris@909 31 :boards, :messages, :news,
Chris@909 32 :attachments, :enumerations
Chris@0 33
Chris@0 34 def setup
Chris@0 35 super
Chris@909 36 set_tmp_attachments_directory
Chris@1464 37 @russian_test = "\xd1\x82\xd0\xb5\xd1\x81\xd1\x82"
Chris@1464 38 if @russian_test.respond_to?(:force_encoding)
Chris@1464 39 @russian_test.force_encoding('UTF-8')
Chris@1464 40 end
Chris@0 41 end
chris@22 42
Chris@1464 43 test "#link_to_if_authorized for authorized user should allow using the :controller and :action for the target link" do
Chris@1464 44 User.current = User.find_by_login('admin')
Chris@441 45
Chris@1464 46 @project = Issue.first.project # Used by helper
Chris@1464 47 response = link_to_if_authorized('By controller/actionr',
Chris@1464 48 {:controller => 'issues', :action => 'edit', :id => Issue.first.id})
Chris@1464 49 assert_match /href/, response
Chris@1464 50 end
Chris@441 51
Chris@1464 52 test "#link_to_if_authorized for unauthorized user should display nothing if user isn't authorized" do
Chris@1464 53 User.current = User.find_by_login('dlopper')
Chris@1464 54 @project = Project.find('private-child')
Chris@1464 55 issue = @project.issues.first
Chris@1464 56 assert !issue.visible?
chris@22 57
Chris@1464 58 response = link_to_if_authorized('Never displayed',
Chris@1464 59 {:controller => 'issues', :action => 'show', :id => issue})
Chris@1464 60 assert_nil response
chris@22 61 end
Chris@441 62
Chris@0 63 def test_auto_links
Chris@0 64 to_test = {
Chris@0 65 'http://foo.bar' => '<a class="external" href="http://foo.bar">http://foo.bar</a>',
Chris@0 66 'http://foo.bar/~user' => '<a class="external" href="http://foo.bar/~user">http://foo.bar/~user</a>',
Chris@0 67 'http://foo.bar.' => '<a class="external" href="http://foo.bar">http://foo.bar</a>.',
Chris@0 68 'https://foo.bar.' => '<a class="external" href="https://foo.bar">https://foo.bar</a>.',
Chris@0 69 'This is a link: http://foo.bar.' => 'This is a link: <a class="external" href="http://foo.bar">http://foo.bar</a>.',
Chris@0 70 'A link (eg. http://foo.bar).' => 'A link (eg. <a class="external" href="http://foo.bar">http://foo.bar</a>).',
Chris@0 71 'http://foo.bar/foo.bar#foo.bar.' => '<a class="external" href="http://foo.bar/foo.bar#foo.bar">http://foo.bar/foo.bar#foo.bar</a>.',
Chris@0 72 'http://www.foo.bar/Test_(foobar)' => '<a class="external" href="http://www.foo.bar/Test_(foobar)">http://www.foo.bar/Test_(foobar)</a>',
Chris@0 73 '(see inline link : http://www.foo.bar/Test_(foobar))' => '(see inline link : <a class="external" href="http://www.foo.bar/Test_(foobar)">http://www.foo.bar/Test_(foobar)</a>)',
Chris@0 74 '(see inline link : http://www.foo.bar/Test)' => '(see inline link : <a class="external" href="http://www.foo.bar/Test">http://www.foo.bar/Test</a>)',
Chris@0 75 '(see inline link : http://www.foo.bar/Test).' => '(see inline link : <a class="external" href="http://www.foo.bar/Test">http://www.foo.bar/Test</a>).',
Chris@0 76 '(see "inline link":http://www.foo.bar/Test_(foobar))' => '(see <a href="http://www.foo.bar/Test_(foobar)" class="external">inline link</a>)',
Chris@0 77 '(see "inline link":http://www.foo.bar/Test)' => '(see <a href="http://www.foo.bar/Test" class="external">inline link</a>)',
Chris@0 78 '(see "inline link":http://www.foo.bar/Test).' => '(see <a href="http://www.foo.bar/Test" class="external">inline link</a>).',
Chris@0 79 'www.foo.bar' => '<a class="external" href="http://www.foo.bar">www.foo.bar</a>',
Chris@0 80 'http://foo.bar/page?p=1&t=z&s=' => '<a class="external" href="http://foo.bar/page?p=1&#38;t=z&#38;s=">http://foo.bar/page?p=1&#38;t=z&#38;s=</a>',
Chris@0 81 'http://foo.bar/page#125' => '<a class="external" href="http://foo.bar/page#125">http://foo.bar/page#125</a>',
Chris@0 82 'http://foo@www.bar.com' => '<a class="external" href="http://foo@www.bar.com">http://foo@www.bar.com</a>',
Chris@0 83 'http://foo:bar@www.bar.com' => '<a class="external" href="http://foo:bar@www.bar.com">http://foo:bar@www.bar.com</a>',
Chris@0 84 'ftp://foo.bar' => '<a class="external" href="ftp://foo.bar">ftp://foo.bar</a>',
Chris@0 85 'ftps://foo.bar' => '<a class="external" href="ftps://foo.bar">ftps://foo.bar</a>',
Chris@0 86 'sftp://foo.bar' => '<a class="external" href="sftp://foo.bar">sftp://foo.bar</a>',
Chris@0 87 # two exclamation marks
Chris@0 88 'http://example.net/path!602815048C7B5C20!302.html' => '<a class="external" href="http://example.net/path!602815048C7B5C20!302.html">http://example.net/path!602815048C7B5C20!302.html</a>',
Chris@0 89 # escaping
Chris@1115 90 'http://foo"bar' => '<a class="external" href="http://foo&quot;bar">http://foo&quot;bar</a>',
chris@37 91 # wrap in angle brackets
Chris@1464 92 '<http://foo.bar>' => '&lt;<a class="external" href="http://foo.bar">http://foo.bar</a>&gt;',
Chris@1464 93 # invalid urls
Chris@1464 94 'http://' => 'http://',
Chris@1464 95 'www.' => 'www.',
Chris@1464 96 'test-www.bar.com' => 'test-www.bar.com',
Chris@0 97 }
Chris@0 98 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
Chris@0 99 end
Chris@441 100
Chris@1115 101 if 'ruby'.respond_to?(:encoding)
Chris@1115 102 def test_auto_links_with_non_ascii_characters
Chris@1115 103 to_test = {
Chris@1464 104 "http://foo.bar/#{@russian_test}" =>
Chris@1464 105 %|<a class="external" href="http://foo.bar/#{@russian_test}">http://foo.bar/#{@russian_test}</a>|
Chris@1115 106 }
Chris@1115 107 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
Chris@1115 108 end
Chris@1115 109 else
Chris@1115 110 puts 'Skipping test_auto_links_with_non_ascii_characters, unsupported ruby version'
Chris@1115 111 end
Chris@1115 112
Chris@0 113 def test_auto_mailto
Chris@1464 114 to_test = {
Chris@1464 115 'test@foo.bar' => '<a class="email" href="mailto:test@foo.bar">test@foo.bar</a>',
Chris@1464 116 'test@www.foo.bar' => '<a class="email" href="mailto:test@www.foo.bar">test@www.foo.bar</a>',
Chris@1464 117 }
Chris@1464 118 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
Chris@0 119 end
Chris@441 120
Chris@0 121 def test_inline_images
Chris@0 122 to_test = {
Chris@0 123 '!http://foo.bar/image.jpg!' => '<img src="http://foo.bar/image.jpg" alt="" />',
Chris@0 124 'floating !>http://foo.bar/image.jpg!' => 'floating <div style="float:right"><img src="http://foo.bar/image.jpg" alt="" /></div>',
Chris@0 125 'with class !(some-class)http://foo.bar/image.jpg!' => 'with class <img src="http://foo.bar/image.jpg" class="some-class" alt="" />',
Chris@1115 126 '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="" />',
Chris@0 127 '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" />',
Chris@0 128 '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;" />',
Chris@0 129 }
Chris@0 130 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
Chris@0 131 end
Chris@441 132
Chris@0 133 def test_inline_images_inside_tags
Chris@0 134 raw = <<-RAW
Chris@0 135 h1. !foo.png! Heading
Chris@0 136
Chris@0 137 Centered image:
Chris@0 138
Chris@0 139 p=. !bar.gif!
Chris@0 140 RAW
Chris@0 141
Chris@0 142 assert textilizable(raw).include?('<img src="foo.png" alt="" />')
Chris@0 143 assert textilizable(raw).include?('<img src="bar.gif" alt="" />')
Chris@0 144 end
Chris@441 145
Chris@0 146 def test_attached_images
Chris@0 147 to_test = {
Chris@1464 148 'Inline image: !logo.gif!' => 'Inline image: <img src="/attachments/download/3/logo.gif" title="This is a logo" alt="This is a logo" />',
Chris@1464 149 'Inline image: !logo.GIF!' => 'Inline image: <img src="/attachments/download/3/logo.gif" title="This is a logo" alt="This is a logo" />',
Chris@0 150 'No match: !ogo.gif!' => 'No match: <img src="ogo.gif" alt="" />',
Chris@0 151 'No match: !ogo.GIF!' => 'No match: <img src="ogo.GIF" alt="" />',
Chris@0 152 # link image
Chris@1464 153 '!logo.gif!:http://foo.bar/' => '<a href="http://foo.bar/"><img src="/attachments/download/3/logo.gif" title="This is a logo" alt="This is a logo" /></a>',
Chris@0 154 }
Chris@1464 155 attachments = Attachment.all
Chris@0 156 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text, :attachments => attachments) }
Chris@0 157 end
Chris@441 158
Chris@909 159 def test_attached_images_filename_extension
Chris@909 160 set_tmp_attachments_directory
Chris@909 161 a1 = Attachment.new(
Chris@909 162 :container => Issue.find(1),
Chris@909 163 :file => mock_file_with_options({:original_filename => "testtest.JPG"}),
Chris@909 164 :author => User.find(1))
Chris@909 165 assert a1.save
Chris@909 166 assert_equal "testtest.JPG", a1.filename
Chris@909 167 assert_equal "image/jpeg", a1.content_type
Chris@909 168 assert a1.image?
Chris@909 169
Chris@909 170 a2 = Attachment.new(
Chris@909 171 :container => Issue.find(1),
Chris@909 172 :file => mock_file_with_options({:original_filename => "testtest.jpeg"}),
Chris@909 173 :author => User.find(1))
Chris@909 174 assert a2.save
Chris@909 175 assert_equal "testtest.jpeg", a2.filename
Chris@909 176 assert_equal "image/jpeg", a2.content_type
Chris@909 177 assert a2.image?
Chris@909 178
Chris@909 179 a3 = Attachment.new(
Chris@909 180 :container => Issue.find(1),
Chris@909 181 :file => mock_file_with_options({:original_filename => "testtest.JPE"}),
Chris@909 182 :author => User.find(1))
Chris@909 183 assert a3.save
Chris@909 184 assert_equal "testtest.JPE", a3.filename
Chris@909 185 assert_equal "image/jpeg", a3.content_type
Chris@909 186 assert a3.image?
Chris@909 187
Chris@909 188 a4 = Attachment.new(
Chris@909 189 :container => Issue.find(1),
Chris@909 190 :file => mock_file_with_options({:original_filename => "Testtest.BMP"}),
Chris@909 191 :author => User.find(1))
Chris@909 192 assert a4.save
Chris@909 193 assert_equal "Testtest.BMP", a4.filename
Chris@909 194 assert_equal "image/x-ms-bmp", a4.content_type
Chris@909 195 assert a4.image?
Chris@909 196
Chris@909 197 to_test = {
Chris@909 198 'Inline image: !testtest.jpg!' =>
Chris@1464 199 'Inline image: <img src="/attachments/download/' + a1.id.to_s + '/testtest.JPG" alt="" />',
Chris@909 200 'Inline image: !testtest.jpeg!' =>
Chris@1464 201 'Inline image: <img src="/attachments/download/' + a2.id.to_s + '/testtest.jpeg" alt="" />',
Chris@909 202 'Inline image: !testtest.jpe!' =>
Chris@1464 203 'Inline image: <img src="/attachments/download/' + a3.id.to_s + '/testtest.JPE" alt="" />',
Chris@909 204 'Inline image: !testtest.bmp!' =>
Chris@1464 205 'Inline image: <img src="/attachments/download/' + a4.id.to_s + '/Testtest.BMP" alt="" />',
Chris@909 206 }
Chris@909 207
Chris@909 208 attachments = [a1, a2, a3, a4]
Chris@909 209 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text, :attachments => attachments) }
Chris@909 210 end
Chris@909 211
Chris@909 212 def test_attached_images_should_read_later
Chris@1115 213 set_fixtures_attachments_directory
Chris@909 214 a1 = Attachment.find(16)
Chris@909 215 assert_equal "testfile.png", a1.filename
Chris@909 216 assert a1.readable?
Chris@909 217 assert (! a1.visible?(User.anonymous))
Chris@909 218 assert a1.visible?(User.find(2))
Chris@909 219 a2 = Attachment.find(17)
Chris@909 220 assert_equal "testfile.PNG", a2.filename
Chris@909 221 assert a2.readable?
Chris@909 222 assert (! a2.visible?(User.anonymous))
Chris@909 223 assert a2.visible?(User.find(2))
Chris@909 224 assert a1.created_on < a2.created_on
Chris@909 225
Chris@909 226 to_test = {
Chris@909 227 'Inline image: !testfile.png!' =>
Chris@1464 228 'Inline image: <img src="/attachments/download/' + a2.id.to_s + '/testfile.PNG" alt="" />',
Chris@909 229 'Inline image: !Testfile.PNG!' =>
Chris@1464 230 'Inline image: <img src="/attachments/download/' + a2.id.to_s + '/testfile.PNG" alt="" />',
Chris@909 231 }
Chris@909 232 attachments = [a1, a2]
Chris@909 233 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text, :attachments => attachments) }
Chris@909 234 set_tmp_attachments_directory
Chris@909 235 end
Chris@909 236
Chris@0 237 def test_textile_external_links
Chris@0 238 to_test = {
Chris@0 239 'This is a "link":http://foo.bar' => 'This is a <a href="http://foo.bar" class="external">link</a>',
Chris@0 240 'This is an intern "link":/foo/bar' => 'This is an intern <a href="/foo/bar">link</a>',
Chris@0 241 '"link (Link title)":http://foo.bar' => '<a href="http://foo.bar" title="Link title" class="external">link</a>',
Chris@0 242 '"link (Link title with "double-quotes")":http://foo.bar' => '<a href="http://foo.bar" title="Link title with &quot;double-quotes&quot;" class="external">link</a>',
Chris@0 243 "This is not a \"Link\":\n\nAnother paragraph" => "This is not a \"Link\":</p>\n\n\n\t<p>Another paragraph",
Chris@0 244 # no multiline link text
Chris@0 245 "This is a double quote \"on the first line\nand another on a second line\":test" => "This is a double quote \"on the first line<br />and another on a second line\":test",
Chris@0 246 # mailto link
Chris@0 247 "\"system administrator\":mailto:sysadmin@example.com?subject=redmine%20permissions" => "<a href=\"mailto:sysadmin@example.com?subject=redmine%20permissions\">system administrator</a>",
Chris@0 248 # two exclamation marks
Chris@0 249 '"a link":http://example.net/path!602815048C7B5C20!302.html' => '<a href="http://example.net/path!602815048C7B5C20!302.html" class="external">a link</a>',
Chris@0 250 # escaping
Chris@0 251 '"test":http://foo"bar' => '<a href="http://foo&quot;bar" class="external">test</a>',
Chris@0 252 }
Chris@0 253 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
Chris@0 254 end
Chris@119 255
Chris@1115 256 if 'ruby'.respond_to?(:encoding)
Chris@1115 257 def test_textile_external_links_with_non_ascii_characters
Chris@1115 258 to_test = {
Chris@1464 259 %|This is a "link":http://foo.bar/#{@russian_test}| =>
Chris@1464 260 %|This is a <a href="http://foo.bar/#{@russian_test}" class="external">link</a>|
Chris@1115 261 }
Chris@1115 262 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
Chris@1115 263 end
Chris@1115 264 else
Chris@1115 265 puts 'Skipping test_textile_external_links_with_non_ascii_characters, unsupported ruby version'
Chris@1115 266 end
Chris@1115 267
Chris@0 268 def test_redmine_links
Chris@441 269 issue_link = link_to('#3', {:controller => 'issues', :action => 'show', :id => 3},
Chris@1464 270 :class => Issue.find(3).css_classes, :title => 'Error 281 when updating a recipe (New)')
Chris@1464 271 note_link = link_to('#3-14', {:controller => 'issues', :action => 'show', :id => 3, :anchor => 'note-14'},
Chris@1464 272 :class => Issue.find(3).css_classes, :title => 'Error 281 when updating a recipe (New)')
Chris@1464 273 note_link2 = link_to('#3#note-14', {:controller => 'issues', :action => 'show', :id => 3, :anchor => 'note-14'},
Chris@1464 274 :class => Issue.find(3).css_classes, :title => 'Error 281 when updating a recipe (New)')
Chris@441 275
Chris@1464 276 revision_link = link_to('r1', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 1},
Chris@1464 277 :class => 'changeset', :title => 'My very first commit do not escaping #<>&')
Chris@1464 278 revision_link2 = link_to('r2', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 2},
Chris@0 279 :class => 'changeset', :title => 'This commit fixes #1, #2 and references #1 & #3')
Chris@441 280
Chris@1464 281 changeset_link2 = link_to('691322a8eb01e11fd7',
Chris@1464 282 {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 1},
Chris@1464 283 :class => 'changeset', :title => 'My very first commit do not escaping #<>&')
Chris@1464 284
Chris@0 285 document_link = link_to('Test document', {:controller => 'documents', :action => 'show', :id => 1},
Chris@0 286 :class => 'document')
Chris@441 287
Chris@0 288 version_link = link_to('1.0', {:controller => 'versions', :action => 'show', :id => 2},
Chris@0 289 :class => 'version')
Chris@0 290
Chris@909 291 board_url = {:controller => 'boards', :action => 'show', :id => 2, :project_id => 'ecookbook'}
Chris@909 292
Chris@0 293 message_url = {:controller => 'messages', :action => 'show', :board_id => 1, :id => 4}
Chris@909 294
Chris@909 295 news_url = {:controller => 'news', :action => 'show', :id => 1}
Chris@441 296
Chris@0 297 project_url = {:controller => 'projects', :action => 'show', :id => 'subproject1'}
Chris@441 298
Chris@1115 299 source_url = '/projects/ecookbook/repository/entry/some/file'
Chris@1115 300 source_url_with_rev = '/projects/ecookbook/repository/revisions/52/entry/some/file'
Chris@1115 301 source_url_with_ext = '/projects/ecookbook/repository/entry/some/file.ext'
Chris@1115 302 source_url_with_rev_and_ext = '/projects/ecookbook/repository/revisions/52/entry/some/file.ext'
Chris@1464 303 source_url_with_branch = '/projects/ecookbook/repository/revisions/branch/entry/some/file'
Chris@1115 304
Chris@1115 305 export_url = '/projects/ecookbook/repository/raw/some/file'
Chris@1115 306 export_url_with_rev = '/projects/ecookbook/repository/revisions/52/raw/some/file'
Chris@1115 307 export_url_with_ext = '/projects/ecookbook/repository/raw/some/file.ext'
Chris@1115 308 export_url_with_rev_and_ext = '/projects/ecookbook/repository/revisions/52/raw/some/file.ext'
Chris@1464 309 export_url_with_branch = '/projects/ecookbook/repository/revisions/branch/raw/some/file'
Chris@441 310
Chris@0 311 to_test = {
Chris@0 312 # tickets
Chris@0 313 '#3, [#3], (#3) and #3.' => "#{issue_link}, [#{issue_link}], (#{issue_link}) and #{issue_link}.",
Chris@1115 314 # ticket notes
Chris@1115 315 '#3-14' => note_link,
Chris@1464 316 '#3#note-14' => note_link2,
Chris@1115 317 # should not ignore leading zero
Chris@1115 318 '#03' => '#03',
Chris@0 319 # changesets
Chris@1464 320 'r1' => revision_link,
Chris@1464 321 'r1.' => "#{revision_link}.",
Chris@1464 322 'r1, r2' => "#{revision_link}, #{revision_link2}",
Chris@1464 323 'r1,r2' => "#{revision_link},#{revision_link2}",
Chris@1464 324 'commit:691322a8eb01e11fd7' => changeset_link2,
Chris@0 325 # documents
Chris@0 326 'document#1' => document_link,
Chris@0 327 'document:"Test document"' => document_link,
Chris@0 328 # versions
Chris@0 329 'version#2' => version_link,
Chris@0 330 'version:1.0' => version_link,
Chris@0 331 'version:"1.0"' => version_link,
Chris@0 332 # source
Chris@1115 333 'source:some/file' => link_to('source:some/file', source_url, :class => 'source'),
Chris@0 334 'source:/some/file' => link_to('source:/some/file', source_url, :class => 'source'),
Chris@0 335 'source:/some/file.' => link_to('source:/some/file', source_url, :class => 'source') + ".",
Chris@0 336 'source:/some/file.ext.' => link_to('source:/some/file.ext', source_url_with_ext, :class => 'source') + ".",
Chris@0 337 'source:/some/file. ' => link_to('source:/some/file', source_url, :class => 'source') + ".",
Chris@0 338 'source:/some/file.ext. ' => link_to('source:/some/file.ext', source_url_with_ext, :class => 'source') + ".",
Chris@0 339 'source:/some/file, ' => link_to('source:/some/file', source_url, :class => 'source') + ",",
Chris@1115 340 'source:/some/file@52' => link_to('source:/some/file@52', source_url_with_rev, :class => 'source'),
Chris@1464 341 'source:/some/file@branch' => link_to('source:/some/file@branch', source_url_with_branch, :class => 'source'),
Chris@1115 342 'source:/some/file.ext@52' => link_to('source:/some/file.ext@52', source_url_with_rev_and_ext, :class => 'source'),
Chris@1115 343 'source:/some/file#L110' => link_to('source:/some/file#L110', source_url + "#L110", :class => 'source'),
Chris@1115 344 'source:/some/file.ext#L110' => link_to('source:/some/file.ext#L110', source_url_with_ext + "#L110", :class => 'source'),
Chris@1115 345 'source:/some/file@52#L110' => link_to('source:/some/file@52#L110', source_url_with_rev + "#L110", :class => 'source'),
Chris@1115 346 # export
Chris@1115 347 'export:/some/file' => link_to('export:/some/file', export_url, :class => 'source download'),
Chris@1115 348 'export:/some/file.ext' => link_to('export:/some/file.ext', export_url_with_ext, :class => 'source download'),
Chris@1115 349 'export:/some/file@52' => link_to('export:/some/file@52', export_url_with_rev, :class => 'source download'),
Chris@1115 350 'export:/some/file.ext@52' => link_to('export:/some/file.ext@52', export_url_with_rev_and_ext, :class => 'source download'),
Chris@1464 351 'export:/some/file@branch' => link_to('export:/some/file@branch', export_url_with_branch, :class => 'source download'),
Chris@909 352 # forum
Chris@909 353 'forum#2' => link_to('Discussion', board_url, :class => 'board'),
Chris@909 354 'forum:Discussion' => link_to('Discussion', board_url, :class => 'board'),
Chris@0 355 # message
Chris@0 356 'message#4' => link_to('Post 2', message_url, :class => 'message'),
Chris@210 357 'message#5' => link_to('RE: post 2', message_url.merge(:anchor => 'message-5', :r => 5), :class => 'message'),
Chris@909 358 # news
Chris@909 359 'news#1' => link_to('eCookbook first release !', news_url, :class => 'news'),
Chris@909 360 'news:"eCookbook first release !"' => link_to('eCookbook first release !', news_url, :class => 'news'),
Chris@0 361 # project
Chris@0 362 'project#3' => link_to('eCookbook Subproject 1', project_url, :class => 'project'),
Chris@0 363 'project:subproject1' => link_to('eCookbook Subproject 1', project_url, :class => 'project'),
Chris@0 364 'project:"eCookbook subProject 1"' => link_to('eCookbook Subproject 1', project_url, :class => 'project'),
Chris@0 365 # not found
Chris@0 366 '#0123456789' => '#0123456789',
Chris@0 367 # invalid expressions
Chris@0 368 'source:' => 'source:',
Chris@0 369 # url hash
Chris@0 370 "http://foo.bar/FAQ#3" => '<a class="external" href="http://foo.bar/FAQ#3">http://foo.bar/FAQ#3</a>',
Chris@0 371 }
Chris@0 372 @project = Project.find(1)
Chris@0 373 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text), "#{text} failed" }
Chris@0 374 end
Chris@441 375
Chris@1294 376 def test_redmine_links_with_a_different_project_before_current_project
Chris@1294 377 vp1 = Version.generate!(:project_id => 1, :name => '1.4.4')
Chris@1294 378 vp3 = Version.generate!(:project_id => 3, :name => '1.4.4')
Chris@1294 379
Chris@1294 380 @project = Project.find(3)
Chris@1294 381 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>),
Chris@1294 382 textilizable("ecookbook:version:1.4.4 version:1.4.4")
Chris@1294 383 end
Chris@1294 384
Chris@1115 385 def test_escaped_redmine_links_should_not_be_parsed
Chris@1115 386 to_test = [
Chris@1115 387 '#3.',
Chris@1115 388 '#3-14.',
Chris@1115 389 '#3#-note14.',
Chris@1115 390 'r1',
Chris@1115 391 'document#1',
Chris@1115 392 'document:"Test document"',
Chris@1115 393 'version#2',
Chris@1115 394 'version:1.0',
Chris@1115 395 'version:"1.0"',
Chris@1115 396 'source:/some/file'
Chris@1115 397 ]
Chris@1115 398 @project = Project.find(1)
Chris@1115 399 to_test.each { |text| assert_equal "<p>#{text}</p>", textilizable("!" + text), "#{text} failed" }
Chris@1115 400 end
Chris@1115 401
Chris@210 402 def test_cross_project_redmine_links
Chris@210 403 source_link = link_to('ecookbook:source:/some/file', {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :path => ['some', 'file']},
Chris@210 404 :class => 'source')
Chris@441 405
Chris@210 406 changeset_link = link_to('ecookbook:r2', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 2},
Chris@210 407 :class => 'changeset', :title => 'This commit fixes #1, #2 and references #1 & #3')
Chris@441 408
Chris@210 409 to_test = {
Chris@210 410 # documents
Chris@210 411 'document:"Test document"' => 'document:"Test document"',
Chris@210 412 'ecookbook:document:"Test document"' => '<a href="/documents/1" class="document">Test document</a>',
Chris@210 413 'invalid:document:"Test document"' => 'invalid:document:"Test document"',
Chris@210 414 # versions
Chris@210 415 'version:"1.0"' => 'version:"1.0"',
Chris@909 416 'ecookbook:version:"1.0"' => '<a href="/versions/2" class="version">1.0</a>',
Chris@210 417 'invalid:version:"1.0"' => 'invalid:version:"1.0"',
Chris@210 418 # changeset
Chris@210 419 'r2' => 'r2',
Chris@210 420 'ecookbook:r2' => changeset_link,
Chris@210 421 'invalid:r2' => 'invalid:r2',
Chris@210 422 # source
Chris@210 423 'source:/some/file' => 'source:/some/file',
Chris@210 424 'ecookbook:source:/some/file' => source_link,
Chris@210 425 'invalid:source:/some/file' => 'invalid:source:/some/file',
Chris@210 426 }
Chris@210 427 @project = Project.find(3)
Chris@210 428 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text), "#{text} failed" }
Chris@210 429 end
Chris@119 430
Chris@1115 431 def test_multiple_repositories_redmine_links
Chris@1294 432 svn = Repository::Subversion.create!(:project_id => 1, :identifier => 'svn_repo-1', :url => 'file:///foo/hg')
Chris@1115 433 Changeset.create!(:repository => svn, :committed_on => Time.now, :revision => '123')
Chris@1115 434 hg = Repository::Mercurial.create!(:project_id => 1, :identifier => 'hg1', :url => '/foo/hg')
Chris@1115 435 Changeset.create!(:repository => hg, :committed_on => Time.now, :revision => '123', :scmid => 'abcd')
Chris@1115 436
Chris@1115 437 changeset_link = link_to('r2', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 2},
Chris@1115 438 :class => 'changeset', :title => 'This commit fixes #1, #2 and references #1 & #3')
Chris@1294 439 svn_changeset_link = link_to('svn_repo-1|r123', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :repository_id => 'svn_repo-1', :rev => 123},
Chris@1115 440 :class => 'changeset', :title => '')
Chris@1115 441 hg_changeset_link = link_to('hg1|abcd', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :repository_id => 'hg1', :rev => 'abcd'},
Chris@1115 442 :class => 'changeset', :title => '')
Chris@1115 443
Chris@1115 444 source_link = link_to('source:some/file', {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :path => ['some', 'file']}, :class => 'source')
Chris@1115 445 hg_source_link = link_to('source:hg1|some/file', {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :repository_id => 'hg1', :path => ['some', 'file']}, :class => 'source')
Chris@1115 446
Chris@1115 447 to_test = {
Chris@1115 448 'r2' => changeset_link,
Chris@1294 449 'svn_repo-1|r123' => svn_changeset_link,
Chris@1115 450 'invalid|r123' => 'invalid|r123',
Chris@1115 451 'commit:hg1|abcd' => hg_changeset_link,
Chris@1115 452 'commit:invalid|abcd' => 'commit:invalid|abcd',
Chris@1115 453 # source
Chris@1115 454 'source:some/file' => source_link,
Chris@1115 455 'source:hg1|some/file' => hg_source_link,
Chris@1115 456 'source:invalid|some/file' => 'source:invalid|some/file',
Chris@1115 457 }
Chris@1115 458
Chris@1115 459 @project = Project.find(1)
Chris@1115 460 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text), "#{text} failed" }
Chris@1115 461 end
Chris@1115 462
Chris@1115 463 def test_cross_project_multiple_repositories_redmine_links
Chris@1115 464 svn = Repository::Subversion.create!(:project_id => 1, :identifier => 'svn1', :url => 'file:///foo/hg')
Chris@1115 465 Changeset.create!(:repository => svn, :committed_on => Time.now, :revision => '123')
Chris@1115 466 hg = Repository::Mercurial.create!(:project_id => 1, :identifier => 'hg1', :url => '/foo/hg')
Chris@1115 467 Changeset.create!(:repository => hg, :committed_on => Time.now, :revision => '123', :scmid => 'abcd')
Chris@1115 468
Chris@1115 469 changeset_link = link_to('ecookbook:r2', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 2},
Chris@1115 470 :class => 'changeset', :title => 'This commit fixes #1, #2 and references #1 & #3')
Chris@1115 471 svn_changeset_link = link_to('ecookbook:svn1|r123', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :repository_id => 'svn1', :rev => 123},
Chris@1115 472 :class => 'changeset', :title => '')
Chris@1115 473 hg_changeset_link = link_to('ecookbook:hg1|abcd', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :repository_id => 'hg1', :rev => 'abcd'},
Chris@1115 474 :class => 'changeset', :title => '')
Chris@1115 475
Chris@1115 476 source_link = link_to('ecookbook:source:some/file', {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :path => ['some', 'file']}, :class => 'source')
Chris@1115 477 hg_source_link = link_to('ecookbook:source:hg1|some/file', {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :repository_id => 'hg1', :path => ['some', 'file']}, :class => 'source')
Chris@1115 478
Chris@1115 479 to_test = {
Chris@1115 480 'ecookbook:r2' => changeset_link,
Chris@1115 481 'ecookbook:svn1|r123' => svn_changeset_link,
Chris@1115 482 'ecookbook:invalid|r123' => 'ecookbook:invalid|r123',
Chris@1115 483 'ecookbook:commit:hg1|abcd' => hg_changeset_link,
Chris@1115 484 'ecookbook:commit:invalid|abcd' => 'ecookbook:commit:invalid|abcd',
Chris@1115 485 'invalid:commit:invalid|abcd' => 'invalid:commit:invalid|abcd',
Chris@1115 486 # source
Chris@1115 487 'ecookbook:source:some/file' => source_link,
Chris@1115 488 'ecookbook:source:hg1|some/file' => hg_source_link,
Chris@1115 489 'ecookbook:source:invalid|some/file' => 'ecookbook:source:invalid|some/file',
Chris@1115 490 'invalid:source:invalid|some/file' => 'invalid:source:invalid|some/file',
Chris@1115 491 }
Chris@1115 492
Chris@1115 493 @project = Project.find(3)
Chris@1115 494 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text), "#{text} failed" }
Chris@1115 495 end
Chris@1115 496
Chris@119 497 def test_redmine_links_git_commit
Chris@119 498 changeset_link = link_to('abcd',
Chris@119 499 {
Chris@119 500 :controller => 'repositories',
Chris@119 501 :action => 'revision',
Chris@119 502 :id => 'subproject1',
Chris@119 503 :rev => 'abcd',
Chris@119 504 },
Chris@119 505 :class => 'changeset', :title => 'test commit')
Chris@119 506 to_test = {
Chris@119 507 'commit:abcd' => changeset_link,
Chris@119 508 }
Chris@119 509 @project = Project.find(3)
Chris@119 510 r = Repository::Git.create!(:project => @project, :url => '/tmp/test/git')
Chris@119 511 assert r
Chris@119 512 c = Changeset.new(:repository => r,
Chris@119 513 :committed_on => Time.now,
Chris@119 514 :revision => 'abcd',
Chris@119 515 :scmid => 'abcd',
Chris@119 516 :comments => 'test commit')
Chris@119 517 assert( c.save )
Chris@119 518 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
Chris@119 519 end
Chris@119 520
Chris@119 521 # TODO: Bazaar commit id contains mail address, so it contains '@' and '_'.
Chris@119 522 def test_redmine_links_darcs_commit
Chris@119 523 changeset_link = link_to('20080308225258-98289-abcd456efg.gz',
Chris@119 524 {
Chris@119 525 :controller => 'repositories',
Chris@119 526 :action => 'revision',
Chris@119 527 :id => 'subproject1',
Chris@119 528 :rev => '123',
Chris@119 529 },
Chris@119 530 :class => 'changeset', :title => 'test commit')
Chris@119 531 to_test = {
Chris@119 532 'commit:20080308225258-98289-abcd456efg.gz' => changeset_link,
Chris@119 533 }
Chris@119 534 @project = Project.find(3)
Chris@245 535 r = Repository::Darcs.create!(
Chris@245 536 :project => @project, :url => '/tmp/test/darcs',
Chris@245 537 :log_encoding => 'UTF-8')
Chris@119 538 assert r
Chris@119 539 c = Changeset.new(:repository => r,
Chris@119 540 :committed_on => Time.now,
Chris@119 541 :revision => '123',
Chris@119 542 :scmid => '20080308225258-98289-abcd456efg.gz',
Chris@119 543 :comments => 'test commit')
Chris@119 544 assert( c.save )
Chris@119 545 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
Chris@119 546 end
Chris@119 547
Chris@119 548 def test_redmine_links_mercurial_commit
Chris@119 549 changeset_link_rev = link_to('r123',
Chris@119 550 {
Chris@119 551 :controller => 'repositories',
Chris@119 552 :action => 'revision',
Chris@119 553 :id => 'subproject1',
Chris@119 554 :rev => '123' ,
Chris@119 555 },
Chris@119 556 :class => 'changeset', :title => 'test commit')
Chris@119 557 changeset_link_commit = link_to('abcd',
Chris@119 558 {
Chris@119 559 :controller => 'repositories',
Chris@119 560 :action => 'revision',
Chris@119 561 :id => 'subproject1',
Chris@119 562 :rev => 'abcd' ,
Chris@119 563 },
Chris@119 564 :class => 'changeset', :title => 'test commit')
Chris@119 565 to_test = {
Chris@119 566 'r123' => changeset_link_rev,
Chris@119 567 'commit:abcd' => changeset_link_commit,
Chris@119 568 }
Chris@119 569 @project = Project.find(3)
Chris@119 570 r = Repository::Mercurial.create!(:project => @project, :url => '/tmp/test')
Chris@119 571 assert r
Chris@119 572 c = Changeset.new(:repository => r,
Chris@119 573 :committed_on => Time.now,
Chris@119 574 :revision => '123',
Chris@119 575 :scmid => 'abcd',
Chris@119 576 :comments => 'test commit')
Chris@119 577 assert( c.save )
Chris@119 578 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
Chris@119 579 end
Chris@119 580
Chris@0 581 def test_attachment_links
Chris@0 582 to_test = {
Chris@1464 583 'attachment:error281.txt' => '<a href="/attachments/download/1/error281.txt" class="attachment">error281.txt</a>'
Chris@0 584 }
Chris@0 585 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text, :attachments => Issue.find(3).attachments), "#{text} failed" }
Chris@0 586 end
Chris@441 587
Chris@1294 588 def test_attachment_link_should_link_to_latest_attachment
Chris@1294 589 set_tmp_attachments_directory
Chris@1294 590 a1 = Attachment.generate!(:filename => "test.txt", :created_on => 1.hour.ago)
Chris@1294 591 a2 = Attachment.generate!(:filename => "test.txt")
Chris@1294 592
Chris@1464 593 assert_equal %(<p><a href="/attachments/download/#{a2.id}/test.txt" class="attachment">test.txt</a></p>),
Chris@1294 594 textilizable('attachment:test.txt', :attachments => [a1, a2])
Chris@1294 595 end
Chris@1294 596
Chris@0 597 def test_wiki_links
Chris@1464 598 russian_eacape = CGI.escape(@russian_test)
Chris@0 599 to_test = {
Chris@0 600 '[[CookBook documentation]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation" class="wiki-page">CookBook documentation</a>',
Chris@0 601 '[[Another page|Page]]' => '<a href="/projects/ecookbook/wiki/Another_page" class="wiki-page">Page</a>',
Chris@909 602 # title content should be formatted
Chris@909 603 '[[Another page|With _styled_ *title*]]' => '<a href="/projects/ecookbook/wiki/Another_page" class="wiki-page">With <em>styled</em> <strong>title</strong></a>',
Chris@909 604 '[[Another page|With title containing <strong>HTML entities &amp; markups</strong>]]' => '<a href="/projects/ecookbook/wiki/Another_page" class="wiki-page">With title containing &lt;strong&gt;HTML entities &amp; markups&lt;/strong&gt;</a>',
Chris@0 605 # link with anchor
Chris@0 606 '[[CookBook documentation#One-section]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation#One-section" class="wiki-page">CookBook documentation</a>',
Chris@0 607 '[[Another page#anchor|Page]]' => '<a href="/projects/ecookbook/wiki/Another_page#anchor" class="wiki-page">Page</a>',
Chris@1115 608 # UTF8 anchor
Chris@1464 609 "[[Another_page##{@russian_test}|#{@russian_test}]]" =>
Chris@1464 610 %|<a href="/projects/ecookbook/wiki/Another_page##{russian_eacape}" class="wiki-page">#{@russian_test}</a>|,
Chris@0 611 # page that doesn't exist
Chris@0 612 '[[Unknown page]]' => '<a href="/projects/ecookbook/wiki/Unknown_page" class="wiki-page new">Unknown page</a>',
Chris@0 613 '[[Unknown page|404]]' => '<a href="/projects/ecookbook/wiki/Unknown_page" class="wiki-page new">404</a>',
Chris@0 614 # link to another project wiki
chris@37 615 '[[onlinestore:]]' => '<a href="/projects/onlinestore/wiki" class="wiki-page">onlinestore</a>',
chris@37 616 '[[onlinestore:|Wiki]]' => '<a href="/projects/onlinestore/wiki" class="wiki-page">Wiki</a>',
Chris@0 617 '[[onlinestore:Start page]]' => '<a href="/projects/onlinestore/wiki/Start_page" class="wiki-page">Start page</a>',
Chris@0 618 '[[onlinestore:Start page|Text]]' => '<a href="/projects/onlinestore/wiki/Start_page" class="wiki-page">Text</a>',
Chris@0 619 '[[onlinestore:Unknown page]]' => '<a href="/projects/onlinestore/wiki/Unknown_page" class="wiki-page new">Unknown page</a>',
Chris@0 620 # striked through link
Chris@0 621 '-[[Another page|Page]]-' => '<del><a href="/projects/ecookbook/wiki/Another_page" class="wiki-page">Page</a></del>',
Chris@0 622 '-[[Another page|Page]] link-' => '<del><a href="/projects/ecookbook/wiki/Another_page" class="wiki-page">Page</a> link</del>',
Chris@0 623 # escaping
Chris@0 624 '![[Another page|Page]]' => '[[Another page|Page]]',
Chris@0 625 # project does not exist
Chris@0 626 '[[unknowproject:Start]]' => '[[unknowproject:Start]]',
Chris@0 627 '[[unknowproject:Start|Page title]]' => '[[unknowproject:Start|Page title]]',
Chris@0 628 }
Chris@909 629
Chris@0 630 @project = Project.find(1)
Chris@0 631 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
Chris@0 632 end
Chris@441 633
Chris@909 634 def test_wiki_links_within_local_file_generation_context
Chris@909 635
Chris@909 636 to_test = {
Chris@909 637 # link to a page
Chris@909 638 '[[CookBook documentation]]' => '<a href="CookBook_documentation.html" class="wiki-page">CookBook documentation</a>',
Chris@909 639 '[[CookBook documentation|documentation]]' => '<a href="CookBook_documentation.html" class="wiki-page">documentation</a>',
Chris@909 640 '[[CookBook documentation#One-section]]' => '<a href="CookBook_documentation.html#One-section" class="wiki-page">CookBook documentation</a>',
Chris@909 641 '[[CookBook documentation#One-section|documentation]]' => '<a href="CookBook_documentation.html#One-section" class="wiki-page">documentation</a>',
Chris@909 642 # page that doesn't exist
Chris@909 643 '[[Unknown page]]' => '<a href="Unknown_page.html" class="wiki-page new">Unknown page</a>',
Chris@909 644 '[[Unknown page|404]]' => '<a href="Unknown_page.html" class="wiki-page new">404</a>',
Chris@909 645 '[[Unknown page#anchor]]' => '<a href="Unknown_page.html#anchor" class="wiki-page new">Unknown page</a>',
Chris@909 646 '[[Unknown page#anchor|404]]' => '<a href="Unknown_page.html#anchor" class="wiki-page new">404</a>',
Chris@909 647 }
Chris@909 648
Chris@909 649 @project = Project.find(1)
Chris@909 650
Chris@909 651 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text, :wiki_links => :local) }
Chris@909 652 end
Chris@909 653
Chris@1115 654 def test_wiki_links_within_wiki_page_context
Chris@1115 655
Chris@1115 656 page = WikiPage.find_by_title('Another_page' )
Chris@1115 657
Chris@1115 658 to_test = {
Chris@1115 659 # link to another page
Chris@1115 660 '[[CookBook documentation]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation" class="wiki-page">CookBook documentation</a>',
Chris@1115 661 '[[CookBook documentation|documentation]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation" class="wiki-page">documentation</a>',
Chris@1115 662 '[[CookBook documentation#One-section]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation#One-section" class="wiki-page">CookBook documentation</a>',
Chris@1115 663 '[[CookBook documentation#One-section|documentation]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation#One-section" class="wiki-page">documentation</a>',
Chris@1115 664 # link to the current page
Chris@1115 665 '[[Another page]]' => '<a href="/projects/ecookbook/wiki/Another_page" class="wiki-page">Another page</a>',
Chris@1115 666 '[[Another page|Page]]' => '<a href="/projects/ecookbook/wiki/Another_page" class="wiki-page">Page</a>',
Chris@1115 667 '[[Another page#anchor]]' => '<a href="#anchor" class="wiki-page">Another page</a>',
Chris@1115 668 '[[Another page#anchor|Page]]' => '<a href="#anchor" class="wiki-page">Page</a>',
Chris@1115 669 # page that doesn't exist
Chris@1115 670 '[[Unknown page]]' => '<a href="/projects/ecookbook/wiki/Unknown_page?parent=Another_page" class="wiki-page new">Unknown page</a>',
Chris@1115 671 '[[Unknown page|404]]' => '<a href="/projects/ecookbook/wiki/Unknown_page?parent=Another_page" class="wiki-page new">404</a>',
Chris@1115 672 '[[Unknown page#anchor]]' => '<a href="/projects/ecookbook/wiki/Unknown_page?parent=Another_page#anchor" class="wiki-page new">Unknown page</a>',
Chris@1115 673 '[[Unknown page#anchor|404]]' => '<a href="/projects/ecookbook/wiki/Unknown_page?parent=Another_page#anchor" class="wiki-page new">404</a>',
Chris@1115 674 }
Chris@1115 675
Chris@1115 676 @project = Project.find(1)
Chris@1115 677
Chris@1115 678 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(WikiContent.new( :text => text, :page => page ), :text) }
Chris@1115 679 end
Chris@1115 680
Chris@1115 681 def test_wiki_links_anchor_option_should_prepend_page_title_to_href
Chris@1115 682
Chris@1115 683 to_test = {
Chris@1115 684 # link to a page
Chris@1115 685 '[[CookBook documentation]]' => '<a href="#CookBook_documentation" class="wiki-page">CookBook documentation</a>',
Chris@1115 686 '[[CookBook documentation|documentation]]' => '<a href="#CookBook_documentation" class="wiki-page">documentation</a>',
Chris@1115 687 '[[CookBook documentation#One-section]]' => '<a href="#CookBook_documentation_One-section" class="wiki-page">CookBook documentation</a>',
Chris@1115 688 '[[CookBook documentation#One-section|documentation]]' => '<a href="#CookBook_documentation_One-section" class="wiki-page">documentation</a>',
Chris@1115 689 # page that doesn't exist
Chris@1115 690 '[[Unknown page]]' => '<a href="#Unknown_page" class="wiki-page new">Unknown page</a>',
Chris@1115 691 '[[Unknown page|404]]' => '<a href="#Unknown_page" class="wiki-page new">404</a>',
Chris@1115 692 '[[Unknown page#anchor]]' => '<a href="#Unknown_page_anchor" class="wiki-page new">Unknown page</a>',
Chris@1115 693 '[[Unknown page#anchor|404]]' => '<a href="#Unknown_page_anchor" class="wiki-page new">404</a>',
Chris@1115 694 }
Chris@1115 695
Chris@1115 696 @project = Project.find(1)
Chris@1115 697
Chris@1115 698 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text, :wiki_links => :anchor) }
Chris@1115 699 end
Chris@1115 700
Chris@0 701 def test_html_tags
Chris@0 702 to_test = {
Chris@0 703 "<div>content</div>" => "<p>&lt;div&gt;content&lt;/div&gt;</p>",
Chris@0 704 "<div class=\"bold\">content</div>" => "<p>&lt;div class=\"bold\"&gt;content&lt;/div&gt;</p>",
Chris@0 705 "<script>some script;</script>" => "<p>&lt;script&gt;some script;&lt;/script&gt;</p>",
Chris@0 706 # do not escape pre/code tags
Chris@0 707 "<pre>\nline 1\nline2</pre>" => "<pre>\nline 1\nline2</pre>",
Chris@0 708 "<pre><code>\nline 1\nline2</code></pre>" => "<pre><code>\nline 1\nline2</code></pre>",
Chris@0 709 "<pre><div>content</div></pre>" => "<pre>&lt;div&gt;content&lt;/div&gt;</pre>",
Chris@0 710 "HTML comment: <!-- no comments -->" => "<p>HTML comment: &lt;!-- no comments --&gt;</p>",
Chris@0 711 "<!-- opening comment" => "<p>&lt;!-- opening comment</p>",
Chris@0 712 # remove attributes except class
Chris@0 713 "<pre class='foo'>some text</pre>" => "<pre class='foo'>some text</pre>",
Chris@119 714 '<pre class="foo">some text</pre>' => '<pre class="foo">some text</pre>',
Chris@119 715 "<pre class='foo bar'>some text</pre>" => "<pre class='foo bar'>some text</pre>",
Chris@119 716 '<pre class="foo bar">some text</pre>' => '<pre class="foo bar">some text</pre>',
Chris@0 717 "<pre onmouseover='alert(1)'>some text</pre>" => "<pre>some text</pre>",
Chris@119 718 # xss
Chris@119 719 '<pre><code class=""onmouseover="alert(1)">text</code></pre>' => '<pre><code>text</code></pre>',
Chris@119 720 '<pre class=""onmouseover="alert(1)">text</pre>' => '<pre>text</pre>',
Chris@0 721 }
Chris@0 722 to_test.each { |text, result| assert_equal result, textilizable(text) }
Chris@0 723 end
Chris@441 724
Chris@0 725 def test_allowed_html_tags
Chris@0 726 to_test = {
Chris@0 727 "<pre>preformatted text</pre>" => "<pre>preformatted text</pre>",
Chris@0 728 "<notextile>no *textile* formatting</notextile>" => "no *textile* formatting",
Chris@0 729 "<notextile>this is <tag>a tag</tag></notextile>" => "this is &lt;tag&gt;a tag&lt;/tag&gt;"
Chris@0 730 }
Chris@0 731 to_test.each { |text, result| assert_equal result, textilizable(text) }
Chris@0 732 end
Chris@441 733
Chris@0 734 def test_pre_tags
Chris@0 735 raw = <<-RAW
Chris@0 736 Before
Chris@0 737
Chris@0 738 <pre>
Chris@0 739 <prepared-statement-cache-size>32</prepared-statement-cache-size>
Chris@0 740 </pre>
Chris@0 741
Chris@0 742 After
Chris@0 743 RAW
Chris@0 744
Chris@0 745 expected = <<-EXPECTED
Chris@0 746 <p>Before</p>
Chris@0 747 <pre>
Chris@0 748 &lt;prepared-statement-cache-size&gt;32&lt;/prepared-statement-cache-size&gt;
Chris@0 749 </pre>
Chris@0 750 <p>After</p>
Chris@0 751 EXPECTED
Chris@441 752
Chris@0 753 assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '')
Chris@0 754 end
Chris@441 755
Chris@0 756 def test_pre_content_should_not_parse_wiki_and_redmine_links
Chris@0 757 raw = <<-RAW
Chris@0 758 [[CookBook documentation]]
Chris@0 759
Chris@0 760 #1
Chris@0 761
Chris@0 762 <pre>
Chris@0 763 [[CookBook documentation]]
Chris@0 764
Chris@0 765 #1
Chris@0 766 </pre>
Chris@0 767 RAW
Chris@0 768
Chris@0 769 expected = <<-EXPECTED
Chris@0 770 <p><a href="/projects/ecookbook/wiki/CookBook_documentation" class="wiki-page">CookBook documentation</a></p>
Chris@1464 771 <p><a href="/issues/1" class="#{Issue.find(1).css_classes}" title="Can&#x27;t print recipes (New)">#1</a></p>
Chris@0 772 <pre>
Chris@0 773 [[CookBook documentation]]
Chris@0 774
Chris@0 775 #1
Chris@0 776 </pre>
Chris@0 777 EXPECTED
Chris@441 778
Chris@0 779 @project = Project.find(1)
Chris@0 780 assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '')
Chris@0 781 end
Chris@441 782
Chris@0 783 def test_non_closing_pre_blocks_should_be_closed
Chris@0 784 raw = <<-RAW
Chris@0 785 <pre><code>
Chris@0 786 RAW
Chris@0 787
Chris@0 788 expected = <<-EXPECTED
Chris@0 789 <pre><code>
Chris@0 790 </code></pre>
Chris@0 791 EXPECTED
Chris@441 792
Chris@0 793 @project = Project.find(1)
Chris@0 794 assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '')
Chris@0 795 end
Chris@441 796
Chris@0 797 def test_syntax_highlight
Chris@0 798 raw = <<-RAW
Chris@0 799 <pre><code class="ruby">
Chris@0 800 # Some ruby code here
Chris@0 801 </code></pre>
Chris@0 802 RAW
Chris@0 803
Chris@0 804 expected = <<-EXPECTED
Chris@1115 805 <pre><code class="ruby syntaxhl"><span class=\"CodeRay\"><span class="comment"># Some ruby code here</span></span>
Chris@0 806 </code></pre>
Chris@0 807 EXPECTED
Chris@0 808
Chris@0 809 assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '')
Chris@0 810 end
Chris@441 811
Chris@1115 812 def test_to_path_param
Chris@1115 813 assert_equal 'test1/test2', to_path_param('test1/test2')
Chris@1115 814 assert_equal 'test1/test2', to_path_param('/test1/test2/')
Chris@1115 815 assert_equal 'test1/test2', to_path_param('//test1/test2/')
Chris@1115 816 assert_equal nil, to_path_param('/')
Chris@1115 817 end
Chris@1115 818
Chris@0 819 def test_wiki_links_in_tables
Chris@0 820 to_test = {"|[[Page|Link title]]|[[Other Page|Other title]]|\n|Cell 21|[[Last page]]|" =>
Chris@0 821 '<tr><td><a href="/projects/ecookbook/wiki/Page" class="wiki-page new">Link title</a></td>' +
Chris@0 822 '<td><a href="/projects/ecookbook/wiki/Other_Page" class="wiki-page new">Other title</a></td>' +
Chris@0 823 '</tr><tr><td>Cell 21</td><td><a href="/projects/ecookbook/wiki/Last_page" class="wiki-page new">Last page</a></td></tr>'
Chris@0 824 }
Chris@0 825 @project = Project.find(1)
Chris@0 826 to_test.each { |text, result| assert_equal "<table>#{result}</table>", textilizable(text).gsub(/[\t\n]/, '') }
Chris@0 827 end
Chris@441 828
Chris@0 829 def test_text_formatting
Chris@0 830 to_test = {'*_+bold, italic and underline+_*' => '<strong><em><ins>bold, italic and underline</ins></em></strong>',
Chris@0 831 '(_text within parentheses_)' => '(<em>text within parentheses</em>)',
Chris@0 832 'a *Humane Web* Text Generator' => 'a <strong>Humane Web</strong> Text Generator',
Chris@0 833 'a H *umane* W *eb* T *ext* G *enerator*' => 'a H <strong>umane</strong> W <strong>eb</strong> T <strong>ext</strong> G <strong>enerator</strong>',
Chris@0 834 'a *H* umane *W* eb *T* ext *G* enerator' => 'a <strong>H</strong> umane <strong>W</strong> eb <strong>T</strong> ext <strong>G</strong> enerator',
Chris@0 835 }
Chris@0 836 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
Chris@0 837 end
Chris@441 838
Chris@0 839 def test_wiki_horizontal_rule
Chris@0 840 assert_equal '<hr />', textilizable('---')
Chris@0 841 assert_equal '<p>Dashes: ---</p>', textilizable('Dashes: ---')
Chris@0 842 end
Chris@441 843
Chris@0 844 def test_footnotes
Chris@0 845 raw = <<-RAW
Chris@0 846 This is some text[1].
Chris@0 847
Chris@0 848 fn1. This is the foot note
Chris@0 849 RAW
Chris@0 850
Chris@0 851 expected = <<-EXPECTED
Chris@0 852 <p>This is some text<sup><a href=\"#fn1\">1</a></sup>.</p>
Chris@0 853 <p id="fn1" class="footnote"><sup>1</sup> This is the foot note</p>
Chris@0 854 EXPECTED
Chris@0 855
Chris@0 856 assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '')
Chris@0 857 end
Chris@441 858
Chris@441 859 def test_headings
Chris@441 860 raw = 'h1. Some heading'
Chris@441 861 expected = %|<a name="Some-heading"></a>\n<h1 >Some heading<a href="#Some-heading" class="wiki-anchor">&para;</a></h1>|
Chris@441 862
Chris@441 863 assert_equal expected, textilizable(raw)
Chris@441 864 end
Chris@441 865
Chris@909 866 def test_headings_with_special_chars
Chris@909 867 # This test makes sure that the generated anchor names match the expected
Chris@909 868 # ones even if the heading text contains unconventional characters
Chris@909 869 raw = 'h1. Some heading related to version 0.5'
Chris@909 870 anchor = sanitize_anchor_name("Some-heading-related-to-version-0.5")
Chris@909 871 expected = %|<a name="#{anchor}"></a>\n<h1 >Some heading related to version 0.5<a href="##{anchor}" class="wiki-anchor">&para;</a></h1>|
Chris@909 872
Chris@909 873 assert_equal expected, textilizable(raw)
Chris@909 874 end
Chris@909 875
Chris@909 876 def test_headings_in_wiki_single_page_export_should_be_prepended_with_page_title
Chris@1115 877 page = WikiPage.new( :title => 'Page Title', :wiki_id => 1 )
Chris@1115 878 content = WikiContent.new( :text => 'h1. Some heading', :page => page )
Chris@909 879
Chris@909 880 expected = %|<a name="Page_Title_Some-heading"></a>\n<h1 >Some heading<a href="#Page_Title_Some-heading" class="wiki-anchor">&para;</a></h1>|
Chris@909 881
Chris@909 882 assert_equal expected, textilizable(content, :text, :wiki_links => :anchor )
Chris@909 883 end
Chris@909 884
Chris@0 885 def test_table_of_content
Chris@0 886 raw = <<-RAW
Chris@0 887 {{toc}}
Chris@0 888
Chris@0 889 h1. Title
Chris@0 890
Chris@0 891 Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas sed libero.
Chris@0 892
Chris@0 893 h2. Subtitle with a [[Wiki]] link
Chris@0 894
Chris@0 895 Nullam commodo metus accumsan nulla. Curabitur lobortis dui id dolor.
Chris@0 896
Chris@0 897 h2. Subtitle with [[Wiki|another Wiki]] link
Chris@0 898
Chris@0 899 h2. Subtitle with %{color:red}red text%
Chris@119 900
Chris@119 901 <pre>
Chris@119 902 some code
Chris@119 903 </pre>
Chris@119 904
chris@37 905 h3. Subtitle with *some* _modifiers_
Chris@0 906
Chris@929 907 h3. Subtitle with @inline code@
Chris@929 908
Chris@0 909 h1. Another title
Chris@0 910
chris@37 911 h3. An "Internet link":http://www.redmine.org/ inside subtitle
Chris@0 912
Chris@0 913 h2. "Project Name !/attachments/1234/logo_small.gif! !/attachments/5678/logo_2.png!":/projects/projectname/issues
Chris@0 914
Chris@0 915 RAW
Chris@0 916
chris@37 917 expected = '<ul class="toc">' +
chris@37 918 '<li><a href="#Title">Title</a>' +
chris@37 919 '<ul>' +
Chris@441 920 '<li><a href="#Subtitle-with-a-Wiki-link">Subtitle with a Wiki link</a></li>' +
Chris@441 921 '<li><a href="#Subtitle-with-another-Wiki-link">Subtitle with another Wiki link</a></li>' +
chris@37 922 '<li><a href="#Subtitle-with-red-text">Subtitle with red text</a>' +
chris@37 923 '<ul>' +
chris@37 924 '<li><a href="#Subtitle-with-some-modifiers">Subtitle with some modifiers</a></li>' +
Chris@929 925 '<li><a href="#Subtitle-with-inline-code">Subtitle with inline code</a></li>' +
chris@37 926 '</ul>' +
chris@37 927 '</li>' +
chris@37 928 '</ul>' +
chris@37 929 '</li>' +
chris@37 930 '<li><a href="#Another-title">Another title</a>' +
chris@37 931 '<ul>' +
chris@37 932 '<li>' +
chris@37 933 '<ul>' +
chris@37 934 '<li><a href="#An-Internet-link-inside-subtitle">An Internet link inside subtitle</a></li>' +
chris@37 935 '</ul>' +
chris@37 936 '</li>' +
chris@37 937 '<li><a href="#Project-Name">Project Name</a></li>' +
chris@37 938 '</ul>' +
chris@37 939 '</li>' +
Chris@0 940 '</ul>'
Chris@0 941
chris@37 942 @project = Project.find(1)
Chris@909 943 assert textilizable(raw).gsub("\n", "").include?(expected)
chris@37 944 end
Chris@441 945
Chris@929 946 def test_table_of_content_should_generate_unique_anchors
Chris@929 947 raw = <<-RAW
Chris@929 948 {{toc}}
Chris@929 949
Chris@929 950 h1. Title
Chris@929 951
Chris@929 952 h2. Subtitle
Chris@929 953
Chris@929 954 h2. Subtitle
Chris@929 955 RAW
Chris@929 956
Chris@929 957 expected = '<ul class="toc">' +
Chris@929 958 '<li><a href="#Title">Title</a>' +
Chris@929 959 '<ul>' +
Chris@929 960 '<li><a href="#Subtitle">Subtitle</a></li>' +
Chris@929 961 '<li><a href="#Subtitle-2">Subtitle</a></li>'
Chris@929 962 '</ul>'
Chris@929 963 '</li>' +
Chris@929 964 '</ul>'
Chris@929 965
Chris@929 966 @project = Project.find(1)
Chris@929 967 result = textilizable(raw).gsub("\n", "")
Chris@929 968 assert_include expected, result
Chris@929 969 assert_include '<a name="Subtitle">', result
Chris@929 970 assert_include '<a name="Subtitle-2">', result
Chris@929 971 end
Chris@929 972
chris@37 973 def test_table_of_content_should_contain_included_page_headings
chris@37 974 raw = <<-RAW
chris@37 975 {{toc}}
chris@37 976
chris@37 977 h1. Included
chris@37 978
chris@37 979 {{include(Child_1)}}
chris@37 980 RAW
chris@37 981
chris@37 982 expected = '<ul class="toc">' +
chris@37 983 '<li><a href="#Included">Included</a></li>' +
Chris@441 984 '<li><a href="#Child-page-1">Child page 1</a></li>' +
chris@37 985 '</ul>'
chris@37 986
chris@37 987 @project = Project.find(1)
Chris@0 988 assert textilizable(raw).gsub("\n", "").include?(expected)
Chris@0 989 end
Chris@0 990
Chris@929 991 def test_section_edit_links
Chris@929 992 raw = <<-RAW
Chris@929 993 h1. Title
Chris@929 994
Chris@929 995 Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas sed libero.
Chris@929 996
Chris@929 997 h2. Subtitle with a [[Wiki]] link
Chris@929 998
Chris@929 999 h2. Subtitle with *some* _modifiers_
Chris@929 1000
Chris@929 1001 h2. Subtitle with @inline code@
Chris@929 1002
Chris@929 1003 <pre>
Chris@929 1004 some code
Chris@929 1005
Chris@929 1006 h2. heading inside pre
Chris@929 1007
Chris@929 1008 <h2>html heading inside pre</h2>
Chris@929 1009 </pre>
Chris@929 1010
Chris@929 1011 h2. Subtitle after pre tag
Chris@929 1012 RAW
Chris@929 1013
Chris@929 1014 @project = Project.find(1)
Chris@929 1015 set_language_if_valid 'en'
Chris@929 1016 result = textilizable(raw, :edit_section_links => {:controller => 'wiki', :action => 'edit', :project_id => '1', :id => 'Test'}).gsub("\n", "")
Chris@929 1017
Chris@929 1018 # heading that contains inline code
Chris@1464 1019 assert_match Regexp.new('<div class="contextual" id="section-4" title="Edit this section">' +
Chris@929 1020 '<a href="/projects/1/wiki/Test/edit\?section=4"><img alt="Edit" src="/images/edit.png(\?\d+)?" /></a></div>' +
Chris@929 1021 '<a name="Subtitle-with-inline-code"></a>' +
Chris@929 1022 '<h2 >Subtitle with <code>inline code</code><a href="#Subtitle-with-inline-code" class="wiki-anchor">&para;</a></h2>'),
Chris@929 1023 result
Chris@929 1024
Chris@929 1025 # last heading
Chris@1464 1026 assert_match Regexp.new('<div class="contextual" id="section-5" title="Edit this section">' +
Chris@929 1027 '<a href="/projects/1/wiki/Test/edit\?section=5"><img alt="Edit" src="/images/edit.png(\?\d+)?" /></a></div>' +
Chris@929 1028 '<a name="Subtitle-after-pre-tag"></a>' +
Chris@929 1029 '<h2 >Subtitle after pre tag<a href="#Subtitle-after-pre-tag" class="wiki-anchor">&para;</a></h2>'),
Chris@929 1030 result
Chris@929 1031 end
Chris@929 1032
Chris@0 1033 def test_default_formatter
Chris@1115 1034 with_settings :text_formatting => 'unknown' do
Chris@1115 1035 text = 'a *link*: http://www.example.net/'
Chris@1115 1036 assert_equal '<p>a *link*: <a class="external" href="http://www.example.net/">http://www.example.net/</a></p>', textilizable(text)
Chris@1115 1037 end
Chris@0 1038 end
Chris@441 1039
Chris@0 1040 def test_due_date_distance_in_words
Chris@0 1041 to_test = { Date.today => 'Due in 0 days',
Chris@0 1042 Date.today + 1 => 'Due in 1 day',
Chris@0 1043 Date.today + 100 => 'Due in about 3 months',
Chris@0 1044 Date.today + 20000 => 'Due in over 54 years',
Chris@0 1045 Date.today - 1 => '1 day late',
Chris@0 1046 Date.today - 100 => 'about 3 months late',
Chris@0 1047 Date.today - 20000 => 'over 54 years late',
Chris@0 1048 }
Chris@119 1049 ::I18n.locale = :en
Chris@0 1050 to_test.each do |date, expected|
Chris@0 1051 assert_equal expected, due_date_distance_in_words(date)
Chris@0 1052 end
Chris@0 1053 end
Chris@441 1054
Chris@1115 1055 def test_avatar_enabled
Chris@1115 1056 with_settings :gravatar_enabled => '1' do
Chris@1115 1057 assert avatar(User.find_by_mail('jsmith@somenet.foo')).include?(Digest::MD5.hexdigest('jsmith@somenet.foo'))
Chris@1115 1058 assert avatar('jsmith <jsmith@somenet.foo>').include?(Digest::MD5.hexdigest('jsmith@somenet.foo'))
Chris@1115 1059 # Default size is 50
Chris@1115 1060 assert avatar('jsmith <jsmith@somenet.foo>').include?('size=50')
Chris@1115 1061 assert avatar('jsmith <jsmith@somenet.foo>', :size => 24).include?('size=24')
Chris@1115 1062 # Non-avatar options should be considered html options
Chris@1115 1063 assert avatar('jsmith <jsmith@somenet.foo>', :title => 'John Smith').include?('title="John Smith"')
Chris@1115 1064 # The default class of the img tag should be gravatar
Chris@1115 1065 assert avatar('jsmith <jsmith@somenet.foo>').include?('class="gravatar"')
Chris@1115 1066 assert !avatar('jsmith <jsmith@somenet.foo>', :class => 'picture').include?('class="gravatar"')
Chris@1115 1067 assert_nil avatar('jsmith')
Chris@1115 1068 assert_nil avatar(nil)
Chris@1115 1069 end
Chris@1115 1070 end
Chris@441 1071
Chris@1115 1072 def test_avatar_disabled
Chris@1115 1073 with_settings :gravatar_enabled => '0' do
Chris@1115 1074 assert_equal '', avatar(User.find_by_mail('jsmith@somenet.foo'))
Chris@1115 1075 end
Chris@0 1076 end
Chris@441 1077
Chris@0 1078 def test_link_to_user
Chris@0 1079 user = User.find(2)
Chris@1115 1080 assert_equal '<a href="/users/2" class="user active">John Smith</a>', link_to_user(user)
Chris@0 1081 end
Chris@441 1082
Chris@0 1083 def test_link_to_user_should_not_link_to_locked_user
Chris@1115 1084 with_current_user nil do
Chris@1115 1085 user = User.find(5)
Chris@1115 1086 assert user.locked?
Chris@1115 1087 assert_equal 'Dave2 Lopper2', link_to_user(user)
Chris@1115 1088 end
Chris@1115 1089 end
Chris@1115 1090
Chris@1115 1091 def test_link_to_user_should_link_to_locked_user_if_current_user_is_admin
Chris@1115 1092 with_current_user User.find(1) do
Chris@1115 1093 user = User.find(5)
Chris@1115 1094 assert user.locked?
Chris@1115 1095 assert_equal '<a href="/users/5" class="user locked">Dave2 Lopper2</a>', link_to_user(user)
Chris@1115 1096 end
Chris@0 1097 end
Chris@441 1098
Chris@0 1099 def test_link_to_user_should_not_link_to_anonymous
Chris@0 1100 user = User.anonymous
Chris@0 1101 assert user.anonymous?
Chris@0 1102 t = link_to_user(user)
Chris@0 1103 assert_equal ::I18n.t(:label_user_anonymous), t
Chris@0 1104 end
Chris@14 1105
Chris@1464 1106 def test_link_to_attachment
Chris@1464 1107 a = Attachment.find(3)
Chris@1464 1108 assert_equal '<a href="/attachments/3/logo.gif">logo.gif</a>',
Chris@1464 1109 link_to_attachment(a)
Chris@1464 1110 assert_equal '<a href="/attachments/3/logo.gif">Text</a>',
Chris@1464 1111 link_to_attachment(a, :text => 'Text')
Chris@1464 1112 assert_equal '<a href="/attachments/3/logo.gif" class="foo">logo.gif</a>',
Chris@1464 1113 link_to_attachment(a, :class => 'foo')
Chris@1464 1114 assert_equal '<a href="/attachments/download/3/logo.gif">logo.gif</a>',
Chris@1464 1115 link_to_attachment(a, :download => true)
Chris@1464 1116 assert_equal '<a href="http://test.host/attachments/3/logo.gif">logo.gif</a>',
Chris@1464 1117 link_to_attachment(a, :only_path => false)
Chris@1464 1118 end
Chris@1464 1119
Chris@1464 1120 def test_thumbnail_tag
Chris@1464 1121 a = Attachment.find(3)
Chris@1464 1122 assert_equal '<a href="/attachments/3/logo.gif" title="logo.gif"><img alt="3" src="/attachments/thumbnail/3" /></a>',
Chris@1464 1123 thumbnail_tag(a)
Chris@1464 1124 end
Chris@1464 1125
Chris@14 1126 def test_link_to_project
Chris@14 1127 project = Project.find(1)
Chris@14 1128 assert_equal %(<a href="/projects/ecookbook">eCookbook</a>),
Chris@14 1129 link_to_project(project)
Chris@14 1130 assert_equal %(<a href="/projects/ecookbook/settings">eCookbook</a>),
Chris@14 1131 link_to_project(project, :action => 'settings')
Chris@14 1132 assert_equal %(<a href="http://test.host/projects/ecookbook?jump=blah">eCookbook</a>),
Chris@14 1133 link_to_project(project, {:only_path => false, :jump => 'blah'})
Chris@14 1134 assert_equal %(<a href="/projects/ecookbook/settings" class="project">eCookbook</a>),
Chris@14 1135 link_to_project(project, {:action => 'settings'}, :class => "project")
Chris@14 1136 end
Chris@909 1137
Chris@1464 1138 def test_link_to_project_settings
Chris@1464 1139 project = Project.find(1)
Chris@1464 1140 assert_equal '<a href="/projects/ecookbook/settings">eCookbook</a>', link_to_project_settings(project)
Chris@1464 1141
Chris@1464 1142 project.status = Project::STATUS_CLOSED
Chris@1464 1143 assert_equal '<a href="/projects/ecookbook">eCookbook</a>', link_to_project_settings(project)
Chris@1464 1144
Chris@1464 1145 project.status = Project::STATUS_ARCHIVED
Chris@1464 1146 assert_equal 'eCookbook', link_to_project_settings(project)
Chris@1464 1147 end
Chris@1464 1148
Chris@929 1149 def test_link_to_legacy_project_with_numerical_identifier_should_use_id
Chris@929 1150 # numeric identifier are no longer allowed
Chris@929 1151 Project.update_all "identifier=25", "id=1"
Chris@929 1152
Chris@929 1153 assert_equal '<a href="/projects/1">eCookbook</a>',
Chris@929 1154 link_to_project(Project.find(1))
Chris@929 1155 end
Chris@929 1156
Chris@909 1157 def test_principals_options_for_select_with_users
Chris@1115 1158 User.current = nil
Chris@909 1159 users = [User.find(2), User.find(4)]
Chris@909 1160 assert_equal %(<option value="2">John Smith</option><option value="4">Robert Hill</option>),
Chris@909 1161 principals_options_for_select(users)
Chris@909 1162 end
Chris@909 1163
Chris@909 1164 def test_principals_options_for_select_with_selected
Chris@1115 1165 User.current = nil
Chris@909 1166 users = [User.find(2), User.find(4)]
Chris@909 1167 assert_equal %(<option value="2">John Smith</option><option value="4" selected="selected">Robert Hill</option>),
Chris@909 1168 principals_options_for_select(users, User.find(4))
Chris@909 1169 end
Chris@909 1170
Chris@909 1171 def test_principals_options_for_select_with_users_and_groups
Chris@1115 1172 User.current = nil
Chris@909 1173 users = [User.find(2), Group.find(11), User.find(4), Group.find(10)]
Chris@909 1174 assert_equal %(<option value="2">John Smith</option><option value="4">Robert Hill</option>) +
Chris@909 1175 %(<optgroup label="Groups"><option value="10">A Team</option><option value="11">B Team</option></optgroup>),
Chris@909 1176 principals_options_for_select(users)
Chris@909 1177 end
Chris@909 1178
Chris@909 1179 def test_principals_options_for_select_with_empty_collection
Chris@909 1180 assert_equal '', principals_options_for_select([])
Chris@909 1181 end
Chris@1115 1182
Chris@1115 1183 def test_principals_options_for_select_should_include_me_option_when_current_user_is_in_collection
Chris@1115 1184 users = [User.find(2), User.find(4)]
Chris@1115 1185 User.current = User.find(4)
Chris@1115 1186 assert_include '<option value="4">&lt;&lt; me &gt;&gt;</option>', principals_options_for_select(users)
Chris@1115 1187 end
Chris@1115 1188
Chris@1115 1189 def test_stylesheet_link_tag_should_pick_the_default_stylesheet
Chris@1115 1190 assert_match 'href="/stylesheets/styles.css"', stylesheet_link_tag("styles")
Chris@1115 1191 end
Chris@1115 1192
Chris@1115 1193 def test_stylesheet_link_tag_for_plugin_should_pick_the_plugin_stylesheet
Chris@1115 1194 assert_match 'href="/plugin_assets/foo/stylesheets/styles.css"', stylesheet_link_tag("styles", :plugin => :foo)
Chris@1115 1195 end
Chris@1115 1196
Chris@1115 1197 def test_image_tag_should_pick_the_default_image
Chris@1115 1198 assert_match 'src="/images/image.png"', image_tag("image.png")
Chris@1115 1199 end
Chris@1115 1200
Chris@1115 1201 def test_image_tag_should_pick_the_theme_image_if_it_exists
Chris@1115 1202 theme = Redmine::Themes.themes.last
Chris@1115 1203 theme.images << 'image.png'
Chris@1115 1204
Chris@1115 1205 with_settings :ui_theme => theme.id do
Chris@1115 1206 assert_match %|src="/themes/#{theme.dir}/images/image.png"|, image_tag("image.png")
Chris@1115 1207 assert_match %|src="/images/other.png"|, image_tag("other.png")
Chris@1115 1208 end
Chris@1115 1209 ensure
Chris@1115 1210 theme.images.delete 'image.png'
Chris@1115 1211 end
Chris@1115 1212
Chris@1115 1213 def test_image_tag_sfor_plugin_should_pick_the_plugin_image
Chris@1115 1214 assert_match 'src="/plugin_assets/foo/images/image.png"', image_tag("image.png", :plugin => :foo)
Chris@1115 1215 end
Chris@1115 1216
Chris@1115 1217 def test_javascript_include_tag_should_pick_the_default_javascript
Chris@1115 1218 assert_match 'src="/javascripts/scripts.js"', javascript_include_tag("scripts")
Chris@1115 1219 end
Chris@1115 1220
Chris@1115 1221 def test_javascript_include_tag_for_plugin_should_pick_the_plugin_javascript
Chris@1115 1222 assert_match 'src="/plugin_assets/foo/javascripts/scripts.js"', javascript_include_tag("scripts", :plugin => :foo)
Chris@1115 1223 end
Chris@1115 1224
Chris@1464 1225 def test_raw_json_should_escape_closing_tags
Chris@1464 1226 s = raw_json(["<foo>bar</foo>"])
Chris@1464 1227 assert_equal '["<foo>bar<\/foo>"]', s
Chris@1464 1228 end
Chris@1115 1229
Chris@1464 1230 def test_raw_json_should_be_html_safe
Chris@1464 1231 s = raw_json(["foo"])
Chris@1464 1232 assert s.html_safe?
Chris@1464 1233 end
Chris@1464 1234
Chris@1464 1235 def test_html_title_should_app_title_if_not_set
Chris@1464 1236 assert_equal 'Redmine', html_title
Chris@1464 1237 end
Chris@1464 1238
Chris@1464 1239 def test_html_title_should_join_items
Chris@1464 1240 html_title 'Foo', 'Bar'
Chris@1464 1241 assert_equal 'Foo - Bar - Redmine', html_title
Chris@1464 1242 end
Chris@1464 1243
Chris@1464 1244 def test_html_title_should_append_current_project_name
Chris@1464 1245 @project = Project.find(1)
Chris@1464 1246 html_title 'Foo', 'Bar'
Chris@1464 1247 assert_equal 'Foo - Bar - eCookbook - Redmine', html_title
Chris@1464 1248 end
Chris@1464 1249
Chris@1464 1250 def test_title_should_return_a_h2_tag
Chris@1464 1251 assert_equal '<h2>Foo</h2>', title('Foo')
Chris@1464 1252 end
Chris@1464 1253
Chris@1464 1254 def test_title_should_set_html_title
Chris@1464 1255 title('Foo')
Chris@1464 1256 assert_equal 'Foo - Redmine', html_title
Chris@1464 1257 end
Chris@1464 1258
Chris@1464 1259 def test_title_should_turn_arrays_into_links
Chris@1464 1260 assert_equal '<h2><a href="/foo">Foo</a></h2>', title(['Foo', '/foo'])
Chris@1464 1261 assert_equal 'Foo - Redmine', html_title
Chris@1464 1262 end
Chris@1464 1263
Chris@1464 1264 def test_title_should_join_items
Chris@1464 1265 assert_equal '<h2>Foo &#187; Bar</h2>', title('Foo', 'Bar')
Chris@1464 1266 assert_equal 'Bar - Foo - Redmine', html_title
Chris@1115 1267 end
Chris@0 1268 end