3 # ====================[ crossbar.t ]====================
5 # ....................{ INITIALIZATION }....................
8 use Test::More tests => 22;
11 add_module('crossbar.pl');
13 # The crossbar page is editable only by administrators. Consequently, we enable
14 # the administrator option when calling the update_page() function on the
16 my @update_crossbar_page_options = ('', '', 1);
18 # ....................{ TESTS =vanilla }....................
19 test_page(update_page($CrossbarPageName, 'mu', @update_crossbar_page_options),
20 '<div class="crossbar"><p>mu</p></div>');
21 test_page(get_page('HomePage'), '<div class="crossbar"><p>mu</p></div>');
23 # Verify that raw pages are not mangled
24 $page = get_page('action=browse raw=1 id=HomePage');
25 test_page($page, 'This page is empty');
26 test_page_negative($page, 'mu');
28 # Verify that images pages are not mangled
29 AppendStringToFile($ConfigFile, "\$UploadAllowed = 1;\n");
30 test_page(update_page('Alex', "#FILE image/png\niVBORw0KGgoAAAA"),
31 'This page contains an uploaded file:');
34 $page = get_page('action=download id=Alex');
36 $page =~ s/^.*\r\n\r\n//s; # strip headers
38 test_page(MIME::Base64::encode($page), '^iVBORw0KGgoAAAA');
40 # ....................{ TESTS =sidebar }....................
41 add_module('sidebar.pl');
43 update_page('SideBar', 'mysidebar');
44 update_page('Crossbar', 'mycrossbar');
46 $page = get_page('HomePage');
48 '//div[@class="sidebar"]/p[text()="mysidebar"]',
49 '//div[@class="crossbar"]/p[text()="mycrossbar"]');
50 # verify that these two are not nested
51 negative_xpath_test($page,
52 '//div[@class="sidebar"]/div[@class="crossbar"]',
53 '//div[@class="crossbar"]/div[@class="sidebar"]');
55 # uninstall sidebar.pl
56 remove_module('sidebar.pl');
57 *GetHeader = *OldSideBarGetHeader;
59 # ....................{ TESTS =toc }....................
61 add_module('usemod.pl');
63 AppendStringToFile($ConfigFile, "\$TocAutomatic = 0;\n");
65 # Test a crossbar page without Table of Contents markup and a page with Table of
67 update_page($CrossbarPageName, "bla
71 bla", @update_crossbar_page_options);
72 test_page(update_page('test', "bla
80 quotemeta(qq{<div class="crossbar"><p>bla</p><h2>mu</h2>}),
81 quotemeta(qq{bla </p><div class="toc"><h2>$TocHeaderText</h2>}),
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">one</a></li></ol>}),
83 quotemeta(qq{one</a></li></ol></div><p>murks}));
84 quotemeta(qq{<h2 id="${TocAnchorPrefix}1">two</h2>}),
85 quotemeta(qq{<h2 id="${TocAnchorPrefix}3">one</h2>}),
87 # Test a crossbar page with Table of Contents markup and a page without Table of
89 update_page($CrossbarPageName, "bla
94 <toc>", @update_crossbar_page_options);
95 test_page(update_page('test', "bla
102 quotemeta(qq{<div class="crossbar"><p>bla</p><h2>mu</h2>}),
103 quotemeta(qq{<p>bla </p><div class="toc"><h2>$TocHeaderText</h2>}),
104 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>}),
105 quotemeta(qq{one</a></li></ol></div></div><div class="content browse"><p>bla}));
106 quotemeta(qq{<h2 id="${TocAnchorPrefix}1">two</h2>}),
107 quotemeta(qq{<h2 id="${TocAnchorPrefix}3">one</h2>}),
109 remove_rule(\&TocRule);
110 remove_rule(\&UsemodRule);
112 # ....................{ TESTS =forms }....................
113 add_module('forms.pl');
115 # Markup the crossbar page prior to locking the crossbar page. This should ensure
116 # that forms on that page are not interpreted.
117 test_page(update_page($CrossbarPageName,
118 '<form><h1>mu</h1></form>', @update_crossbar_page_options),
119 '<div class="crossbar"><p><form><h1>mu</h1></form></p></div>');
121 # Lock the crossbar page, mark it up again, and ensure that forms on that page
122 # are now interpreted.
123 xpath_test(get_page("action=pagelock id=$CrossbarPageName set=1 pwd=foo"),
124 '//p/text()[string()="Lock for "]/following-sibling::a[@href="http://localhost/wiki.pl/Crossbar"][@class="local"][text()="Crossbar"]/following-sibling::text()[string()=" created."]');
125 test_page(get_page("action=browse id=$CrossbarPageName cache=0"),
126 '<div class="crossbar"><form><h1>mu</h1></form></div>');
127 # While rendering the Crossbar as part of the HomePage, it should still
128 # be considered "locked", and therefore the form should render
130 test_page(get_page('HomePage'),
131 '<div class="crossbar"><form><h1>mu</h1></form></div>');
133 =head1 COPYRIGHT AND LICENSE
135 The information below applies to everything in this distribution,
138 Copyleft 2008 by B.w.Curry <http://www.raiazome.com>.
139 Copyright (C) 2008 Alex Schroeder <alex@gnu.org>
141 This program is free software; you can redistribute it and/or modify
142 it under the terms of the GNU General Public License as published by
143 the Free Software Foundation; either version 3 of the License, or
144 (at your option) any later version.
146 This program is distributed in the hope that it will be useful,
147 but WITHOUT ANY WARRANTY; without even the implied warranty of
148 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
149 GNU General Public License for more details.
151 You should have received a copy of the GNU General Public License
152 along with this program. If not, see L<http://www.gnu.org/licenses/>.