Merge "chore: Move authevents logging into AuthManager"
[mediawiki.git] / tests / phpunit / includes / parser / CoreParserFunctionsTest.php
blob0338d4432104475b7655aca2414b4eb2707423f2
1 <?php
3 namespace MediaWiki\Tests\Parser;
5 use MediaWiki\Language\RawMessage;
6 use MediaWiki\Parser\CoreParserFunctions;
7 use MediaWiki\User\User;
8 use MediaWikiLangTestCase;
10 /**
11 * @group Database
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}}' ) )
28 ->parse();
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' ];
38 yield [ '', '' ];
39 yield [ '', ' ' ];
40 yield [ '', '__' ];
41 yield [ '', '#xyzzy' ];
42 yield [ '', '#' ];
43 yield [ '', ':' ];
44 yield [ '', ':#' ];
45 yield [ '', 'User:' ];
46 yield [ '', 'User:#' ];
49 /**
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' ];
63 yield [ '', '' ];
64 yield [ '', ' ' ];
65 yield [ '', '__' ];
66 yield [ '', '#xyzzy' ];
67 yield [ '', '#' ];
68 yield [ '', ':' ];
69 yield [ '', ':#' ];
70 yield [ '', 'Talk:' ];
71 yield [ '', 'User talk:#' ];
72 yield [ '', 'User:#' ];
75 /**
76 * @dataProvider provideSubjectpagename
78 public function testSubjectpagename( $expected, $title ) {
79 $parser = $this->getServiceContainer()->getParser();
81 $this->assertSame( $expected, CoreParserFunctions::subjectpagename( $parser, $title ) );