annotate .svn/pristine/e0/e088e5d4b6c4b6c95679e610fde9533e4329854a.svn-base @ 1298:4f746d8966dd redmine_2.3_integration

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