From b176b5b8acd5559789c78925954e17f867f4cd05 Mon Sep 17 00:00:00 2001 From: umherirrender Date: Fri, 10 Jan 2014 21:40:25 +0100 Subject: [PATCH] Add title tests about interwiki prefix Also test $wgLocalInterwiki. The js part does not respect interwikis, so there is no need to add tests for that. Change-Id: I407355295b65bc67eb171da435c1505797569d3e --- tests/phpunit/includes/TitleTest.php | 33 ++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/tests/phpunit/includes/TitleTest.php b/tests/phpunit/includes/TitleTest.php index 54e61998b2..078dfefdf4 100644 --- a/tests/phpunit/includes/TitleTest.php +++ b/tests/phpunit/includes/TitleTest.php @@ -40,6 +40,21 @@ class TitleTest extends MediaWikiTestCase { * @todo This method should be split into 2 separate tests each with a provider */ public function testSecureAndSplit() { + $this->setMwGlobals( array( + 'wgLocalInterwiki' => 'localtestiw', + 'wgHooks' => array( + 'InterwikiLoadPrefix' => array( + function ( $prefix, &$data ) { + if ( $prefix === 'localtestiw' ) { + $data = array( 'iw_url' => 'localtestiw' ); + } elseif ( $prefix === 'remotetestiw' ) { + $data = array( 'iw_url' => 'remotetestiw' ); + } + return false; + } + ) + ) + )); // Valid foreach ( array( 'Sandbox', @@ -58,7 +73,17 @@ class TitleTest extends MediaWikiTestCase { 'A~~', // Length is 256 total, but only title part matters 'Category:' . str_repeat( 'x', 248 ), - str_repeat( 'x', 252 ) + str_repeat( 'x', 252 ), + // interwiki prefix + 'localtestiw: #anchor', + 'localtestiw:foo', + 'localtestiw: foo # anchor', + 'localtestiw: Talk: Sandbox # anchor', + 'remotetestiw:', + 'remotetestiw: Talk: # anchor', + 'remotetestiw: #bar', + 'remotetestiw: Talk:', + 'remotetestiw: Talk: Foo' ) as $text ) { $this->assertInstanceOf( 'Title', Title::newFromText( $text ), "Valid: $text" ); } @@ -106,7 +131,11 @@ class TitleTest extends MediaWikiTestCase { // Namespace prefix without actual title 'Talk:', 'Category: ', - 'Category: #bar' + 'Category: #bar', + // interwiki prefix + 'localtestiw:', + 'localtestiw: Talk: # anchor', + 'localtestiw: Talk:' ) as $text ) { $this->assertNull( Title::newFromText( $text ), "Invalid: $text" ); } -- 2.20.1