Files
oddmuse/test-markup.pl
Alex Schroeder 53e26bcc3e new tests
2004-03-18 23:54:36 +00:00

1191 lines
38 KiB
Perl
Executable File

#!/usr/bin/perl -w
# Copyright (C) 2003 Alex Schroeder <alex@emacswiki.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the
# Free Software Foundation, Inc.
# 59 Temple Place, Suite 330
# Boston, MA 02111-1307 USA
# This program uses test-wrapper.el to run ApplyRules,
# because ApplyRules prints the result to stdout.
# Import the functions
package OddMuse;
$RunCGI = 0;
do 'wiki.pl';
my ($passed, $failed) = (0, 0);
my $resultfile = "/tmp/test-markup-result-$$";
my $redirect;
undef $/;
$| = 1; # no output buffering
sub update_page {
my ($id, $text, $summary, $minor, $admin, @rest) = @_;
print '*';
my $pwd = $admin ? 'foo' : 'wrong';
$id = UrlEncode($id);
$text = UrlEncode($text);
$summary = UrlEncode($summary);
$minor = $minor ? 'on' : 'off';
my $rest = join(' ', @rest);
$redirect = `perl wiki.pl Save=1 title=$id summary=$summary recent_edit=$minor text=$text pwd=$pwd $rest`;
open(F,"perl wiki.pl action=browse id=$id|");
my $output = <F>;
close F;
return $output;
}
sub get_page {
my ($params) = @_;
print '+';
open(F,"perl wiki.pl $params |");
my $output = <F>;
close F;
return $output;
}
sub test_page {
my $page = shift;
my $printpage = 0;
foreach my $str (@_) {
print '.';
if ($page =~ /$str/) {
$passed++;
} else {
$failed++;
$printpage = 1;
print "\nSimple Test: Did not find \"", $str, '"';
}
}
print "\n\nPage content:\n", $page, "\n" if $printpage;
}
sub test_page_negative {
my $page = shift;
my $printpage = 0;
foreach my $str (@_) {
print '.';
if ($page =~ /$str/) {
$failed++;
$printpage = 1;
print "\nSimple negative Test: Found \"", $str, '"';
} else {
$passed++;
}
}
print "\n\nPage content:\n", $page, "\n" if $printpage;
}
sub run_tests {
# translate embedded newlines (other backslashes remain untouched)
my %New;
foreach (keys %Test) {
$Test{$_} =~ s/\\n/\n/g;
my $new = $Test{$_};
s/\\n/\n/g;
$New{$_} = $new;
}
# Note that the order of tests is not specified!
foreach my $input (keys %New) {
print '.';
open(F,"|perl test-wrapper.pl > $resultfile");
print F $input;
close F;
open(F,$resultfile);
my $output = <F>;
close F;
if ($output eq $New{$input}) {
$passed++;
} else {
$failed++;
print "\n\"", $input, '" -> "', $output, '" instead of "', $New{$input}, "\"\n";
}
}
}
# Create temporary data directory as expected by the script
system('/bin/rm -rf /tmp/oddmuse');
die "Cannot remove /tmp/oddmuse!\n" if -e '/tmp/oddmuse';
mkdir '/tmp/oddmuse';
# goto markup;
$ENV{'REMOTE_ADDR'} = 'test-markup';
# --------------------
print '[clusters]';
open(F,'>/tmp/oddmuse/config');
print F "\$SurgeProtection = 0;\n";
print F "\$PageCluster = 'Cluster';\n";
close(F);
update_page('ClusterIdea', 'This is just a page.', 'one');
update_page('ClusterIdea', "This is just a page.\nBut somebody has to do it.", 'two');
update_page('ClusterIdea', "This is just a page.\nNobody wants it.", 'three', 1);
update_page('ClusterIdea', "MainPage\nThis is just a page.\nBut somebody has to do it.", 'four');
@Test = split('\n',<<'EOT');
Cluster.*MainPage
EOT
test_page(get_page('action=rc'), @Test);
@Test = split('\n',<<'EOT');
Cluster.*MainPage
ClusterIdea.*two
ClusterIdea.*one
EOT
test_page(get_page('action=rc all=1'), @Test);
@Test = split('\n',<<'EOT');
Cluster.*MainPage
ClusterIdea.*three
ClusterIdea.*two
ClusterIdea.*one
EOT
test_page(get_page('action=rc all=1 showedit=1'), @Test);
@Test = split('\n',<<'EOT');
Finally the main page
Updates in the last [0-9]+ days
diff.*ClusterIdea.*history.*four
for.*MainPage.*only
1 day
action=browse;id=MainPage;rcclusteronly=MainPage;days=1
EOT
update_page('MainPage', 'Finally the main page.');
test_page(get_page('action=browse id=MainPage rcclusteronly=MainPage'), @Test);
@Test = split('\n',<<'EOT');
Finally the main page
Updates in the last [0-9]+ days
diff.*ClusterIdea.*four
for.*MainPage.*only
1 day
EOT
test_page(get_page('action=browse id=MainPage rcclusteronly=MainPage showedit=1'),
(@Test, 'action=browse;id=MainPage;rcclusteronly=MainPage;showedit=1;days=1'));
test_page(get_page('action=browse id=MainPage rcclusteronly=MainPage all=1'),
(@Test, 'action=browse;id=MainPage;rcclusteronly=MainPage;all=1;days=1'));
@Test = split('\n',<<'EOT');
Finally the main page
Updates in the last [0-9]+ days
diff.*ClusterIdea.*five
diff.*ClusterIdea.*four
for.*MainPage.*only
1 day
action=browse;id=MainPage;rcclusteronly=MainPage;all=1;showedit=1;days=1
EOT
update_page('ClusterIdea', "MainPage\nSomebody has to do it.", 'five', 1);
test_page(get_page('action=browse id=MainPage rcclusteronly=MainPage all=1 showedit=1'), @Test);
# --------------------
print '[rss]';
# create simple config file
open(F,'>/tmp/oddmuse/config');
print F "\$SurgeProtection = 0;\n";
close(F);
use Cwd;
$dir = cwd;
$uri = "file://$dir";
@Test = split('\n',<<'EOT');
PRNewswire: Texas Software Startup, Serenity Systems, Advises Business Users to Get Off Windows
http://linuxtoday.com/story.php3\?sn=9443
LinuxPR: MyDesktop Launches Linux Software Section
http://linuxtoday.com/story.php3\?sn=9442
LinuxPR: Franklin Institute Science Museum Chooses Linux
http://linuxtoday.com/story.php3\?sn=9441
Yellow Dog Linux releases updated am-utils
http://linuxtoday.com/story.php3\?sn=9440
LinuxPR: LinuxCare Adds Laser5 Linux To Roster of Supported Linux Distributions
http://linuxtoday.com/story.php3\?sn=9439
EOT
update_page('RSS', "<rss $uri/linuxtoday.rdf>");
test_page(get_page('RSS'), @Test);
@Test = split('\n',<<'EOT');
Xskat 3.1
http://freshmeat.net/news/1999/09/01/936224942.html
Java Test Driver 1.1
http://freshmeat.net/news/1999/09/01/936224907.html
WaveLAN/IEEE driver 1.0.1
http://freshmeat.net/news/1999/09/01/936224545.html
macfork 1.0
http://freshmeat.net/news/1999/09/01/936224336.html
QScheme 0.2.2
http://freshmeat.net/news/1999/09/01/936223755.html
CompuPic 4.6 build 1018
http://freshmeat.net/news/1999/09/01/936223729.html
eXtace 1.1.16
http://freshmeat.net/news/1999/09/01/936223709.html
GTC 0.3
http://freshmeat.net/news/1999/09/01/936223686.html
RocketJSP 0.9c
http://freshmeat.net/news/1999/09/01/936223646.html
Majik 3D 0.0/M3
http://freshmeat.net/news/1999/09/01/936223622.html
EOT
update_page('RSS', "<rss $uri/fm.rdf>");
test_page(get_page('RSS'), @Test);
@Test = split('\n',<<'EOT');
GTKeyboard 0.85
http://freshmeat.net/news/1999/06/21/930003829.html
EOT
update_page('RSS', "<rss $uri/rss1.0.rdf>");
test_page(get_page('RSS'), @Test);
# @Test = split('\n',<<'EOT');
# Berufsverbot für Mediendesigner?
# http://www.heise.de/tp/deutsch/inhalt/te/15886/1.html
# Experimentell bestätigt:
# http://www.heise.de/tp/deutsch/inhalt/lis/15882/1.html
# Clash im Internet?
# http://www.heise.de/tp/deutsch/special/med/15787/1.html
# Die Einheit der Umma gegen die jüdische Weltmacht
# http://www.heise.de/tp/deutsch/special/ost/15879/1.html
# Im Krieg mit dem Satan
# http://www.heise.de/tp/deutsch/inhalt/co/15880/1.html
# Der dritte Mann
# http://www.heise.de/tp/deutsch/inhalt/co/15876/1.html
# Leicht neben dem Ziel
# http://www.heise.de/tp/deutsch/inhalt/mein/15867/1.html
# Wale sollten Nordkorea meiden
# http://www.heise.de/tp/deutsch/inhalt/co/15878/1.html
# Afghanistan-Krieg und Irak-Besatzung haben al-Qaida gestärkt
# http://www.heise.de/tp/deutsch/inhalt/co/15874/1.html
# Der mit dem Dinosaurier tanzt
# http://www.heise.de/tp/deutsch/inhalt/lis/15863/1.html
# Terroranschlag überschattet das Genfer Abkommen
# http://www.heise.de/tp/deutsch/special/ost/15873/1.html
# "Barwatch" in Kanada
# http://www.heise.de/tp/deutsch/inhalt/te/15871/1.html
# Die Türken kommen!
# http://www.heise.de/tp/deutsch/special/irak/15870/1.html
# Neue Regelungen zur Telekommunikationsüberwachung
# http://www.heise.de/tp/deutsch/inhalt/te/15869/1.html
# Ein Lied vom Tod
# http://www.heise.de/tp/deutsch/inhalt/kino/15862/1.html
# EOT
# update_page('RSS', "<rss $uri/heise.rdf>");
# test_page(get_page('RSS'), @Test);
# Note, cannot identify BayleShanks as author in the mb.rdf
@Test = split('\n',<<'EOT');
MeatBall:LionKimbro
2003-10-24T22:49:33\+06:00
CommunityWiki:RecentNearChanges
http://www.usemod.com/cgi-bin/mb.pl\?LionKimbro
2003-10-24T21:02:53\+00:00
unified rc for here and meatball
<span class="contributor"><span> \. \. \. \. </span>AlexSchroeder</span>
http://www.emacswiki.org/cgi-bin/community\?action=browse;id=RecentNearChanges;revision=1
EOT
update_page('RSS', "<rss $uri/mb.rdf $uri/community.rdf>");
test_page(get_page('RSS'), @Test);
# --------------------
print '[redirection]';
update_page('Miles_Davis', 'Featuring [[John Coltrane]]'); # plain link
update_page('John_Coltrane', '#REDIRECT Coltrane'); # no redirect
update_page('Sonny_Stitt', '#REDIRECT [[Stitt]]'); # redirect
update_page('Keith_Jarret', 'Plays with [[Gary Peacock]]'); # link to perm. anchor
update_page('Jack_DeJohnette', 'A friend of [::Gary Peacock]'); # define perm. anchor
test_page(get_page('Miles_Davis'), ('Featuring', 'John Coltrane'));
test_page(get_page('John_Coltrane'), ('<li>REDIRECT Coltrane'));
test_page(get_page('Sonny_Stitt'),
('Status: 302', 'Location: .*wiki.pl\?action=browse;oldid=Sonny_Stitt;id=Stitt'));
test_page(get_page('Keith_Jarret'),
('Plays with', 'wiki.pl/Gary_Peacock', 'Keith Jarret', 'Gary Peacock'));
test_page(get_page('Gary_Peacock'),
('Status: 302', 'Location: .*wiki.pl/Jack_DeJohnette#Gary_Peacock'));
test_page(get_page('Jack_DeJohnette'),
('A friend of', 'Gary Peacock', 'name="Gary_Peacock"', 'class="definition"',
'title="Click to search for references to this permanent anchor"'));
# --------------------
print '[recent changes]';
$host1 = 'tisch';
$host2 = 'stuhl';
$ENV{'REMOTE_ADDR'} = $host1;
update_page('Mendacibombus', 'This is the place.', 'samba', 0, 0, ('username=berta'));
update_page('Bombia', 'This is the time.', 'tango', 0, 0, ('username=alex'));
$ENV{'REMOTE_ADDR'} = $host2;
update_page('Confusibombus', 'This is order.', 'ballet', 1, 0, ('username=berta'));
update_page('Mucidobombus', 'This is chaos.', 'tarantella', 0, 0, ('username=alex'));
@Positives = split('\n',<<'EOT');
for time or place only
Mendacibombus.*samba
Bombia.*tango
EOT
@Negatives = split('\n',<<'EOT');
Confusibombus
ballet
Mucidobombus
tarantella
EOT
$page = get_page('action=rc rcfilteronly=time%20or%20place');
test_page($page, @Positives);
test_page_negative($page, @Negatives);
@Positives = split('\n',<<'EOT');
Mucidobombus.*tarantella
EOT
@Negatives = split('\n',<<'EOT');
Mendacibombus
samba
Bombia
tango
Confusibombus
ballet
EOT
$page = get_page('action=rc rcfilteronly=order%20or%20chaos');
test_page($page, @Positives);
test_page_negative($page, @Negatives);
@Positives = split('\n',<<'EOT');
EOT
@Negatives = split('\n',<<'EOT');
Mucidobombus
tarantella
Mendacibombus
samba
Bombia
tango
Confusibombus
ballet
EOT
$page = get_page('action=rc rcfilteronly=order%20and%20chaos');
test_page($page, @Positives);
test_page_negative($page, @Negatives);
@Positives = split('\n',<<'EOT');
Mendacibombus.*samba
Bombia.*tango
EOT
@Negatives = split('\n',<<'EOT');
Mucidobombus
tarantella
Confusibombus
ballet
EOT
$page = get_page('action=rc rchostonly=tisch');
test_page($page, @Positives);
test_page_negative($page, @Negatives);
@Positives = split('\n',<<'EOT');
Mucidobombus.*tarantella
EOT
@Negatives = split('\n',<<'EOT');
Confusibombus
ballet
Bombia
tango
Mendacibombus
samba
EOT
$page = get_page('action=rc rchostonly=stuhl'); # no minor edits!
test_page($page, @Positives);
test_page_negative($page, @Negatives);
@Positives = split('\n',<<'EOT');
Mucidobombus.*tarantella
Confusibombus.*ballet
EOT
@Negatives = split('\n',<<'EOT');
Mendacibombus
samba
Bombia
tango
EOT
$page = get_page('action=rc rchostonly=stuhl showedit=1'); # with minor edits!
test_page($page, @Positives);
test_page_negative($page, @Negatives);
@Positives = split('\n',<<'EOT');
Mendacibombus.*samba
EOT
@Negatives = split('\n',<<'EOT');
Mucidobombus
tarantella
Bombia
tango
Confusibombus
ballet
EOT
$page = get_page('action=rc rcuseronly=berta');
test_page($page, @Positives);
test_page_negative($page, @Negatives);
@Positives = split('\n',<<'EOT');
Mucidobombus.*tarantella
Bombia.*tango
EOT
@Negatives = split('\n',<<'EOT');
Confusibombus
ballet
Mendacibombus
samba
EOT
$page = get_page('action=rc rcuseronly=alex');
test_page($page, @Positives);
test_page_negative($page, @Negatives);
@Positives = split('\n',<<'EOT');
Bombia.*tango
EOT
@Negatives = split('\n',<<'EOT');
Mucidobombus
tarantella
Confusibombus
ballet
Mendacibombus
samba
EOT
$page = get_page('action=rc rcidonly=Bombia');
test_page($page, @Positives);
test_page_negative($page, @Negatives);
# --------------------
print '[conflicts]';
# simple edit
@Test = split('\n',<<'EOT');
test test test
EOT
$ENV{'REMOTE_ADDR'} = 'confusibombus';
test_page(update_page('ConflictTest', "test\ntest\ntest\n"), @Test);
# edit from another address should result in conflict warning
$ENV{'REMOTE_ADDR'} = 'megabombus';
test_page(update_page('ConflictTest', "test\ntest\ntest\nend\n"), @Test);
@Test = split('\n',<<'EOT');
This page was changed by somebody else
Please check whether you overwrote those changes
EOT
test_page($redirect, map { UrlEncode($_); } @Test); # test cookie!
# test normal merging -- first get oldtime, then do two conflicting edits
@Test = split('\n',<<'EOT');
foo test bar end
EOT
update_page('ConflictTest', "test\ntest\ntest\nend\n");
$_ = `perl wiki.pl action=edit id=ConflictTest`;
/name="oldtime" value="([0-9]+)"/;
my $oldtime = $1;
$ENV{'REMOTE_ADDR'} = 'confusibombus';
update_page('ConflictTest', "foo\ntest\ntest\nend\n");
$ENV{'REMOTE_ADDR'} = 'megabombus';
test_page(update_page('ConflictTest', "test\ntest\nbar\nend\n", '', '', '', "oldtime=$oldtime"), @Test);
# test conflict during merging -- first get oldtime, then do two conflicting edits
my $str = QuoteHtml(<<'EOT');
test
<<<<<<< you
bar
||||||| ancestor
test
=======
foo
>>>>>>> other
test
EOT
$str = "\n<pre>\n$str</pre>\n\n";
@Test = ($str);
update_page('ConflictTest', "test\ntest\ntest\nend\n");
$_ = `perl wiki.pl action=edit id=ConflictTest`;
/name="oldtime" value="([0-9]+)"/;
$oldtime = $1;
$ENV{'REMOTE_ADDR'} = 'confusibombus';
update_page('ConflictTest', "test\nfoo\ntest\nend\n");
$ENV{'REMOTE_ADDR'} = 'megabombus';
test_page(update_page('ConflictTest', "test\nbar\ntest\nend\n", '', '', '', "oldtime=$oldtime"), @Test);
@Test = split('\n',<<'EOT');
This page was changed by somebody else
The changes conflict
EOT
test_page($redirect, map { UrlEncode($_); } @Test); # test cookie!
# test conflict during merging without merge! -- first get oldtime, then do two conflicting edits
open(F,'>/tmp/oddmuse/config');
print F "\$SurgeProtection = 0;\n";
print F "\$ENV{'PATH'} = '';\n";
close(F);
@Test = split('\n',<<'EOT');
test bar test end
EOT
update_page('ConflictTest', "test\ntest\ntest\nend\n");
$_ = `perl wiki.pl action=edit id=ConflictTest`;
/name="oldtime" value="([0-9]+)"/;
$oldtime = $1;
$ENV{'REMOTE_ADDR'} = 'confusibombus';
update_page('ConflictTest', "test\nfoo\ntest\nend\n");
$ENV{'REMOTE_ADDR'} = 'megabombus';
test_page(update_page('ConflictTest', "test\nbar\ntest\nend\n", '', '', '', "oldtime=$oldtime"), @Test);
@Test = split('\n',<<'EOT');
This page was changed by somebody else
Please check whether you overwrote those changes
EOT
test_page($redirect, map { UrlEncode($_); } @Test); # test cookie!
# --------------------
print '[html cache]';
# create config file with WikiLinks=0
open(F,'>/tmp/oddmuse/config');
print F "\$WikiLinks = 0;\n";
print F "\$SurgeProtection = 0;\n";
close(F);
### Maintenance with cache resetting
@Test = split('\n',<<'EOT');
This is a WikiLink.
EOT
test_page(update_page('CacheTest', 'This is a WikiLink.', '', 1), @Test);
# create new config file with WikiLinks=1
open(F,'>/tmp/oddmuse/config');
print F "\$WikiLinks = 1;\n";
print F "\$AdminPass = 'foo';\n";
print F "\$SurgeProtection = 0;\n";
close(F);
# without new edit, the cached version persists
test_page(get_page('CacheTest'), @Test);
# refresh the cache using the all action
@Test = split('\n',<<'EOT');
This is a WikiLink<a class="edit" title="Click to create this page" href="http://localhost/wiki.pl\?action=edit;id=WikiLink">\?</a>.
EOT
get_page('action=all cache=0');
test_page(get_page('CacheTest'), @Test);
# --------------------
print '[search and replace]';
open(F,'>/tmp/oddmuse/config');
print F "\$NetworkFile = 1;\n";
print F "\$AdminPass = 'foo';\n";
print F "\$SurgeProtection = 0;\n";
close(F);
# Test search
@Test = split('\n',<<'EOT');
<h1>Search for: fooz</h1>
<p>1 pages found.</p>
<span class="result"><a class="local" href="http://localhost/wiki.pl/SearchAndReplace">SearchAndReplace</a></span>
This is <strong>fooz</strong> and this is barz.
EOT
update_page('SearchAndReplace', 'This is fooz and this is barz.', '', 1);
test_page(get_page('search=fooz'), @Test);
# Make sure only admins can replace
@Test = split('\n',<<'EOT');
This operation is restricted to administrators only...
EOT
test_page(get_page('search=foo replace=bar'), @Test);
# Simple replace
@Test = split('\n',<<'EOT');
<h1>Replaced: fooz -&gt; fuuz</h1>
<p>1 pages found.</p>
This is <strong>fuuz</strong> and this is barz.
EOT
test_page(get_page('search=fooz replace=fuuz pwd=foo'), @Test);
# Replace with backreferences
@Test = split('\n',<<'EOT');
This is xfuu and this is xbar.
EOT
get_page('search=([a-z]%2b)z replace=x%241 pwd=foo');
test_page(get_page('SearchAndReplace'), @Test);
## Check headers especially the quoting of non-ASCII characters.
@Test = split('\n',<<'EOT');
<h1><a title="Click to search for references to this page" href="http://localhost/wiki.pl\?search=Alexander\+Schr\%c3\%b6der">Alexander Schröder</a></h1>
Edit <a class="local" href="http://localhost/wiki.pl/Alexander_Schr\%c3\%b6der">Alexander Schröder</a>!
EOT
test_page(update_page("Alexander_Schröder", "Edit [[Alexander Schröder]]!"), @Test);
# --------------------
print '[banning]';
## Edit banned hosts as a normal user should fail
$localhost = 'confusibombus';
$ENV{'REMOTE_ADDR'} = $localhost;
@Test = split('\n',<<'EOT');
Describe the new page here
EOT
test_page(update_page('BannedHosts', "Foo\nBar\n $localhost\n", 'banning me'), @Test);
## Edit banned hosts as admin should succeed
@Test = split('\n',<<"EOT");
Foo
$localhost
EOT
test_page(update_page('BannedHosts', "Foo\nBar\n $localhost\n", 'banning me', 0, 1), @Test);
## Edit banned hosts as a normal user should fail
@Test = split('\n',<<"EOT");
Foo
$localhost
EOT
test_page(update_page('BannedHosts', "Something else.", 'banning me'), @Test);
## Try to edit another page as a banned user
@Test = split('\n',<<'EOT');
Describe the new page here
EOT
test_page(update_page('BannedUser', 'This is a test which should fail.', 'banning test'), @Test);
## Try to edit the same page as a banned user with admin password
@Test = split('\n',<<'EOT');
This is a test
EOT
test_page(update_page('BannedUser', 'This is a test.', 'banning test', 0, 1), @Test);
## Unbann myself again, testing the regexp
@Test = split('\n',<<'EOT');
Foo
Bar
EOT
test_page(update_page('BannedHosts', "Foo\nBar\n", 'banning me', 0, 1), @Test);
# --------------------
print '[journal]';
## Create diary pages
update_page('2003-06-13', "Freitag");
update_page('2003-06-14', "Samstag");
update_page('2003-06-15', "Sonntag");
@Test = split('\n',<<'EOT');
This is my journal
2003-06-15
Sonntag
2003-06-14
Samstag
EOT
test_page(update_page('Summary', "This is my journal:\n\n<journal 2>"), @Test);
test_page(update_page('2003-01-01', "This is my journal -- recursive:\n\n<journal>"), @Test);
push @Test, 'journal';
test_page(update_page('2003-01-01', "This is my journal -- truly recursive:\n\n<journal>"), @Test);
@Test = split('\n',<<'EOT');
2003-06-15(.|\n)*2003-06-14
EOT
test_page(update_page('Summary', "Counting down:\n\n<journal 2>"), @Test);
@Test = split('\n',<<'EOT');
2003-01-01(.|\n)*2003-06-13(.|\n)*2003-06-14
EOT
test_page(update_page('Summary', "Counting up:\n\n<journal 3 reverse>"), @Test);
# --------------------
print '[revisions]';
## Test revision and diff stuff
update_page('KeptRevisions', 'first');
update_page('KeptRevisions', 'second');
update_page('KeptRevisions', 'third');
update_page('KeptRevisions', 'fourth', '', 1);
update_page('KeptRevisions', 'fifth', '', 1);
# Show the current revision
@Test = split('\n',<<'EOT');
KeptRevisions
fifth
EOT
test_page(get_page(KeptRevisions), @Test);
# Show the other revision
@Test = split('\n',<<'EOT');
Showing revision 2
second
EOT
test_page(get_page('action=browse revision=2 id=KeptRevisions'), @Test);
@Test = split('\n',<<'EOT');
Showing revision 1
first
EOT
test_page(get_page('action=browse revision=1 id=KeptRevisions'), @Test);
# Show the current revision if an inexisting revision is asked for
@Test = split('\n',<<'EOT');
Revision 9 not available \(showing current revision instead\)
fifth
EOT
test_page(get_page('action=browse revision=9 id=KeptRevisions'), @Test);
# Show a major diff
@Test = split('\n',<<'EOT');
Difference \(from prior major revision\)
third
fifth
EOT
test_page(get_page('action=browse diff=1 id=KeptRevisions'), @Test);
# Show a minor diff
@Test = split('\n',<<'EOT');
Difference \(from prior minor revision\)
fourth
fifth
EOT
test_page(get_page('action=browse diff=2 id=KeptRevisions'), @Test);
# Show a diff from the history page comparing two specific revisions
@Test = split('\n',<<'EOT');
Difference \(from revision 2 to revision 4\)
second
fourth
EOT
test_page(get_page('action=browse diff=1 revision=4 diffrevision=2 id=KeptRevisions'), @Test);
# --------------------
print '[lock on creation]';
open(F,'>/tmp/oddmuse/config');
print F "\$SurgeProtection = 0;\n";
print F "\$AdminPass = 'foo';\n";
close(F);
## Create a sample page, and test for regular expressions in the output
@Test = split('\n',<<'EOT');
SandBox
This is a test.
<h1><a title="Click to search for references to this page" href="http://localhost/wiki.pl\?search=SandBox">SandBox</a></h1>
EOT
test_page(update_page('SandBox', 'This is a test.', 'first test'), @Test);
## Test RecentChanges
@Test = split('\n',<<'EOT');
RecentChanges
first test
EOT
test_page(get_page('action=rc'), @Test);
## Updated the page
@Test = split('\n',<<'EOT');
RecentChanges
This is another test.
EOT
test_page(update_page('SandBox', 'This is another test.', 'second test'), @Test);
## Test RecentChanges
@Test = split('\n',<<'EOT');
RecentChanges
second test
EOT
test_page(get_page('action=rc'), @Test);
## Attempt to create InterMap page as normal user
@Test = split('\n',<<'EOT');
Describe the new page here
EOT
test_page(update_page('InterMap', " OddMuse http://www.emacswiki.org/cgi-bin/oddmuse.pl?\n", 'required'), @Test);
## Create InterMap page as admin
## The OddMuse intermap entry is required for later tests.
@Test = split('\n',<<'EOT');
OddMuse
http://www\.emacswiki\.org/cgi-bin/oddmuse\.pl\?
PlanetMath
http://planetmath\.org/encyclopedia/\%s\.html
EOT
test_page(update_page('InterMap', " OddMuse http://www.emacswiki.org/cgi-bin/oddmuse.pl?\n PlanetMath http://planetmath.org/encyclopedia/%s.html", 'required', 0, 1), @Test);
## Verify the InterMap stayed locked
@Test = split('\n',<<'EOT');
OddMuse
EOT
test_page(update_page('InterMap', "All your edits are blong to us!\n", 'required'), @Test);
# --------------------
print '[markup]';
open(F,'>/tmp/oddmuse/config');
print F "\$NetworkFile = 1;\n";
print F "\$AdminPass = 'foo';\n";
print F "\$SurgeProtection = 0;\n";
print F "\%Smilies = ('HAHA!' => '/pics/haha.png');\n";
close(F);
update_page('InterMap', " OddMuse http://www.emacswiki.org/cgi-bin/oddmuse.pl?\n PlanetMath http://planetmath.org/encyclopedia/%s.html", 'required', 0, 1);
%Test = split('\n',<<'EOT');
HAHA!
<img class="smiley" src="/pics/haha.png" alt="HAHA!" />
do not eat 0 from text
do not eat 0 from text
ordinary text
ordinary text
\nparagraph
<p>paragraph
* one\n*two
<ul><li>one </li><li>two</li></ul>
# one\n# two
<ol><li>one </li><li>two</li></ol>
* one\n#two
<ul><li>one </li></ul><ol><li>two</li></ol>
* one\n**two
<ul><li>one <ul><li>two</li></ul></li></ul>
* one\n**two\n***three\n*four
<ul><li>one <ul><li>two <ul><li>three </li></ul></li></ul></li><li>four</li></ul>
* one\n**two\n***three\n*four\n**five\n*six
<ul><li>one <ul><li>two <ul><li>three </li></ul></li></ul></li><li>four <ul><li>five </li></ul></li><li>six</li></ul>
* one\n* two\n** one and two\n** two and three\n* three
<ul><li>one </li><li>two <ul><li>one and two </li><li>two and three </li></ul></li><li>three</li></ul>
# one\n# two\n## one and two\n## two and three\n# three
<ol><li>one </li><li>two <ol><li>one and two </li><li>two and three </li></ol></li><li>three</li></ol>
: one\n: two\n:: one and two\n:: two and three\n: three
<dl class="quote"><dt /><dd>one </dd><dt /><dd>two <dl class="quote"><dt /><dd>one and two </dd><dt /><dd>two and three </dd></dl></dd><dt /><dd>three</dd></dl>
;one:eins\n;two:zwei
<dl><dt>one</dt><dd>eins </dd><dt>two</dt><dd>zwei</dd></dl>
This is ''emphasized''.
This is <em>emphasized</em>.
This is '''strong'''.
This is <strong>strong</strong>.
This is ''longer emphasized'' text.
This is <em>longer emphasized</em> text.
This is '''longer strong''' text.
This is <strong>longer strong</strong> text.
This is ''emphasized text containing '''longer strong''' text''.
This is <em>emphasized text containing <strong>longer strong</strong> text</em>.
WikiWord
WikiWord<a class="edit" title="Click to create this page" href="http://localhost/test-wrapper.pl?action=edit;id=WikiWord">?</a>
WikiWord:
WikiWord<a class="edit" title="Click to create this page" href="http://localhost/test-wrapper.pl?action=edit;id=WikiWord">?</a>:
OddMuse
OddMuse<a class="edit" title="Click to create this page" href="http://localhost/test-wrapper.pl?action=edit;id=OddMuse">?</a>
OddMuse:
OddMuse<a class="edit" title="Click to create this page" href="http://localhost/test-wrapper.pl?action=edit;id=OddMuse">?</a>:
OddMuse:test
<a class="inter" href="http://www.emacswiki.org/cgi-bin/oddmuse.pl?test"><span class="site">OddMuse</span>:<span class="page">test</span></a>
OddMuse:test: or not
<a class="inter" href="http://www.emacswiki.org/cgi-bin/oddmuse.pl?test"><span class="site">OddMuse</span>:<span class="page">test</span></a>: or not
OddMuse:test, and foo
<a class="inter" href="http://www.emacswiki.org/cgi-bin/oddmuse.pl?test"><span class="site">OddMuse</span>:<span class="page">test</span></a>, and foo
PlanetMath:ZipfsLaw, and foo
<a class="inter" href="http://planetmath.org/encyclopedia/ZipfsLaw.html"><span class="site">PlanetMath</span>:<span class="page">ZipfsLaw</span></a>, and foo
[OddMuse:test]
<a class="inter number" href="http://www.emacswiki.org/cgi-bin/oddmuse.pl?test"><span><span class="bracket">[</span>1<span class="bracket">]</span></span></a>
Foo::Bar
Foo::Bar
!WikiLink
WikiLink
!foo
!foo
![[Free Link]]
![Free Link]<a class="edit" title="Click to create this page" href="http://localhost/test-wrapper.pl?action=edit;id=Free_Link">?</a>
||one||
<table class="user"><tr><td>one</td></tr></table>
introduction\n\n||one||two||three||\n||||one two||three||
introduction<p><table class="user"><tr><td>one</td><td>two</td><td>three</td></tr><tr><td colspan="2">one two</td><td>three</td></tr></table>
||one||two||three||\n||||one two||three||\n\nfooter
<table class="user"><tr><td>one</td><td>two</td><td>three</td></tr><tr><td colspan="2">one two</td><td>three</td></tr></table><p>footer
introduction\n\n||one||two||three||\n||||one two||three||\n\nfooter
introduction<p><table class="user"><tr><td>one</td><td>two</td><td>three</td></tr><tr><td colspan="2">one two</td><td>three</td></tr></table><p>footer
http://www.emacswiki.org
<a class="url" href="http://www.emacswiki.org">http://www.emacswiki.org</a>
<http://www.emacswiki.org>
<<a class="url" href="http://www.emacswiki.org">http://www.emacswiki.org</a>>
http://www.emacswiki.org/
<a class="url" href="http://www.emacswiki.org/">http://www.emacswiki.org/</a>
http://www.emacswiki.org.
<a class="url" href="http://www.emacswiki.org">http://www.emacswiki.org</a>.
http://www.emacswiki.org,
<a class="url" href="http://www.emacswiki.org">http://www.emacswiki.org</a>,
http://www.emacswiki.org;
<a class="url" href="http://www.emacswiki.org">http://www.emacswiki.org</a>;
http://www.emacswiki.org:
<a class="url" href="http://www.emacswiki.org">http://www.emacswiki.org</a>:
http://www.emacswiki.org?
<a class="url" href="http://www.emacswiki.org">http://www.emacswiki.org</a>?
http://www.emacswiki.org/?
<a class="url" href="http://www.emacswiki.org/">http://www.emacswiki.org/</a>?
http://www.emacswiki.org!
<a class="url" href="http://www.emacswiki.org">http://www.emacswiki.org</a>!
http://www.emacswiki.org'
<a class="url" href="http://www.emacswiki.org">http://www.emacswiki.org</a>'
http://www.emacswiki.org"
<a class="url" href="http://www.emacswiki.org">http://www.emacswiki.org</a>"
http://www.emacswiki.org!
<a class="url" href="http://www.emacswiki.org">http://www.emacswiki.org</a>!
http://www.emacswiki.org(
<a class="url" href="http://www.emacswiki.org">http://www.emacswiki.org</a>(
http://www.emacswiki.org)
<a class="url" href="http://www.emacswiki.org">http://www.emacswiki.org</a>)
http://www.emacswiki.org&
<a class="url" href="http://www.emacswiki.org">http://www.emacswiki.org</a>&
http://www.emacswiki.org#
<a class="url" href="http://www.emacswiki.org">http://www.emacswiki.org</a>#
http://www.emacswiki.org%
<a class="url" href="http://www.emacswiki.org">http://www.emacswiki.org</a>%
[http://www.emacswiki.org]
<a class="url number" href="http://www.emacswiki.org"><span><span class="bracket">[</span>1<span class="bracket">]</span></span></a>
[http://www.emacswiki.org] and [http://www.emacswiki.org]
<a class="url number" href="http://www.emacswiki.org"><span><span class="bracket">[</span>1<span class="bracket">]</span></span></a> and <a class="url number" href="http://www.emacswiki.org"><span><span class="bracket">[</span>2<span class="bracket">]</span></span></a>
[http://www.emacswiki.org],
<a class="url number" href="http://www.emacswiki.org"><span><span class="bracket">[</span>1<span class="bracket">]</span></span></a>,
[http://www.emacswiki.org and a label]
<a class="url outside" href="http://www.emacswiki.org">and a label</a>
[file://home/foo/tutorial.pdf local link]
<a class="url outside" href="file://home/foo/tutorial.pdf">local link</a>
file://home/foo/tutorial.pdf
<a class="url" href="file://home/foo/tutorial.pdf">file://home/foo/tutorial.pdf</a>
file:///home/foo/tutorial.pdf
file:///home/foo/tutorial.pdf
mailto:alex@emacswiki.org
<a class="url" href="mailto:alex@emacswiki.org">mailto:alex@emacswiki.org</a>
source
<pre> source</pre>
source\n etc\n
<pre> source\n etc\n</pre>
source\n \n etc\n
<pre> source\n \n etc\n</pre>
source\n \n etc\n\nother
<pre> source\n \n etc\n</pre><p>other
EOT
run_tests();
markup:
print '[link pattern]';
system('/bin/rm -rf /tmp/oddmuse');
die "Cannot remove /tmp/oddmuse!\n" if -e '/tmp/oddmuse';
mkdir '/tmp/oddmuse';
open(F,'>/tmp/oddmuse/config');
print F "\$AllNetworkFiles = 1;\n";
print F "\$SurgeProtection = 0;\n";
print F "\$AdminPass = 'foo';\n";
close(F);
update_page('HomePage', "This page exists.");
update_page('InterMap', " Oddmuse http://www.emacswiki.org/cgi-bin/oddmuse.pl?\n PlanetMath http://planetmath.org/encyclopedia/%s.html", 'required', 0, 1);
%Test = split('\n',<<'EOT');
file://home/foo/tutorial.pdf
<a class="url" href="file://home/foo/tutorial.pdf">file://home/foo/tutorial.pdf</a>
file:///home/foo/tutorial.pdf
<a class="url" href="file:///home/foo/tutorial.pdf">file:///home/foo/tutorial.pdf</a>
image inline: [[image:HomePage]], [[image:OtherPage]]
image inline: <a class="upload image" href="http://localhost/test-wrapper.pl/HomePage"><img class="upload" src="http://localhost/test-wrapper.pl/download/HomePage" alt="HomePage" /></a>, [image:OtherPage<a class="edit" title="Click to create this page" href="http://localhost/test-wrapper.pl?action=edit;id=OtherPage;upload=1">?</a>]
traditional local link: HomePage, OtherPage
traditional local link: <a class="local" href="http://localhost/test-wrapper.pl/HomePage">HomePage</a>, OtherPage<a class="edit" title="Click to create this page" href="http://localhost/test-wrapper.pl?action=edit;id=OtherPage">?</a>
traditional local link with extra brackets: [HomePage], [OtherPage]
traditional local link with extra brackets: <a class="local number" title="HomePage" href="http://localhost/test-wrapper.pl/HomePage"><span><span class="bracket">[</span>1<span class="bracket">]</span></span></a>, [OtherPage<a class="edit" title="Click to create this page" href="http://localhost/test-wrapper.pl?action=edit;id=OtherPage">?</a>]
traditional local link with other text: [HomePage homepage], [OtherPage other page]
traditional local link with other text: [<a class="local" href="http://localhost/test-wrapper.pl/HomePage">HomePage</a> homepage], [OtherPage<a class="edit" title="Click to create this page" href="http://localhost/test-wrapper.pl?action=edit;id=OtherPage">?</a> other page]
free link: [[home page]], [[other page]]
free link: [home page]<a class="edit" title="Click to create this page" href="http://localhost/test-wrapper.pl?action=edit;id=home_page">?</a>, [other page]<a class="edit" title="Click to create this page" href="http://localhost/test-wrapper.pl?action=edit;id=other_page">?</a>
free link with extra brackets: [[[home page]]], [[[other page]]]
free link with extra brackets: [home_page<a class="edit" title="Click to create this page" href="http://localhost/test-wrapper.pl?action=edit;id=home_page">?</a>], [other_page<a class="edit" title="Click to create this page" href="http://localhost/test-wrapper.pl?action=edit;id=other_page">?</a>]
free link with other text: [[home page|da homepage]], [[other page|da other homepage]]
free link with other text: [[home page|da homepage]], [[other page|da other homepage]]
URL: http://www.oddmuse.org/
URL: <a class="url" href="http://www.oddmuse.org/">http://www.oddmuse.org/</a>
URL in brackets: [http://www.oddmuse.org/]
URL in brackets: <a class="url number" href="http://www.oddmuse.org/"><span><span class="bracket">[</span>1<span class="bracket">]</span></span></a>
URL in brackets with other text: [http://www.oddmuse.org/ oddmuse]
URL in brackets with other text: <a class="url outside" href="http://www.oddmuse.org/">oddmuse</a>
URL abbreviation: Oddmuse:Link_Pattern
URL abbreviation: <a class="inter" href="http://www.emacswiki.org/cgi-bin/oddmuse.pl?Link_Pattern"><span class="site">Oddmuse</span>:<span class="page">Link_Pattern</span></a>
URL abbreviation with extra brackets: [Oddmuse:Link_Pattern]
URL abbreviation with extra brackets: <a class="inter number" href="http://www.emacswiki.org/cgi-bin/oddmuse.pl?Link_Pattern"><span><span class="bracket">[</span>1<span class="bracket">]</span></span></a>
URL abbreviation with other text: [Oddmuse:Link_Pattern link patterns]
URL abbreviation with other text: <a class="inter outside" href="http://www.emacswiki.org/cgi-bin/oddmuse.pl?Link_Pattern">link patterns</a>
EOT
run_tests();
open(F,'>>/tmp/oddmuse/config');
print F "\$BracketWiki = 1;\n";
close(F);
%Test = split('\n',<<'EOT');
traditional local link: HomePage, OtherPage
traditional local link: <a class="local" href="http://localhost/test-wrapper.pl/HomePage">HomePage</a>, OtherPage<a class="edit" title="Click to create this page" href="http://localhost/test-wrapper.pl?action=edit;id=OtherPage">?</a>
traditional local link with extra brackets: [HomePage], [OtherPage]
traditional local link with extra brackets: <a class="local number" title="HomePage" href="http://localhost/test-wrapper.pl/HomePage"><span><span class="bracket">[</span>1<span class="bracket">]</span></span></a>, [OtherPage<a class="edit" title="Click to create this page" href="http://localhost/test-wrapper.pl?action=edit;id=OtherPage">?</a>]
traditional local link with other text: [HomePage homepage], [OtherPage other page]
traditional local link with other text: <a class="local" href="http://localhost/test-wrapper.pl/HomePage">homepage</a>, [OtherPage<a class="edit" title="Click to create this page" href="http://localhost/test-wrapper.pl?action=edit;id=OtherPage">?</a> other page]
free link: [[home page]], [[other page]]
free link: [home page]<a class="edit" title="Click to create this page" href="http://localhost/test-wrapper.pl?action=edit;id=home_page">?</a>, [other page]<a class="edit" title="Click to create this page" href="http://localhost/test-wrapper.pl?action=edit;id=other_page">?</a>
free link with extra brackets: [[[home page]]], [[[other page]]]
free link with extra brackets: [home_page<a class="edit" title="Click to create this page" href="http://localhost/test-wrapper.pl?action=edit;id=home_page">?</a>], [other_page<a class="edit" title="Click to create this page" href="http://localhost/test-wrapper.pl?action=edit;id=other_page">?</a>]
free link with other text: [[home page|da homepage]], [[other page|da other homepage]]
free link with other text: [home page<a class="edit" title="Click to create this page" href="http://localhost/test-wrapper.pl?action=edit;id=home_page">?</a> da homepage], [other page<a class="edit" title="Click to create this page" href="http://localhost/test-wrapper.pl?action=edit;id=other_page">?</a> da other homepage]
URL: http://www.oddmuse.org/
URL: <a class="url" href="http://www.oddmuse.org/">http://www.oddmuse.org/</a>
URL in brackets: [http://www.oddmuse.org/]
URL in brackets: <a class="url number" href="http://www.oddmuse.org/"><span><span class="bracket">[</span>1<span class="bracket">]</span></span></a>
URL in brackets with other text: [http://www.oddmuse.org/ oddmuse]
URL in brackets with other text: <a class="url outside" href="http://www.oddmuse.org/">oddmuse</a>
URL abbreviation: Oddmuse:Link_Pattern
URL abbreviation: <a class="inter" href="http://www.emacswiki.org/cgi-bin/oddmuse.pl?Link_Pattern"><span class="site">Oddmuse</span>:<span class="page">Link_Pattern</span></a>
URL abbreviation with extra brackets: [Oddmuse:Link_Pattern]
URL abbreviation with extra brackets: <a class="inter number" href="http://www.emacswiki.org/cgi-bin/oddmuse.pl?Link_Pattern"><span><span class="bracket">[</span>1<span class="bracket">]</span></span></a>
URL abbreviation with other text: [Oddmuse:Link_Pattern link patterns]
URL abbreviation with other text: <a class="inter outside" href="http://www.emacswiki.org/cgi-bin/oddmuse.pl?Link_Pattern">link patterns</a>
EOT
run_tests();
### END OF TESTS
print "\n";
print "$passed passed, $failed failed.\n";