annotate .svn/pristine/bb/bb26d7134db2daa8e385e20efdf915f60c0f95a4.svn-base @ 1477:f2ad2199b49a bibplugin_integration

Close obsolete branch bibplugin_integration
author Chris Cannam
date Fri, 30 Nov 2012 14:41:31 +0000
parents cbb26bc654de
children
rev   line source
Chris@909 1 # Redmine - project management software
Chris@909 2 # Copyright (C) 2006-2011 Jean-Philippe Lang
Chris@909 3 #
Chris@909 4 # This program is free software; you can redistribute it and/or
Chris@909 5 # modify it under the terms of the GNU General Public License
Chris@909 6 # as published by the Free Software Foundation; either version 2
Chris@909 7 # of the License, or (at your option) any later version.
Chris@909 8 #
Chris@909 9 # This program is distributed in the hope that it will be useful,
Chris@909 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@909 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@909 12 # GNU General Public License for more details.
Chris@909 13 #
Chris@909 14 # You should have received a copy of the GNU General Public License
Chris@909 15 # along with this program; if not, write to the Free Software
Chris@909 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@909 17
Chris@909 18 require File.expand_path('../../../test_helper', __FILE__)
Chris@909 19
Chris@909 20 class ApplicationHelperTest < ActionView::TestCase
Chris@909 21 fixtures :projects, :roles, :enabled_modules, :users,
Chris@909 22 :repositories, :changesets,
Chris@909 23 :trackers, :issue_statuses, :issues, :versions, :documents,
Chris@909 24 :wikis, :wiki_pages, :wiki_contents,
Chris@909 25 :boards, :messages, :news,
Chris@909 26 :attachments, :enumerations
Chris@909 27
Chris@909 28 def setup
Chris@909 29 super
Chris@909 30 set_tmp_attachments_directory
Chris@909 31 end
Chris@909 32
Chris@909 33 context "#link_to_if_authorized" do
Chris@909 34 context "authorized user" do
Chris@909 35 should "be tested"
Chris@909 36 end
Chris@909 37
Chris@909 38 context "unauthorized user" do
Chris@909 39 should "be tested"
Chris@909 40 end
Chris@909 41
Chris@909 42 should "allow using the :controller and :action for the target link" do
Chris@909 43 User.current = User.find_by_login('admin')
Chris@909 44
Chris@909 45 @project = Issue.first.project # Used by helper
Chris@909 46 response = link_to_if_authorized("By controller/action",
Chris@909 47 {:controller => 'issues', :action => 'edit', :id => Issue.first.id})
Chris@909 48 assert_match /href/, response
Chris@909 49 end
Chris@909 50
Chris@909 51 end
Chris@909 52
Chris@909 53 def test_auto_links
Chris@909 54 to_test = {
Chris@909 55 'http://foo.bar' => '<a class="external" href="http://foo.bar">http://foo.bar</a>',
Chris@909 56 'http://foo.bar/~user' => '<a class="external" href="http://foo.bar/~user">http://foo.bar/~user</a>',
Chris@909 57 'http://foo.bar.' => '<a class="external" href="http://foo.bar">http://foo.bar</a>.',
Chris@909 58 'https://foo.bar.' => '<a class="external" href="https://foo.bar">https://foo.bar</a>.',
Chris@909 59 'This is a link: http://foo.bar.' => 'This is a link: <a class="external" href="http://foo.bar">http://foo.bar</a>.',
Chris@909 60 'A link (eg. http://foo.bar).' => 'A link (eg. <a class="external" href="http://foo.bar">http://foo.bar</a>).',
Chris@909 61 '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@909 62 'http://www.foo.bar/Test_(foobar)' => '<a class="external" href="http://www.foo.bar/Test_(foobar)">http://www.foo.bar/Test_(foobar)</a>',
Chris@909 63 '(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@909 64 '(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@909 65 '(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@909 66 '(see "inline link":http://www.foo.bar/Test_(foobar))' => '(see <a href="http://www.foo.bar/Test_(foobar)" class="external">inline link</a>)',
Chris@909 67 '(see "inline link":http://www.foo.bar/Test)' => '(see <a href="http://www.foo.bar/Test" class="external">inline link</a>)',
Chris@909 68 '(see "inline link":http://www.foo.bar/Test).' => '(see <a href="http://www.foo.bar/Test" class="external">inline link</a>).',
Chris@909 69 'www.foo.bar' => '<a class="external" href="http://www.foo.bar">www.foo.bar</a>',
Chris@909 70 '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@909 71 'http://foo.bar/page#125' => '<a class="external" href="http://foo.bar/page#125">http://foo.bar/page#125</a>',
Chris@909 72 'http://foo@www.bar.com' => '<a class="external" href="http://foo@www.bar.com">http://foo@www.bar.com</a>',
Chris@909 73 'http://foo:bar@www.bar.com' => '<a class="external" href="http://foo:bar@www.bar.com">http://foo:bar@www.bar.com</a>',
Chris@909 74 'ftp://foo.bar' => '<a class="external" href="ftp://foo.bar">ftp://foo.bar</a>',
Chris@909 75 'ftps://foo.bar' => '<a class="external" href="ftps://foo.bar">ftps://foo.bar</a>',
Chris@909 76 'sftp://foo.bar' => '<a class="external" href="sftp://foo.bar">sftp://foo.bar</a>',
Chris@909 77 # two exclamation marks
Chris@909 78 'http://example.net/path!602815048C7B5C20!302.html' => '<a class="external" href="http://example.net/path!602815048C7B5C20!302.html">http://example.net/path!602815048C7B5C20!302.html</a>',
Chris@909 79 # escaping
Chris@909 80 'http://foo"bar' => '<a class="external" href="http://foo&quot;bar">http://foo"bar</a>',
Chris@909 81 # wrap in angle brackets
Chris@909 82 '<http://foo.bar>' => '&lt;<a class="external" href="http://foo.bar">http://foo.bar</a>&gt;'
Chris@909 83 }
Chris@909 84 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
Chris@909 85 end
Chris@909 86
Chris@909 87 def test_auto_mailto
Chris@909 88 assert_equal '<p><a class="email" href="mailto:test@foo.bar">test@foo.bar</a></p>',
Chris@909 89 textilizable('test@foo.bar')
Chris@909 90 end
Chris@909 91
Chris@909 92 def test_inline_images
Chris@909 93 to_test = {
Chris@909 94 '!http://foo.bar/image.jpg!' => '<img src="http://foo.bar/image.jpg" alt="" />',
Chris@909 95 'floating !>http://foo.bar/image.jpg!' => 'floating <div style="float:right"><img src="http://foo.bar/image.jpg" alt="" /></div>',
Chris@909 96 'with class !(some-class)http://foo.bar/image.jpg!' => 'with class <img src="http://foo.bar/image.jpg" class="some-class" alt="" />',
Chris@909 97 # inline styles should be stripped
Chris@909 98 'with style !{width:100px;height100px}http://foo.bar/image.jpg!' => 'with style <img src="http://foo.bar/image.jpg" alt="" />',
Chris@909 99 'with title !http://foo.bar/image.jpg(This is a title)!' => 'with title <img src="http://foo.bar/image.jpg" title="This is a title" alt="This is a title" />',
Chris@909 100 'with title !http://foo.bar/image.jpg(This is a double-quoted "title")!' => 'with title <img src="http://foo.bar/image.jpg" title="This is a double-quoted &quot;title&quot;" alt="This is a double-quoted &quot;title&quot;" />',
Chris@909 101 }
Chris@909 102 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
Chris@909 103 end
Chris@909 104
Chris@909 105 def test_inline_images_inside_tags
Chris@909 106 raw = <<-RAW
Chris@909 107 h1. !foo.png! Heading
Chris@909 108
Chris@909 109 Centered image:
Chris@909 110
Chris@909 111 p=. !bar.gif!
Chris@909 112 RAW
Chris@909 113
Chris@909 114 assert textilizable(raw).include?('<img src="foo.png" alt="" />')
Chris@909 115 assert textilizable(raw).include?('<img src="bar.gif" alt="" />')
Chris@909 116 end
Chris@909 117
Chris@909 118 def test_attached_images
Chris@909 119 to_test = {
Chris@909 120 'Inline image: !logo.gif!' => 'Inline image: <img src="/attachments/download/3" title="This is a logo" alt="This is a logo" />',
Chris@909 121 'Inline image: !logo.GIF!' => 'Inline image: <img src="/attachments/download/3" title="This is a logo" alt="This is a logo" />',
Chris@909 122 'No match: !ogo.gif!' => 'No match: <img src="ogo.gif" alt="" />',
Chris@909 123 'No match: !ogo.GIF!' => 'No match: <img src="ogo.GIF" alt="" />',
Chris@909 124 # link image
Chris@909 125 '!logo.gif!:http://foo.bar/' => '<a href="http://foo.bar/"><img src="/attachments/download/3" title="This is a logo" alt="This is a logo" /></a>',
Chris@909 126 }
Chris@909 127 attachments = Attachment.find(:all)
Chris@909 128 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text, :attachments => attachments) }
Chris@909 129 end
Chris@909 130
Chris@909 131 def test_attached_images_filename_extension
Chris@909 132 set_tmp_attachments_directory
Chris@909 133 a1 = Attachment.new(
Chris@909 134 :container => Issue.find(1),
Chris@909 135 :file => mock_file_with_options({:original_filename => "testtest.JPG"}),
Chris@909 136 :author => User.find(1))
Chris@909 137 assert a1.save
Chris@909 138 assert_equal "testtest.JPG", a1.filename
Chris@909 139 assert_equal "image/jpeg", a1.content_type
Chris@909 140 assert a1.image?
Chris@909 141
Chris@909 142 a2 = Attachment.new(
Chris@909 143 :container => Issue.find(1),
Chris@909 144 :file => mock_file_with_options({:original_filename => "testtest.jpeg"}),
Chris@909 145 :author => User.find(1))
Chris@909 146 assert a2.save
Chris@909 147 assert_equal "testtest.jpeg", a2.filename
Chris@909 148 assert_equal "image/jpeg", a2.content_type
Chris@909 149 assert a2.image?
Chris@909 150
Chris@909 151 a3 = Attachment.new(
Chris@909 152 :container => Issue.find(1),
Chris@909 153 :file => mock_file_with_options({:original_filename => "testtest.JPE"}),
Chris@909 154 :author => User.find(1))
Chris@909 155 assert a3.save
Chris@909 156 assert_equal "testtest.JPE", a3.filename
Chris@909 157 assert_equal "image/jpeg", a3.content_type
Chris@909 158 assert a3.image?
Chris@909 159
Chris@909 160 a4 = Attachment.new(
Chris@909 161 :container => Issue.find(1),
Chris@909 162 :file => mock_file_with_options({:original_filename => "Testtest.BMP"}),
Chris@909 163 :author => User.find(1))
Chris@909 164 assert a4.save
Chris@909 165 assert_equal "Testtest.BMP", a4.filename
Chris@909 166 assert_equal "image/x-ms-bmp", a4.content_type
Chris@909 167 assert a4.image?
Chris@909 168
Chris@909 169 to_test = {
Chris@909 170 'Inline image: !testtest.jpg!' =>
Chris@909 171 'Inline image: <img src="/attachments/download/' + a1.id.to_s + '" alt="" />',
Chris@909 172 'Inline image: !testtest.jpeg!' =>
Chris@909 173 'Inline image: <img src="/attachments/download/' + a2.id.to_s + '" alt="" />',
Chris@909 174 'Inline image: !testtest.jpe!' =>
Chris@909 175 'Inline image: <img src="/attachments/download/' + a3.id.to_s + '" alt="" />',
Chris@909 176 'Inline image: !testtest.bmp!' =>
Chris@909 177 'Inline image: <img src="/attachments/download/' + a4.id.to_s + '" alt="" />',
Chris@909 178 }
Chris@909 179
Chris@909 180 attachments = [a1, a2, a3, a4]
Chris@909 181 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text, :attachments => attachments) }
Chris@909 182 end
Chris@909 183
Chris@909 184 def test_attached_images_should_read_later
Chris@909 185 Attachment.storage_path = "#{Rails.root}/test/fixtures/files"
Chris@909 186 a1 = Attachment.find(16)
Chris@909 187 assert_equal "testfile.png", a1.filename
Chris@909 188 assert a1.readable?
Chris@909 189 assert (! a1.visible?(User.anonymous))
Chris@909 190 assert a1.visible?(User.find(2))
Chris@909 191 a2 = Attachment.find(17)
Chris@909 192 assert_equal "testfile.PNG", a2.filename
Chris@909 193 assert a2.readable?
Chris@909 194 assert (! a2.visible?(User.anonymous))
Chris@909 195 assert a2.visible?(User.find(2))
Chris@909 196 assert a1.created_on < a2.created_on
Chris@909 197
Chris@909 198 to_test = {
Chris@909 199 'Inline image: !testfile.png!' =>
Chris@909 200 'Inline image: <img src="/attachments/download/' + a2.id.to_s + '" alt="" />',
Chris@909 201 'Inline image: !Testfile.PNG!' =>
Chris@909 202 'Inline image: <img src="/attachments/download/' + a2.id.to_s + '" alt="" />',
Chris@909 203 }
Chris@909 204 attachments = [a1, a2]
Chris@909 205 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text, :attachments => attachments) }
Chris@909 206 set_tmp_attachments_directory
Chris@909 207 end
Chris@909 208
Chris@909 209 def test_textile_external_links
Chris@909 210 to_test = {
Chris@909 211 'This is a "link":http://foo.bar' => 'This is a <a href="http://foo.bar" class="external">link</a>',
Chris@909 212 'This is an intern "link":/foo/bar' => 'This is an intern <a href="/foo/bar">link</a>',
Chris@909 213 '"link (Link title)":http://foo.bar' => '<a href="http://foo.bar" title="Link title" class="external">link</a>',
Chris@909 214 '"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@909 215 "This is not a \"Link\":\n\nAnother paragraph" => "This is not a \"Link\":</p>\n\n\n\t<p>Another paragraph",
Chris@909 216 # no multiline link text
Chris@909 217 "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@909 218 # mailto link
Chris@909 219 "\"system administrator\":mailto:sysadmin@example.com?subject=redmine%20permissions" => "<a href=\"mailto:sysadmin@example.com?subject=redmine%20permissions\">system administrator</a>",
Chris@909 220 # two exclamation marks
Chris@909 221 '"a link":http://example.net/path!602815048C7B5C20!302.html' => '<a href="http://example.net/path!602815048C7B5C20!302.html" class="external">a link</a>',
Chris@909 222 # escaping
Chris@909 223 '"test":http://foo"bar' => '<a href="http://foo&quot;bar" class="external">test</a>',
Chris@909 224 }
Chris@909 225 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
Chris@909 226 end
Chris@909 227
Chris@909 228 def test_redmine_links
Chris@909 229 issue_link = link_to('#3', {:controller => 'issues', :action => 'show', :id => 3},
Chris@909 230 :class => 'issue status-1 priority-1 overdue', :title => 'Error 281 when updating a recipe (New)')
Chris@909 231
Chris@909 232 changeset_link = link_to('r1', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 1},
Chris@909 233 :class => 'changeset', :title => 'My very first commit')
Chris@909 234 changeset_link2 = link_to('r2', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 2},
Chris@909 235 :class => 'changeset', :title => 'This commit fixes #1, #2 and references #1 & #3')
Chris@909 236
Chris@909 237 document_link = link_to('Test document', {:controller => 'documents', :action => 'show', :id => 1},
Chris@909 238 :class => 'document')
Chris@909 239
Chris@909 240 version_link = link_to('1.0', {:controller => 'versions', :action => 'show', :id => 2},
Chris@909 241 :class => 'version')
Chris@909 242
Chris@909 243 board_url = {:controller => 'boards', :action => 'show', :id => 2, :project_id => 'ecookbook'}
Chris@909 244
Chris@909 245 message_url = {:controller => 'messages', :action => 'show', :board_id => 1, :id => 4}
Chris@909 246
Chris@909 247 news_url = {:controller => 'news', :action => 'show', :id => 1}
Chris@909 248
Chris@909 249 project_url = {:controller => 'projects', :action => 'show', :id => 'subproject1'}
Chris@909 250
Chris@909 251 source_url = {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :path => ['some', 'file']}
Chris@909 252 source_url_with_ext = {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :path => ['some', 'file.ext']}
Chris@909 253
Chris@909 254 to_test = {
Chris@909 255 # tickets
Chris@909 256 '#3, [#3], (#3) and #3.' => "#{issue_link}, [#{issue_link}], (#{issue_link}) and #{issue_link}.",
Chris@909 257 # changesets
Chris@909 258 'r1' => changeset_link,
Chris@909 259 'r1.' => "#{changeset_link}.",
Chris@909 260 'r1, r2' => "#{changeset_link}, #{changeset_link2}",
Chris@909 261 'r1,r2' => "#{changeset_link},#{changeset_link2}",
Chris@909 262 # documents
Chris@909 263 'document#1' => document_link,
Chris@909 264 'document:"Test document"' => document_link,
Chris@909 265 # versions
Chris@909 266 'version#2' => version_link,
Chris@909 267 'version:1.0' => version_link,
Chris@909 268 'version:"1.0"' => version_link,
Chris@909 269 # source
Chris@909 270 'source:/some/file' => link_to('source:/some/file', source_url, :class => 'source'),
Chris@909 271 'source:/some/file.' => link_to('source:/some/file', source_url, :class => 'source') + ".",
Chris@909 272 'source:/some/file.ext.' => link_to('source:/some/file.ext', source_url_with_ext, :class => 'source') + ".",
Chris@909 273 'source:/some/file. ' => link_to('source:/some/file', source_url, :class => 'source') + ".",
Chris@909 274 'source:/some/file.ext. ' => link_to('source:/some/file.ext', source_url_with_ext, :class => 'source') + ".",
Chris@909 275 'source:/some/file, ' => link_to('source:/some/file', source_url, :class => 'source') + ",",
Chris@909 276 'source:/some/file@52' => link_to('source:/some/file@52', source_url.merge(:rev => 52), :class => 'source'),
Chris@909 277 'source:/some/file.ext@52' => link_to('source:/some/file.ext@52', source_url_with_ext.merge(:rev => 52), :class => 'source'),
Chris@909 278 'source:/some/file#L110' => link_to('source:/some/file#L110', source_url.merge(:anchor => 'L110'), :class => 'source'),
Chris@909 279 'source:/some/file.ext#L110' => link_to('source:/some/file.ext#L110', source_url_with_ext.merge(:anchor => 'L110'), :class => 'source'),
Chris@909 280 'source:/some/file@52#L110' => link_to('source:/some/file@52#L110', source_url.merge(:rev => 52, :anchor => 'L110'), :class => 'source'),
Chris@909 281 'export:/some/file' => link_to('export:/some/file', source_url.merge(:format => 'raw'), :class => 'source download'),
Chris@909 282 # forum
Chris@909 283 'forum#2' => link_to('Discussion', board_url, :class => 'board'),
Chris@909 284 'forum:Discussion' => link_to('Discussion', board_url, :class => 'board'),
Chris@909 285 # message
Chris@909 286 'message#4' => link_to('Post 2', message_url, :class => 'message'),
Chris@909 287 'message#5' => link_to('RE: post 2', message_url.merge(:anchor => 'message-5', :r => 5), :class => 'message'),
Chris@909 288 # news
Chris@909 289 'news#1' => link_to('eCookbook first release !', news_url, :class => 'news'),
Chris@909 290 'news:"eCookbook first release !"' => link_to('eCookbook first release !', news_url, :class => 'news'),
Chris@909 291 # project
Chris@909 292 'project#3' => link_to('eCookbook Subproject 1', project_url, :class => 'project'),
Chris@909 293 'project:subproject1' => link_to('eCookbook Subproject 1', project_url, :class => 'project'),
Chris@909 294 'project:"eCookbook subProject 1"' => link_to('eCookbook Subproject 1', project_url, :class => 'project'),
Chris@909 295 # escaping
Chris@909 296 '!#3.' => '#3.',
Chris@909 297 '!r1' => 'r1',
Chris@909 298 '!document#1' => 'document#1',
Chris@909 299 '!document:"Test document"' => 'document:"Test document"',
Chris@909 300 '!version#2' => 'version#2',
Chris@909 301 '!version:1.0' => 'version:1.0',
Chris@909 302 '!version:"1.0"' => 'version:"1.0"',
Chris@909 303 '!source:/some/file' => 'source:/some/file',
Chris@909 304 # not found
Chris@909 305 '#0123456789' => '#0123456789',
Chris@909 306 # invalid expressions
Chris@909 307 'source:' => 'source:',
Chris@909 308 # url hash
Chris@909 309 "http://foo.bar/FAQ#3" => '<a class="external" href="http://foo.bar/FAQ#3">http://foo.bar/FAQ#3</a>',
Chris@909 310 }
Chris@909 311 @project = Project.find(1)
Chris@909 312 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text), "#{text} failed" }
Chris@909 313 end
Chris@909 314
Chris@909 315 def test_cross_project_redmine_links
Chris@909 316 source_link = link_to('ecookbook:source:/some/file', {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :path => ['some', 'file']},
Chris@909 317 :class => 'source')
Chris@909 318
Chris@909 319 changeset_link = link_to('ecookbook:r2', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 2},
Chris@909 320 :class => 'changeset', :title => 'This commit fixes #1, #2 and references #1 & #3')
Chris@909 321
Chris@909 322 to_test = {
Chris@909 323 # documents
Chris@909 324 'document:"Test document"' => 'document:"Test document"',
Chris@909 325 'ecookbook:document:"Test document"' => '<a href="/documents/1" class="document">Test document</a>',
Chris@909 326 'invalid:document:"Test document"' => 'invalid:document:"Test document"',
Chris@909 327 # versions
Chris@909 328 'version:"1.0"' => 'version:"1.0"',
Chris@909 329 'ecookbook:version:"1.0"' => '<a href="/versions/2" class="version">1.0</a>',
Chris@909 330 'invalid:version:"1.0"' => 'invalid:version:"1.0"',
Chris@909 331 # changeset
Chris@909 332 'r2' => 'r2',
Chris@909 333 'ecookbook:r2' => changeset_link,
Chris@909 334 'invalid:r2' => 'invalid:r2',
Chris@909 335 # source
Chris@909 336 'source:/some/file' => 'source:/some/file',
Chris@909 337 'ecookbook:source:/some/file' => source_link,
Chris@909 338 'invalid:source:/some/file' => 'invalid:source:/some/file',
Chris@909 339 }
Chris@909 340 @project = Project.find(3)
Chris@909 341 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text), "#{text} failed" }
Chris@909 342 end
Chris@909 343
Chris@909 344 def test_redmine_links_git_commit
Chris@909 345 changeset_link = link_to('abcd',
Chris@909 346 {
Chris@909 347 :controller => 'repositories',
Chris@909 348 :action => 'revision',
Chris@909 349 :id => 'subproject1',
Chris@909 350 :rev => 'abcd',
Chris@909 351 },
Chris@909 352 :class => 'changeset', :title => 'test commit')
Chris@909 353 to_test = {
Chris@909 354 'commit:abcd' => changeset_link,
Chris@909 355 }
Chris@909 356 @project = Project.find(3)
Chris@909 357 r = Repository::Git.create!(:project => @project, :url => '/tmp/test/git')
Chris@909 358 assert r
Chris@909 359 c = Changeset.new(:repository => r,
Chris@909 360 :committed_on => Time.now,
Chris@909 361 :revision => 'abcd',
Chris@909 362 :scmid => 'abcd',
Chris@909 363 :comments => 'test commit')
Chris@909 364 assert( c.save )
Chris@909 365 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
Chris@909 366 end
Chris@909 367
Chris@909 368 # TODO: Bazaar commit id contains mail address, so it contains '@' and '_'.
Chris@909 369 def test_redmine_links_darcs_commit
Chris@909 370 changeset_link = link_to('20080308225258-98289-abcd456efg.gz',
Chris@909 371 {
Chris@909 372 :controller => 'repositories',
Chris@909 373 :action => 'revision',
Chris@909 374 :id => 'subproject1',
Chris@909 375 :rev => '123',
Chris@909 376 },
Chris@909 377 :class => 'changeset', :title => 'test commit')
Chris@909 378 to_test = {
Chris@909 379 'commit:20080308225258-98289-abcd456efg.gz' => changeset_link,
Chris@909 380 }
Chris@909 381 @project = Project.find(3)
Chris@909 382 r = Repository::Darcs.create!(
Chris@909 383 :project => @project, :url => '/tmp/test/darcs',
Chris@909 384 :log_encoding => 'UTF-8')
Chris@909 385 assert r
Chris@909 386 c = Changeset.new(:repository => r,
Chris@909 387 :committed_on => Time.now,
Chris@909 388 :revision => '123',
Chris@909 389 :scmid => '20080308225258-98289-abcd456efg.gz',
Chris@909 390 :comments => 'test commit')
Chris@909 391 assert( c.save )
Chris@909 392 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
Chris@909 393 end
Chris@909 394
Chris@909 395 def test_redmine_links_mercurial_commit
Chris@909 396 changeset_link_rev = link_to('r123',
Chris@909 397 {
Chris@909 398 :controller => 'repositories',
Chris@909 399 :action => 'revision',
Chris@909 400 :id => 'subproject1',
Chris@909 401 :rev => '123' ,
Chris@909 402 },
Chris@909 403 :class => 'changeset', :title => 'test commit')
Chris@909 404 changeset_link_commit = link_to('abcd',
Chris@909 405 {
Chris@909 406 :controller => 'repositories',
Chris@909 407 :action => 'revision',
Chris@909 408 :id => 'subproject1',
Chris@909 409 :rev => 'abcd' ,
Chris@909 410 },
Chris@909 411 :class => 'changeset', :title => 'test commit')
Chris@909 412 to_test = {
Chris@909 413 'r123' => changeset_link_rev,
Chris@909 414 'commit:abcd' => changeset_link_commit,
Chris@909 415 }
Chris@909 416 @project = Project.find(3)
Chris@909 417 r = Repository::Mercurial.create!(:project => @project, :url => '/tmp/test')
Chris@909 418 assert r
Chris@909 419 c = Changeset.new(:repository => r,
Chris@909 420 :committed_on => Time.now,
Chris@909 421 :revision => '123',
Chris@909 422 :scmid => 'abcd',
Chris@909 423 :comments => 'test commit')
Chris@909 424 assert( c.save )
Chris@909 425 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
Chris@909 426 end
Chris@909 427
Chris@909 428 def test_attachment_links
Chris@909 429 attachment_link = link_to('error281.txt', {:controller => 'attachments', :action => 'download', :id => '1'}, :class => 'attachment')
Chris@909 430 to_test = {
Chris@909 431 'attachment:error281.txt' => attachment_link
Chris@909 432 }
Chris@909 433 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text, :attachments => Issue.find(3).attachments), "#{text} failed" }
Chris@909 434 end
Chris@909 435
Chris@909 436 def test_wiki_links
Chris@909 437 to_test = {
Chris@909 438 '[[CookBook documentation]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation" class="wiki-page">CookBook documentation</a>',
Chris@909 439 '[[Another page|Page]]' => '<a href="/projects/ecookbook/wiki/Another_page" class="wiki-page">Page</a>',
Chris@909 440 # title content should be formatted
Chris@909 441 '[[Another page|With _styled_ *title*]]' => '<a href="/projects/ecookbook/wiki/Another_page" class="wiki-page">With <em>styled</em> <strong>title</strong></a>',
Chris@909 442 '[[Another page|With title containing <strong>HTML entities &amp; markups</strong>]]' => '<a href="/projects/ecookbook/wiki/Another_page" class="wiki-page">With title containing &lt;strong&gt;HTML entities &amp; markups&lt;/strong&gt;</a>',
Chris@909 443 # link with anchor
Chris@909 444 '[[CookBook documentation#One-section]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation#One-section" class="wiki-page">CookBook documentation</a>',
Chris@909 445 '[[Another page#anchor|Page]]' => '<a href="/projects/ecookbook/wiki/Another_page#anchor" class="wiki-page">Page</a>',
Chris@909 446 # page that doesn't exist
Chris@909 447 '[[Unknown page]]' => '<a href="/projects/ecookbook/wiki/Unknown_page" class="wiki-page new">Unknown page</a>',
Chris@909 448 '[[Unknown page|404]]' => '<a href="/projects/ecookbook/wiki/Unknown_page" class="wiki-page new">404</a>',
Chris@909 449 # link to another project wiki
Chris@909 450 '[[onlinestore:]]' => '<a href="/projects/onlinestore/wiki" class="wiki-page">onlinestore</a>',
Chris@909 451 '[[onlinestore:|Wiki]]' => '<a href="/projects/onlinestore/wiki" class="wiki-page">Wiki</a>',
Chris@909 452 '[[onlinestore:Start page]]' => '<a href="/projects/onlinestore/wiki/Start_page" class="wiki-page">Start page</a>',
Chris@909 453 '[[onlinestore:Start page|Text]]' => '<a href="/projects/onlinestore/wiki/Start_page" class="wiki-page">Text</a>',
Chris@909 454 '[[onlinestore:Unknown page]]' => '<a href="/projects/onlinestore/wiki/Unknown_page" class="wiki-page new">Unknown page</a>',
Chris@909 455 # striked through link
Chris@909 456 '-[[Another page|Page]]-' => '<del><a href="/projects/ecookbook/wiki/Another_page" class="wiki-page">Page</a></del>',
Chris@909 457 '-[[Another page|Page]] link-' => '<del><a href="/projects/ecookbook/wiki/Another_page" class="wiki-page">Page</a> link</del>',
Chris@909 458 # escaping
Chris@909 459 '![[Another page|Page]]' => '[[Another page|Page]]',
Chris@909 460 # project does not exist
Chris@909 461 '[[unknowproject:Start]]' => '[[unknowproject:Start]]',
Chris@909 462 '[[unknowproject:Start|Page title]]' => '[[unknowproject:Start|Page title]]',
Chris@909 463 }
Chris@909 464
Chris@909 465 @project = Project.find(1)
Chris@909 466 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
Chris@909 467 end
Chris@909 468
Chris@909 469 def test_wiki_links_within_local_file_generation_context
Chris@909 470
Chris@909 471 to_test = {
Chris@909 472 # link to a page
Chris@909 473 '[[CookBook documentation]]' => '<a href="CookBook_documentation.html" class="wiki-page">CookBook documentation</a>',
Chris@909 474 '[[CookBook documentation|documentation]]' => '<a href="CookBook_documentation.html" class="wiki-page">documentation</a>',
Chris@909 475 '[[CookBook documentation#One-section]]' => '<a href="CookBook_documentation.html#One-section" class="wiki-page">CookBook documentation</a>',
Chris@909 476 '[[CookBook documentation#One-section|documentation]]' => '<a href="CookBook_documentation.html#One-section" class="wiki-page">documentation</a>',
Chris@909 477 # page that doesn't exist
Chris@909 478 '[[Unknown page]]' => '<a href="Unknown_page.html" class="wiki-page new">Unknown page</a>',
Chris@909 479 '[[Unknown page|404]]' => '<a href="Unknown_page.html" class="wiki-page new">404</a>',
Chris@909 480 '[[Unknown page#anchor]]' => '<a href="Unknown_page.html#anchor" class="wiki-page new">Unknown page</a>',
Chris@909 481 '[[Unknown page#anchor|404]]' => '<a href="Unknown_page.html#anchor" class="wiki-page new">404</a>',
Chris@909 482 }
Chris@909 483
Chris@909 484 @project = Project.find(1)
Chris@909 485
Chris@909 486 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text, :wiki_links => :local) }
Chris@909 487 end
Chris@909 488
Chris@909 489 def test_html_tags
Chris@909 490 to_test = {
Chris@909 491 "<div>content</div>" => "<p>&lt;div&gt;content&lt;/div&gt;</p>",
Chris@909 492 "<div class=\"bold\">content</div>" => "<p>&lt;div class=\"bold\"&gt;content&lt;/div&gt;</p>",
Chris@909 493 "<script>some script;</script>" => "<p>&lt;script&gt;some script;&lt;/script&gt;</p>",
Chris@909 494 # do not escape pre/code tags
Chris@909 495 "<pre>\nline 1\nline2</pre>" => "<pre>\nline 1\nline2</pre>",
Chris@909 496 "<pre><code>\nline 1\nline2</code></pre>" => "<pre><code>\nline 1\nline2</code></pre>",
Chris@909 497 "<pre><div>content</div></pre>" => "<pre>&lt;div&gt;content&lt;/div&gt;</pre>",
Chris@909 498 "HTML comment: <!-- no comments -->" => "<p>HTML comment: &lt;!-- no comments --&gt;</p>",
Chris@909 499 "<!-- opening comment" => "<p>&lt;!-- opening comment</p>",
Chris@909 500 # remove attributes except class
Chris@909 501 "<pre class='foo'>some text</pre>" => "<pre class='foo'>some text</pre>",
Chris@909 502 '<pre class="foo">some text</pre>' => '<pre class="foo">some text</pre>',
Chris@909 503 "<pre class='foo bar'>some text</pre>" => "<pre class='foo bar'>some text</pre>",
Chris@909 504 '<pre class="foo bar">some text</pre>' => '<pre class="foo bar">some text</pre>',
Chris@909 505 "<pre onmouseover='alert(1)'>some text</pre>" => "<pre>some text</pre>",
Chris@909 506 # xss
Chris@909 507 '<pre><code class=""onmouseover="alert(1)">text</code></pre>' => '<pre><code>text</code></pre>',
Chris@909 508 '<pre class=""onmouseover="alert(1)">text</pre>' => '<pre>text</pre>',
Chris@909 509 }
Chris@909 510 to_test.each { |text, result| assert_equal result, textilizable(text) }
Chris@909 511 end
Chris@909 512
Chris@909 513 def test_allowed_html_tags
Chris@909 514 to_test = {
Chris@909 515 "<pre>preformatted text</pre>" => "<pre>preformatted text</pre>",
Chris@909 516 "<notextile>no *textile* formatting</notextile>" => "no *textile* formatting",
Chris@909 517 "<notextile>this is <tag>a tag</tag></notextile>" => "this is &lt;tag&gt;a tag&lt;/tag&gt;"
Chris@909 518 }
Chris@909 519 to_test.each { |text, result| assert_equal result, textilizable(text) }
Chris@909 520 end
Chris@909 521
Chris@909 522 def test_pre_tags
Chris@909 523 raw = <<-RAW
Chris@909 524 Before
Chris@909 525
Chris@909 526 <pre>
Chris@909 527 <prepared-statement-cache-size>32</prepared-statement-cache-size>
Chris@909 528 </pre>
Chris@909 529
Chris@909 530 After
Chris@909 531 RAW
Chris@909 532
Chris@909 533 expected = <<-EXPECTED
Chris@909 534 <p>Before</p>
Chris@909 535 <pre>
Chris@909 536 &lt;prepared-statement-cache-size&gt;32&lt;/prepared-statement-cache-size&gt;
Chris@909 537 </pre>
Chris@909 538 <p>After</p>
Chris@909 539 EXPECTED
Chris@909 540
Chris@909 541 assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '')
Chris@909 542 end
Chris@909 543
Chris@909 544 def test_pre_content_should_not_parse_wiki_and_redmine_links
Chris@909 545 raw = <<-RAW
Chris@909 546 [[CookBook documentation]]
Chris@909 547
Chris@909 548 #1
Chris@909 549
Chris@909 550 <pre>
Chris@909 551 [[CookBook documentation]]
Chris@909 552
Chris@909 553 #1
Chris@909 554 </pre>
Chris@909 555 RAW
Chris@909 556
Chris@909 557 expected = <<-EXPECTED
Chris@909 558 <p><a href="/projects/ecookbook/wiki/CookBook_documentation" class="wiki-page">CookBook documentation</a></p>
Chris@909 559 <p><a href="/issues/1" class="issue status-1 priority-1" title="Can't print recipes (New)">#1</a></p>
Chris@909 560 <pre>
Chris@909 561 [[CookBook documentation]]
Chris@909 562
Chris@909 563 #1
Chris@909 564 </pre>
Chris@909 565 EXPECTED
Chris@909 566
Chris@909 567 @project = Project.find(1)
Chris@909 568 assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '')
Chris@909 569 end
Chris@909 570
Chris@909 571 def test_non_closing_pre_blocks_should_be_closed
Chris@909 572 raw = <<-RAW
Chris@909 573 <pre><code>
Chris@909 574 RAW
Chris@909 575
Chris@909 576 expected = <<-EXPECTED
Chris@909 577 <pre><code>
Chris@909 578 </code></pre>
Chris@909 579 EXPECTED
Chris@909 580
Chris@909 581 @project = Project.find(1)
Chris@909 582 assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '')
Chris@909 583 end
Chris@909 584
Chris@909 585 def test_syntax_highlight
Chris@909 586 raw = <<-RAW
Chris@909 587 <pre><code class="ruby">
Chris@909 588 # Some ruby code here
Chris@909 589 </code></pre>
Chris@909 590 RAW
Chris@909 591
Chris@909 592 expected = <<-EXPECTED
Chris@909 593 <pre><code class="ruby syntaxhl"><span class=\"CodeRay\"><span class="line-numbers">1</span><span class="comment"># Some ruby code here</span></span>
Chris@909 594 </code></pre>
Chris@909 595 EXPECTED
Chris@909 596
Chris@909 597 assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '')
Chris@909 598 end
Chris@909 599
Chris@909 600 def test_wiki_links_in_tables
Chris@909 601 to_test = {"|[[Page|Link title]]|[[Other Page|Other title]]|\n|Cell 21|[[Last page]]|" =>
Chris@909 602 '<tr><td><a href="/projects/ecookbook/wiki/Page" class="wiki-page new">Link title</a></td>' +
Chris@909 603 '<td><a href="/projects/ecookbook/wiki/Other_Page" class="wiki-page new">Other title</a></td>' +
Chris@909 604 '</tr><tr><td>Cell 21</td><td><a href="/projects/ecookbook/wiki/Last_page" class="wiki-page new">Last page</a></td></tr>'
Chris@909 605 }
Chris@909 606 @project = Project.find(1)
Chris@909 607 to_test.each { |text, result| assert_equal "<table>#{result}</table>", textilizable(text).gsub(/[\t\n]/, '') }
Chris@909 608 end
Chris@909 609
Chris@909 610 def test_text_formatting
Chris@909 611 to_test = {'*_+bold, italic and underline+_*' => '<strong><em><ins>bold, italic and underline</ins></em></strong>',
Chris@909 612 '(_text within parentheses_)' => '(<em>text within parentheses</em>)',
Chris@909 613 'a *Humane Web* Text Generator' => 'a <strong>Humane Web</strong> Text Generator',
Chris@909 614 '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@909 615 '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@909 616 }
Chris@909 617 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
Chris@909 618 end
Chris@909 619
Chris@909 620 def test_wiki_horizontal_rule
Chris@909 621 assert_equal '<hr />', textilizable('---')
Chris@909 622 assert_equal '<p>Dashes: ---</p>', textilizable('Dashes: ---')
Chris@909 623 end
Chris@909 624
Chris@909 625 def test_footnotes
Chris@909 626 raw = <<-RAW
Chris@909 627 This is some text[1].
Chris@909 628
Chris@909 629 fn1. This is the foot note
Chris@909 630 RAW
Chris@909 631
Chris@909 632 expected = <<-EXPECTED
Chris@909 633 <p>This is some text<sup><a href=\"#fn1\">1</a></sup>.</p>
Chris@909 634 <p id="fn1" class="footnote"><sup>1</sup> This is the foot note</p>
Chris@909 635 EXPECTED
Chris@909 636
Chris@909 637 assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '')
Chris@909 638 end
Chris@909 639
Chris@909 640 def test_headings
Chris@909 641 raw = 'h1. Some heading'
Chris@909 642 expected = %|<a name="Some-heading"></a>\n<h1 >Some heading<a href="#Some-heading" class="wiki-anchor">&para;</a></h1>|
Chris@909 643
Chris@909 644 assert_equal expected, textilizable(raw)
Chris@909 645 end
Chris@909 646
Chris@909 647 def test_headings_with_special_chars
Chris@909 648 # This test makes sure that the generated anchor names match the expected
Chris@909 649 # ones even if the heading text contains unconventional characters
Chris@909 650 raw = 'h1. Some heading related to version 0.5'
Chris@909 651 anchor = sanitize_anchor_name("Some-heading-related-to-version-0.5")
Chris@909 652 expected = %|<a name="#{anchor}"></a>\n<h1 >Some heading related to version 0.5<a href="##{anchor}" class="wiki-anchor">&para;</a></h1>|
Chris@909 653
Chris@909 654 assert_equal expected, textilizable(raw)
Chris@909 655 end
Chris@909 656
Chris@909 657 def test_wiki_links_within_wiki_page_context
Chris@909 658
Chris@909 659 page = WikiPage.find_by_title('Another_page' )
Chris@909 660
Chris@909 661 to_test = {
Chris@909 662 # link to another page
Chris@909 663 '[[CookBook documentation]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation" class="wiki-page">CookBook documentation</a>',
Chris@909 664 '[[CookBook documentation|documentation]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation" class="wiki-page">documentation</a>',
Chris@909 665 '[[CookBook documentation#One-section]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation#One-section" class="wiki-page">CookBook documentation</a>',
Chris@909 666 '[[CookBook documentation#One-section|documentation]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation#One-section" class="wiki-page">documentation</a>',
Chris@909 667 # link to the current page
Chris@909 668 '[[Another page]]' => '<a href="/projects/ecookbook/wiki/Another_page" class="wiki-page">Another page</a>',
Chris@909 669 '[[Another page|Page]]' => '<a href="/projects/ecookbook/wiki/Another_page" class="wiki-page">Page</a>',
Chris@909 670 '[[Another page#anchor]]' => '<a href="#anchor" class="wiki-page">Another page</a>',
Chris@909 671 '[[Another page#anchor|Page]]' => '<a href="#anchor" class="wiki-page">Page</a>',
Chris@909 672 # page that doesn't exist
Chris@909 673 '[[Unknown page]]' => '<a href="/projects/ecookbook/wiki/Unknown_page" class="wiki-page new">Unknown page</a>',
Chris@909 674 '[[Unknown page|404]]' => '<a href="/projects/ecookbook/wiki/Unknown_page" class="wiki-page new">404</a>',
Chris@909 675 '[[Unknown page#anchor]]' => '<a href="/projects/ecookbook/wiki/Unknown_page#anchor" class="wiki-page new">Unknown page</a>',
Chris@909 676 '[[Unknown page#anchor|404]]' => '<a href="/projects/ecookbook/wiki/Unknown_page#anchor" class="wiki-page new">404</a>',
Chris@909 677 }
Chris@909 678
Chris@909 679 @project = Project.find(1)
Chris@909 680
Chris@909 681 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(WikiContent.generate!( :text => text, :page => page ), :text) }
Chris@909 682 end
Chris@909 683
Chris@909 684 def test_wiki_links_anchor_option_should_prepend_page_title_to_href
Chris@909 685
Chris@909 686 to_test = {
Chris@909 687 # link to a page
Chris@909 688 '[[CookBook documentation]]' => '<a href="#CookBook_documentation" class="wiki-page">CookBook documentation</a>',
Chris@909 689 '[[CookBook documentation|documentation]]' => '<a href="#CookBook_documentation" class="wiki-page">documentation</a>',
Chris@909 690 '[[CookBook documentation#One-section]]' => '<a href="#CookBook_documentation_One-section" class="wiki-page">CookBook documentation</a>',
Chris@909 691 '[[CookBook documentation#One-section|documentation]]' => '<a href="#CookBook_documentation_One-section" class="wiki-page">documentation</a>',
Chris@909 692 # page that doesn't exist
Chris@909 693 '[[Unknown page]]' => '<a href="#Unknown_page" class="wiki-page new">Unknown page</a>',
Chris@909 694 '[[Unknown page|404]]' => '<a href="#Unknown_page" class="wiki-page new">404</a>',
Chris@909 695 '[[Unknown page#anchor]]' => '<a href="#Unknown_page_anchor" class="wiki-page new">Unknown page</a>',
Chris@909 696 '[[Unknown page#anchor|404]]' => '<a href="#Unknown_page_anchor" class="wiki-page new">404</a>',
Chris@909 697 }
Chris@909 698
Chris@909 699 @project = Project.find(1)
Chris@909 700
Chris@909 701 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text, :wiki_links => :anchor) }
Chris@909 702 end
Chris@909 703
Chris@909 704 def test_headings_in_wiki_single_page_export_should_be_prepended_with_page_title
Chris@909 705 page = WikiPage.generate!( :title => 'Page Title' )
Chris@909 706 content = WikiContent.generate!( :text => 'h1. Some heading', :page => page )
Chris@909 707
Chris@909 708 expected = %|<a name="Page_Title_Some-heading"></a>\n<h1 >Some heading<a href="#Page_Title_Some-heading" class="wiki-anchor">&para;</a></h1>|
Chris@909 709
Chris@909 710 assert_equal expected, textilizable(content, :text, :wiki_links => :anchor )
Chris@909 711 end
Chris@909 712
Chris@909 713 def test_table_of_content
Chris@909 714 raw = <<-RAW
Chris@909 715 {{toc}}
Chris@909 716
Chris@909 717 h1. Title
Chris@909 718
Chris@909 719 Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas sed libero.
Chris@909 720
Chris@909 721 h2. Subtitle with a [[Wiki]] link
Chris@909 722
Chris@909 723 Nullam commodo metus accumsan nulla. Curabitur lobortis dui id dolor.
Chris@909 724
Chris@909 725 h2. Subtitle with [[Wiki|another Wiki]] link
Chris@909 726
Chris@909 727 h2. Subtitle with %{color:red}red text%
Chris@909 728
Chris@909 729 <pre>
Chris@909 730 some code
Chris@909 731 </pre>
Chris@909 732
Chris@909 733 h3. Subtitle with *some* _modifiers_
Chris@909 734
Chris@909 735 h1. Another title
Chris@909 736
Chris@909 737 h3. An "Internet link":http://www.redmine.org/ inside subtitle
Chris@909 738
Chris@909 739 h2. "Project Name !/attachments/1234/logo_small.gif! !/attachments/5678/logo_2.png!":/projects/projectname/issues
Chris@909 740
Chris@909 741 RAW
Chris@909 742
Chris@909 743 expected = '<ul class="toc">' +
Chris@909 744 '<li><a href="#Title">Title</a>' +
Chris@909 745 '<ul>' +
Chris@909 746 '<li><a href="#Subtitle-with-a-Wiki-link">Subtitle with a Wiki link</a></li>' +
Chris@909 747 '<li><a href="#Subtitle-with-another-Wiki-link">Subtitle with another Wiki link</a></li>' +
Chris@909 748 '<li><a href="#Subtitle-with-red-text">Subtitle with red text</a>' +
Chris@909 749 '<ul>' +
Chris@909 750 '<li><a href="#Subtitle-with-some-modifiers">Subtitle with some modifiers</a></li>' +
Chris@909 751 '</ul>' +
Chris@909 752 '</li>' +
Chris@909 753 '</ul>' +
Chris@909 754 '</li>' +
Chris@909 755 '<li><a href="#Another-title">Another title</a>' +
Chris@909 756 '<ul>' +
Chris@909 757 '<li>' +
Chris@909 758 '<ul>' +
Chris@909 759 '<li><a href="#An-Internet-link-inside-subtitle">An Internet link inside subtitle</a></li>' +
Chris@909 760 '</ul>' +
Chris@909 761 '</li>' +
Chris@909 762 '<li><a href="#Project-Name">Project Name</a></li>' +
Chris@909 763 '</ul>' +
Chris@909 764 '</li>' +
Chris@909 765 '</ul>'
Chris@909 766
Chris@909 767 @project = Project.find(1)
Chris@909 768 assert textilizable(raw).gsub("\n", "").include?(expected)
Chris@909 769 end
Chris@909 770
Chris@909 771 def test_table_of_content_should_contain_included_page_headings
Chris@909 772 raw = <<-RAW
Chris@909 773 {{toc}}
Chris@909 774
Chris@909 775 h1. Included
Chris@909 776
Chris@909 777 {{include(Child_1)}}
Chris@909 778 RAW
Chris@909 779
Chris@909 780 expected = '<ul class="toc">' +
Chris@909 781 '<li><a href="#Included">Included</a></li>' +
Chris@909 782 '<li><a href="#Child-page-1">Child page 1</a></li>' +
Chris@909 783 '</ul>'
Chris@909 784
Chris@909 785 @project = Project.find(1)
Chris@909 786 assert textilizable(raw).gsub("\n", "").include?(expected)
Chris@909 787 end
Chris@909 788
Chris@909 789 def test_default_formatter
Chris@909 790 Setting.text_formatting = 'unknown'
Chris@909 791 text = 'a *link*: http://www.example.net/'
Chris@909 792 assert_equal '<p>a *link*: <a href="http://www.example.net/">http://www.example.net/</a></p>', textilizable(text)
Chris@909 793 Setting.text_formatting = 'textile'
Chris@909 794 end
Chris@909 795
Chris@909 796 def test_due_date_distance_in_words
Chris@909 797 to_test = { Date.today => 'Due in 0 days',
Chris@909 798 Date.today + 1 => 'Due in 1 day',
Chris@909 799 Date.today + 100 => 'Due in about 3 months',
Chris@909 800 Date.today + 20000 => 'Due in over 54 years',
Chris@909 801 Date.today - 1 => '1 day late',
Chris@909 802 Date.today - 100 => 'about 3 months late',
Chris@909 803 Date.today - 20000 => 'over 54 years late',
Chris@909 804 }
Chris@909 805 ::I18n.locale = :en
Chris@909 806 to_test.each do |date, expected|
Chris@909 807 assert_equal expected, due_date_distance_in_words(date)
Chris@909 808 end
Chris@909 809 end
Chris@909 810
Chris@909 811 def test_avatar
Chris@909 812 # turn on avatars
Chris@909 813 Setting.gravatar_enabled = '1'
Chris@909 814 assert avatar(User.find_by_mail('jsmith@somenet.foo')).include?(Digest::MD5.hexdigest('jsmith@somenet.foo'))
Chris@909 815 assert avatar('jsmith <jsmith@somenet.foo>').include?(Digest::MD5.hexdigest('jsmith@somenet.foo'))
Chris@909 816 assert_nil avatar('jsmith')
Chris@909 817 assert_nil avatar(nil)
Chris@909 818
Chris@909 819 # turn off avatars
Chris@909 820 Setting.gravatar_enabled = '0'
Chris@909 821 assert_equal '', avatar(User.find_by_mail('jsmith@somenet.foo'))
Chris@909 822 end
Chris@909 823
Chris@909 824 def test_link_to_user
Chris@909 825 user = User.find(2)
Chris@909 826 t = link_to_user(user)
Chris@909 827 assert_equal "<a href=\"/users/2\">#{ user.name }</a>", t
Chris@909 828 end
Chris@909 829
Chris@909 830 def test_link_to_user_should_not_link_to_locked_user
Chris@909 831 user = User.find(5)
Chris@909 832 assert user.locked?
Chris@909 833 t = link_to_user(user)
Chris@909 834 assert_equal user.name, t
Chris@909 835 end
Chris@909 836
Chris@909 837 def test_link_to_user_should_not_link_to_anonymous
Chris@909 838 user = User.anonymous
Chris@909 839 assert user.anonymous?
Chris@909 840 t = link_to_user(user)
Chris@909 841 assert_equal ::I18n.t(:label_user_anonymous), t
Chris@909 842 end
Chris@909 843
Chris@909 844 def test_link_to_project
Chris@909 845 project = Project.find(1)
Chris@909 846 assert_equal %(<a href="/projects/ecookbook">eCookbook</a>),
Chris@909 847 link_to_project(project)
Chris@909 848 assert_equal %(<a href="/projects/ecookbook/settings">eCookbook</a>),
Chris@909 849 link_to_project(project, :action => 'settings')
Chris@909 850 assert_equal %(<a href="http://test.host/projects/ecookbook?jump=blah">eCookbook</a>),
Chris@909 851 link_to_project(project, {:only_path => false, :jump => 'blah'})
Chris@909 852 assert_equal %(<a href="/projects/ecookbook/settings" class="project">eCookbook</a>),
Chris@909 853 link_to_project(project, {:action => 'settings'}, :class => "project")
Chris@909 854 end
Chris@909 855
Chris@909 856 def test_principals_options_for_select_with_users
Chris@909 857 users = [User.find(2), User.find(4)]
Chris@909 858 assert_equal %(<option value="2">John Smith</option><option value="4">Robert Hill</option>),
Chris@909 859 principals_options_for_select(users)
Chris@909 860 end
Chris@909 861
Chris@909 862 def test_principals_options_for_select_with_selected
Chris@909 863 users = [User.find(2), User.find(4)]
Chris@909 864 assert_equal %(<option value="2">John Smith</option><option value="4" selected="selected">Robert Hill</option>),
Chris@909 865 principals_options_for_select(users, User.find(4))
Chris@909 866 end
Chris@909 867
Chris@909 868 def test_principals_options_for_select_with_users_and_groups
Chris@909 869 users = [User.find(2), Group.find(11), User.find(4), Group.find(10)]
Chris@909 870 assert_equal %(<option value="2">John Smith</option><option value="4">Robert Hill</option>) +
Chris@909 871 %(<optgroup label="Groups"><option value="10">A Team</option><option value="11">B Team</option></optgroup>),
Chris@909 872 principals_options_for_select(users)
Chris@909 873 end
Chris@909 874
Chris@909 875 def test_principals_options_for_select_with_empty_collection
Chris@909 876 assert_equal '', principals_options_for_select([])
Chris@909 877 end
Chris@909 878 end