wiki.techinc.nl/tests/phpunit/includes/parser/CoreParserFunctionsTest.php
Tim Starling 5e30a927bc tests: Make some PHPUnit data providers static
Just methods where adding "static" to the declaration was enough, I
didn't do anything with providers that used $this.

Initially by search and replace. There were many mistakes which I
found mostly by running the PHPStorm inspection which searches for
$this usage in a static method. Later I used the PHPStorm "make static"
action which avoids the more obvious mistakes.

Bug: T332865
Change-Id: I47ed6692945607dfa5c139d42edbd934fa4f3a36
2023-03-24 02:53:57 +00:00

78 lines
2.1 KiB
PHP

<?php
use MediaWiki\Language\RawMessage;
/**
* @group Database
* @covers CoreParserFunctions
*/
class CoreParserFunctionsTest extends MediaWikiLangTestCase {
public function testGender() {
$userOptionsManager = $this->getServiceContainer()->getUserOptionsManager();
$user = User::createNew( '*Female' );
$userOptionsManager->setOption( $user, 'gender', 'female' );
$user->saveSettings();
$msg = ( new RawMessage( '{{GENDER:*Female|m|f|o}}' ) )->parse();
$this->assertEquals( 'f', $msg, 'Works unescaped' );
$escapedName = wfEscapeWikiText( '*Female' );
$msg2 = ( new RawMessage( '{{GENDER:' . $escapedName . '|m|f|o}}' ) )
->parse();
$this->assertEquals( 'f', $msg2, 'Works escaped' );
}
public static function provideTalkpagename() {
yield [ 'Talk:Foo bar', 'foo_bar' ];
yield [ 'Talk:Foo', ' foo ' ];
yield [ 'Talk:Foo', 'Talk:Foo' ];
yield [ 'User talk:Foo', 'User:foo' ];
yield [ '', 'Special:Foo' ];
yield [ '', '' ];
yield [ '', ' ' ];
yield [ '', '__' ];
yield [ '', '#xyzzy' ];
yield [ '', '#' ];
yield [ '', ':' ];
yield [ '', ':#' ];
yield [ '', 'User:' ];
yield [ '', 'User:#' ];
}
/**
* @dataProvider provideTalkpagename
*/
public function testTalkpagename( $expected, $title ) {
$parser = $this->getServiceContainer()->getParser();
$this->assertSame( $expected, CoreParserFunctions::talkpagename( $parser, $title ) );
}
public static function provideSubjectpagename() {
yield [ 'Foo bar', 'Talk:foo_bar' ];
yield [ 'Foo', ' Talk:foo ' ];
yield [ 'User:Foo', 'User talk:foo' ];
yield [ 'Special:Foo', 'Special:Foo' ];
yield [ '', '' ];
yield [ '', ' ' ];
yield [ '', '__' ];
yield [ '', '#xyzzy' ];
yield [ '', '#' ];
yield [ '', ':' ];
yield [ '', ':#' ];
yield [ '', 'Talk:' ];
yield [ '', 'User talk:#' ];
yield [ '', 'User:#' ];
}
/**
* @dataProvider provideSubjectpagename
*/
public function testSubjectpagename( $expected, $title ) {
$parser = $this->getServiceContainer()->getParser();
$this->assertSame( $expected, CoreParserFunctions::subjectpagename( $parser, $title ) );
}
}