Chris@1296: # encoding: utf-8
Chris@1296: #
Chris@1296: # Redmine - project management software
Chris@1296: # Copyright (C) 2006-2012 Jean-Philippe Lang
Chris@1296: #
Chris@1296: # This program is free software; you can redistribute it and/or
Chris@1296: # modify it under the terms of the GNU General Public License
Chris@1296: # as published by the Free Software Foundation; either version 2
Chris@1296: # of the License, or (at your option) any later version.
Chris@1296: #
Chris@1296: # This program is distributed in the hope that it will be useful,
Chris@1296: # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1296: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1296: # GNU General Public License for more details.
Chris@1296: #
Chris@1296: # You should have received a copy of the GNU General Public License
Chris@1296: # along with this program; if not, write to the Free Software
Chris@1296: # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1296:
Chris@1296: require File.expand_path('../../../test_helper', __FILE__)
Chris@1296:
Chris@1296: class ApplicationHelperTest < ActionView::TestCase
Chris@1296: include ERB::Util
Chris@1296:
Chris@1296: fixtures :projects, :roles, :enabled_modules, :users,
Chris@1296: :repositories, :changesets,
Chris@1296: :trackers, :issue_statuses, :issues, :versions, :documents,
Chris@1296: :wikis, :wiki_pages, :wiki_contents,
Chris@1296: :boards, :messages, :news,
Chris@1296: :attachments, :enumerations
Chris@1296:
Chris@1296: def setup
Chris@1296: super
Chris@1296: set_tmp_attachments_directory
Chris@1296: end
Chris@1296:
Chris@1296: context "#link_to_if_authorized" do
Chris@1296: context "authorized user" do
Chris@1296: should "be tested"
Chris@1296: end
Chris@1296:
Chris@1296: context "unauthorized user" do
Chris@1296: should "be tested"
Chris@1296: end
Chris@1296:
Chris@1296: should "allow using the :controller and :action for the target link" do
Chris@1296: User.current = User.find_by_login('admin')
Chris@1296:
Chris@1296: @project = Issue.first.project # Used by helper
Chris@1296: response = link_to_if_authorized("By controller/action",
Chris@1296: {:controller => 'issues', :action => 'edit', :id => Issue.first.id})
Chris@1296: assert_match /href/, response
Chris@1296: end
Chris@1296:
Chris@1296: end
Chris@1296:
Chris@1296: def test_auto_links
Chris@1296: to_test = {
Chris@1296: 'http://foo.bar' => 'http://foo.bar',
Chris@1296: 'http://foo.bar/~user' => 'http://foo.bar/~user',
Chris@1296: 'http://foo.bar.' => 'http://foo.bar.',
Chris@1296: 'https://foo.bar.' => 'https://foo.bar.',
Chris@1296: 'This is a link: http://foo.bar.' => 'This is a link: http://foo.bar.',
Chris@1296: 'A link (eg. http://foo.bar).' => 'A link (eg. http://foo.bar).',
Chris@1296: 'http://foo.bar/foo.bar#foo.bar.' => 'http://foo.bar/foo.bar#foo.bar.',
Chris@1296: 'http://www.foo.bar/Test_(foobar)' => 'http://www.foo.bar/Test_(foobar)',
Chris@1296: '(see inline link : http://www.foo.bar/Test_(foobar))' => '(see inline link : http://www.foo.bar/Test_(foobar))',
Chris@1296: '(see inline link : http://www.foo.bar/Test)' => '(see inline link : http://www.foo.bar/Test)',
Chris@1296: '(see inline link : http://www.foo.bar/Test).' => '(see inline link : http://www.foo.bar/Test).',
Chris@1296: '(see "inline link":http://www.foo.bar/Test_(foobar))' => '(see inline link)',
Chris@1296: '(see "inline link":http://www.foo.bar/Test)' => '(see inline link)',
Chris@1296: '(see "inline link":http://www.foo.bar/Test).' => '(see inline link).',
Chris@1296: 'www.foo.bar' => 'www.foo.bar',
Chris@1296: 'http://foo.bar/page?p=1&t=z&s=' => 'http://foo.bar/page?p=1&t=z&s=',
Chris@1296: 'http://foo.bar/page#125' => 'http://foo.bar/page#125',
Chris@1296: 'http://foo@www.bar.com' => 'http://foo@www.bar.com',
Chris@1296: 'http://foo:bar@www.bar.com' => 'http://foo:bar@www.bar.com',
Chris@1296: 'ftp://foo.bar' => 'ftp://foo.bar',
Chris@1296: 'ftps://foo.bar' => 'ftps://foo.bar',
Chris@1296: 'sftp://foo.bar' => 'sftp://foo.bar',
Chris@1296: # two exclamation marks
Chris@1296: 'http://example.net/path!602815048C7B5C20!302.html' => 'http://example.net/path!602815048C7B5C20!302.html',
Chris@1296: # escaping
Chris@1296: 'http://foo"bar' => 'http://foo"bar',
Chris@1296: # wrap in angle brackets
Chris@1296: ' #{result} #{result} #{result} #{result} #{result} #{result}',
Chris@1296: 'floating !>http://foo.bar/image.jpg!' => 'floating
',
Chris@1296: 'with style !{width:100px;height:100px}http://foo.bar/image.jpg!' => 'with style
',
Chris@1296: 'with title !http://foo.bar/image.jpg(This is a title)!' => 'with title
',
Chris@1296: 'with title !http://foo.bar/image.jpg(This is a double-quoted "title")!' => 'with title
',
Chris@1296: }
Chris@1296: to_test.each { |text, result| assert_equal "
')
Chris@1296: assert textilizable(raw).include?('
')
Chris@1296: end
Chris@1296:
Chris@1296: def test_attached_images
Chris@1296: to_test = {
Chris@1296: 'Inline image: !logo.gif!' => 'Inline image:
',
Chris@1296: 'Inline image: !logo.GIF!' => 'Inline image:
',
Chris@1296: 'No match: !ogo.gif!' => 'No match:
',
Chris@1296: 'No match: !ogo.GIF!' => 'No match:
',
Chris@1296: # link image
Chris@1296: '!logo.gif!:http://foo.bar/' => '
',
Chris@1296: }
Chris@1296: attachments = Attachment.find(:all)
Chris@1296: to_test.each { |text, result| assert_equal "
',
Chris@1296: 'Inline image: !testtest.jpeg!' =>
Chris@1296: 'Inline image:
',
Chris@1296: 'Inline image: !testtest.jpe!' =>
Chris@1296: 'Inline image:
',
Chris@1296: 'Inline image: !testtest.bmp!' =>
Chris@1296: 'Inline image:
',
Chris@1296: }
Chris@1296:
Chris@1296: attachments = [a1, a2, a3, a4]
Chris@1296: to_test.each { |text, result| assert_equal "
',
Chris@1296: 'Inline image: !Testfile.PNG!' =>
Chris@1296: 'Inline image:
',
Chris@1296: }
Chris@1296: attachments = [a1, a2]
Chris@1296: to_test.each { |text, result| assert_equal "
Another paragraph",
Chris@1296: # no multiline link text
Chris@1296: "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
and another on a second line\":test",
Chris@1296: # mailto link
Chris@1296: "\"system administrator\":mailto:sysadmin@example.com?subject=redmine%20permissions" => "system administrator",
Chris@1296: # two exclamation marks
Chris@1296: '"a link":http://example.net/path!602815048C7B5C20!302.html' => 'a link',
Chris@1296: # escaping
Chris@1296: '"test":http://foo"bar' => 'test',
Chris@1296: }
Chris@1296: to_test.each { |text, result| assert_equal "
#{result}
", textilizable(text) } Chris@1296: end Chris@1296: Chris@1296: if 'ruby'.respond_to?(:encoding) Chris@1296: def test_textile_external_links_with_non_ascii_characters Chris@1296: to_test = { Chris@1296: 'This is a "link":http://foo.bar/тест' => 'This is a link' Chris@1296: } Chris@1296: to_test.each { |text, result| assert_equal "#{result}
", textilizable(text) } Chris@1296: end Chris@1296: else Chris@1296: puts 'Skipping test_textile_external_links_with_non_ascii_characters, unsupported ruby version' Chris@1296: end Chris@1296: Chris@1296: def test_redmine_links Chris@1296: issue_link = link_to('#3', {:controller => 'issues', :action => 'show', :id => 3}, Chris@1296: :class => 'issue status-1 priority-4 priority-lowest overdue', :title => 'Error 281 when updating a recipe (New)') Chris@1296: note_link = link_to('#3', {:controller => 'issues', :action => 'show', :id => 3, :anchor => 'note-14'}, Chris@1296: :class => 'issue status-1 priority-4 priority-lowest overdue', :title => 'Error 281 when updating a recipe (New)') Chris@1296: Chris@1296: changeset_link = link_to('r1', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 1}, Chris@1296: :class => 'changeset', :title => 'My very first commit') Chris@1296: changeset_link2 = link_to('r2', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 2}, Chris@1296: :class => 'changeset', :title => 'This commit fixes #1, #2 and references #1 & #3') Chris@1296: Chris@1296: document_link = link_to('Test document', {:controller => 'documents', :action => 'show', :id => 1}, Chris@1296: :class => 'document') Chris@1296: Chris@1296: version_link = link_to('1.0', {:controller => 'versions', :action => 'show', :id => 2}, Chris@1296: :class => 'version') Chris@1296: Chris@1296: board_url = {:controller => 'boards', :action => 'show', :id => 2, :project_id => 'ecookbook'} Chris@1296: Chris@1296: message_url = {:controller => 'messages', :action => 'show', :board_id => 1, :id => 4} Chris@1296: Chris@1296: news_url = {:controller => 'news', :action => 'show', :id => 1} Chris@1296: Chris@1296: project_url = {:controller => 'projects', :action => 'show', :id => 'subproject1'} Chris@1296: Chris@1296: source_url = '/projects/ecookbook/repository/entry/some/file' Chris@1296: source_url_with_rev = '/projects/ecookbook/repository/revisions/52/entry/some/file' Chris@1296: source_url_with_ext = '/projects/ecookbook/repository/entry/some/file.ext' Chris@1296: source_url_with_rev_and_ext = '/projects/ecookbook/repository/revisions/52/entry/some/file.ext' Chris@1296: Chris@1296: export_url = '/projects/ecookbook/repository/raw/some/file' Chris@1296: export_url_with_rev = '/projects/ecookbook/repository/revisions/52/raw/some/file' Chris@1296: export_url_with_ext = '/projects/ecookbook/repository/raw/some/file.ext' Chris@1296: export_url_with_rev_and_ext = '/projects/ecookbook/repository/revisions/52/raw/some/file.ext' Chris@1296: Chris@1296: to_test = { Chris@1296: # tickets Chris@1296: '#3, [#3], (#3) and #3.' => "#{issue_link}, [#{issue_link}], (#{issue_link}) and #{issue_link}.", Chris@1296: # ticket notes Chris@1296: '#3-14' => note_link, Chris@1296: '#3#note-14' => note_link, Chris@1296: # should not ignore leading zero Chris@1296: '#03' => '#03', Chris@1296: # changesets Chris@1296: 'r1' => changeset_link, Chris@1296: 'r1.' => "#{changeset_link}.", Chris@1296: 'r1, r2' => "#{changeset_link}, #{changeset_link2}", Chris@1296: 'r1,r2' => "#{changeset_link},#{changeset_link2}", Chris@1296: # documents Chris@1296: 'document#1' => document_link, Chris@1296: 'document:"Test document"' => document_link, Chris@1296: # versions Chris@1296: 'version#2' => version_link, Chris@1296: 'version:1.0' => version_link, Chris@1296: 'version:"1.0"' => version_link, Chris@1296: # source Chris@1296: 'source:some/file' => link_to('source:some/file', source_url, :class => 'source'), Chris@1296: 'source:/some/file' => link_to('source:/some/file', source_url, :class => 'source'), Chris@1296: 'source:/some/file.' => link_to('source:/some/file', source_url, :class => 'source') + ".", Chris@1296: 'source:/some/file.ext.' => link_to('source:/some/file.ext', source_url_with_ext, :class => 'source') + ".", Chris@1296: 'source:/some/file. ' => link_to('source:/some/file', source_url, :class => 'source') + ".", Chris@1296: 'source:/some/file.ext. ' => link_to('source:/some/file.ext', source_url_with_ext, :class => 'source') + ".", Chris@1296: 'source:/some/file, ' => link_to('source:/some/file', source_url, :class => 'source') + ",", Chris@1296: 'source:/some/file@52' => link_to('source:/some/file@52', source_url_with_rev, :class => 'source'), Chris@1296: 'source:/some/file.ext@52' => link_to('source:/some/file.ext@52', source_url_with_rev_and_ext, :class => 'source'), Chris@1296: 'source:/some/file#L110' => link_to('source:/some/file#L110', source_url + "#L110", :class => 'source'), Chris@1296: 'source:/some/file.ext#L110' => link_to('source:/some/file.ext#L110', source_url_with_ext + "#L110", :class => 'source'), Chris@1296: 'source:/some/file@52#L110' => link_to('source:/some/file@52#L110', source_url_with_rev + "#L110", :class => 'source'), Chris@1296: # export Chris@1296: 'export:/some/file' => link_to('export:/some/file', export_url, :class => 'source download'), Chris@1296: 'export:/some/file.ext' => link_to('export:/some/file.ext', export_url_with_ext, :class => 'source download'), Chris@1296: 'export:/some/file@52' => link_to('export:/some/file@52', export_url_with_rev, :class => 'source download'), Chris@1296: 'export:/some/file.ext@52' => link_to('export:/some/file.ext@52', export_url_with_rev_and_ext, :class => 'source download'), Chris@1296: # forum Chris@1296: 'forum#2' => link_to('Discussion', board_url, :class => 'board'), Chris@1296: 'forum:Discussion' => link_to('Discussion', board_url, :class => 'board'), Chris@1296: # message Chris@1296: 'message#4' => link_to('Post 2', message_url, :class => 'message'), Chris@1296: 'message#5' => link_to('RE: post 2', message_url.merge(:anchor => 'message-5', :r => 5), :class => 'message'), Chris@1296: # news Chris@1296: 'news#1' => link_to('eCookbook first release !', news_url, :class => 'news'), Chris@1296: 'news:"eCookbook first release !"' => link_to('eCookbook first release !', news_url, :class => 'news'), Chris@1296: # project Chris@1296: 'project#3' => link_to('eCookbook Subproject 1', project_url, :class => 'project'), Chris@1296: 'project:subproject1' => link_to('eCookbook Subproject 1', project_url, :class => 'project'), Chris@1296: 'project:"eCookbook subProject 1"' => link_to('eCookbook Subproject 1', project_url, :class => 'project'), Chris@1296: # not found Chris@1296: '#0123456789' => '#0123456789', Chris@1296: # invalid expressions Chris@1296: 'source:' => 'source:', Chris@1296: # url hash Chris@1296: "http://foo.bar/FAQ#3" => 'http://foo.bar/FAQ#3', Chris@1296: } Chris@1296: @project = Project.find(1) Chris@1296: to_test.each { |text, result| assert_equal "#{result}
", textilizable(text), "#{text} failed" } Chris@1296: end Chris@1296: Chris@1296: def test_escaped_redmine_links_should_not_be_parsed Chris@1296: to_test = [ Chris@1296: '#3.', Chris@1296: '#3-14.', Chris@1296: '#3#-note14.', Chris@1296: 'r1', Chris@1296: 'document#1', Chris@1296: 'document:"Test document"', Chris@1296: 'version#2', Chris@1296: 'version:1.0', Chris@1296: 'version:"1.0"', Chris@1296: 'source:/some/file' Chris@1296: ] Chris@1296: @project = Project.find(1) Chris@1296: to_test.each { |text| assert_equal "#{text}
", textilizable("!" + text), "#{text} failed" } Chris@1296: end Chris@1296: Chris@1296: def test_cross_project_redmine_links Chris@1296: source_link = link_to('ecookbook:source:/some/file', {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :path => ['some', 'file']}, Chris@1296: :class => 'source') Chris@1296: Chris@1296: changeset_link = link_to('ecookbook:r2', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 2}, Chris@1296: :class => 'changeset', :title => 'This commit fixes #1, #2 and references #1 & #3') Chris@1296: Chris@1296: to_test = { Chris@1296: # documents Chris@1296: 'document:"Test document"' => 'document:"Test document"', Chris@1296: 'ecookbook:document:"Test document"' => 'Test document', Chris@1296: 'invalid:document:"Test document"' => 'invalid:document:"Test document"', Chris@1296: # versions Chris@1296: 'version:"1.0"' => 'version:"1.0"', Chris@1296: 'ecookbook:version:"1.0"' => '1.0', Chris@1296: 'invalid:version:"1.0"' => 'invalid:version:"1.0"', Chris@1296: # changeset Chris@1296: 'r2' => 'r2', Chris@1296: 'ecookbook:r2' => changeset_link, Chris@1296: 'invalid:r2' => 'invalid:r2', Chris@1296: # source Chris@1296: 'source:/some/file' => 'source:/some/file', Chris@1296: 'ecookbook:source:/some/file' => source_link, Chris@1296: 'invalid:source:/some/file' => 'invalid:source:/some/file', Chris@1296: } Chris@1296: @project = Project.find(3) Chris@1296: to_test.each { |text, result| assert_equal "#{result}
", textilizable(text), "#{text} failed" } Chris@1296: end Chris@1296: Chris@1296: def test_multiple_repositories_redmine_links Chris@1296: svn = Repository::Subversion.create!(:project_id => 1, :identifier => 'svn1', :url => 'file:///foo/hg') Chris@1296: Changeset.create!(:repository => svn, :committed_on => Time.now, :revision => '123') Chris@1296: hg = Repository::Mercurial.create!(:project_id => 1, :identifier => 'hg1', :url => '/foo/hg') Chris@1296: Changeset.create!(:repository => hg, :committed_on => Time.now, :revision => '123', :scmid => 'abcd') Chris@1296: Chris@1296: changeset_link = link_to('r2', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 2}, Chris@1296: :class => 'changeset', :title => 'This commit fixes #1, #2 and references #1 & #3') Chris@1296: svn_changeset_link = link_to('svn1|r123', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :repository_id => 'svn1', :rev => 123}, Chris@1296: :class => 'changeset', :title => '') Chris@1296: hg_changeset_link = link_to('hg1|abcd', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :repository_id => 'hg1', :rev => 'abcd'}, Chris@1296: :class => 'changeset', :title => '') Chris@1296: Chris@1296: source_link = link_to('source:some/file', {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :path => ['some', 'file']}, :class => 'source') Chris@1296: 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: Chris@1296: to_test = { Chris@1296: 'r2' => changeset_link, Chris@1296: 'svn1|r123' => svn_changeset_link, Chris@1296: 'invalid|r123' => 'invalid|r123', Chris@1296: 'commit:hg1|abcd' => hg_changeset_link, Chris@1296: 'commit:invalid|abcd' => 'commit:invalid|abcd', Chris@1296: # source Chris@1296: 'source:some/file' => source_link, Chris@1296: 'source:hg1|some/file' => hg_source_link, Chris@1296: 'source:invalid|some/file' => 'source:invalid|some/file', Chris@1296: } Chris@1296: Chris@1296: @project = Project.find(1) Chris@1296: to_test.each { |text, result| assert_equal "#{result}
", textilizable(text), "#{text} failed" } Chris@1296: end Chris@1296: Chris@1296: def test_cross_project_multiple_repositories_redmine_links Chris@1296: svn = Repository::Subversion.create!(:project_id => 1, :identifier => 'svn1', :url => 'file:///foo/hg') Chris@1296: Changeset.create!(:repository => svn, :committed_on => Time.now, :revision => '123') Chris@1296: hg = Repository::Mercurial.create!(:project_id => 1, :identifier => 'hg1', :url => '/foo/hg') Chris@1296: Changeset.create!(:repository => hg, :committed_on => Time.now, :revision => '123', :scmid => 'abcd') Chris@1296: Chris@1296: changeset_link = link_to('ecookbook:r2', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 2}, Chris@1296: :class => 'changeset', :title => 'This commit fixes #1, #2 and references #1 & #3') Chris@1296: svn_changeset_link = link_to('ecookbook:svn1|r123', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :repository_id => 'svn1', :rev => 123}, Chris@1296: :class => 'changeset', :title => '') Chris@1296: hg_changeset_link = link_to('ecookbook:hg1|abcd', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :repository_id => 'hg1', :rev => 'abcd'}, Chris@1296: :class => 'changeset', :title => '') Chris@1296: Chris@1296: source_link = link_to('ecookbook:source:some/file', {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :path => ['some', 'file']}, :class => 'source') Chris@1296: 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: Chris@1296: to_test = { Chris@1296: 'ecookbook:r2' => changeset_link, Chris@1296: 'ecookbook:svn1|r123' => svn_changeset_link, Chris@1296: 'ecookbook:invalid|r123' => 'ecookbook:invalid|r123', Chris@1296: 'ecookbook:commit:hg1|abcd' => hg_changeset_link, Chris@1296: 'ecookbook:commit:invalid|abcd' => 'ecookbook:commit:invalid|abcd', Chris@1296: 'invalid:commit:invalid|abcd' => 'invalid:commit:invalid|abcd', Chris@1296: # source Chris@1296: 'ecookbook:source:some/file' => source_link, Chris@1296: 'ecookbook:source:hg1|some/file' => hg_source_link, Chris@1296: 'ecookbook:source:invalid|some/file' => 'ecookbook:source:invalid|some/file', Chris@1296: 'invalid:source:invalid|some/file' => 'invalid:source:invalid|some/file', Chris@1296: } Chris@1296: Chris@1296: @project = Project.find(3) Chris@1296: to_test.each { |text, result| assert_equal "#{result}
", textilizable(text), "#{text} failed" } Chris@1296: end Chris@1296: Chris@1296: def test_redmine_links_git_commit Chris@1296: changeset_link = link_to('abcd', Chris@1296: { Chris@1296: :controller => 'repositories', Chris@1296: :action => 'revision', Chris@1296: :id => 'subproject1', Chris@1296: :rev => 'abcd', Chris@1296: }, Chris@1296: :class => 'changeset', :title => 'test commit') Chris@1296: to_test = { Chris@1296: 'commit:abcd' => changeset_link, Chris@1296: } Chris@1296: @project = Project.find(3) Chris@1296: r = Repository::Git.create!(:project => @project, :url => '/tmp/test/git') Chris@1296: assert r Chris@1296: c = Changeset.new(:repository => r, Chris@1296: :committed_on => Time.now, Chris@1296: :revision => 'abcd', Chris@1296: :scmid => 'abcd', Chris@1296: :comments => 'test commit') Chris@1296: assert( c.save ) Chris@1296: to_test.each { |text, result| assert_equal "#{result}
", textilizable(text) } Chris@1296: end Chris@1296: Chris@1296: # TODO: Bazaar commit id contains mail address, so it contains '@' and '_'. Chris@1296: def test_redmine_links_darcs_commit Chris@1296: changeset_link = link_to('20080308225258-98289-abcd456efg.gz', Chris@1296: { Chris@1296: :controller => 'repositories', Chris@1296: :action => 'revision', Chris@1296: :id => 'subproject1', Chris@1296: :rev => '123', Chris@1296: }, Chris@1296: :class => 'changeset', :title => 'test commit') Chris@1296: to_test = { Chris@1296: 'commit:20080308225258-98289-abcd456efg.gz' => changeset_link, Chris@1296: } Chris@1296: @project = Project.find(3) Chris@1296: r = Repository::Darcs.create!( Chris@1296: :project => @project, :url => '/tmp/test/darcs', Chris@1296: :log_encoding => 'UTF-8') Chris@1296: assert r Chris@1296: c = Changeset.new(:repository => r, Chris@1296: :committed_on => Time.now, Chris@1296: :revision => '123', Chris@1296: :scmid => '20080308225258-98289-abcd456efg.gz', Chris@1296: :comments => 'test commit') Chris@1296: assert( c.save ) Chris@1296: to_test.each { |text, result| assert_equal "#{result}
", textilizable(text) } Chris@1296: end Chris@1296: Chris@1296: def test_redmine_links_mercurial_commit Chris@1296: changeset_link_rev = link_to('r123', Chris@1296: { Chris@1296: :controller => 'repositories', Chris@1296: :action => 'revision', Chris@1296: :id => 'subproject1', Chris@1296: :rev => '123' , Chris@1296: }, Chris@1296: :class => 'changeset', :title => 'test commit') Chris@1296: changeset_link_commit = link_to('abcd', Chris@1296: { Chris@1296: :controller => 'repositories', Chris@1296: :action => 'revision', Chris@1296: :id => 'subproject1', Chris@1296: :rev => 'abcd' , Chris@1296: }, Chris@1296: :class => 'changeset', :title => 'test commit') Chris@1296: to_test = { Chris@1296: 'r123' => changeset_link_rev, Chris@1296: 'commit:abcd' => changeset_link_commit, Chris@1296: } Chris@1296: @project = Project.find(3) Chris@1296: r = Repository::Mercurial.create!(:project => @project, :url => '/tmp/test') Chris@1296: assert r Chris@1296: c = Changeset.new(:repository => r, Chris@1296: :committed_on => Time.now, Chris@1296: :revision => '123', Chris@1296: :scmid => 'abcd', Chris@1296: :comments => 'test commit') Chris@1296: assert( c.save ) Chris@1296: to_test.each { |text, result| assert_equal "#{result}
", textilizable(text) } Chris@1296: end Chris@1296: Chris@1296: def test_attachment_links Chris@1296: attachment_link = link_to('error281.txt', {:controller => 'attachments', :action => 'download', :id => '1'}, :class => 'attachment') Chris@1296: to_test = { Chris@1296: 'attachment:error281.txt' => attachment_link Chris@1296: } Chris@1296: to_test.each { |text, result| assert_equal "#{result}
", textilizable(text, :attachments => Issue.find(3).attachments), "#{text} failed" } Chris@1296: end Chris@1296: Chris@1296: def test_wiki_links Chris@1296: to_test = { Chris@1296: '[[CookBook documentation]]' => 'CookBook documentation', Chris@1296: '[[Another page|Page]]' => 'Page', Chris@1296: # title content should be formatted Chris@1296: '[[Another page|With _styled_ *title*]]' => 'With styled title', Chris@1296: '[[Another page|With title containing HTML entities & markups]]' => 'With title containing <strong>HTML entities & markups</strong>', Chris@1296: # link with anchor Chris@1296: '[[CookBook documentation#One-section]]' => 'CookBook documentation', Chris@1296: '[[Another page#anchor|Page]]' => 'Page', Chris@1296: # UTF8 anchor Chris@1296: '[[Another_page#Тест|Тест]]' => %|Тест|, Chris@1296: # page that doesn't exist Chris@1296: '[[Unknown page]]' => 'Unknown page', Chris@1296: '[[Unknown page|404]]' => '404', Chris@1296: # link to another project wiki Chris@1296: '[[onlinestore:]]' => 'onlinestore', Chris@1296: '[[onlinestore:|Wiki]]' => 'Wiki', Chris@1296: '[[onlinestore:Start page]]' => 'Start page', Chris@1296: '[[onlinestore:Start page|Text]]' => 'Text', Chris@1296: '[[onlinestore:Unknown page]]' => 'Unknown page', Chris@1296: # striked through link Chris@1296: '-[[Another page|Page]]-' => '#{result}
", textilizable(text) } Chris@1296: end Chris@1296: Chris@1296: def test_wiki_links_within_local_file_generation_context Chris@1296: Chris@1296: to_test = { Chris@1296: # link to a page Chris@1296: '[[CookBook documentation]]' => 'CookBook documentation', Chris@1296: '[[CookBook documentation|documentation]]' => 'documentation', Chris@1296: '[[CookBook documentation#One-section]]' => 'CookBook documentation', Chris@1296: '[[CookBook documentation#One-section|documentation]]' => 'documentation', Chris@1296: # page that doesn't exist Chris@1296: '[[Unknown page]]' => 'Unknown page', Chris@1296: '[[Unknown page|404]]' => '404', Chris@1296: '[[Unknown page#anchor]]' => 'Unknown page', Chris@1296: '[[Unknown page#anchor|404]]' => '404', Chris@1296: } Chris@1296: Chris@1296: @project = Project.find(1) Chris@1296: Chris@1296: to_test.each { |text, result| assert_equal "#{result}
", textilizable(text, :wiki_links => :local) } Chris@1296: end Chris@1296: Chris@1296: def test_wiki_links_within_wiki_page_context Chris@1296: Chris@1296: page = WikiPage.find_by_title('Another_page' ) Chris@1296: Chris@1296: to_test = { Chris@1296: # link to another page Chris@1296: '[[CookBook documentation]]' => 'CookBook documentation', Chris@1296: '[[CookBook documentation|documentation]]' => 'documentation', Chris@1296: '[[CookBook documentation#One-section]]' => 'CookBook documentation', Chris@1296: '[[CookBook documentation#One-section|documentation]]' => 'documentation', Chris@1296: # link to the current page Chris@1296: '[[Another page]]' => 'Another page', Chris@1296: '[[Another page|Page]]' => 'Page', Chris@1296: '[[Another page#anchor]]' => 'Another page', Chris@1296: '[[Another page#anchor|Page]]' => 'Page', Chris@1296: # page that doesn't exist Chris@1296: '[[Unknown page]]' => 'Unknown page', Chris@1296: '[[Unknown page|404]]' => '404', Chris@1296: '[[Unknown page#anchor]]' => 'Unknown page', Chris@1296: '[[Unknown page#anchor|404]]' => '404', Chris@1296: } Chris@1296: Chris@1296: @project = Project.find(1) Chris@1296: Chris@1296: to_test.each { |text, result| assert_equal "#{result}
", textilizable(WikiContent.new( :text => text, :page => page ), :text) } Chris@1296: end Chris@1296: Chris@1296: def test_wiki_links_anchor_option_should_prepend_page_title_to_href Chris@1296: Chris@1296: to_test = { Chris@1296: # link to a page Chris@1296: '[[CookBook documentation]]' => 'CookBook documentation', Chris@1296: '[[CookBook documentation|documentation]]' => 'documentation', Chris@1296: '[[CookBook documentation#One-section]]' => 'CookBook documentation', Chris@1296: '[[CookBook documentation#One-section|documentation]]' => 'documentation', Chris@1296: # page that doesn't exist Chris@1296: '[[Unknown page]]' => 'Unknown page', Chris@1296: '[[Unknown page|404]]' => '404', Chris@1296: '[[Unknown page#anchor]]' => 'Unknown page', Chris@1296: '[[Unknown page#anchor|404]]' => '404', Chris@1296: } Chris@1296: Chris@1296: @project = Project.find(1) Chris@1296: Chris@1296: to_test.each { |text, result| assert_equal "#{result}
", textilizable(text, :wiki_links => :anchor) } Chris@1296: end Chris@1296: Chris@1296: def test_html_tags Chris@1296: to_test = { Chris@1296: "<div>content</div>
", Chris@1296: "<div class=\"bold\">content</div>
", Chris@1296: "" => "<script>some script;</script>
", Chris@1296: # do not escape pre/code tags Chris@1296: "\nline 1\nline2" => "
\nline 1\nline2", Chris@1296: "
\nline 1\nline2
" => "\nline 1\nline2
",
Chris@1296: "" => "content
<div>content</div>", Chris@1296: "HTML comment: " => "
HTML comment: <!-- no comments -->
", Chris@1296: "