diff --git a/t/headers.t b/t/headers.t new file mode 100644 index 00000000..3b093614 --- /dev/null +++ b/t/headers.t @@ -0,0 +1,44 @@ +require 't/test.pl'; +package OddMuse; +use Test::More tests => 13; + +clear_pages(); + +# without portrait-support + +# nothing +update_page('headers', "== no header ==\n\ntext\n"); +test_page(get_page('headers'), '== no header =='); + +# usemod only +add_module('usemod.pl'); +update_page('headers', "== is header ==\n\ntext\n"); +test_page(get_page('headers'), '

is header

'); + +# toc + usemod only +add_module('toc.pl'); +update_page('headers', "== one ==\ntext\n== two ==\ntext\n== three ==\ntext\n"); +test_page(get_page('headers'), + '
  • one
  • ', + '
  • two
  • ', + '

    one

    ', + '

    two

    ', ); +remove_module('usemod.pl'); +remove_rule(\&UsemodRule); + +# toc + headers +add_module('headers.pl'); +update_page('headers', "one\n===\ntext\ntwo\n---\ntext\nthree\n====\ntext\n"); +test_page(get_page('headers'), + '
  • one', + '
    1. two
    ', + '
  • three
  • ', + '

    one

    ', + '

    two

    ', + '

    three

    ', ); +remove_module('toc.pl'); +remove_rule(\&TocRule); + +# headers only +update_page('headers', "is header\n=========\n\ntext\n"); +test_page(get_page('headers'), '

    is header

    '); diff --git a/t/hr.t b/t/hr.t new file mode 100644 index 00000000..7c9516b3 --- /dev/null +++ b/t/hr.t @@ -0,0 +1,54 @@ +require 't/test.pl'; +package OddMuse; +use Test::More tests => 8; + +clear_pages(); + +# without portrait-support + +# nothing +update_page('hr', "one\n----\ntwo\n"); +test_page(get_page('hr'), 'one ---- two'); + +# usemod only +add_module('usemod.pl'); +update_page('hr', "one\n----\nthree\n"); +test_page(get_page('hr'), + '

    one


    three

    '); +remove_rule(\&UsemodRule); + +# headers only +add_module('headers.pl'); +update_page('hr', "one\n----\ntwo\n"); +test_page(get_page('hr'), + '

    one

    two

    '); + +update_page('hr', "one\n\n----\nthree\n"); +test_page(get_page('hr'), + '

    one


    three

    '); +remove_rule(\&HeadersRule); + +# with portrait support + +clear_pages(); + +# just portrait-support +add_module('portrait-support.pl'); +update_page('hr', "[new]one\n----\ntwo\n"); +test_page(get_page('hr'), + '

    one


    two

    '); + +# usemod and portrait-support +add_module('usemod.pl'); +update_page('hr', "one\n----\nthree\n"); +test_page(get_page('hr'), + '

    one


    three

    '); +remove_rule(\&UsemodRule); + +# headers and portrait-support +add_module('headers.pl'); +update_page('hr', "one\n----\ntwo\n"); +test_page(get_page('hr'), '

    one

    two

    '); + +update_page('hr', "one\n\n----\nthree\n"); +test_page(get_page('hr'), '

    one


    three

    '); diff --git a/t/links.t b/t/links.t new file mode 100644 index 00000000..d52d0b9f --- /dev/null +++ b/t/links.t @@ -0,0 +1,84 @@ +require 't/test.pl'; +package OddMuse; +use Test::More tests => 55; + +clear_pages(); +add_module('links.pl'); + +update_page('InterMap', + " Oddmuse http://www.emacswiki.org/cgi-bin/oddmuse.pl?\n", + 'required', 0, 1); + +update_page('a', 'Oddmuse:foo(no) [Oddmuse:bar] [Oddmuse:baz text] ' + . '[Oddmuse:bar(no)] [Oddmuse:baz(no) text] ' + . '[[Oddmuse:foo_(bar)]] [[[Oddmuse:foo (baz)]]] [[Oddmuse:foo (quux)|text]]'); +$InterInit = 0; +InitVariables(); + +my @Test = map { quotemeta } split('\n',<<'EOT'); +"a" -> "Oddmuse:foo" +"a" -> "Oddmuse:bar" +"a" -> "Oddmuse:baz" +"a" -> "Oddmuse:foo_(bar)" +"a" -> "Oddmuse:foo (baz)" +"a" -> "Oddmuse:foo (quux)" +EOT + +test_page_negative(get_page('action=links raw=1'), @Test); +test_page(get_page('action=links raw=1 inter=1'), @Test); + +@Test = split('\n',<<'EOT'); +//a[@class="local"][@href="http://localhost/wiki.pl/a"][text()="a"] +//a[@class="inter Oddmuse"][@href="http://www.emacswiki.org/cgi-bin/oddmuse.pl?foo"]/span[@class="site"][text()="Oddmuse"]/following-sibling::text()[string()=":"]/following-sibling::span[@class="page"][text()="foo"] +//a[@class="inter Oddmuse"][@href="http://www.emacswiki.org/cgi-bin/oddmuse.pl?bar"]/span[@class="site"][text()="Oddmuse"]/following-sibling::text()[string()=":"]/following-sibling::span[@class="page"][text()="bar"] +//a[@class="inter Oddmuse"][@href="http://www.emacswiki.org/cgi-bin/oddmuse.pl?baz"]/span[@class="site"][text()="Oddmuse"]/following-sibling::text()[string()=":"]/following-sibling::span[@class="page"][text()="baz"] +//a[@class="inter Oddmuse"][@href="http://www.emacswiki.org/cgi-bin/oddmuse.pl?foo_(bar)"]/span[@class="site"][text()="Oddmuse"]/following-sibling::text()[string()=":"]/following-sibling::span[@class="page"][text()="foo_(bar)"] +EOT + +negative_xpath_test(get_page('action=links'), @Test); +xpath_test(get_page('action=links inter=1'), @Test); + +AppendStringToFile($ConfigFile, "\$BracketWiki = 0;\n"); + +update_page('a', '[[b]] [[[c]]] [[d|e]] FooBar [FooBaz] [FooQuux fnord] '); +$page = get_page('action=links raw=1'); + +test_page($page, split('\n',<<'EOT')); +"a" -> "b" +"a" -> "c" +"a" -> "FooBar" +"a" -> "FooBaz" +"a" -> "FooQuux" +EOT + +test_page_negative($page, '"a" -> "d"'); + +AppendStringToFile($ConfigFile, "\$BracketWiki = 1;\n"); + +update_page('a', '[[b]] [[[c]]] [[d|e]] FooBar [FooBaz] [FooQuux fnord] ' + . 'http://www.oddmuse.org/ [http://www.emacswiki.org/] ' + . '[http://www.communitywiki.org/ cw]'); + +@Test1 = split('\n',<<'EOT'); +"a" -> "b" +"a" -> "c" +"a" -> "d" +"a" -> "FooBar" +"a" -> "FooBaz" +"a" -> "FooQuux" +EOT + +@Test2 = split('\n',<<'EOT'); +"a" -> "http://www.oddmuse.org/" +"a" -> "http://www.emacswiki.org/" +"a" -> "http://www.communitywiki.org/" +EOT + +$page = get_page('action=links raw=1'); +test_page($page, @Test1); +test_page_negative($page, @Test2); +$page = get_page('action=links raw=1 url=1'); +test_page($page, @Test1, @Test2); +$page = get_page('action=links raw=1 links=0 url=1'); +test_page_negative($page, @Test1); +test_page($page, @Test2); diff --git a/t/near.t b/t/near.t new file mode 100644 index 00000000..67cd477e --- /dev/null +++ b/t/near.t @@ -0,0 +1,26 @@ +require 't/test.pl'; +package OddMuse; +use Test::More tests => 5; + +clear_pages(); + +CreateDir($NearDir); +WriteStringToFile("$NearDir/EmacsWiki", "AlexSchroeder\nFooBar\n"); + +update_page('InterMap', " EmacsWiki http://www.emacswiki.org/cgi-bin/wiki/%s\n", + 'required', 0, 1); +update_page('NearMap', " EmacsWiki" + . " http://www.emacswiki.org/cgi-bin/emacs?action=index;raw=1" + . " http://www.emacswiki.org/cgi-bin/emacs?search=%s;raw=1;near=0\n", + 'required', 0, 1); + +xpath_test(update_page('FooBaz', "Try FooBar instead!\n"), + '//a[@class="near"][@title="EmacsWiki"][@href="http://www.emacswiki.org/cgi-bin/wiki/FooBar"][text()="FooBar"]', + '//div[@class="near"]/p/a[@class="local"][@href="http://localhost/wiki.pl/EditNearLinks"][text()="EditNearLinks"]/following-sibling::text()[string()=": "]/following-sibling::a[@class="edit"][@title="Click to edit this page"][@href="http://localhost/wiki.pl?action=edit;id=FooBar"][text()="FooBar"]'); + +xpath_test(update_page('FooBar', "Test by AlexSchroeder!\n"), + '//div[@class="sister"]/p/a[@title="EmacsWiki:FooBar"][@href="http://www.emacswiki.org/cgi-bin/wiki/FooBar"]/img[@src="file:///tmp/oddmuse/EmacsWiki.png"][@alt="EmacsWiki:FooBar"]'); + +xpath_test(get_page('search=alexschroeder'), + '//p[text()="Near pages:"]', + '//a[@class="near"][@title="EmacsWiki"][@href="http://www.emacswiki.org/cgi-bin/wiki/AlexSchroeder"][text()="AlexSchroeder"]'); diff --git a/t/portrait.t b/t/portrait.t new file mode 100644 index 00000000..4febd4cb --- /dev/null +++ b/t/portrait.t @@ -0,0 +1,62 @@ +require 't/test.pl'; +package OddMuse; +use Test::More tests => 18; + +clear_pages(); +add_module('portrait-support.pl'); + +# nothing +update_page('headers', "[new]foo\n== no header ==\n\ntext\n"); +test_page(get_page('headers'), + '

    foo == no header ==

    text

    '); + +# usemod only +add_module('usemod.pl'); +update_page('headers', "[new]foo\n== is header ==\n\ntext\n"); +test_page(get_page('headers'), '

    foo

    is header

    '); + +# usemod + toc only +add_module('toc.pl'); +update_page('headers', + "[new]foo\n== one ==\ntext\n== two ==\ntext\n== three ==\ntext\n"); +test_page(get_page('headers'), + # default to before the header + '

    foo

    ', + '

    Contents

      ', + '
    1. one
    2. ', + '
    3. two
    4. ', + '
    5. three
    ', + '

    one

    text

    ', + '

    two

    ', ); +remove_module('toc.pl'); +remove_rule(\&TocRule); +remove_module('usemod.pl'); +remove_rule(\&UsemodRule); + +# headers only +add_module('headers.pl'); +update_page('headers', "[new]foo\nis header\n=========\n\ntext\n"); +test_page(get_page('headers'), '

    foo

    is header

    '); +remove_module('headers.pl'); +remove_rule(\&HeadersRule); + +# portrait-support, toc, and usemod + +add_module('usemod.pl'); +add_module('toc.pl'); +update_page('headers', "[new]foo\n== one ==\ntext\n== two ==\ntext\n== three ==\ntext\n"); +test_page(get_page('headers'), + '
  • one
  • ', + '
  • two
  • ', + '

    foo

    ', + '

    one

    ', + '

    two

    ', ); + +run_tests(split('\n',<<'EOT')); +[new]\nfoo +

    foo

    +:[new]\nfoo +

    foo

    +::[new]\nfoo +

    foo

    +EOT diff --git a/t/sidebar.t b/t/sidebar.t new file mode 100644 index 00000000..11827bad --- /dev/null +++ b/t/sidebar.t @@ -0,0 +1,69 @@ +require 't/test.pl'; +package OddMuse; +use Test::More tests => 17; + +clear_pages(); + +add_module('sidebar.pl'); + +test_page(update_page('SideBar', 'mu'), ''); +test_page(get_page('HomePage'), ''); + +# with toc + +add_module('toc.pl'); +add_module('usemod.pl'); + +AppendStringToFile($ConfigFile, "\$TocAutomatic = 0;\n"); + +update_page('SideBar', "bla\n\n" + . "== mu ==\n\n" + . "bla"); + +test_page(update_page('test', "bla\n" + . "\n" + . "murks\n" + . "==two=\n" + . "bla\n" + . "===three==\n" + . "bla\n" + . "=one=\n"), + quotemeta('
    1. two
      1. three
    2. one
    '), + quotemeta('

    mu

    '), + quotemeta('

    two

    '), + quotemeta('

    one

    '), + quotemeta('bla

    Contents

    murks')); + +update_page('SideBar', ""); +test_page(update_page('test', "bla\n" + . "murks\n" + . "==two=\n" + . "bla\n" + . "===three==\n" + . "bla\n" + . "=one=\n"), + quotemeta('

    1. two
      1. three
    2. one
    '), + quotemeta('

    two

    '), + quotemeta('

    one

    '), + quotemeta('

    ')); + +remove_rule(\&TocRule); +remove_rule(\&UsemodRule); + +# with forms + +add_module('forms.pl'); + +test_page(update_page('SideBar', '

    mu

    '), + ''); +xpath_test(get_page('action=pagelock id=SideBar set=1 pwd=foo'), + '//p/text()[string()="Lock for "]/following-sibling::a[@href="http://localhost/wiki.pl/SideBar"][@class="local"][text()="SideBar"]/following-sibling::text()[string()=" created."]'); +test_page(get_page('SideBar'), ''); +# While rendering the SideBar as part of the HomePage, it should still +# be considered "locked", and therefore the form should render +# correctly. +test_page(get_page('HomePage'), + ''); +# test_page(get_page('HomePage'), ''); diff --git a/t/toc.t b/t/toc.t new file mode 100644 index 00000000..a05d3d45 --- /dev/null +++ b/t/toc.t @@ -0,0 +1,94 @@ +require 't/test.pl'; +package OddMuse; +use Test::More tests => 22; + +clear_pages(); + +add_module('toc.pl'); +add_module('usemod.pl'); + +InitVariables(); # do this after loading usemod.pl! + +run_tests(split('\n',<<'EOT')); +== make honey ==\n\nMoo.\n +

    make honey

    Moo.

    +EOT + +test_page(update_page('toc', "bla\n" + . "=one=\n" + . "blarg\n" + . "==two==\n" + . "bla\n" + . "==two==\n" + . "mu."), + quotemeta('
    1. one
      1. two
      2. two
    '), + quotemeta('

    one

    '), + quotemeta('

    two

    '), + quotemeta('bla

    Contents

    one

    '),); + +test_page(update_page('toc', "bla\n" + . "==two=\n" + . "bla\n" + . "===three==\n" + . "bla\n" + . "==two==\n"), + quotemeta('
    1. two
      1. three
    2. two
    '), + quotemeta('

    two

    '), + quotemeta('

    three

    ')); + +test_page(update_page('toc', "bla\n" + . "\n" + . "murks\n" + . "==two=\n" + . "bla\n" + . "===three==\n" + . "bla\n" + . "=one=\n"), + quotemeta('
    1. two
      1. three
    2. one
    '), + quotemeta('

    two

    '), + quotemeta('

    one

    '), + quotemeta('bla

    Contents

    murks'),); + +test_page(update_page('toc', "bla\n" + . "=one=\n" + . "blarg\n" + . "==two==\n" + . "bla\n" + . "==two==\n" + . "mu.\n" + . "bla\n" + . "==two==\n" + . "mu.\n" + . "yadda bla\n" + . "==two==\n" + . "mu.\n" + . "yadda

     has no effect! \n"
    +		      . "##bla\n"
    +		      . "==three==\n"
    +		      . "mu.##\n"
    +		      . "=one=\n"
    +		      . "blarg 
    \n"), + quotemeta('
    1. one
      1. two
      2. three
    2. one
    '), + quotemeta('

    one

    '), + quotemeta('

    two

    '), + quotemeta('

    three

    '), + quotemeta('

    one

    '),); + +add_module('markup.pl'); + +test_page(update_page('toc', "bla\n" + . "=one=\n" + . "blarg\n" + . "bla\n" + . "=two=\n" + . "mu.\n" + . "##bla\n" + . "=three=\n" + . "mu.##\n" + . "=four=\n" + . "blarg\n"), + quotemeta('
    1. one
    2. four
    '), + quotemeta('

    one

    '), + quotemeta('

    four

    '),);