Chris@0: # Redmine - project management software Chris@441: # Copyright (C) 2006-2011 Jean-Philippe Lang Chris@0: # Chris@0: # This program is free software; you can redistribute it and/or Chris@0: # modify it under the terms of the GNU General Public License Chris@0: # as published by the Free Software Foundation; either version 2 Chris@0: # of the License, or (at your option) any later version. Chris@441: # Chris@0: # This program is distributed in the hope that it will be useful, Chris@0: # but WITHOUT ANY WARRANTY; without even the implied warranty of Chris@0: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Chris@0: # GNU General Public License for more details. Chris@441: # Chris@0: # You should have received a copy of the GNU General Public License Chris@0: # along with this program; if not, write to the Free Software Chris@0: # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Chris@0: Chris@119: require File.expand_path('../../../test_helper', __FILE__) Chris@0: chris@22: class ApplicationHelperTest < ActionView::TestCase Chris@0: fixtures :projects, :roles, :enabled_modules, :users, Chris@909: :repositories, :changesets, Chris@909: :trackers, :issue_statuses, :issues, :versions, :documents, Chris@909: :wikis, :wiki_pages, :wiki_contents, Chris@909: :boards, :messages, :news, Chris@909: :attachments, :enumerations Chris@0: Chris@0: def setup Chris@0: super Chris@909: set_tmp_attachments_directory Chris@0: end chris@22: chris@22: context "#link_to_if_authorized" do chris@22: context "authorized user" do chris@22: should "be tested" chris@22: end Chris@441: chris@22: context "unauthorized user" do chris@22: should "be tested" chris@22: end Chris@441: chris@22: should "allow using the :controller and :action for the target link" do chris@22: User.current = User.find_by_login('admin') chris@22: chris@22: @project = Issue.first.project # Used by helper chris@22: response = link_to_if_authorized("By controller/action", chris@22: {:controller => 'issues', :action => 'edit', :id => Issue.first.id}) chris@22: assert_match /href/, response chris@22: end Chris@441: chris@22: end Chris@441: Chris@0: def test_auto_links Chris@0: to_test = { Chris@0: 'http://foo.bar' => 'http://foo.bar', Chris@0: 'http://foo.bar/~user' => 'http://foo.bar/~user', Chris@0: 'http://foo.bar.' => 'http://foo.bar.', Chris@0: 'https://foo.bar.' => 'https://foo.bar.', Chris@0: 'This is a link: http://foo.bar.' => 'This is a link: http://foo.bar.', Chris@0: 'A link (eg. http://foo.bar).' => 'A link (eg. http://foo.bar).', Chris@0: 'http://foo.bar/foo.bar#foo.bar.' => 'http://foo.bar/foo.bar#foo.bar.', Chris@0: 'http://www.foo.bar/Test_(foobar)' => 'http://www.foo.bar/Test_(foobar)', Chris@0: '(see inline link : http://www.foo.bar/Test_(foobar))' => '(see inline link : http://www.foo.bar/Test_(foobar))', Chris@0: '(see inline link : http://www.foo.bar/Test)' => '(see inline link : http://www.foo.bar/Test)', Chris@0: '(see inline link : http://www.foo.bar/Test).' => '(see inline link : http://www.foo.bar/Test).', Chris@0: '(see "inline link":http://www.foo.bar/Test_(foobar))' => '(see inline link)', Chris@0: '(see "inline link":http://www.foo.bar/Test)' => '(see inline link)', Chris@0: '(see "inline link":http://www.foo.bar/Test).' => '(see inline link).', Chris@0: 'www.foo.bar' => 'www.foo.bar', Chris@0: 'http://foo.bar/page?p=1&t=z&s=' => 'http://foo.bar/page?p=1&t=z&s=', Chris@0: 'http://foo.bar/page#125' => 'http://foo.bar/page#125', Chris@0: 'http://foo@www.bar.com' => 'http://foo@www.bar.com', Chris@0: 'http://foo:bar@www.bar.com' => 'http://foo:bar@www.bar.com', Chris@0: 'ftp://foo.bar' => 'ftp://foo.bar', Chris@0: 'ftps://foo.bar' => 'ftps://foo.bar', Chris@0: 'sftp://foo.bar' => 'sftp://foo.bar', Chris@0: # two exclamation marks Chris@0: 'http://example.net/path!602815048C7B5C20!302.html' => 'http://example.net/path!602815048C7B5C20!302.html', Chris@0: # escaping Chris@0: 'http://foo"bar' => 'http://foo"bar', chris@37: # wrap in angle brackets chris@37: '' => '<http://foo.bar>' Chris@0: } Chris@0: to_test.each { |text, result| assert_equal "

#{result}

", textilizable(text) } Chris@0: end Chris@441: Chris@0: def test_auto_mailto Chris@441: assert_equal '

', Chris@0: textilizable('test@foo.bar') Chris@0: end Chris@441: Chris@0: def test_inline_images Chris@0: to_test = { Chris@0: '!http://foo.bar/image.jpg!' => '', Chris@0: 'floating !>http://foo.bar/image.jpg!' => 'floating
', Chris@0: 'with class !(some-class)http://foo.bar/image.jpg!' => 'with class ', Chris@0: # inline styles should be stripped Chris@0: 'with style !{width:100px;height100px}http://foo.bar/image.jpg!' => 'with style ', Chris@0: 'with title !http://foo.bar/image.jpg(This is a title)!' => 'with title This is a title', Chris@0: 'with title !http://foo.bar/image.jpg(This is a double-quoted "title")!' => 'with title This is a double-quoted "title"', Chris@0: } Chris@0: to_test.each { |text, result| assert_equal "

#{result}

", textilizable(text) } Chris@0: end Chris@441: Chris@0: def test_inline_images_inside_tags Chris@0: raw = <<-RAW Chris@0: h1. !foo.png! Heading Chris@0: Chris@0: Centered image: Chris@0: Chris@0: p=. !bar.gif! Chris@0: RAW Chris@0: Chris@0: assert textilizable(raw).include?('') Chris@0: assert textilizable(raw).include?('') Chris@0: end Chris@441: Chris@0: def test_attached_images Chris@0: to_test = { Chris@0: 'Inline image: !logo.gif!' => 'Inline image: This is a logo', Chris@0: 'Inline image: !logo.GIF!' => 'Inline image: This is a logo', Chris@0: 'No match: !ogo.gif!' => 'No match: ', Chris@0: 'No match: !ogo.GIF!' => 'No match: ', Chris@0: # link image Chris@0: '!logo.gif!:http://foo.bar/' => 'This is a logo', Chris@0: } Chris@0: attachments = Attachment.find(:all) Chris@0: to_test.each { |text, result| assert_equal "

#{result}

", textilizable(text, :attachments => attachments) } Chris@0: end Chris@441: Chris@909: def test_attached_images_filename_extension Chris@909: set_tmp_attachments_directory Chris@909: a1 = Attachment.new( Chris@909: :container => Issue.find(1), Chris@909: :file => mock_file_with_options({:original_filename => "testtest.JPG"}), Chris@909: :author => User.find(1)) Chris@909: assert a1.save Chris@909: assert_equal "testtest.JPG", a1.filename Chris@909: assert_equal "image/jpeg", a1.content_type Chris@909: assert a1.image? Chris@909: Chris@909: a2 = Attachment.new( Chris@909: :container => Issue.find(1), Chris@909: :file => mock_file_with_options({:original_filename => "testtest.jpeg"}), Chris@909: :author => User.find(1)) Chris@909: assert a2.save Chris@909: assert_equal "testtest.jpeg", a2.filename Chris@909: assert_equal "image/jpeg", a2.content_type Chris@909: assert a2.image? Chris@909: Chris@909: a3 = Attachment.new( Chris@909: :container => Issue.find(1), Chris@909: :file => mock_file_with_options({:original_filename => "testtest.JPE"}), Chris@909: :author => User.find(1)) Chris@909: assert a3.save Chris@909: assert_equal "testtest.JPE", a3.filename Chris@909: assert_equal "image/jpeg", a3.content_type Chris@909: assert a3.image? Chris@909: Chris@909: a4 = Attachment.new( Chris@909: :container => Issue.find(1), Chris@909: :file => mock_file_with_options({:original_filename => "Testtest.BMP"}), Chris@909: :author => User.find(1)) Chris@909: assert a4.save Chris@909: assert_equal "Testtest.BMP", a4.filename Chris@909: assert_equal "image/x-ms-bmp", a4.content_type Chris@909: assert a4.image? Chris@909: Chris@909: to_test = { Chris@909: 'Inline image: !testtest.jpg!' => Chris@909: 'Inline image: ', Chris@909: 'Inline image: !testtest.jpeg!' => Chris@909: 'Inline image: ', Chris@909: 'Inline image: !testtest.jpe!' => Chris@909: 'Inline image: ', Chris@909: 'Inline image: !testtest.bmp!' => Chris@909: 'Inline image: ', Chris@909: } Chris@909: Chris@909: attachments = [a1, a2, a3, a4] Chris@909: to_test.each { |text, result| assert_equal "

#{result}

", textilizable(text, :attachments => attachments) } Chris@909: end Chris@909: Chris@909: def test_attached_images_should_read_later Chris@909: Attachment.storage_path = "#{Rails.root}/test/fixtures/files" Chris@909: a1 = Attachment.find(16) Chris@909: assert_equal "testfile.png", a1.filename Chris@909: assert a1.readable? Chris@909: assert (! a1.visible?(User.anonymous)) Chris@909: assert a1.visible?(User.find(2)) Chris@909: a2 = Attachment.find(17) Chris@909: assert_equal "testfile.PNG", a2.filename Chris@909: assert a2.readable? Chris@909: assert (! a2.visible?(User.anonymous)) Chris@909: assert a2.visible?(User.find(2)) Chris@909: assert a1.created_on < a2.created_on Chris@909: Chris@909: to_test = { Chris@909: 'Inline image: !testfile.png!' => Chris@909: 'Inline image: ', Chris@909: 'Inline image: !Testfile.PNG!' => Chris@909: 'Inline image: ', Chris@909: } Chris@909: attachments = [a1, a2] Chris@909: to_test.each { |text, result| assert_equal "

#{result}

", textilizable(text, :attachments => attachments) } Chris@909: set_tmp_attachments_directory Chris@909: end Chris@909: Chris@0: def test_textile_external_links Chris@0: to_test = { Chris@0: 'This is a "link":http://foo.bar' => 'This is a link', Chris@0: 'This is an intern "link":/foo/bar' => 'This is an intern link', Chris@0: '"link (Link title)":http://foo.bar' => 'link', Chris@0: '"link (Link title with "double-quotes")":http://foo.bar' => 'link', Chris@0: "This is not a \"Link\":\n\nAnother paragraph" => "This is not a \"Link\":

\n\n\n\t

Another paragraph", Chris@0: # no multiline link text Chris@0: "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@0: # mailto link Chris@0: "\"system administrator\":mailto:sysadmin@example.com?subject=redmine%20permissions" => "system administrator", Chris@0: # two exclamation marks Chris@0: '"a link":http://example.net/path!602815048C7B5C20!302.html' => 'a link', Chris@0: # escaping Chris@0: '"test":http://foo"bar' => 'test', Chris@0: } Chris@0: to_test.each { |text, result| assert_equal "

#{result}

", textilizable(text) } Chris@0: end Chris@119: Chris@0: def test_redmine_links Chris@441: issue_link = link_to('#3', {:controller => 'issues', :action => 'show', :id => 3}, Chris@0: :class => 'issue status-1 priority-1 overdue', :title => 'Error 281 when updating a recipe (New)') Chris@441: Chris@0: changeset_link = link_to('r1', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 1}, Chris@0: :class => 'changeset', :title => 'My very first commit') Chris@0: changeset_link2 = link_to('r2', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 2}, Chris@0: :class => 'changeset', :title => 'This commit fixes #1, #2 and references #1 & #3') Chris@441: Chris@0: document_link = link_to('Test document', {:controller => 'documents', :action => 'show', :id => 1}, Chris@0: :class => 'document') Chris@441: Chris@0: version_link = link_to('1.0', {:controller => 'versions', :action => 'show', :id => 2}, Chris@0: :class => 'version') Chris@0: Chris@909: board_url = {:controller => 'boards', :action => 'show', :id => 2, :project_id => 'ecookbook'} Chris@909: Chris@0: message_url = {:controller => 'messages', :action => 'show', :board_id => 1, :id => 4} Chris@909: Chris@909: news_url = {:controller => 'news', :action => 'show', :id => 1} Chris@441: Chris@0: project_url = {:controller => 'projects', :action => 'show', :id => 'subproject1'} Chris@441: Chris@0: source_url = {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :path => ['some', 'file']} Chris@0: source_url_with_ext = {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :path => ['some', 'file.ext']} Chris@441: Chris@0: to_test = { Chris@0: # tickets Chris@0: '#3, [#3], (#3) and #3.' => "#{issue_link}, [#{issue_link}], (#{issue_link}) and #{issue_link}.", Chris@0: # changesets Chris@0: 'r1' => changeset_link, Chris@0: 'r1.' => "#{changeset_link}.", Chris@0: 'r1, r2' => "#{changeset_link}, #{changeset_link2}", Chris@0: 'r1,r2' => "#{changeset_link},#{changeset_link2}", Chris@0: # documents Chris@0: 'document#1' => document_link, Chris@0: 'document:"Test document"' => document_link, Chris@0: # versions Chris@0: 'version#2' => version_link, Chris@0: 'version:1.0' => version_link, Chris@0: 'version:"1.0"' => version_link, Chris@0: # source Chris@0: 'source:/some/file' => link_to('source:/some/file', source_url, :class => 'source'), Chris@0: 'source:/some/file.' => link_to('source:/some/file', source_url, :class => 'source') + ".", Chris@0: 'source:/some/file.ext.' => link_to('source:/some/file.ext', source_url_with_ext, :class => 'source') + ".", Chris@0: 'source:/some/file. ' => link_to('source:/some/file', source_url, :class => 'source') + ".", Chris@0: 'source:/some/file.ext. ' => link_to('source:/some/file.ext', source_url_with_ext, :class => 'source') + ".", Chris@0: 'source:/some/file, ' => link_to('source:/some/file', source_url, :class => 'source') + ",", Chris@0: 'source:/some/file@52' => link_to('source:/some/file@52', source_url.merge(:rev => 52), :class => 'source'), Chris@0: 'source:/some/file.ext@52' => link_to('source:/some/file.ext@52', source_url_with_ext.merge(:rev => 52), :class => 'source'), Chris@0: 'source:/some/file#L110' => link_to('source:/some/file#L110', source_url.merge(:anchor => 'L110'), :class => 'source'), Chris@0: 'source:/some/file.ext#L110' => link_to('source:/some/file.ext#L110', source_url_with_ext.merge(:anchor => 'L110'), :class => 'source'), Chris@0: 'source:/some/file@52#L110' => link_to('source:/some/file@52#L110', source_url.merge(:rev => 52, :anchor => 'L110'), :class => 'source'), Chris@0: 'export:/some/file' => link_to('export:/some/file', source_url.merge(:format => 'raw'), :class => 'source download'), Chris@909: # forum Chris@909: 'forum#2' => link_to('Discussion', board_url, :class => 'board'), Chris@909: 'forum:Discussion' => link_to('Discussion', board_url, :class => 'board'), Chris@0: # message Chris@0: 'message#4' => link_to('Post 2', message_url, :class => 'message'), Chris@210: 'message#5' => link_to('RE: post 2', message_url.merge(:anchor => 'message-5', :r => 5), :class => 'message'), Chris@909: # news Chris@909: 'news#1' => link_to('eCookbook first release !', news_url, :class => 'news'), Chris@909: 'news:"eCookbook first release !"' => link_to('eCookbook first release !', news_url, :class => 'news'), Chris@0: # project Chris@0: 'project#3' => link_to('eCookbook Subproject 1', project_url, :class => 'project'), Chris@0: 'project:subproject1' => link_to('eCookbook Subproject 1', project_url, :class => 'project'), Chris@0: 'project:"eCookbook subProject 1"' => link_to('eCookbook Subproject 1', project_url, :class => 'project'), Chris@0: # escaping Chris@0: '!#3.' => '#3.', Chris@0: '!r1' => 'r1', Chris@0: '!document#1' => 'document#1', Chris@0: '!document:"Test document"' => 'document:"Test document"', Chris@0: '!version#2' => 'version#2', Chris@0: '!version:1.0' => 'version:1.0', Chris@0: '!version:"1.0"' => 'version:"1.0"', Chris@0: '!source:/some/file' => 'source:/some/file', Chris@0: # not found Chris@0: '#0123456789' => '#0123456789', Chris@0: # invalid expressions Chris@0: 'source:' => 'source:', Chris@0: # url hash Chris@0: "http://foo.bar/FAQ#3" => 'http://foo.bar/FAQ#3', Chris@0: } Chris@0: @project = Project.find(1) Chris@0: to_test.each { |text, result| assert_equal "

#{result}

", textilizable(text), "#{text} failed" } Chris@0: end Chris@441: Chris@210: def test_cross_project_redmine_links Chris@210: source_link = link_to('ecookbook:source:/some/file', {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :path => ['some', 'file']}, Chris@210: :class => 'source') Chris@441: Chris@210: changeset_link = link_to('ecookbook:r2', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 2}, Chris@210: :class => 'changeset', :title => 'This commit fixes #1, #2 and references #1 & #3') Chris@441: Chris@210: to_test = { Chris@210: # documents Chris@210: 'document:"Test document"' => 'document:"Test document"', Chris@210: 'ecookbook:document:"Test document"' => 'Test document', Chris@210: 'invalid:document:"Test document"' => 'invalid:document:"Test document"', Chris@210: # versions Chris@210: 'version:"1.0"' => 'version:"1.0"', Chris@909: 'ecookbook:version:"1.0"' => '1.0', Chris@210: 'invalid:version:"1.0"' => 'invalid:version:"1.0"', Chris@210: # changeset Chris@210: 'r2' => 'r2', Chris@210: 'ecookbook:r2' => changeset_link, Chris@210: 'invalid:r2' => 'invalid:r2', Chris@210: # source Chris@210: 'source:/some/file' => 'source:/some/file', Chris@210: 'ecookbook:source:/some/file' => source_link, Chris@210: 'invalid:source:/some/file' => 'invalid:source:/some/file', Chris@210: } Chris@210: @project = Project.find(3) Chris@210: to_test.each { |text, result| assert_equal "

#{result}

", textilizable(text), "#{text} failed" } Chris@210: end Chris@119: Chris@119: def test_redmine_links_git_commit Chris@119: changeset_link = link_to('abcd', Chris@119: { Chris@119: :controller => 'repositories', Chris@119: :action => 'revision', Chris@119: :id => 'subproject1', Chris@119: :rev => 'abcd', Chris@119: }, Chris@119: :class => 'changeset', :title => 'test commit') Chris@119: to_test = { Chris@119: 'commit:abcd' => changeset_link, Chris@119: } Chris@119: @project = Project.find(3) Chris@119: r = Repository::Git.create!(:project => @project, :url => '/tmp/test/git') Chris@119: assert r Chris@119: c = Changeset.new(:repository => r, Chris@119: :committed_on => Time.now, Chris@119: :revision => 'abcd', Chris@119: :scmid => 'abcd', Chris@119: :comments => 'test commit') Chris@119: assert( c.save ) Chris@119: to_test.each { |text, result| assert_equal "

#{result}

", textilizable(text) } Chris@119: end Chris@119: Chris@119: # TODO: Bazaar commit id contains mail address, so it contains '@' and '_'. Chris@119: def test_redmine_links_darcs_commit Chris@119: changeset_link = link_to('20080308225258-98289-abcd456efg.gz', Chris@119: { Chris@119: :controller => 'repositories', Chris@119: :action => 'revision', Chris@119: :id => 'subproject1', Chris@119: :rev => '123', Chris@119: }, Chris@119: :class => 'changeset', :title => 'test commit') Chris@119: to_test = { Chris@119: 'commit:20080308225258-98289-abcd456efg.gz' => changeset_link, Chris@119: } Chris@119: @project = Project.find(3) Chris@245: r = Repository::Darcs.create!( Chris@245: :project => @project, :url => '/tmp/test/darcs', Chris@245: :log_encoding => 'UTF-8') Chris@119: assert r Chris@119: c = Changeset.new(:repository => r, Chris@119: :committed_on => Time.now, Chris@119: :revision => '123', Chris@119: :scmid => '20080308225258-98289-abcd456efg.gz', Chris@119: :comments => 'test commit') Chris@119: assert( c.save ) Chris@119: to_test.each { |text, result| assert_equal "

#{result}

", textilizable(text) } Chris@119: end Chris@119: Chris@119: def test_redmine_links_mercurial_commit Chris@119: changeset_link_rev = link_to('r123', Chris@119: { Chris@119: :controller => 'repositories', Chris@119: :action => 'revision', Chris@119: :id => 'subproject1', Chris@119: :rev => '123' , Chris@119: }, Chris@119: :class => 'changeset', :title => 'test commit') Chris@119: changeset_link_commit = link_to('abcd', Chris@119: { Chris@119: :controller => 'repositories', Chris@119: :action => 'revision', Chris@119: :id => 'subproject1', Chris@119: :rev => 'abcd' , Chris@119: }, Chris@119: :class => 'changeset', :title => 'test commit') Chris@119: to_test = { Chris@119: 'r123' => changeset_link_rev, Chris@119: 'commit:abcd' => changeset_link_commit, Chris@119: } Chris@119: @project = Project.find(3) Chris@119: r = Repository::Mercurial.create!(:project => @project, :url => '/tmp/test') Chris@119: assert r Chris@119: c = Changeset.new(:repository => r, Chris@119: :committed_on => Time.now, Chris@119: :revision => '123', Chris@119: :scmid => 'abcd', Chris@119: :comments => 'test commit') Chris@119: assert( c.save ) Chris@119: to_test.each { |text, result| assert_equal "

#{result}

", textilizable(text) } Chris@119: end Chris@119: Chris@0: def test_attachment_links Chris@0: attachment_link = link_to('error281.txt', {:controller => 'attachments', :action => 'download', :id => '1'}, :class => 'attachment') Chris@0: to_test = { Chris@0: 'attachment:error281.txt' => attachment_link Chris@0: } Chris@0: to_test.each { |text, result| assert_equal "

#{result}

", textilizable(text, :attachments => Issue.find(3).attachments), "#{text} failed" } Chris@0: end Chris@441: Chris@0: def test_wiki_links Chris@0: to_test = { Chris@0: '[[CookBook documentation]]' => 'CookBook documentation', Chris@0: '[[Another page|Page]]' => 'Page', Chris@909: # title content should be formatted Chris@909: '[[Another page|With _styled_ *title*]]' => 'With styled title', Chris@909: '[[Another page|With title containing HTML entities & markups]]' => 'With title containing <strong>HTML entities & markups</strong>', Chris@0: # link with anchor Chris@0: '[[CookBook documentation#One-section]]' => 'CookBook documentation', Chris@0: '[[Another page#anchor|Page]]' => 'Page', Chris@0: # page that doesn't exist Chris@0: '[[Unknown page]]' => 'Unknown page', Chris@0: '[[Unknown page|404]]' => '404', Chris@0: # link to another project wiki chris@37: '[[onlinestore:]]' => 'onlinestore', chris@37: '[[onlinestore:|Wiki]]' => 'Wiki', Chris@0: '[[onlinestore:Start page]]' => 'Start page', Chris@0: '[[onlinestore:Start page|Text]]' => 'Text', Chris@0: '[[onlinestore:Unknown page]]' => 'Unknown page', Chris@0: # striked through link Chris@0: '-[[Another page|Page]]-' => 'Page', Chris@0: '-[[Another page|Page]] link-' => 'Page link', Chris@0: # escaping Chris@0: '![[Another page|Page]]' => '[[Another page|Page]]', Chris@0: # project does not exist Chris@0: '[[unknowproject:Start]]' => '[[unknowproject:Start]]', Chris@0: '[[unknowproject:Start|Page title]]' => '[[unknowproject:Start|Page title]]', Chris@0: } Chris@909: Chris@0: @project = Project.find(1) Chris@0: to_test.each { |text, result| assert_equal "

#{result}

", textilizable(text) } Chris@0: end Chris@441: Chris@909: def test_wiki_links_within_local_file_generation_context Chris@909: Chris@909: to_test = { Chris@909: # link to a page Chris@909: '[[CookBook documentation]]' => 'CookBook documentation', Chris@909: '[[CookBook documentation|documentation]]' => 'documentation', Chris@909: '[[CookBook documentation#One-section]]' => 'CookBook documentation', Chris@909: '[[CookBook documentation#One-section|documentation]]' => 'documentation', Chris@909: # page that doesn't exist Chris@909: '[[Unknown page]]' => 'Unknown page', Chris@909: '[[Unknown page|404]]' => '404', Chris@909: '[[Unknown page#anchor]]' => 'Unknown page', Chris@909: '[[Unknown page#anchor|404]]' => '404', Chris@909: } Chris@909: Chris@909: @project = Project.find(1) Chris@909: Chris@909: to_test.each { |text, result| assert_equal "

#{result}

", textilizable(text, :wiki_links => :local) } Chris@909: end Chris@909: Chris@0: def test_html_tags Chris@0: to_test = { Chris@0: "
content
" => "

<div>content</div>

", Chris@0: "
content
" => "

<div class=\"bold\">content</div>

", Chris@0: "" => "

<script>some script;</script>

", Chris@0: # do not escape pre/code tags Chris@0: "
\nline 1\nline2
" => "
\nline 1\nline2
", Chris@0: "
\nline 1\nline2
" => "
\nline 1\nline2
", Chris@0: "
content
" => "
<div>content</div>
", Chris@0: "HTML comment: " => "

HTML comment: <!-- no comments -->

", Chris@0: "