2016-08-11 15:29:41 +02:00
# Copyright (C) 2006– 2016 Alex Schroeder <alex@gnu.org>
2006-12-22 15:25:58 +00:00
#
2012-05-25 00:57:40 +02:00
# 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 3 of the License, or (at your option) any later
# version.
2006-12-22 15:25:58 +00:00
#
2012-05-25 00:57:40 +02:00
# 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.
2006-12-22 15:25:58 +00:00
#
2012-05-25 00:57:40 +02:00
# You should have received a copy of the GNU General Public License along with
# this program. If not, see <http://www.gnu.org/licenses/>.
2006-12-22 15:25:58 +00:00
require 't/test.pl' ;
package OddMuse ;
2016-08-11 15:29:41 +02:00
use Test::More tests = > 78 ;
2012-05-24 12:25:01 +02:00
use utf8 ; # tests contain UTF-8 characters and it matters
2006-12-22 15:25:58 +00:00
add_module ( 'namespaces.pl' ) ;
2015-07-07 14:17:30 +02:00
AppendStringToFile ( $ ConfigFile , "\$WikiLinks = 1;\n" ) ;
2006-12-22 15:25:58 +00:00
2009-04-06 00:02:54 +00:00
test_page_negative ( get_page ( '/Test?username=alex' ) , 'Wiki Test: Test' ) ;
# editing pages
2006-12-22 15:25:58 +00:00
test_page ( get_page ( 'Test' ) ,
'<title>Wiki: Test</title>' ,
'Status: 404 NOT FOUND' ) ;
2008-09-22 01:24:35 +00:00
test_page ( update_page ( 'Test' , 'Muuu!' , 'main ns' , undef , undef ,
'username=Alex' ) ,
2006-12-22 15:25:58 +00:00
'<p>Muuu!</p>' ) ;
test_page ( get_page ( 'action=browse id=Test ns=Muu' ) ,
'<title>Wiki Muu: Test</title>' ,
'Status: 404 NOT FOUND' ) ;
2008-09-22 01:24:35 +00:00
test_page ( update_page ( 'Test' , 'Mooo!' , 'muu ns' , undef , undef ,
'ns=Muu' , 'username=Berta' ) ,
2006-12-22 15:25:58 +00:00
'<title>Wiki Muu: Test</title>' ,
'<p>Mooo!</p>' ) ;
test_page ( get_page ( 'action=browse id=Test ns=Muu' ) ,
'<title>Wiki Muu: Test</title>' ,
'<p>Mooo!</p>' ) ;
2009-04-06 00:02:54 +00:00
2013-06-05 16:18:10 +02:00
# history
xpath_test ( get_page ( 'action=history id=Test ns=Muu' ) ,
'//table[@class="history"]/tr/td/a[text()="Revision 1"]' ,
'//h1[text()="History of Test"]' ) ;
test_page ( get_page ( 'action=history id=Test ns=Muu raw=1' ) ,
"link: http://localhost/wiki.pl/Muu\\?action=history;id=Test;raw=1\n" ,
"link: http://localhost/wiki.pl/Muu/Test\n" ) ;
2009-04-06 00:02:54 +00:00
# search
2009-04-06 00:27:22 +00:00
$ page = get_page ( '/Muu?search=Mooo raw=1' ) ;
2009-04-06 00:02:54 +00:00
test_page ( $ page , 'description: Mooo!' ) ;
test_page_negative ( $ page , 'description: Muuu!' ) ;
$ page = get_page ( 'search=Muuu raw=1' ) ;
test_page_negative ( $ page , 'description: Mooo!' ) ;
test_page ( $ page , 'description: Muuu!' ) ;
# recent changes
2008-09-22 01:24:35 +00:00
test_page ( get_page ( 'action=rc raw=1' ) ,
'generator: Alex' ,
'generator: Muu:Berta' ) ;
xpath_test ( get_page ( 'action=rc' ) ,
'//a[@class="author"][text()="Alex"][@href="http://localhost/wiki.pl/Alex"]' ,
'//a[@class="author"][text()="Muu:Berta"][@href="http://localhost/wiki.pl/Muu/Berta"]' ) ;
2007-09-24 08:26:52 +00:00
# redirect from Main:Mu to Muu:Mu
2007-09-21 09:31:41 +00:00
update_page ( 'Mu' , '#REDIRECT Muu:Mu' ) ;
test_page ( get_page ( 'action=browse id=Mu' ) ,
2007-11-17 23:56:09 +00:00
'Status: 302' ,
'Location: http://localhost/wiki.pl\?action=browse;ns=Muu;oldid=Main:Mu;id=Mu' ) ;
2007-09-24 08:26:52 +00:00
# check the edit link
xpath_test ( get_page ( 'action=browse id=Mu ns=Muu oldid=Main:Mu' ) ,
'//div[@class="message"]/p[contains(text(),"redirected from")]/a[@class="edit"][@title="Click to edit this page"][@href="http://localhost/wiki.pl?action=edit;id=Mu"][text()="Main:Mu"]' ) ;
# redirect from Muu:Mu
update_page ( 'Mu' , '#REDIRECT Ford:Goo' , undef , undef , undef , 'ns=Muu' ) ;
test_page ( get_page ( 'action=browse id=Mu ns=Muu' ) ,
2007-11-17 23:56:09 +00:00
'Status: 302' ,
'Location: http://localhost/wiki.pl\?action=browse;ns=Ford;oldid=Muu:Mu;id=Goo' ) ;
2007-09-24 08:26:52 +00:00
# check the edit link
xpath_test ( get_page ( 'action=browse id=Goo ns=Ford oldid=Muu:Mu' ) ,
'//div[@class="message"]/p[contains(text(),"redirected from")]/a[@class="edit"][@title="Click to edit this page"][@href="http://localhost/wiki.pl/Muu?action=edit;id=Mu"][text()="Muu:Mu"]' ) ;
# check Main:Mu and verify that only a single redirection hop is allowed
xpath_test ( get_page ( 'action=browse id=Mu ns=Muu oldid=Main:Mu' ) ,
2015-07-07 14:17:30 +02:00
'//div/p[contains(text(),"#REDIRECT")]/a[@href="http://localhost/wiki.pl/Ford/Goo"][@class="inter Ford"]/span[@class="site"][text()="Ford"]/following-sibling::span[@class="interpage"][text()="Goo"]' ) ;
2007-11-17 23:56:09 +00:00
# redirecting back to the Main namespace is different, so test separately
test_page ( update_page ( 'BackHome' , '#REDIRECT Main:HomePage' , undef , undef , undef , 'ns=Muu' ) ,
'Status: 302' ,
'Location: http://localhost/wiki.pl\?action=browse;ns=Main;oldid=Muu:BackHome;id=HomePage' ) ;
# check the edit link
xpath_test ( get_page ( 'action=browse id=HomePage ns=Main oldid=Muu:BackHome' ) ,
'//div[@class="message"]/p[contains(text(),"redirected from")]/a[@class="edit"][@title="Click to edit this page"][@href="http://localhost/wiki.pl/Muu?action=edit;id=BackHome"][text()="Muu:BackHome"]' ) ;
2007-09-24 08:26:52 +00:00
# continue with regular tests
2006-12-22 15:25:58 +00:00
test_page ( get_page ( 'action=browse id=Test ns=Main' ) ,
'<title>Wiki: Test</title>' ,
'<p>Muuu!</p>' ) ;
test_page ( get_page ( 'action=rc raw=1' ) ,
'description: main ns' ,
'description: muu ns' ) ;
test_page_negative ( get_page ( 'action=rc raw=1 local=1' ) ,
'description: muu ns' ) ;
test_page ( get_page ( 'action=rc raw=1 ns=Muu' ) ,
'description: muu ns' ) ;
test_page_negative ( get_page ( 'action=rc raw=1 ns=Muu' ) ,
'description: main ns' ) ;
2007-05-30 08:03:56 +00:00
# add two more edits so that RC will show diff links
update_page ( 'Test' , 'Another Muuu!' , 'main ns' ) ;
update_page ( 'Test' , 'Another Mooo!' , 'muu ns' , undef , undef , 'ns=Muu' ) ;
xpath_test ( get_page ( 'action=rc' ) ,
'//a[@class="local"][@href="http://localhost/wiki.pl/Test"][text()="Test"]' ,
'//a[@class="history"][@href="http://localhost/wiki.pl?action=history;id=Test"][text()="history"]' ,
'//a[@class="diff"][@href="http://localhost/wiki.pl?action=browse;diff=1;id=Test"][text()="diff"]' ,
2007-09-25 15:29:33 +00:00
'//a[@class="local"][@href="http://localhost/wiki.pl/Muu/Test"][text()="Muu:Test"]' ,
2007-05-30 08:03:56 +00:00
'//a[@class="history"][@href="http://localhost/wiki.pl/Muu?action=history;id=Test"][text()="history"]' ,
'//a[@class="diff"][@href="http://localhost/wiki.pl/Muu?action=browse;diff=1;id=Test"][text()="diff"]' ,
) ;
2008-03-07 09:43:51 +00:00
test_page ( get_page ( 'action=rss' ) ,
'<title>Muu:Mu</title>' ,
2008-03-07 09:44:35 +00:00
'<link>http://localhost/wiki.pl/Muu/Mu</link>' ,
2008-03-07 09:43:51 +00:00
'<wiki:history>http://localhost/wiki.pl/Muu\?action=history;id=Mu</wiki:history>' ,
'<wiki:diff>http://localhost/wiki.pl/Muu\?action=browse;diff=1;id=Mu</wiki:diff>' ) ;
2012-07-19 13:58:58 +02:00
# Test Unicode characters in namespaces (BLACK HEART SUIT)
2016-08-11 15:29:41 +02:00
test_page ( update_page ( 'Ümlaute' , 'namespace mit herz' ,
2012-07-19 13:58:58 +02:00
'wo steckt das ü' , undef , undef ,
'ns=Zürich♥' ) , 'namespace mit herz' ) ;
xpath_test ( get_page ( 'action=rc' ) ,
# the exact result depends on filesystem encoding!
2016-08-11 15:29:41 +02:00
'//a[@class="local"][@href="http://localhost/wiki.pl/Z%c3%bcrich%e2%99%a5/%c3%9cmlaute"]' ) ;
2012-07-19 13:58:58 +02:00
# Test potential Latin-1 characters in namespaces (LATIN SMALL LETTER U DIAERESIS)
2016-08-11 15:29:41 +02:00
test_page ( update_page ( 'Ümlaute' , 'namespace mit umlaut' ,
2008-12-02 23:35:15 +00:00
'wo steckt das ü' , undef , undef ,
'ns=Zürich' ) , 'namespace mit umlaut' ) ;
xpath_test ( get_page ( 'action=rc' ) ,
2010-04-21 21:20:23 +00:00
# the exact result depends on filesystem encoding!
2016-08-11 15:29:41 +02:00
'//a[@class="local"][@href="http://localhost/wiki.pl/Z%c3%bcrich/%c3%9cmlaute"]' ) ;
# And using path_info
test_page ( get_page ( '/Zürich/Ümlaute?' ) ,
'namespace mit umlaut' ) ;
2012-07-19 13:58:58 +02:00
2009-03-08 23:43:34 +00:00
# Test rollbacks
test_page ( get_page ( 'action=browse ns=Muu id=Test' ) ,
'Another Mooo!' ) ;
# find first (and only rollback link) for Muu/Test
$ to = xpath_test ( get_page ( 'action=history id=Test ns=Muu username=Alex' ) ,
'//input[@value="rollback"]/attribute::name' ) ;
$ to =~ /rollback-([0-9]+)/ ;
$ to = $ 1 ;
ok ( $ to > 0 , 'found rollback link for Muu/Test' ) ;
2012-03-17 19:33:21 +00:00
2009-03-08 23:43:34 +00:00
# do the rollback
test_page ( get_page ( "action=rollback ns=Muu id=Test to=$to username=Alex" ) ,
'Rolling back changes' , 'Test</a> rolled back' ) ;
$ page = get_page ( 'action=browse ns=Muu id=Test' ) ;
test_page_negative ( $ page , 'Another Mooo!' ) ;
test_page ( $ page , 'Mooo!' ) ;
2012-03-17 19:33:21 +00:00
# verify feed
test_page ( get_page ( 'action=rc ns=Muu raw=1' ) ,
'title: Wiki Muu' , 'title: Test' , 'title: BackHome' ) ;
# now roll back all the pages in the namespace
update_page ( 'Test' , 'spam spam spam' , 'spam' , undef , undef , 'ns=Muu' ) ;
# test it with path_info instead of ns parameter
test_page ( get_page ( "'/Muu?rollback-$to=rollback' 'username=Alex' 'pwd=foo'" ) ,
'Rolling back changes' , 'Test</a> rolled back' ) ;
$ page = get_page ( 'action=browse ns=Muu id=Test' ) ;
test_page_negative ( $ page , 'spam' ) ;
test_page ( $ page , 'Mooo!' ) ;
2009-03-08 23:43:34 +00:00
# verify that local RecentChanges doesn't show anything
test_page_negative ( get_page ( 'action=rc ns=Muu raw=1' ) , 'Rollback' ) ;
# verify that global RecentChanges doesn't show anything
test_page_negative ( get_page ( 'action=rc raw=1' ) , 'Rollback' ) ;
2009-07-03 13:59:50 +00:00
# test oldrc.log reading
ok ( rename ( "$DataDir/Muu/rc.log" , "$DataDir/Muu/oldrc.log" ) ,
"renamed $RcFile to $RcOldFile in the Muu namespace" ) ;
2012-03-17 19:33:21 +00:00
# verify the feed
my $ feed = get_page ( 'action=rc ns=Muu raw=1' ) ;
test_page ( $ feed , 'title: Wiki Muu' , 'title: Test' ) ;
# this page was now rolled back out of existence
test_page_negative ( $ feed , 'title: BackHome' ) ;
# check the entire wiki, too
$ feed = get_page ( 'action=rc raw=1' ) ;
test_page ( $ feed , 'title: Wiki' , 'title: Muu:Test' ) ;
# BackHome never existed and Muu:BackHome was rolled back
test_page_negative ( $ feed , 'title: Muu:BackHome' , 'title: BackHome' ) ;