wiki.techinc.nl/tests/phpunit/includes/TitleTest.php
Antoine Musso efd83c55fc merge in prettyURL patch
This is basicly a merge of r84386 & r84491, see their commit messages for
more details.

r84386 makes wikilinks nicer by updating the URL forge implemented by r2621
r84491 fix an issue with the (un)?watch links. getParamValue should not be
used to guess 'title' or 'action'
2011-05-13 11:41:17 +00:00

122 lines
3.8 KiB
PHP
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
class TitleTest extends MediaWikiTestCase {
function testLegalChars() {
$titlechars = Title::legalChars();
foreach ( range( 1, 255 ) as $num ) {
$chr = chr( $num );
if ( strpos( "#[]{}<>|", $chr ) !== false || preg_match( "/[\\x00-\\x1f\\x7f]/", $chr ) ) {
$this->assertFalse( (bool)preg_match( "/[$titlechars]/", $chr ), "chr($num) = $chr is not a valid titlechar" );
} else {
$this->assertTrue( (bool)preg_match( "/[$titlechars]/", $chr ), "chr($num) = $chr is a valid titlechar" );
}
}
}
/**
* Helper to test getLocalURL
*
* @cover Title:getLocalURL
*/
function assertGetLocalURL( $expected, $dbkey, $query, $articlepath, $actionpaths = array(), $variant = false )
{
global $wgArticlePath;
$wgArticlePath = $articlepath;
global $wgActionPaths;
$wgActionPaths = $actionpaths;
$t = Title::newFromDBKey( $dbkey );
$this->assertEquals( $expected, $t->getLocalURL( $query, $variant ) );
}
/**
* @dataProvider provider1
* @cover Title:getLocalURL
*/
function testGetLocalUrl( $expected, $dbkey, $query )
{
$this->assertGetLocalURL( $expected, $dbkey, $query, '/wiki/$1' );
}
function provider1()
{
return array(
array( '/wiki/Recentchanges', 'Recentchanges', '' ),
array( '/wiki/Recentchanges?foo=2', 'Recentchanges', 'foo=2' ),
array( '/wiki/Recentchanges?foo=A&bar=1', 'Recentchanges', 'foo=A&bar=1' ),
);
}
/**
* @dataProvider provider2
* @cover Title:getLocalURL
*/
function testGetLocalUrlWithArticlePath( $expected, $dbkey, $query, $actions )
{
$this->assertGetLocalURL( $expected, $dbkey, $query, '/wiki/view/$1', $actions );
}
function provider2()
{
return array(
array( '/wiki/view/Recentchanges', 'Recentchanges', '', array( ) ),
array( '/wiki/view/Recentchanges', 'Recentchanges', '', array( 'view' => 'OH MEN' ) ),
array( '/wiki/view/Recentchanges', 'Recentchanges', '', array( 'view' => '/wiki/view/$1' ) ),
array( '/wiki/view/Recentchanges?foo=2', 'Recentchanges', 'foo=2', array( 'view' => '/wiki/view/$1' ) ),
array( '/wiki/view/Recentchanges?foo=A&bar=1', 'Recentchanges', 'foo=A&bar=1', array() ),
);
}
/**
* @dataProvider provider3
* @cover Title:getLocalURL
*/
function testGetLocalUrlWithActionPaths( $expected, $dbkey, $query )
{
$actions = array( 'edit' => '/wiki/edit/$1' );
$this->assertGetLocalURL( $expected, $dbkey, $query, '/wiki/view/$1', $actions );
}
function provider3() {
return array(
array( '/wiki/view/Recentchanges', 'Recentchanges', ''),
array( '/wiki/edit/Recentchanges', 'Recentchanges', 'action=edit' ),
array( '/wiki/edit/Recentchanges?foo=2', 'Recentchanges', 'action=edit&foo=2' ),
array( '/wiki/edit/Recentchanges?foo=2', 'Recentchanges', 'foo=2&action=edit' ),
array( '/wiki/view/Recentchanges?foo=A&bar=1', 'Recentchanges', 'foo=A&bar=1' ),
array( '/wiki/edit/Recentchanges?foo=A&bar=1', 'Recentchanges', 'foo=A&bar=1&action=edit' ),
array( '/wiki/edit/Recentchanges?foo=A&bar=1', 'Recentchanges', 'foo=A&action=edit&bar=1' ),
array( '/wiki/edit/Recentchanges?foo=A&bar=1', 'Recentchanges', 'action=edit&foo=A&bar=1' ),
# FIXME The next two are equals but need investigation:
array( '/wiki/edit/Recentchanges', 'Recentchanges', 'action=view&action=edit' ),
array( '/wiki/view/Recentchanges?action=edit&action=view', 'Recentchanges', 'action=edit&action=view' ),
);
}
/**
* @dataProvider provider4
* @cover Title:getLocalURL
*/
function testGetLocalUrlWithVariantArticlePaths( $expected, $dbkey, $query )
{
# FIXME find a language with variants!
$this->markTestIncomplete();
$actions = array( 'edit' => '/wiki/edit/$1' );
$this->assertGetLocalURL( $expected, $dbkey, $query, '/wiki/view/$1', array(), '/$2/$1' );
}
function provider4() {
return array(
array( '/wiki/view/Recentchanges', 'Recentchanges', '', ),
);
}
}