1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
<?php
namespace MediaWiki\Tests\Parser;
use CoreParserFunctions;
use MediaWiki\Language\RawMessage;
use MediaWiki\User\User;
use MediaWikiLangTestCase;
/**
* @group Database
* @covers \CoreParserFunctions
*/
class CoreParserFunctionsTest extends MediaWikiLangTestCase {
public function testGender() {
$userOptionsManager = $this->getServiceContainer()->getUserOptionsManager();
$username = 'Female*';
$user = User::createNew( $username );
$userOptionsManager->setOption( $user, 'gender', 'female' );
$user->saveSettings();
$msg = ( new RawMessage( '{{GENDER:' . $username . '|m|f|o}}' ) )->parse();
$this->assertEquals( 'f', $msg, 'Works unescaped' );
$escapedName = wfEscapeWikiText( $username );
$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 ) );
}
}
|