Merge "Type hint against LinkTarget in WatchedItemStore"
[lhc/web/wiklou.git] / tests / phpunit / includes / parser / CoreParserFunctionsTest.php
1 <?php
2 use MediaWiki\MediaWikiServices;
3
4 /**
5 * @group Database
6 * @covers CoreParserFunctions
7 */
8 class CoreParserFunctionsTest extends MediaWikiLangTestCase {
9
10 public function testGender() {
11 $user = User::createNew( '*Female' );
12 $user->setOption( 'gender', 'female' );
13 $user->saveSettings();
14
15 $msg = ( new RawMessage( '{{GENDER:*Female|m|f|o}}' ) )->parse();
16 $this->assertEquals( $msg, 'f', 'Works unescaped' );
17 $escapedName = wfEscapeWikiText( '*Female' );
18 $msg2 = ( new RawMessage( '{{GENDER:' . $escapedName . '|m|f|o}}' ) )
19 ->parse();
20 $this->assertEquals( $msg, 'f', 'Works escaped' );
21 }
22
23 public function provideTalkpagename() {
24 yield [ 'Talk:Foo bar', 'foo_bar' ];
25 yield [ 'Talk:Foo', ' foo ' ];
26 yield [ 'Talk:Foo', 'Talk:Foo' ];
27 yield [ 'User talk:Foo', 'User:foo' ];
28 yield [ '', 'Special:Foo' ];
29 yield [ '', '' ];
30 yield [ '', ' ' ];
31 yield [ '', '__' ];
32 yield [ '', '#xyzzy' ];
33 yield [ '', '#' ];
34 yield [ '', ':' ];
35 yield [ '', ':#' ];
36 yield [ '', 'User:' ];
37 yield [ '', 'User:#' ];
38 }
39
40 /**
41 * @dataProvider provideTalkpagename
42 */
43 public function testTalkpagename( $expected, $title ) {
44 $parser = MediaWikiServices::getInstance()->getParser();
45
46 $this->assertSame( $expected, CoreParserFunctions::talkpagename( $parser, $title ) );
47 }
48
49 public function provideSubjectpagename() {
50 yield [ 'Foo bar', 'Talk:foo_bar' ];
51 yield [ 'Foo', ' Talk:foo ' ];
52 yield [ 'User:Foo', 'User talk:foo' ];
53 yield [ 'Special:Foo', 'Special:Foo' ];
54 yield [ '', '' ];
55 yield [ '', ' ' ];
56 yield [ '', '__' ];
57 yield [ '', '#xyzzy' ];
58 yield [ '', '#' ];
59 yield [ '', ':' ];
60 yield [ '', ':#' ];
61 yield [ '', 'Talk:' ];
62 yield [ '', 'User talk:#' ];
63 yield [ '', 'User:#' ];
64 }
65
66 /**
67 * @dataProvider provideTalkpagename
68 */
69 public function testSubjectpagename( $expected, $title ) {
70 $parser = MediaWikiServices::getInstance()->getParser();
71
72 $this->assertSame( $expected, CoreParserFunctions::talkpagename( $parser, $title ) );
73 }
74
75 }