annotate .svn/pristine/1a/1a8020fad87f2bec2c86c62dc30a6bf033a7c796.svn-base @ 1464:261b3d9a4903 redmine-2.4

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