setMwGlobals( array(
'wgContLang' => Language::factory( 'en' ),
) );
}
/**
* Returns a mock GenderCache that will return "female" always.
*
* @return GenderCache
*/
private function getGenderCache() {
$genderCache = $this->getMockBuilder( 'GenderCache' )
->disableOriginalConstructor()
->getMock();
$genderCache->expects( $this->any() )
->method( 'getGenderOf' )
->will( $this->returnValue( 'female' ) );
return $genderCache;
}
public static function provideGetPageUrl() {
return array(
array(
new TitleValue( NS_MAIN, 'Foo_Bar' ),
array(),
'/Foo_Bar'
),
array(
new TitleValue( NS_USER, 'Hansi_Maier', 'stuff' ),
array( 'foo' => 'bar' ),
'/User:Hansi_Maier?foo=bar#stuff'
),
);
}
/**
* @dataProvider provideGetPageUrl
*/
public function testGetPageUrl( TitleValue $title, $params, $url ) {
// NOTE: was of Feb 2014, MediaWikiPageLinkRenderer *ignores* the
// WikitextTitleFormatter we pass here, and relies on the Linker
// class for generating the link! This may break the test e.g.
// of Linker uses a different language for the namespace names.
$lang = Language::factory( 'en' );
$formatter = new MediaWikiTitleCodec( $lang, $this->getGenderCache() );
$renderer = new MediaWikiPageLinkRenderer( $formatter, '/' );
$actual = $renderer->getPageUrl( $title, $params );
$this->assertEquals( $url, $actual );
}
public static function provideRenderHtmlLink() {
return array(
array(
new TitleValue( NS_MAIN, 'Foo_Bar' ),
'Foo Bar',
'!Foo Bar!'
),
array(
//NOTE: Linker doesn't include fragments in "broken" links
//NOTE: once this no longer uses Linker, we will get "2" instead of "User" for the namespace.
new TitleValue( NS_USER, 'Hansi_Maier', 'stuff' ),
'Hansi Maier\'s Stuff',
'!Hansi Maier\'s Stuff!'
),
array(
//NOTE: Linker doesn't include fragments in "broken" links
//NOTE: once this no longer uses Linker, we will get "2" instead of "User" for the namespace.
new TitleValue( NS_USER, 'Hansi_Maier', 'stuff' ),
null,
'!User:Hansi Maier#stuff!'
),
);
}
/**
* @dataProvider provideRenderHtmlLink
*/
public function testRenderHtmlLink( TitleValue $title, $text, $pattern ) {
// NOTE: was of Feb 2014, MediaWikiPageLinkRenderer *ignores* the
// WikitextTitleFormatter we pass here, and relies on the Linker
// class for generating the link! This may break the test e.g.
// of Linker uses a different language for the namespace names.
$lang = Language::factory( 'en' );
$formatter = new MediaWikiTitleCodec( $lang, $this->getGenderCache() );
$renderer = new MediaWikiPageLinkRenderer( $formatter );
$actual = $renderer->renderHtmlLink( $title, $text );
$this->assertRegExp( $pattern, $actual );
}
public static function provideRenderWikitextLink() {
return array(
array(
new TitleValue( NS_MAIN, 'Foo_Bar' ),
'Foo Bar',
'[[:0:Foo Bar|Foo Bar]]'
),
array(
new TitleValue( NS_USER, 'Hansi_Maier', 'stuff' ),
'Hansi Maier\'s Stuff',
'[[:2:Hansi Maier#stuff|Hansi Maier's Stuff]]'
),
array(
new TitleValue( NS_USER, 'Hansi_Maier', 'stuff' ),
null,
'[[:2:Hansi Maier#stuff|2:Hansi Maier#stuff]]'
),
);
}
/**
* @dataProvider provideRenderWikitextLink
*/
public function testRenderWikitextLink( TitleValue $title, $text, $expected ) {
$formatter = $this->getMock( 'TitleFormatter' );
$formatter->expects( $this->any() )
->method( 'getFullText' )
->will( $this->returnCallback(
function ( TitleValue $title ) {
return str_replace( '_', ' ', "$title" );
}
));
$renderer = new MediaWikiPageLinkRenderer( $formatter, '/' );
$actual = $renderer->renderWikitextLink( $title, $text );
$this->assertEquals( $expected, $actual );
}
}