2005-01-20 01:05:23 +01:00
|
|
|
#!/bin/env ruby -w
|
2005-01-16 23:40:44 +01:00
|
|
|
|
|
|
|
require File.dirname(__FILE__) + '/../test_helper'
|
|
|
|
require 'web'
|
|
|
|
require 'revision'
|
2005-01-15 21:26:54 +01:00
|
|
|
|
|
|
|
class RevisionTest < Test::Unit::TestCase
|
|
|
|
|
|
|
|
def setup
|
2005-01-23 04:27:45 +01:00
|
|
|
setup_test_wiki
|
2005-01-16 22:49:27 +01:00
|
|
|
@web.markup = :textile
|
2005-01-15 21:26:54 +01:00
|
|
|
|
2005-01-23 04:27:45 +01:00
|
|
|
@page = @wiki.read_page('wiki1', 'HomePage')
|
|
|
|
['MyWay', 'SmartEngine', 'ThatWay'].each do |page|
|
|
|
|
@wiki.write_page('wiki1', page, page, Time.now, 'Me')
|
|
|
|
end
|
2005-01-18 23:32:50 +01:00
|
|
|
|
2005-01-16 23:16:24 +01:00
|
|
|
@revision = Revision.new(@page, 1,
|
|
|
|
'HisWay would be MyWay in kinda ThatWay in HisWay though MyWay \\OverThere -- ' +
|
|
|
|
'see SmartEngine in that SmartEngineGUI',
|
|
|
|
Time.local(2004, 4, 4, 16, 50), 'DavidHeinemeierHansson')
|
2005-01-15 21:26:54 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_wiki_words
|
|
|
|
assert_equal %w( HisWay MyWay SmartEngine SmartEngineGUI ThatWay ), @revision.wiki_words.sort
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_existing_pages
|
|
|
|
assert_equal %w( MyWay SmartEngine ThatWay ), @revision.existing_pages.sort
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_unexisting_pages
|
|
|
|
assert_equal %w( HisWay SmartEngineGUI ), @revision.unexisting_pages.sort
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_content_with_wiki_links
|
2005-01-16 23:16:24 +01:00
|
|
|
assert_equal '<p><span class="newWikiWord">His Way<a href="../show/HisWay">?</a></span> ' +
|
|
|
|
'would be <a class="existingWikiWord" href="../show/MyWay">My Way</a> in kinda ' +
|
|
|
|
'<a class="existingWikiWord" href="../show/ThatWay">That Way</a> in ' +
|
|
|
|
'<span class="newWikiWord">His Way<a href="../show/HisWay">?</a></span> ' +
|
|
|
|
'though <a class="existingWikiWord" href="../show/MyWay">My Way</a> OverThere—see ' +
|
|
|
|
'<a class="existingWikiWord" href="../show/SmartEngine">Smart Engine</a> in that ' +
|
|
|
|
'<span class="newWikiWord">Smart Engine <span class="caps">GUI</span>' +
|
|
|
|
'<a href="../show/SmartEngineGUI">?</a></span></p>',
|
|
|
|
@revision.display_content
|
2005-01-15 21:26:54 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_bluecloth
|
2005-01-16 22:49:27 +01:00
|
|
|
@web.markup = :markdown
|
2005-01-15 21:26:54 +01:00
|
|
|
|
2005-01-18 23:32:50 +01:00
|
|
|
assert_markup_parsed_as(
|
|
|
|
%{<h1>My Headline</h1>\n\n<p>that <span class="newWikiWord">} +
|
|
|
|
%{Smart Engine GUI<a href="../show/SmartEngineGUI">?</a></span></p>},
|
|
|
|
"My Headline\n===========\n\n that SmartEngineGUI")
|
2005-01-15 21:26:54 +01:00
|
|
|
|
2005-01-18 23:32:50 +01:00
|
|
|
code_block = [
|
|
|
|
'This is a code block:',
|
2005-01-15 21:26:54 +01:00
|
|
|
'',
|
|
|
|
' def a_method(arg)',
|
|
|
|
' return ThatWay',
|
|
|
|
'',
|
2005-01-18 23:32:50 +01:00
|
|
|
'Nice!'
|
|
|
|
].join("\n")
|
2005-01-15 21:26:54 +01:00
|
|
|
|
2005-01-18 23:32:50 +01:00
|
|
|
assert_markup_parsed_as(
|
|
|
|
%{<p>This is a code block:</p>\n\n<pre><code>def a_method(arg)\n} +
|
2005-01-15 21:26:54 +01:00
|
|
|
%{return ThatWay\n</code></pre>\n\n<p>Nice!</p>},
|
2005-01-18 23:32:50 +01:00
|
|
|
code_block)
|
2005-01-15 21:26:54 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_rdoc
|
2005-01-16 22:49:27 +01:00
|
|
|
@web.markup = :rdoc
|
2005-01-15 21:26:54 +01:00
|
|
|
|
2005-01-16 23:16:24 +01:00
|
|
|
@revision = Revision.new(@page, 1, '+hello+ that SmartEngineGUI',
|
|
|
|
Time.local(2004, 4, 4, 16, 50), 'DavidHeinemeierHansson')
|
2005-01-15 21:26:54 +01:00
|
|
|
|
2005-01-18 23:32:50 +01:00
|
|
|
assert_equal "<tt>hello</tt> that <span class=\"newWikiWord\">Smart Engine GUI" +
|
2005-01-16 23:16:24 +01:00
|
|
|
"<a href=\"../show/SmartEngineGUI\">?</a></span>\n\n", @revision.display_content
|
2005-01-15 21:26:54 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_content_with_auto_links
|
2005-01-18 23:32:50 +01:00
|
|
|
assert_markup_parsed_as(
|
|
|
|
'<p><a href="http://www.loudthinking.com/">http://www.loudthinking.com/</a> ' +
|
2005-01-16 23:16:24 +01:00
|
|
|
'points to <a class="existingWikiWord" href="../show/ThatWay">That Way</a> from ' +
|
|
|
|
'<a href="mailto:david@loudthinking.com">david@loudthinking.com</a></p>',
|
2005-01-18 23:32:50 +01:00
|
|
|
'http://www.loudthinking.com/ points to ThatWay from david@loudthinking.com')
|
|
|
|
|
2005-01-15 21:26:54 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_content_with_aliased_links
|
2005-01-18 23:32:50 +01:00
|
|
|
assert_markup_parsed_as(
|
|
|
|
'<p>Would a <a class="existingWikiWord" href="../show/SmartEngine">clever motor' +
|
|
|
|
'</a> go by any other name?</p>',
|
|
|
|
'Would a [[SmartEngine|clever motor]] go by any other name?')
|
2005-01-15 21:26:54 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_content_with_wikiword_in_em
|
2005-01-18 23:32:50 +01:00
|
|
|
assert_markup_parsed_as(
|
|
|
|
'<p><em>should we go <a class="existingWikiWord" href="../show/ThatWay">' +
|
2005-01-16 23:16:24 +01:00
|
|
|
'That Way</a> or <span class="newWikiWord">This Way<a href="../show/ThisWay">?</a>' +
|
2005-01-18 23:32:50 +01:00
|
|
|
'</span> </em></p>',
|
|
|
|
'_should we go ThatWay or ThisWay _')
|
2005-01-15 21:26:54 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_content_with_wikiword_in_tag
|
2005-01-18 23:32:50 +01:00
|
|
|
assert_markup_parsed_as(
|
|
|
|
'<p>That is some <em style="WikiWord">Stylish Emphasis</em></p>',
|
|
|
|
'That is some <em style="WikiWord">Stylish Emphasis</em>')
|
2005-01-15 21:26:54 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_content_with_pre_blocks
|
2005-01-18 23:32:50 +01:00
|
|
|
assert_markup_parsed_as(
|
|
|
|
'A <code>class SmartEngine end</code> would not mark up <pre>CodeBlocks</pre>',
|
|
|
|
'A <code>class SmartEngine end</code> would not mark up <pre>CodeBlocks</pre>')
|
2005-01-15 21:26:54 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_content_with_autolink_in_parentheses
|
2005-01-18 23:32:50 +01:00
|
|
|
assert_markup_parsed_as(
|
|
|
|
'<p>The <span class="caps">W3C</span> body (<a href="http://www.w3c.org">' +
|
2005-01-16 23:16:24 +01:00
|
|
|
'http://www.w3c.org</a>) sets web standards</p>',
|
2005-01-18 23:32:50 +01:00
|
|
|
'The W3C body (http://www.w3c.org) sets web standards')
|
2005-01-15 21:26:54 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_content_with_link_in_parentheses
|
2005-01-18 23:32:50 +01:00
|
|
|
assert_markup_parsed_as(
|
2005-01-19 22:09:08 +01:00
|
|
|
'<p>(<a href="http://wiki.org/wiki.cgi?WhatIsWiki">What is a wiki?</a>)</p>',
|
|
|
|
'("What is a wiki?":http://wiki.org/wiki.cgi?WhatIsWiki)')
|
2005-01-15 21:26:54 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_content_with_image_link
|
2005-01-18 23:32:50 +01:00
|
|
|
assert_markup_parsed_as(
|
|
|
|
'<p>This <img src="http://hobix.com/sample.jpg" alt="" /> is a Textile image link.</p>',
|
|
|
|
'This !http://hobix.com/sample.jpg! is a Textile image link.')
|
2005-01-15 21:26:54 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_content_with_nowiki_text
|
2005-01-18 23:32:50 +01:00
|
|
|
assert_markup_parsed_as(
|
|
|
|
'<p>Do not mark up [[this text]] or http://www.thislink.com.</p>',
|
|
|
|
'Do not mark up <nowiki>[[this text]]</nowiki> ' +
|
|
|
|
'or <nowiki>http://www.thislink.com</nowiki>.')
|
2005-01-15 21:26:54 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_content_with_bracketted_wiki_word
|
2005-01-16 22:49:27 +01:00
|
|
|
@web.brackets_only = true
|
2005-01-18 23:32:50 +01:00
|
|
|
assert_markup_parsed_as(
|
|
|
|
'<p>This is a WikiWord and a tricky name <span class="newWikiWord">' +
|
2005-01-16 23:16:24 +01:00
|
|
|
'Sperberg-McQueen<a href="../show/Sperberg-McQueen">?</a></span>.</p>',
|
2005-01-18 23:32:50 +01:00
|
|
|
'This is a WikiWord and a tricky name [[Sperberg-McQueen]].')
|
2005-01-15 21:26:54 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_content_for_export
|
2005-01-16 23:16:24 +01:00
|
|
|
assert_equal '<p><span class="newWikiWord">His Way</span> would be ' +
|
|
|
|
'<a class="existingWikiWord" href="MyWay.html">My Way</a> in kinda ' +
|
|
|
|
'<a class="existingWikiWord" href="ThatWay.html">That Way</a> in ' +
|
|
|
|
'<span class="newWikiWord">His Way</span> though ' +
|
|
|
|
'<a class="existingWikiWord" href="MyWay.html">My Way</a> OverThere—see ' +
|
|
|
|
'<a class="existingWikiWord" href="SmartEngine.html">Smart Engine</a> in that ' +
|
|
|
|
'<span class="newWikiWord">Smart Engine <span class="caps">GUI</span></span></p>',
|
|
|
|
@revision.display_content_for_export
|
2005-01-15 21:26:54 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_double_replacing
|
|
|
|
@revision.content = "VersionHistory\r\n\r\ncry VersionHistory"
|
2005-01-16 23:16:24 +01:00
|
|
|
assert_equal '<p><span class="newWikiWord">Version History' +
|
|
|
|
"<a href=\"../show/VersionHistory\">?</a></span></p>\n\n\t<p>cry " +
|
|
|
|
'<span class="newWikiWord">Version History<a href="../show/VersionHistory">?</a>' +
|
|
|
|
'</span></p>',
|
|
|
|
@revision.display_content
|
2005-01-15 21:26:54 +01:00
|
|
|
|
|
|
|
@revision.clear_display_cache
|
|
|
|
|
|
|
|
@revision.content = "f\r\nVersionHistory\r\n\r\ncry VersionHistory"
|
2005-01-16 23:16:24 +01:00
|
|
|
assert_equal "<p>f<br />\n<span class=\"newWikiWord\">Version History" +
|
|
|
|
"<a href=\"../show/VersionHistory\">?</a></span></p>\n\n\t<p>cry " +
|
|
|
|
"<span class=\"newWikiWord\">Version History<a href=\"../show/VersionHistory\">?</a>" +
|
|
|
|
"</span></p>",
|
|
|
|
@revision.display_content
|
2005-01-15 21:26:54 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_difficult_wiki_words
|
|
|
|
@revision.content = "[[It's just awesome GUI!]]"
|
2005-01-16 23:16:24 +01:00
|
|
|
assert_equal "<p><span class=\"newWikiWord\">It’s just awesome <span class=\"caps\">GUI" +
|
|
|
|
"</span>!<a href=\"../show/It%27s+just+awesome+GUI%21\">?</a></span></p>",
|
|
|
|
@revision.display_content
|
2005-01-15 21:26:54 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_revisions_diff
|
|
|
|
|
2005-01-18 23:32:50 +01:00
|
|
|
@page.revisions = [
|
|
|
|
Revision.new(@page, 0, 'What a blue and lovely morning',
|
|
|
|
Time.local(2004, 4, 4, 16, 50), 'DavidHeinemeierHansson'),
|
|
|
|
Revision.new(@page, 1, 'What a red and lovely morning today',
|
|
|
|
Time.local(2004, 4, 4, 16, 50), 'DavidHeinemeierHansson')
|
|
|
|
]
|
2005-01-16 23:16:24 +01:00
|
|
|
|
|
|
|
assert_equal "<p>What a <del class=\"diffmod\">blue </del><ins class=\"diffmod\">red " +
|
|
|
|
"</ins>and lovely <del class=\"diffmod\">morning</del><ins class=\"diffmod\">morning " +
|
2005-01-18 23:32:50 +01:00
|
|
|
"today</ins></p>", @page.revisions.last.display_diff
|
|
|
|
end
|
|
|
|
|
2005-01-22 17:38:33 +01:00
|
|
|
def test_link_to_file
|
|
|
|
assert_markup_parsed_as(
|
|
|
|
'<p><span class="newWikiWord">doc.pdf<a href="../file/doc.pdf">?</a></span></p>',
|
|
|
|
'[[doc.pdf:file]]')
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_link_to_pic
|
|
|
|
assert_markup_parsed_as(
|
2005-01-23 04:27:45 +01:00
|
|
|
'<p><img alt="Square" src="../pic/square.jpg" /></p>',
|
2005-01-22 17:38:33 +01:00
|
|
|
'[[square.jpg|Square:pic]]')
|
2005-01-23 04:27:45 +01:00
|
|
|
assert_markup_parsed_as(
|
|
|
|
'<p><img alt="square.jpg" src="../pic/square.jpg" /></p>',
|
|
|
|
'[[square.jpg:pic]]')
|
2005-01-22 17:38:33 +01:00
|
|
|
end
|
|
|
|
|
2005-01-20 01:21:29 +01:00
|
|
|
# TODO Remove the leading underscores from this test when upgrading to RedCloth 3.0.1;
|
|
|
|
# also add a test for the "Unhappy Face" problem (another interesting RedCloth bug)
|
|
|
|
def __test_list_with_tildas
|
2005-01-20 01:05:23 +01:00
|
|
|
list_with_tildas = <<-EOL
|
|
|
|
* "a":~b
|
|
|
|
* c~ d
|
|
|
|
EOL
|
2005-01-20 01:21:29 +01:00
|
|
|
|
2005-01-20 01:05:23 +01:00
|
|
|
assert_markup_parsed_as(
|
|
|
|
"<li><a href=\"~b\">a</a></li>\n" +
|
|
|
|
"<li>c~ d</li>\n",
|
|
|
|
list_with_tildas)
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2005-01-18 23:32:50 +01:00
|
|
|
|
|
|
|
def assert_markup_parsed_as(expected_output, input)
|
|
|
|
revision = Revision.new(@page, 1, input, Time.local(2004, 4, 4, 16, 50), 'AnAuthor')
|
|
|
|
assert_equal expected_output, revision.display_content, 'Textile output not as expected'
|
2005-01-15 21:26:54 +01:00
|
|
|
end
|
2005-01-16 23:16:24 +01:00
|
|
|
|
|
|
|
end
|