2009-05-13 08:44:47 +02:00
#!/usr/bin/env ruby
# encoding: UTF-8
2007-01-22 14:43:50 +01:00
require File . expand_path ( File . dirname ( __FILE__ ) + '/../test_helper' )
2009-02-04 21:26:08 +01:00
class PageRendererTest < ActiveSupport :: TestCase
2007-01-22 14:43:50 +01:00
fixtures :webs , :pages , :revisions , :system , :wiki_references
def setup
@wiki = Wiki . new
@web = webs ( :test_wiki )
@page = pages ( :home_page )
@revision = revisions ( :home_page_second_revision )
end
def test_wiki_word_linking
@web . add_page ( 'SecondPage' , 'Yo, yo. Have you EverBeenHated' ,
Time . now , 'DavidHeinemeierHansson' , test_renderer )
2008-05-15 08:22:13 +02:00
assert_equal ( " <p>Yo, yo. Have you <span class='newWikiWord'>Ever Been Hated " +
" <a href='../show/EverBeenHated'>?</a></span></p> " ,
2007-01-22 14:43:50 +01:00
rendered_content ( @web . page ( " SecondPage " ) ) )
@web . add_page ( 'EverBeenHated' , 'Yo, yo. Have you EverBeenHated' , Time . now ,
'DavidHeinemeierHansson' , test_renderer )
2008-05-15 08:22:13 +02:00
assert_equal ( " <p>Yo, yo. Have you <a class='existingWikiWord' " +
" href='../show/EverBeenHated'>Ever Been Hated</a></p> " ,
2007-01-22 14:43:50 +01:00
rendered_content ( @web . page ( " SecondPage " ) ) )
end
def test_wiki_words
assert_equal %w( HisWay MyWay SmartEngine SmartEngineGUI ThatWay ) ,
test_renderer ( @revision ) . wiki_words . sort
@wiki . write_page ( 'wiki1' , 'NoWikiWord' , 'hey you!' , Time . now , 'Me' , test_renderer )
assert_equal [ ] , test_renderer ( @wiki . read_page ( 'wiki1' , 'NoWikiWord' ) . revisions . last ) . wiki_words
end
def test_existing_pages
assert_equal %w( MyWay SmartEngine ThatWay ) , test_renderer ( @revision ) . existing_pages . sort
end
def test_unexisting_pages
assert_equal %w( HisWay SmartEngineGUI ) , test_renderer ( @revision ) . unexisting_pages . sort
end
def test_content_with_wiki_links
2008-05-15 08:22:13 +02: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> " +
" <math class='maruku-mathml' display='inline' xmlns='http://www.w3.org/1998/Math/MathML'> " +
" <mi>sin</mi><mo stretchy='false'>(</mo><mi>x</mi><mo stretchy='false'>)</mo><semantics> " +
" <annotation-xml encoding='SVG1.1'><svg/></annotation-xml></semantics></math> in kinda " +
" <a class='existingWikiWord' href='../show/ThatWay'>That Way</a> in " +
" <span class='newWikiWord'>His Way<a href='../show/HisWay'>?</a></span> " +
2008-05-21 00:02:10 +02:00
%{ though <a class='existingWikiWord' href='../show/MyWay'>My Way</a> OverThere \342 \200 \223 see } +
2008-05-15 08:22:13 +02:00
" <a class='existingWikiWord' href='../show/SmartEngine'>Smart Engine</a> in that " +
" <span class='newWikiWord'>Smart Engine GUI " +
" <a href='../show/SmartEngineGUI'>?</a></span></p> " ,
2007-01-22 14:43:50 +01:00
test_renderer ( @revision ) . display_content
end
def test_markdown
2007-10-28 00:34:29 +02:00
set_web_property :markup , :markdownMML
assert_markup_parsed_as (
2008-05-15 08:22:13 +02:00
%{ <p>equation <math class='maruku-mathml' } +
%{ display='inline' xmlns='http://www.w3.org/1998/Math/MathML'> } +
%{ <mi>sin</mi><mo stretchy='false'>(</mo><mi>x</mi><mo stretchy='false'>)</mo></math></p> } ,
2007-10-28 00:34:29 +02:00
" equation $ \\ sin(x)$ " )
2007-01-22 14:43:50 +01:00
2008-10-25 07:52:59 +02:00
re = Regexp . new ( '\\A<h1 id=\'my_headline_\\d{1,4}\'>My Headline</h1>\n\n<p>that <span class=\'newWikiWord\'>Smart Engine GUI<a href=\'../show/SmartEngineGUI\'>\?</a></span></p>\\Z' )
2008-10-17 23:26:17 +02:00
assert_match_markup_parsed_as ( re , " My Headline \n =========== \n \n that SmartEngineGUI " )
2007-01-22 14:43:50 +01:00
2008-10-17 23:26:17 +02:00
assert_match_markup_parsed_as ( re , " # My Headline # \n \n that SmartEngineGUI " )
2008-10-25 07:52:59 +02:00
str1 = %{ <div class='un_defn'> \n <h6 id='definition_ \\ d \{ 1,4 \} '>Definition</h6> \n \n <p>Let <math } +
%{ class='maruku-mathml' display='inline' xmlns='http://www.w3.org/1998/Math/MathML'><mi>H</mi> } +
%{ </math> be a subgroup of a group <math class='maruku-mathml' display='inline' xmlns='http://w } +
%{ ww.w3.org/1998/Math/MathML'><mi>G</mi></math>. A <em>left coset</em> of <math class='maruku-m } +
%{ athml' display='inline' xmlns='http://www.w3.org/1998/Math/MathML'><mi>H</mi></math> in <math } +
%{ class='maruku-mathml' display='inline' xmlns='http://www.w3.org/1998/Math/MathML'><mi>G</mi> } +
%{ </math> is a subset of <math class='maruku-mathml' display='inline' xmlns='http://www.w3.org/ } +
%{ 1998/Math/MathML'><mi>G</mi></math> that is of the form <math class='maruku-mathml' display=' } +
%{ inline' xmlns='http://www.w3.org/1998/Math/MathML'><mi>x</mi><mi>H</mi></math>, where <math } +
%{ class='maruku-mathml' display='inline' xmlns='http://www.w3.org/1998/Math/MathML'><mi>x</mi> } +
%{ <mo> \342 \210 \210 </mo><mi>G</mi></math> and <math class='maruku-mathml' display='inline' xmlns } +
%{ ='http://www.w3.org/1998/Math/MathML'><mi>x</mi><mi>H</mi><mo>=</mo><mo stretchy='false'> \\ \{ < } +
%{ /mo><mi>x</mi><mi>h</mi><mo>:</mo><mi>h</mi><mo> \342 \210 \210 </mo><mi>H</mi><mo stretchy='fals } +
%{ e'> \\ \} </mo></math>.</p> \n \n <p>Similarly a <em>right coset</em> of <math class='maruku-mathml' } +
%{ display='inline' xmlns='http://www.w3.org/1998/Math/MathML'><mi>H</mi></math> in <math class } +
%{ ='maruku-mathml' display='inline' xmlns='http://www.w3.org/1998/Math/MathML'><mi>G</mi></math } +
%{ > is a subset of <math class='maruku-mathml' display='inline' xmlns='http://www.w3.org/1998/M } +
%{ ath/MathML'><mi>G</mi></math> that is of the form <math class='maruku-mathml' display='inline } +
%{ ' xmlns='http://www.w3.org/1998/Math/MathML'><mi>H</mi><mi>x</mi></math>, where <math class=' } +
%{ maruku-mathml' display='inline' xmlns='http://www.w3.org/1998/Math/MathML'><mi>H</mi><mi>x</m } +
%{ i><mo>=</mo><mo stretchy='false'> \\ \{ </mo><mi>h</mi><mi>x</mi><mo>:</mo><mi>h</mi><mo> \342 \210 \210 } +
%{ </mo><mi>H</mi><mo stretchy='false'> \\ \} </mo></math>.</p> \n </div> \n \n } +
%{ <div class='num_lemma' id='LeftCosetsDisjoint'> \n <h6 id='lemma_ \\ d \{ 1,4 \} '>Lemma</h6> \n \n <p> } +
%{ Let <math class='maruku-mathml' display='inline' xmlns='http://www.w3.org/1998/Math/MathML'> } +
%{ <mi>H</mi></math> be a subgroup of a group <math class='maruku-mathml' display='inline' xmlns } +
%{ ='http://www.w3.org/1998/Math/MathML'><mi>G</mi></math>, and let <math class='maruku-mathml' } +
%{ display='inline' xmlns='http://www.w3.org/1998/Math/MathML'><mi>x</mi></math> and <math cla } +
%{ ss='maruku-mathml' display='inline' xmlns='http://www.w3.org/1998/Math/MathML'><mi>y</mi></ma } +
%{ th> be elements of <math class='maruku-mathml' display='inline' xmlns='http://www.w3.org/1998/ } +
%{ Math/MathML'><mi>G</mi></math>. Suppose that <math class='maruku-mathml' display='inline' xmln } +
%{ s='http://www.w3.org/1998/Math/MathML'><mi>x</mi><mi>H</mi><mo> \342 \210 \251 </mo><mi>y</mi><mi> } +
%{ H</mi></math> is non-empty. Then <math class='maruku-mathml' display='inline' xmlns='http://ww } +
%{ w.w3.org/1998/Math/MathML'><mi>x</mi><mi>H</mi><mo>=</mo><mi>y</mi><mi>H</mi></math>.</p> \n </d } +
%{ iv> \n \n <div class='proof'> \n <h6 id='proof_ \\ d \{ 1,4 \} '>Proof</h6> \n \n <p>Let <math class='maruku-m } +
%{ athml' display='inline' xmlns='http://www.w3.org/1998/Math/MathML'><mi>z</mi></math> be some e } +
%{ lement of <math class='maruku-mathml' display='inline' xmlns='http://www.w3.org/1998/Math/Math } +
%{ ML'><mi>x</mi><mi>H</mi><mo> \342 \210 \251 </mo><mi>y</mi><mi>H</mi></math>.</p> \n </div> \n \n } +
%{ <div class='num_lemma' id='SizeOfLeftCoset'> \n <h6 id='lemma_ \\ d \{ 1,4 \} '>Lemma</h6> \n \n <p> } +
%{ Let <math class='maruku-mathml' display='inline' xmlns='http://www.w3.org/1998/Math/MathML'> } +
%{ <mi>H</mi></math> be a finite subgroup of a group <math class='maruku-mathml' display='inline' xmlns } +
%{ ='http://www.w3.org/1998/Math/MathML'><mi>G</mi></math>.</p> \n </div> \n \n } +
%{ <div class='num_theorem' id='Lagrange'> \n <h6 id='theorem_ \\ d \{ 1,4 \} '>Theorem</h6> \n \n <p><strong> \\ (Lagrange \342 \200 \231 s Theorem \\ ).</strong> Let <math class='maruku-mathml' display='inline' xmlns='http://www.w3.org/1998/Math/MathML'><mi>G</mi></math> be a finite group, and let <math class='maruku-mathml' display='inline' xmlns='http://www.w3.org/1998/Math/MathML'><mi>H</mi></math> be a subgroup of <math class='maruku-mathml' display='inline' xmlns='http://www.w3.org/1998/Math/MathML'><mi>G</mi></math>.</p> \n </div> }
str2 = <<END_THM
+ - - { : . un_defn }
###### Definition
Let $H $ be a subgroup of a group $G $. A * left coset * of $H $ in $G $ is a subset of $G $ that is of the form $x H $, where $x \ \ in G $ and $x H = \ \ { x h : h \ \ in H \ \ } $.
Similarly a * right coset * of $H $ in $G $ is a subset of $G $ that is of the form $H x $, where $H x = \ \ { h x : h \ \ in H \ \ } $.
= - -
+ - - { : . num_lemma #LeftCosetsDisjoint}
###### Lemma
Let $H $ be a subgroup of a group $G $, and let $x $ and $y $ be
elements of $G $. Suppose that $x H \ \ cap y H $ is non - empty . Then $x H = y H $.
= - -
+ - - { : . proof }
###### Proof
Let $z $ be some element of $x H \ \ cap y H $.
= - -
+ - - { : . num_lemma #SizeOfLeftCoset}
###### Lemma
Let $H $ be a finite subgroup of a group $G $.
= - -
+ - - { : . num_theorem #Lagrange}
###### Theorem
** ( Lagrange ' s Theorem ) . ** Let $G $ be a finite group , and let $H $ be a subgroup of $G $.
= - -
END_THM
assert_match_markup_parsed_as ( Regexp . new ( str1 ) , str2 )
2007-06-13 08:56:44 +02:00
2007-12-21 15:53:45 +01:00
assert_markup_parsed_as (
2008-05-15 08:22:13 +02:00
%{ <p>SVG <animateColor title='MathML'><span class='newWikiWord'> } +
%{ Math ML<a href='../show/MathML'>?</a></span></animateColor></p> } ,
2007-12-21 15:53:45 +01:00
" SVG <animateColor title='MathML'>MathML</animateColor> " )
2007-10-26 07:48:43 +02:00
assert_markup_parsed_as (
2008-05-15 08:22:13 +02:00
%{ <div class='maruku-equation'><math class='maruku-mathml' display='block' } +
%{ xmlns='http://www.w3.org/1998/Math/MathML'><mi>sin</mi><mo stretchy='false'> } +
%{ (</mo><mi>x</mi><mo stretchy='false'>)</mo><semantics><annotation-xml encoding='SVG1.1'> } +
2008-10-24 05:44:53 +02:00
%{ <svg/></annotation-xml></semantics></math><span class='maruku-eq-tex'><code style='display: none;'> } +
2009-05-13 08:44:47 +02:00
%{ \\ sin(x) \\ begin { svg } <svg/> \\ end { svg } </code></span></div> } ,
2008-05-21 09:06:31 +02:00
" $$ \\ sin(x) \\ begin{svg}<svg/> \\ end{svg}$$ " )
2007-10-26 07:48:43 +02:00
2007-01-22 14:43:50 +01:00
code_block = [
'This is a code block:' ,
'' ,
' def a_method(arg)' ,
' return ThatWay' ,
'' ,
'Nice!'
] . join ( " \n " )
assert_markup_parsed_as (
%{ <p>This is a code block:</p> \n \n <pre><code>def a_method(arg) \n } +
2007-06-14 06:05:15 +02:00
%{ return ThatWay</code></pre> \n \n <p>Nice!</p> } ,
2007-01-22 14:43:50 +01:00
code_block )
2008-05-21 21:14:43 +02:00
assert_markup_parsed_as ( %{ <p>You then needed to edit (or create) a user.js file in } +
%{ your Mozilla profile, which read either (<span class='newWikiWord'>Mac OSX<a h } +
%{ ref='../show/MacOSX'>?</a></span>)</p> \n \n <pre><code> user_pref("font.mat } +
%{ hfont-family", "Math1,Math2,Math4,Symbol");</code></pre> } ,
%{ You then needed to edit (or create) a user.js file in your Mozilla profile, whic } +
%{ h read either (MacOSX) \n \n user_pref("font.mathfont-family", "Math1,Math2,Math4,Symbol"); } )
2007-10-28 00:34:29 +02:00
2007-10-28 20:04:30 +01:00
assert_markup_parsed_as (
2008-05-15 08:22:13 +02:00
%{ <p><math class='maruku-mathml' } +
%{ display='inline' xmlns='http://www.w3.org/1998/Math/MathML'> } +
%{ <mi>sin</mi><mo stretchy='false'>(</mo><mi>x</mi><mo stretchy='false'>)</mo></math> ecuasi \303 \263 n</p> } ,
2007-10-28 20:04:30 +01:00
" $ \\ sin(x)$ ecuasi \303 \263 n " )
assert_markup_parsed_as (
2008-05-15 08:22:13 +02:00
%{ <p>ecuasi \303 \263 n</p> \n <div class='maruku-equation'><math class='maruku-mathml' } +
%{ display='block' xmlns='http://www.w3.org/1998/Math/MathML'><mi>sin</mi> } +
%{ <mo stretchy='false'>(</mo><mi>x</mi><mo stretchy='false'>)</mo></math> } +
2008-10-24 05:44:53 +02:00
%{ <span class='maruku-eq-tex'><code style='display: none;'> \\ sin(x)</code></span></div> } ,
2007-10-28 20:04:30 +01:00
" ecuasi \303 \263 n \n $$ \\ sin(x)$$ " )
2007-12-21 08:48:59 +01:00
assert_markup_parsed_as (
2008-05-15 08:22:13 +02:00
%{ <p>ecuasi \303 \263 n</p> \n \n <p><math class='maruku-mathml' } +
%{ display='inline' xmlns='http://www.w3.org/1998/Math/MathML'> } +
%{ <mi>sin</mi><mo stretchy='false'>(</mo><mi>x</mi><mo stretchy='false'>)</mo></math></p> } ,
2007-12-21 08:48:59 +01:00
" ecuasi \303 \263 n \n \n $ \\ sin(x)$ " )
2007-10-28 00:34:29 +02:00
assert_markup_parsed_as (
2008-05-15 08:22:13 +02:00
%{ <p>ecuasi \303 \263 n <math class='maruku-mathml' } +
%{ display='inline' xmlns='http://www.w3.org/1998/Math/MathML'> } +
%{ <mi>sin</mi><mo stretchy='false'>(</mo><mi>x</mi><mo stretchy='false'>)</mo></math></p> } ,
2007-10-28 00:34:29 +02:00
" ecuasi \303 \263 n $ \\ sin(x)$ " )
2007-01-22 14:43:50 +01:00
end
2009-03-10 06:15:03 +01:00
def test_have_latest_itex2mml
2009-10-04 10:46:06 +02:00
2009-10-05 09:36:00 +02:00
assert_markup_parsed_as (
%{ <p>equation <math class='maruku-mathml' displa } +
2009-11-06 21:32:45 +01:00
%{ y='inline' xmlns='http://www.w3.org/1998/Math/ } +
%{ MathML'><mi>A</mi><mo>=</mo><maction actiontyp } +
%{ e='tooltip'><mi>B</mi><mtext>Spoons!</mtext></ } +
%{ maction></math></p> } ,
" equation $A= \\ tooltip{Spoons!}{B}$ " )
assert_markup_parsed_as (
%{ <p>equation <math class='maruku-mathml' displa } +
2009-10-05 09:36:00 +02:00
%{ y='inline' xmlns='http://www.w3.org/1998/Math/ } +
%{ MathML'><mi>A</mi><mpadded lspace='-100%width' } +
%{ width='0'><mi>B</mi></mpadded></math></p> } ,
" equation $A \\ mathllap{B}$ " )
2009-10-04 10:46:06 +02:00
assert_markup_parsed_as (
%{ <p>equation <math class='maruku-mathml' displa } +
%{ y='inline' xmlns='http://www.w3.org/1998/Math/ } +
%{ MathML'><mi>A</mi><mo> \342 \211 \224 </mo><mi>B</ } +
%{ mi></math></p> } ,
" equation $A \\ coloneqq B$ " )
2009-09-13 18:23:57 +02:00
assert_markup_parsed_as (
%{ <p>equation <math class='maruku-mathml' displa } +
%{ y='inline' xmlns='http://www.w3.org/1998/Math/ } +
%{ MathML'><mi>A</mi><mo> \342 \206 \255 </mo><mi>B</ } +
%{ mi></math></p> } ,
" equation $A \\ leftrightsquigarrow B$ " )
2009-08-28 18:10:34 +02:00
assert_markup_parsed_as (
%{ <p>equation <math class='maruku-mathml' displa } +
%{ y='inline' xmlns='http://www.w3.org/1998/Math/ } +
%{ MathML'><munder><mi>A</mi><mo> \314 \262 </mo></m } +
%{ under></math></p> } ,
" equation $ \\ underline{A}$ " )
2009-03-09 05:29:06 +01:00
assert_markup_parsed_as (
%{ <p>equation <math class='maruku-mathml' } +
%{ display='inline' xmlns='http://www.w3.org/1998/Math/MathML'> } +
%{ <mi>A</mi><mo> \342 \205 \213 </mo><mi>B</mi></math></p> } ,
" equation $A \\ invamp B$ " )
2009-03-25 04:37:58 +01:00
assert_markup_parsed_as (
%{ <p>blackboard digits: <math class='maruku-mathml' display=' } +
%{ inline' xmlns='http://www.w3.org/1998/Math/MathML'><mi>math } +
2009-08-28 18:10:34 +02:00
%{ bb</mi><mn>123</mn></math></p> } ,
2009-03-25 04:37:58 +01:00
" blackboard digits: $ \ mathbb{123}$ " )
2009-07-09 22:40:45 +02:00
assert_markup_parsed_as (
%{ <p> \\ rlap: <math class='maruku-mathml' display=' } +
2009-10-05 09:36:00 +02:00
%{ inline' xmlns='http://www.w3.org/1998/Math/MathML'> } +
%{ <mn>123</mn></math></p> } ,
2009-07-09 22:40:45 +02:00
'\rlap: $\rlap{123}$' )
2009-03-09 05:29:06 +01:00
end
2009-03-10 06:15:03 +01:00
def test_blahtex
if Kernel :: system ( 'blahtex --help > /dev/null 2>&1' )
set_web_property :markup , :markdownPNG
re = Regexp . new (
%{ <p>equation <span class='maruku-inline'><img alt=' \\ $a \\ \\ sin \\ ( \\ \\ theta \\ ) \\ $' } +
%{ class='maruku-png' src=' \ . \ ./files/pngs/ \\ w+ \ .png' style='vertical-align: -0 \ .5 } +
2009-05-13 08:44:47 +02:00
%{ 55555555555556ex; height: 2 \ .33333333333333ex;'/></span></p> } )
2009-03-10 06:15:03 +01:00
assert_match_markup_parsed_as ( re , 'equation $a\sin(\theta)$' )
re = Regexp . new (
%{ <div class='maruku-equation'><img alt=' \\ $a \\ \\ sin \\ ( \\ \\ theta \\ ) \\ $' } +
2009-05-13 08:44:47 +02:00
%{ class='maruku-png' src=' \ . \ ./files/pngs/ \\ w+ \ .png' style='height: 2 \ .333333333 } +
%{ 33333ex;'/><span class='maruku-eq-tex'><code style='display: none;'>a \\ \\ sin } +
2009-03-10 06:15:03 +01:00
%{ \\ ( \\ \\ theta \\ )< \ /code>< \ /span>< \ /div> } )
assert_match_markup_parsed_as ( re , '$$a\sin(\theta)$$' )
else
print " \n BlahTeX not found ... skipping. \n "
end
end
2007-01-22 14:43:50 +01:00
def test_markdown_hyperlink_with_slash
# in response to a bug, see http://dev.instiki.org/attachment/ticket/177
set_web_property :markup , :markdown
assert_markup_parsed_as (
2008-05-15 08:22:13 +02:00
" <p><a href='http://example/with/slash'>text</a></p> " ,
2007-01-22 14:43:50 +01:00
'[text](http://example/with/slash)' )
end
def test_mixed_formatting
textile_and_markdown = [
'Markdown heading' ,
'================' ,
'' ,
'h2. Textile heading' ,
'' ,
'*some* **text** _with_ -styles-' ,
'' ,
'* list 1' ,
'* list 2'
] . join ( " \n " )
2009-01-14 23:11:07 +01:00
set_web_property :markup , :markdownMML
2008-10-17 23:26:17 +02:00
re = Regexp . new (
'<h1 id=\'markdown_heading_\d{1,4}\'>Markdown heading</h1>\n\n' +
2007-01-22 14:43:50 +01:00
" <p>h2. Textile heading</p> \n \n " +
" <p><em>some</em> <strong>text</strong> <em>with</em> -styles-</p> \n \n " +
2008-10-17 23:26:17 +02:00
" <ul> \n <li>list 1</li> \n \n <li>list 2</li> \n </ul> " )
2007-01-22 14:43:50 +01:00
2008-10-17 23:26:17 +02:00
assert_match_markup_parsed_as ( re , textile_and_markdown )
2007-01-22 14:43:50 +01:00
set_web_property :markup , :textile
assert_markup_parsed_as (
2007-06-14 06:05:15 +02:00
" <p>Markdown heading<br/>================</p> \n \n \n \t <h2>Textile heading</h2> " +
2007-01-22 14:43:50 +01:00
" \n \n \n \t <p><strong>some</strong> <b>text</b> <em>with</em> <del>styles</del></p> " +
" \n \n \n \t <ul> \n \t <li>list 1</li> \n \t \t <li>list 2</li> \n \t </ul> " ,
textile_and_markdown )
set_web_property :markup , :mixed
assert_markup_parsed_as (
" <h1>Markdown heading</h1> \n \n \n \t <h2>Textile heading</h2> \n \n \n \t " +
" <p><strong>some</strong> <b>text</b> <em>with</em> <del>styles</del></p> \n \n \n \t " +
" <ul> \n \t <li>list 1</li> \n \t \t <li>list 2</li> \n \t </ul> " ,
textile_and_markdown )
end
def test_rdoc
set_web_property :markup , :rdoc
@revision = Revision . new ( :page = > @page , :content = > '+hello+ that SmartEngineGUI' ,
:author = > Author . new ( 'DavidHeinemeierHansson' ) )
2008-05-15 08:22:13 +02:00
assert_equal " <tt>hello</tt> that <span class='newWikiWord'>Smart Engine GUI " +
" <a href='../show/SmartEngineGUI'>?</a></span> \n \n " ,
2007-01-22 14:43:50 +01:00
test_renderer ( @revision ) . display_content
end
2007-10-06 23:04:11 +02:00
# def test_content_with_auto_links
# assert_markup_parsed_as(
# '<p><a href="http://www.loudthinking.com/">http://www.loudthinking.com/</a> ' +
# 'points to <a class="existingWikiWord" href="../show/ThatWay">That Way</a> from ' +
# '<a href="mailto:david@loudthinking.com">david@loudthinking.com</a></p>',
# 'http://www.loudthinking.com/ points to ThatWay from david@loudthinking.com')
#
# end
2007-01-22 14:43:50 +01:00
def test_content_with_aliased_links
assert_markup_parsed_as (
2008-05-15 08:22:13 +02:00
" <p>Would a <a class='existingWikiWord' href='../show/SmartEngine'>clever motor " +
2007-01-22 14:43:50 +01:00
'</a> go by any other name?</p>' ,
'Would a [[SmartEngine|clever motor]] go by any other name?' )
end
def test_content_with_wikiword_in_em
assert_markup_parsed_as (
2008-05-15 08:22:13 +02:00
" <p><em>should we go <a class='existingWikiWord' href='../show/ThatWay'> " +
" That Way</a> or <span class='newWikiWord'>This Way<a href='../show/ThisWay'>?</a> " +
2007-09-11 19:04:26 +02:00
'</span></em></p>' ,
2007-01-22 14:43:50 +01:00
'_should we go ThatWay or ThisWay _' )
end
2009-06-07 04:08:08 +02:00
def test_content_with_redirected_link
assert_markup_parsed_as (
" <p>This is a redirected link: <a class='existingWikiWord' href='../show/liquor'> " +
" booze</a>. This is not: <span class='newWikiWord'>hooch<a href='../show/hooch'>?</a> " +
'</span></p>' ,
'This is a redirected link: [[booze]]. This is not: [[hooch]]' )
end
2009-01-14 23:11:07 +01:00
def test_content_with_wikiword_in_equations
assert_markup_parsed_as (
" <p>should we go <a class='existingWikiWord' href='../show/ThatWay'> " +
" That Way</a> or</p> \n <div class='maruku-equation' id='eq:eq1'> " +
2009-10-10 06:18:17 +02:00
" <span class='maruku-eq-number'>(1)</span><math class='maruku-mathml' display='block' " +
2009-01-14 23:11:07 +01:00
" xmlns='http://www.w3.org/1998/Math/MathML'><mi>ThisWay</mi></math> " +
" <span class='maruku-eq-tex'><code style='display: none;'>ThisWay</code> " +
2009-10-10 06:18:17 +02:00
" </span></div> " ,
2009-01-14 23:11:07 +01:00
" should we go ThatWay or \n \\ [ThisWay \\ ] \n " )
assert_markup_parsed_as (
" <p>should we go <a class='existingWikiWord' href='../show/ThatWay'> " +
" That Way</a> or</p> \n <div class='maruku-equation'> " +
" <math class='maruku-mathml' display='block' " +
" xmlns='http://www.w3.org/1998/Math/MathML'><mi>ThisWay</mi></math> " +
" <span class='maruku-eq-tex'><code style='display: none;'>ThisWay</code> " +
" </span></div> " ,
" should we go ThatWay or \n $$ThisWay$$ \n " )
assert_markup_parsed_as (
" <p>should we go <a class='existingWikiWord' href='../show/ThatWay'> " +
" That Way</a> or</p> \n <div class='maruku-equation'> " +
" <math class='maruku-mathml' display='block' " +
" xmlns='http://www.w3.org/1998/Math/MathML'><mi>ThisWay</mi><mi>$</mi> " +
2009-10-10 06:18:17 +02:00
" <mn>100</mn><mi>ThatWay</mi></math> " +
2009-01-14 23:11:07 +01:00
" <span class='maruku-eq-tex'><code style='display: none;'>ThisWay \\ $100 " +
" ThatWay</code></span></div> " ,
" should we go ThatWay or \n $$ThisWay \\ $100 ThatWay $$ \n " )
assert_markup_parsed_as (
" <p>should we go <a class='existingWikiWord' href='../show/ThatWay'> " +
" That Way</a> or <math class='maruku-mathml' display='inline' " +
" xmlns='http://www.w3.org/1998/Math/MathML'><mi>ThisWay</mi></math> today.</p> " ,
" should we go ThatWay or <math class='maruku-mathml' display='inline' " +
" xmlns='http://www.w3.org/1998/Math/MathML'><mi>ThisWay</mi></math> today. " )
assert_markup_parsed_as (
" <p>should we go <a class='existingWikiWord' href='../show/ThatWay'> " +
" That Way</a> or <math class='maruku-mathml' display='inline' " +
" xmlns='http://www.w3.org/1998/Math/MathML'><mi>ThisWay</mi></math>.</p> " ,
" should we go ThatWay or $ThisWay$. " )
end
2009-01-16 19:51:43 +01:00
def test_content_with_wikiword_in_equations_textile
set_web_property :markup , :textile
assert_markup_parsed_as (
" <p>$$<span class='newWikiWord'>foo<a href='../show/foo'>? " +
" </a></span>$$<br/>$<span class='newWikiWord'>foo<a " +
" href='../show/foo'>?</a></span>$</p> " ,
" $$[[foo]]$$ \n $[[foo]]$ " )
end
2007-05-11 18:47:38 +02:00
# wikiwords are invalid as styles, must be in "name: value" form
def test_content_with_wikiword_in_style_tag
2007-01-22 14:43:50 +01:00
assert_markup_parsed_as (
2008-05-15 08:22:13 +02:00
" <p>That is some <em style=''>Stylish Emphasis</em></p> " ,
" That is some <em style='WikiWord'>Stylish Emphasis</em> " )
2007-01-22 14:43:50 +01:00
end
2007-05-11 18:47:38 +02:00
# validates format of style..
def test_content_with_valid_style_in_style_tag
assert_markup_parsed_as (
2008-05-15 08:22:13 +02:00
" <p>That is some <em style='text-align: right;'>Stylish Emphasis</em></p> " ,
" That is some <em style='text-align: right'>Stylish Emphasis</em> " )
2007-05-11 18:47:38 +02:00
end
2007-01-22 14:43:50 +01:00
def test_content_with_escaped_wikiword
# there should be no wiki link
assert_markup_parsed_as ( '<p>WikiWord</p>' , '\WikiWord' )
end
def test_content_with_pre_blocks
2007-10-07 08:59:50 +02:00
set_web_property :markup , :markdownMML
2007-01-22 14:43:50 +01:00
assert_markup_parsed_as (
2007-10-07 08:59:50 +02:00
" <p>A <code>class SmartEngine</code> would not mark up</p> \n \n <pre><code>CodeBlocks</code></pre> \n \n <p>would it?</p> " ,
" A `class SmartEngine` would not mark up \n \n CodeBlocks \n \n would it? " )
assert_markup_parsed_as (
" <p>A <code>class SmartEngine</code> would not mark up</p> \n <pre>CodeBlocks</pre> \n <p>would it?</p> " ,
" A <code>class SmartEngine</code> would not mark up \n \n <pre>CodeBlocks</pre> \n \n would it? " )
2007-01-22 14:43:50 +01:00
end
2007-10-06 23:04:11 +02:00
# def test_content_with_autolink_in_parentheses
# assert_markup_parsed_as(
# '<p>The W3C body (<a href="http://www.w3c.org">' +
# 'http://www.w3c.org</a>) sets web standards</p>',
# 'The W3C body (http://www.w3c.org) sets web standards')
# end
2007-01-22 14:43:50 +01:00
def test_content_with_link_in_parentheses
assert_markup_parsed_as (
2008-05-15 08:22:13 +02:00
" <p>(<a href='http://wiki.org/wiki.cgi?WhatIsWiki'>What is a wiki?</a>)</p> " ,
2007-09-11 19:04:26 +02:00
'([What is a wiki?](http://wiki.org/wiki.cgi?WhatIsWiki))' )
2007-01-22 14:43:50 +01:00
end
def test_content_with_image_link
assert_markup_parsed_as (
2008-05-15 08:22:13 +02:00
" <p>This <img alt='' src='http://hobix.com/sample.jpg'/> is a Markdown image link.</p> " ,
2007-09-11 19:04:26 +02:00
'This ![](http://hobix.com/sample.jpg) is a Markdown image link.' )
2007-01-22 14:43:50 +01:00
end
def test_content_with_inlined_img_tag
assert_markup_parsed_as (
2008-05-15 08:22:13 +02:00
" <p>This <img alt='' src='http://hobix.com/sample.jpg'/> is an inline image link.</p> " ,
2007-01-22 14:43:50 +01:00
'This <img src="http://hobix.com/sample.jpg" alt="" /> is an inline image link.' )
2007-05-11 18:47:38 +02:00
# currently, upper case HTML elements are not allowed
2007-01-22 14:43:50 +01:00
assert_markup_parsed_as (
2008-05-21 09:06:31 +02:00
" <p>This <IMG SRC='http://hobix.com/sample.jpg' alt=''/> is an inline image link.</p> " ,
2007-09-11 19:04:26 +02:00
'This <IMG SRC="http://hobix.com/sample.jpg" alt="" /> is an inline image link.' )
2007-01-22 14:43:50 +01:00
end
def test_nowiki_tag
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>.' )
end
2008-05-21 00:02:10 +02:00
def test_malformed_nowiki
assert_markup_parsed_as (
'<p><i><b/></i></p>' ,
'<nowiki><i><b></i></b></nowiki> ' )
end
2007-01-22 14:43:50 +01:00
def test_multiline_nowiki_tag
assert_markup_parsed_as (
" <p>Do not mark \n up [[this text]] \n and http://this.url.com but markup " +
2008-05-15 08:22:13 +02:00
" <span class='newWikiWord'>this<a href='../show/this'>?</a></span></p> " ,
2007-01-22 14:43:50 +01:00
" Do not <nowiki>mark \n up [[this text]] \n " +
" and http://this.url.com </nowiki> but markup [[this]] " )
end
2007-09-12 03:49:56 +02:00
2008-05-21 00:02:10 +02:00
def test_markdown_nowiki_tag
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>.' )
end
2007-09-12 03:49:56 +02:00
def test_sanitize_nowiki_tag
assert_markup_parsed_as (
2008-05-21 21:14:43 +02:00
'<p>[[test]]&<a href=\'a&b\'>shebang</a> <script>alert("xss!");</script> *foo*</p>' ,
2007-09-12 03:49:56 +02:00
'<nowiki>[[test]]&<a href="a&b">shebang</a> <script>alert("xss!");</script> *foo*</nowiki>' )
end
2008-05-17 22:02:16 +02:00
def test_entities
assert_markup_parsed_as (
" <p>Known: \342 \210 \256 . Pass-through: &. Unknown: &foo;.</p> " ,
" Known: ∮. Pass-through: &. Unknown: &foo;. " )
end
2007-01-22 14:43:50 +01:00
def test_content_with_bracketted_wiki_word
set_web_property :brackets_only , true
assert_markup_parsed_as (
2008-05-15 08:22:13 +02:00
" <p>This is a WikiWord and a tricky name <span class='newWikiWord'> " +
" Sperberg-McQueen<a href='../show/Sperberg-McQueen'>?</a></span>.</p> " ,
2007-01-22 14:43:50 +01:00
'This is a WikiWord and a tricky name [[Sperberg-McQueen]].' )
end
def test_content_for_export
2008-05-15 08:22:13 +02:00
assert_equal " <p><span class='newWikiWord'>His Way</span> would be " +
" <a class='existingWikiWord' href='MyWay.html'>My Way</a> " +
" <math class='maruku-mathml' display='inline' xmlns='http://www.w3.org/1998/Math/MathML'> " +
" <mi>sin</mi><mo stretchy='false'>(</mo><mi>x</mi><mo stretchy='false'>)</mo><semantics> " +
" <annotation-xml encoding='SVG1.1'><svg/></annotation-xml></semantics></math> in kinda " +
" <a class='existingWikiWord' href='ThatWay.html'>That Way</a> in " +
" <span class='newWikiWord'>His Way</span> though " +
2008-05-21 00:02:10 +02:00
%{ <a class='existingWikiWord' href='MyWay.html'>My Way</a> OverThere \342 \200 \223 see } +
2008-05-15 08:22:13 +02:00
" <a class='existingWikiWord' href='SmartEngine.html'>Smart Engine</a> in that " +
" <span class='newWikiWord'>Smart Engine GUI</span></p> " ,
2007-01-22 14:43:50 +01:00
test_renderer ( @revision ) . display_content_for_export
end
def test_double_replacing
@revision . content = " VersionHistory \r \n \r \n cry VersionHistory "
2008-05-15 08:22:13 +02:00
assert_equal " <p><span class='newWikiWord'>Version History " +
" <a href='../show/VersionHistory'>?</a></span></p> \n \n <p>cry " +
" <span class='newWikiWord'>Version History<a href='../show/VersionHistory'>?</a> " +
2007-01-22 14:43:50 +01:00
'</span></p>' ,
test_renderer ( @revision ) . display_content
@revision . content = " f \r \n VersionHistory \r \n \r \n cry VersionHistory "
2008-05-15 08:22:13 +02:00
assert_equal " <p>f <span class='newWikiWord'>Version History " +
" <a href='../show/VersionHistory'>?</a></span></p> \n \n <p>cry " +
" <span class='newWikiWord'>Version History<a href='../show/VersionHistory'>?</a> " +
2007-01-22 14:43:50 +01:00
" </span></p> " ,
test_renderer ( @revision ) . display_content
end
def test_difficult_wiki_words
@revision . content = " [[It's just awesome GUI!]] "
2008-05-22 09:46:45 +02:00
assert_equal " <p><span class='newWikiWord'>It& # 39;s just awesome GUI! " +
2008-05-15 08:22:13 +02:00
" <a href='../show/It%27s+just+awesome+GUI%21'>?</a></span></p> " ,
2007-01-22 14:43:50 +01:00
test_renderer ( @revision ) . display_content
end
def test_revisions_diff
Revision . create ( :page = > @page , :content = > 'What a blue and lovely morning' ,
:author = > Author . new ( 'DavidHeinemeierHansson' ) , :revised_at = > Time . now )
Revision . create ( :page = > @page , :content = > 'What a red and lovely morning today' ,
:author = > Author . new ( 'DavidHeinemeierHansson' ) , :revised_at = > Time . now )
2009-08-04 07:02:04 +02:00
@page . reload
2007-06-13 08:56:44 +02:00
assert_equal " <p><span> What a<del class='diffmod'> blue</del><ins class='diffmod'> red " +
" </ins> and lovely morning<ins class='diffins'> today</ins></span></p> " , test_renderer ( @page . revisions . last ) . display_diff
2007-01-22 14:43:50 +01:00
end
2008-05-17 08:43:11 +02:00
def test_nowiki_sanitization
assert_markup_parsed_as ( '<p>This sentence contains <span>a & b</span> ' +
2008-05-21 21:14:43 +02:00
'<script>alert("XSS!");</script>. Do not touch!</p>' ,
2008-05-17 08:43:11 +02:00
'This sentence contains <nowiki><span>a & b</span> <script>alert("XSS!");' +
'</script></nowiki>. Do not touch!' )
end
2007-01-22 14:43:50 +01:00
def test_link_to_file
assert_markup_parsed_as (
2008-05-15 08:22:13 +02:00
" <p><span class='newWikiWord'>doc.pdf<a href='../file/doc.pdf'>?</a></span></p> " ,
2007-01-22 14:43:50 +01:00
'[[doc.pdf:file]]' )
end
2007-10-10 06:56:55 +02:00
def test_link_to_pic_and_file
2007-01-22 14:43:50 +01:00
WikiFile . delete_all
require 'fileutils'
Security: Instiki 0.16.2
On Webs with file uploads enabled, uploaded files were stored
(in version 0.16.1 and earlier) in the public/ directory.
This was a security threat. A miscreant could upload a .html file.
When a user clicked on the link to the file, it was opened (unsanitized)
in the browser.
As of version 0.16.2, uploaded files are stored in the webs/
directory. Now, when the user clicks on the link, the file is sent
with the
Content-Disposition: attachment
header set, which causes the file to be downloaded, rather than opened
in the browser. As always, files downloaded from the internets should be
treated with caution. At least, this way, they are not aoutomatically
opened in the browser.
To move your existing uploaded files to the new location, do a
rake upgrade_instiki
2009-01-26 07:21:30 +01:00
FileUtils . rm_rf ( " #{ RAILS_ROOT } /webs/wiki1/files/* " )
2007-01-22 14:43:50 +01:00
@web . wiki_files . create ( :file_name = > 'square.jpg' , :description = > 'Square' , :content = > 'never mind' )
assert_markup_parsed_as (
2008-05-15 08:22:13 +02:00
" <p><img alt='Blue Square' src='../file/square.jpg'/></p> " ,
2007-10-09 10:16:07 +02:00
'[[square.jpg|Blue Square:pic]]' )
2007-01-22 14:43:50 +01:00
assert_markup_parsed_as (
2008-05-15 08:22:13 +02:00
" <p><img alt='Square' src='../file/square.jpg'/></p> " ,
2007-01-22 14:43:50 +01:00
'[[square.jpg:pic]]' )
2007-10-10 06:56:55 +02:00
assert_markup_parsed_as (
2008-05-15 08:22:13 +02:00
" <p><a class='existingWikiWord' href='../file/square.jpg' title='Square'>Blue Square</a></p> " ,
2007-10-10 06:56:55 +02:00
'[[square.jpg|Blue Square:file]]' )
2009-03-04 05:27:26 +01:00
assert_markup_parsed_as (
" <p><video controls='controls' src='../file/square.jpg'>Blue Square</video></p> " ,
'[[square.jpg|Blue Square:video]]' )
assert_markup_parsed_as (
" <p><audio controls='controls' src='../file/square.jpg'>Blue Square</audio></p> " ,
'[[square.jpg|Blue Square:audio]]' )
2007-10-10 06:56:55 +02:00
assert_markup_parsed_as (
2008-05-15 08:22:13 +02:00
" <p><a class='existingWikiWord' href='../file/square.jpg' title='Square'>Square</a></p> " ,
2007-10-10 06:56:55 +02:00
'[[square.jpg:file]]' )
end
def test_link_to_pic_and_file_null_desc
WikiFile . delete_all
require 'fileutils'
Security: Instiki 0.16.2
On Webs with file uploads enabled, uploaded files were stored
(in version 0.16.1 and earlier) in the public/ directory.
This was a security threat. A miscreant could upload a .html file.
When a user clicked on the link to the file, it was opened (unsanitized)
in the browser.
As of version 0.16.2, uploaded files are stored in the webs/
directory. Now, when the user clicks on the link, the file is sent
with the
Content-Disposition: attachment
header set, which causes the file to be downloaded, rather than opened
in the browser. As always, files downloaded from the internets should be
treated with caution. At least, this way, they are not aoutomatically
opened in the browser.
To move your existing uploaded files to the new location, do a
rake upgrade_instiki
2009-01-26 07:21:30 +01:00
FileUtils . rm_rf ( " #{ RAILS_ROOT } /webs/wiki1/files/* " )
2007-10-10 06:56:55 +02:00
@web . wiki_files . create ( :file_name = > 'square.jpg' , :description = > '' , :content = > 'never mind' )
assert_markup_parsed_as (
2008-05-15 08:22:13 +02:00
" <p><img alt='Blue Square' src='../file/square.jpg'/></p> " ,
2007-10-10 06:56:55 +02:00
'[[square.jpg|Blue Square:pic]]' )
assert_markup_parsed_as (
2008-05-15 08:22:13 +02:00
" <p><img alt='' src='../file/square.jpg'/></p> " ,
2007-10-10 06:56:55 +02:00
'[[square.jpg:pic]]' )
assert_markup_parsed_as (
2008-05-15 08:22:13 +02:00
" <p><a class='existingWikiWord' href='../file/square.jpg' title=''>Blue Square</a></p> " ,
2007-10-10 06:56:55 +02:00
'[[square.jpg|Blue Square:file]]' )
assert_markup_parsed_as (
2008-05-15 08:22:13 +02:00
" <p><a class='existingWikiWord' href='../file/square.jpg' title=''></a></p> " ,
2007-10-10 06:56:55 +02:00
'[[square.jpg:file]]' )
2007-01-22 14:43:50 +01:00
end
def test_link_to_non_existant_pic
assert_markup_parsed_as (
2008-05-15 08:22:13 +02:00
" <p><span class='newWikiWord'>NonExistant<a href='../file/NonExistant.jpg'>?</a> " +
2007-01-22 14:43:50 +01:00
'</span></p>' ,
'[[NonExistant.jpg|NonExistant:pic]]' )
assert_markup_parsed_as (
2008-05-15 08:22:13 +02:00
" <p><span class='newWikiWord'>NonExistant.jpg<a href='../file/NonExistant.jpg'>?</a> " +
2007-01-22 14:43:50 +01:00
'</span></p>' ,
'[[NonExistant.jpg:pic]]' )
end
def test_wiki_link_with_colon
assert_markup_parsed_as (
2008-05-15 08:22:13 +02:00
" <p><span class='newWikiWord'>Instiki:Colon<a href='../../instiki/show/Colon'>?</a></span></p> " ,
2007-10-06 23:04:11 +02:00
'[[Instiki:Colon]]' )
2007-01-22 14:43:50 +01:00
end
def test_list_with_tildas
list_with_tildas = <<-EOL
2007-09-11 19:04:26 +02:00
* [ a ] ( ~ b )
* c ~ d
2007-01-22 14:43:50 +01:00
EOL
assert_markup_parsed_as (
2008-05-15 08:22:13 +02:00
" <ul> \n <li><a href='~b'>a</a></li> \n \n <li>c~ d</li> \n </ul> " ,
2007-01-22 14:43:50 +01:00
list_with_tildas )
end
def test_textile_image_in_mixed_wiki
set_web_property :markup , :mixed
assert_markup_parsed_as (
2008-01-12 06:53:29 +01:00
" <p><img alt='' src='http://google.com'/> \n ss</p> " ,
2007-01-22 14:43:50 +01:00
" !http://google.com! \r \n ss " )
end
def test_references_creation_links
new_page = @web . add_page ( 'NewPage' , 'HomePage NewPage' ,
Time . local ( 2004 , 4 , 4 , 16 , 50 ) , 'AlexeyVerkhovsky' , test_renderer )
references = new_page . wiki_references ( true )
assert_equal 2 , references . size
assert_equal 'HomePage' , references [ 0 ] . referenced_name
assert_equal WikiReference :: LINKED_PAGE , references [ 0 ] . link_type
assert_equal 'NewPage' , references [ 1 ] . referenced_name
assert_equal WikiReference :: LINKED_PAGE , references [ 1 ] . link_type
end
def test_references_creation_includes
new_page = @web . add_page ( 'NewPage' , '[[!include IncludedPage]]' ,
Time . local ( 2004 , 4 , 4 , 16 , 50 ) , 'AlexeyVerkhovsky' , test_renderer )
references = new_page . wiki_references ( true )
assert_equal 1 , references . size
assert_equal 'IncludedPage' , references [ 0 ] . referenced_name
assert_equal WikiReference :: INCLUDED_PAGE , references [ 0 ] . link_type
end
def test_references_creation_categories
new_page = @web . add_page ( 'NewPage' , " Foo \n category: NewPageCategory " ,
Time . local ( 2004 , 4 , 4 , 16 , 50 ) , 'AlexeyVerkhovsky' , test_renderer )
references = new_page . wiki_references ( true )
assert_equal 1 , references . size
assert_equal 'NewPageCategory' , references [ 0 ] . referenced_name
assert_equal WikiReference :: CATEGORY , references [ 0 ] . link_type
end
2007-09-12 03:49:56 +02:00
def test_references_creation_sanitized_categories
new_page = @web . add_page ( 'NewPage' , " Foo \n category: <script>alert('XSS');</script> " ,
Time . local ( 2004 , 4 , 4 , 16 , 50 ) , 'AlexeyVerkhovsky' , test_renderer )
references = new_page . wiki_references ( true )
assert_equal 1 , references . size
assert_equal " <script>alert(& # 39;XSS& # 39;);</script> " , references [ 0 ] . referenced_name
assert_equal WikiReference :: CATEGORY , references [ 0 ] . link_type
end
2007-01-22 14:43:50 +01:00
def test_rendering_included_page_under_different_modes
included = @web . add_page ( 'Included' , 'link to HomePage' , Time . now , 'AnAuthor' , test_renderer )
main = @web . add_page ( 'Main' , '[[!include Included]]' , Time . now , 'AnAuthor' , test_renderer )
2008-05-15 08:22:13 +02:00
assert_equal " <p>link to <a class='existingWikiWord' href='../show/HomePage'>Home Page</a></p> " ,
2007-01-22 14:43:50 +01:00
test_renderer ( main ) . display_content
2008-05-15 08:22:13 +02:00
assert_equal " <p>link to <a class='existingWikiWord' href='../published/HomePage'>Home Page</a></p> " ,
2007-01-22 14:43:50 +01:00
test_renderer ( main ) . display_published
2008-05-15 08:22:13 +02:00
assert_equal " <p>link to <a class='existingWikiWord' href='HomePage.html'>Home Page</a></p> " ,
2007-01-22 14:43:50 +01:00
test_renderer ( main ) . display_content_for_export
end
2009-01-15 05:55:59 +01:00
def test_rendering_included_page_backslashes_in_equations
included = @web . add_page ( 'Included' , '\\\\ $\begin{matrix} a \\\\ b\end{matrix}$' , Time . now , 'AnAuthor' , test_renderer )
main = @web . add_page ( 'Main' , '[[!include Included]]' , Time . now , 'AnAuthor' , test_renderer )
assert_equal " <p> \\ <math class='maruku-mathml' display='inline' " +
" xmlns='http://www.w3.org/1998/Math/MathML'><mrow><mtable rowspacing='0.5ex'> " +
" <mtr><mtd><mi>a</mi></mtd></mtr> <mtr><mtd><mi>b</mi></mtd></mtr></mtable> " +
" </mrow></math></p> " ,
test_renderer ( main ) . display_content
end
2007-01-22 14:43:50 +01:00
private
def add_sample_pages
@in_love = @web . add_page ( 'EverBeenInLove' , 'Who am I me' ,
Time . local ( 2004 , 4 , 4 , 16 , 50 ) , 'DavidHeinemeierHansson' , test_renderer )
@hated = @web . add_page ( 'EverBeenHated' , 'I am me EverBeenHated' ,
Time . local ( 2004 , 4 , 4 , 16 , 51 ) , 'DavidHeinemeierHansson' , test_renderer )
end
def assert_markup_parsed_as ( expected_output , input )
revision = Revision . new ( :page = > @page , :content = > input , :author = > Author . new ( 'AnAuthor' ) )
2009-06-07 04:08:08 +02:00
assert_equal expected_output , test_renderer ( revision ) . display_content ( true ) , 'Rendering output not as expected'
2007-01-22 14:43:50 +01:00
end
2008-10-17 23:26:17 +02:00
def assert_match_markup_parsed_as ( expected_output , input )
revision = Revision . new ( :page = > @page , :content = > input , :author = > Author . new ( 'AnAuthor' ) )
assert_match expected_output , test_renderer ( revision ) . display_content , 'Rendering output not as expected'
end
2007-01-22 14:43:50 +01:00
def rendered_content ( page )
test_renderer ( page . revisions . last ) . display_content
end
2007-06-13 00:37:55 +02:00
end