wiki.pl: Port some fixes from upstream
[Orgmuse.git] / t / toc.t
blob6617ed34a22854a6b41a1effe1d08757ace576e4
1 #!/usr/bin/env perl
2 # Copyright (C) 2006, 2007 Alex Schroeder <alex@gnu.org>
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 require 't/test.pl';
18 package OddMuse;
19 use Test::More tests => 30;
21 clear_pages();
23 add_module('toc.pl');
24 add_module('usemod.pl');
26 InitVariables(); # do this after loading usemod.pl!
28 # Note that we're not calling TocInit between tests, so we rely on
29 # them being run in order.
30 run_tests('== make honey ==\n\nMoo.\n',
31 qq{<h2 id="${TocAnchorPrefix}1">make honey</h2><p>Moo.</p>},
32 '== make honey ==\nMoo.\n== make honey ==\nMoo.\n',
33 qq{<h2 id="${TocAnchorPrefix}2">make honey</h2><p>Moo. </p><h2 id="${TocAnchorPrefix}3">make honey</h2><p>Moo.</p>},
36 test_page(update_page('toc', "bla\n"
37 . "<toc/fnord/mu>\n"
38 . "murks\n"
39 . "==two=\n"
40 . "bla\n"
41 . "===three==\n"
42 . "bla\n"
43 . "=one=\n"),
44 quotemeta('<div class="toc fnord mu">'));
46 # check whether the toc remains in the HTML cache
48 test_page(get_page('toc'),
49 quotemeta('<div class="toc fnord mu">'));
51 # no cache
53 test_page(get_page('action=browse id=toc cache=0'),
54 quotemeta('<div class="toc fnord mu">'));
56 # check again!
58 test_page(get_page('toc'),
59 quotemeta('<div class="toc fnord mu">'));
61 # details of the toc
63 test_page(update_page('toc', "bla\n"
64 . "=one=\n"
65 . "blarg\n"
66 . "==two==\n"
67 . "bla\n"
68 . "==two==\n"
69 . "mu."),
70 quotemeta(qq{<ol><li><a href="#${TocAnchorPrefix}1">one</a></li><li><a href="#${TocAnchorPrefix}2">two</a></li><li><a href="#${TocAnchorPrefix}3">two</a></li></ol>}),
71 quotemeta(qq{<h2 id="${TocAnchorPrefix}1">one</h2>}),
72 quotemeta(qq{<h2 id="${TocAnchorPrefix}2">two</h2>}),
73 quotemeta(qq{bla </p><div class="toc"><h2>$TocHeaderText</h2><ol><li><a }),
74 quotemeta(qq{two</a></li></ol></div><h2 id="${TocAnchorPrefix}1">one</h2>}));
76 test_page(update_page('toc', "bla\n"
77 . "==two=\n"
78 . "bla\n"
79 . "===three==\n"
80 . "bla\n"
81 . "==two==\n"),
82 quotemeta(qq{<ol><li><a href="#${TocAnchorPrefix}1">two</a><ol><li><a href="#${TocAnchorPrefix}2">three</a></li></ol></li><li><a href="#${TocAnchorPrefix}3">two</a></li></ol>}),
83 quotemeta(qq{<h2 id="${TocAnchorPrefix}1">two</h2>}),
84 quotemeta(qq{<h3 id="${TocAnchorPrefix}2">three</h3>}));
86 test_page(update_page('toc', "bla\n"
87 . "<toc>\n"
88 . "murks\n"
89 . "==two=\n"
90 . "bla\n"
91 . "===three==\n"
92 . "bla\n"
93 . "=one=\n"),
94 quotemeta(qq{<ol><li><a href="#${TocAnchorPrefix}1">two</a><ol><li><a href="#${TocAnchorPrefix}2">three</a></li></ol></li><li><a href="#${TocAnchorPrefix}3">one</a></li></ol>}),
95 quotemeta(qq{<h2 id="${TocAnchorPrefix}1">two</h2>}),
96 quotemeta(qq{<h2 id="${TocAnchorPrefix}3">one</h2>}),
97 quotemeta(qq{bla </p><div class="toc"><h2>$TocHeaderText</h2><ol><li><a }),
98 quotemeta('one</a></li></ol></div><p>murks'));
100 test_page(update_page('toc', "bla\n"
101 . "=one=\n"
102 . "blarg\n"
103 . "==two==\n"
104 . "<nowiki>bla\n"
105 . "==two==\n"
106 . "mu.</nowiki>\n"
107 . "<nowiki>bla\n"
108 . "==two==\n"
109 . "mu.</nowiki>\n"
110 . "yadda <code>bla\n"
111 . "==two==\n"
112 . "mu.</code>\n"
113 . "yadda <pre> has no effect! \n"
114 . "##bla\n"
115 . "==three==\n"
116 . "mu.##\n"
117 . "=one=\n"
118 . "blarg </pre>\n"),
119 quotemeta(qq{<ol><li><a href="#${TocAnchorPrefix}1">one</a></li><li><a href="#${TocAnchorPrefix}2">two</a></li><li><a href="#${TocAnchorPrefix}3">three</a></li><li><a href="#${TocAnchorPrefix}4">one</a></li></ol>}),
120 quotemeta(qq{<h2 id="${TocAnchorPrefix}1">one</h2>}),
121 quotemeta(qq{<h2 id="${TocAnchorPrefix}2">two</h2>}),
122 quotemeta(qq{<h2 id="${TocAnchorPrefix}3">three</h2>}),
123 quotemeta(qq{<h2 id="${TocAnchorPrefix}4">one</h2>}));
125 add_module('markup.pl');
127 test_page(update_page('toc', "bla\n"
128 . "=one=\n"
129 . "blarg\n"
130 . "<code>##bla\n"
131 . "=two=\n"
132 . "mu.</code>\n"
133 . "##bla\n"
134 . "=three=\n"
135 . "mu.##\n"
136 . "=four=\n"
137 . "blarg\n"),
138 quotemeta(qq{<ol><li><a href="#${TocAnchorPrefix}1">one</a></li><li><a href="#${TocAnchorPrefix}2">four</a></li></ol>}),
139 quotemeta(qq{<h2 id="${TocAnchorPrefix}1">one</h2>}),
140 quotemeta(qq{<h2 id="${TocAnchorPrefix}2">four</h2>}));
142 test_page(update_page('toc', "bla\n"
143 . "=one=\n"
144 . "blarg ##<code>## and <code>##</code>\n"
145 . "=two=\n"
146 . "blarg ##</code>##\n"),
147 quotemeta(qq{<ol><li><a href="#${TocAnchorPrefix}1">one</a></li><li><a href="#${TocAnchorPrefix}2">two</a></li></ol>}),
148 quotemeta(qq{<h2 id="${TocAnchorPrefix}1">one</h2>}),
149 quotemeta(qq{<h2 id="${TocAnchorPrefix}2">two</h2>}));