Debian Codegraph @

tests/phpunit/includes/parser/CoreParserFunctionsTest.php

raw symbols SCIP
1 <?php
2
3 namespace MediaWiki\Tests\Parser;
4
5 use MediaWiki\Language\RawMessage;
6 use MediaWiki\Parser\CoreParserFunctions;
7 use MediaWiki\User\User;
8 use MediaWikiLangTestCase;
9
10 /**
11 * @group Database
12 * @covers \MediaWiki\Parser\CoreParserFunctions
13 */
14 class CoreParserFunctionsTest extends MediaWikiLangTestCase {
15
16 public function testGender() {
17 $userOptionsManager = $this->getServiceContainer()->getUserOptionsManager();
18
19 $username = 'Female*';
20 $user = User::createNew( $username );
21 $userOptionsManager->setOption( $user, 'gender', 'female' );
22 $user->saveSettings();
23
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' );
30 }
31
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:#' ];
47 }
48
49 /**
50 * @dataProvider provideTalkpagename
51 */
52 public function testTalkpagename( $expected, $title ) {
53 $parser = $this->getServiceContainer()->getParser();
54
55 $this->assertSame( $expected, CoreParserFunctions::talkpagename( $parser, $title ) );
56 }
57
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:#' ];
73 }
74
75 /**
76 * @dataProvider provideSubjectpagename
77 */
78 public function testSubjectpagename( $expected, $title ) {
79 $parser = $this->getServiceContainer()->getParser();
80
81 $this->assertSame( $expected, CoreParserFunctions::subjectpagename( $parser, $title ) );
82 }
83
84 }