annotate .svn/pristine/14/14b30558ff27714592e93e747cd5345cdd0c4589.svn-base @ 1327:287f201c2802 redmine-2.2-integration

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