3 namespace MediaWiki\Tests\Parser
;
5 use MediaWiki\Language\RawMessage
;
6 use MediaWiki\Parser\CoreParserFunctions
;
7 use MediaWiki\User\User
;
8 use MediaWikiLangTestCase
;
12 * @covers \MediaWiki\Parser\CoreParserFunctions
14 class CoreParserFunctionsTest
extends MediaWikiLangTestCase
{
16 public function testGender() {
17 $userOptionsManager = $this->getServiceContainer()->getUserOptionsManager();
19 $username = 'Female*';
20 $user = User
::createNew( $username );
21 $userOptionsManager->setOption( $user, 'gender', 'female' );
22 $user->saveSettings();
24 $msg = ( new RawMessage( '{{GENDER:' . $username . '|m|f|o}}' ) )->parse();
25 $this->assertEquals( 'f', $msg, 'Works unescaped' );
26 $escapedName = wfEscapeWikiText( $username );
27 $msg2 = ( new RawMessage( '{{GENDER:' . $escapedName . '|m|f|o}}' ) )
29 $this->assertEquals( 'f', $msg2, 'Works escaped' );
32 public static function provideTalkpagename() {
33 yield
[ 'Talk:Foo bar', 'foo_bar' ];
34 yield
[ 'Talk:Foo', ' foo ' ];
35 yield
[ 'Talk:Foo', 'Talk:Foo' ];
36 yield
[ 'User talk:Foo', 'User:foo' ];
37 yield
[ '', 'Special:Foo' ];
41 yield
[ '', '#xyzzy' ];
45 yield
[ '', 'User:' ];
46 yield
[ '', 'User:#' ];
50 * @dataProvider provideTalkpagename
52 public function testTalkpagename( $expected, $title ) {
53 $parser = $this->getServiceContainer()->getParser();
55 $this->assertSame( $expected, CoreParserFunctions
::talkpagename( $parser, $title ) );
58 public static function provideSubjectpagename() {
59 yield
[ 'Foo bar', 'Talk:foo_bar' ];
60 yield
[ 'Foo', ' Talk:foo ' ];
61 yield
[ 'User:Foo', 'User talk:foo' ];
62 yield
[ 'Special:Foo', 'Special:Foo' ];
66 yield
[ '', '#xyzzy' ];
70 yield
[ '', 'Talk:' ];
71 yield
[ '', 'User talk:#' ];
72 yield
[ '', 'User:#' ];
76 * @dataProvider provideSubjectpagename
78 public function testSubjectpagename( $expected, $title ) {
79 $parser = $this->getServiceContainer()->getParser();
81 $this->assertSame( $expected, CoreParserFunctions
::subjectpagename( $parser, $title ) );