MediaWiki REL1_31
ExternalUserNamesTest.php
Go to the documentation of this file.
1<?php
2
4
9
10 public function provideGetUserLinkTitle() {
11 return [
12 [ 'valid:>User1', Title::makeTitle( NS_MAIN, ':User:User1', '', 'valid' ) ],
13 [
14 'valid:valid:>User1',
15 Title::makeTitle( NS_MAIN, 'valid::User:User1', '', 'valid' )
16 ],
17 [
18 '127.0.0.1',
19 Title::makeTitle( NS_SPECIAL, 'Contributions/127.0.0.1', '', '' )
20 ],
21 [ 'invalid:>User1', null ]
22 ];
23 }
24
29 public function testGetUserLinkTitle( $username, $expected ) {
30 $interwikiLookupMock = $this->getMockBuilder( InterwikiLookup::class )
31 ->getMock();
32
33 $interwikiValueMap = [
34 [ 'valid', true ],
35 [ 'invalid', false ]
36 ];
37 $interwikiLookupMock->expects( $this->any() )
38 ->method( 'isValidInterwiki' )
39 ->will( $this->returnValueMap( $interwikiValueMap ) );
40
41 $this->setService( 'InterwikiLookup', $interwikiLookupMock );
42
43 $this->assertEquals(
44 $expected,
46 );
47 }
48
49 public function provideApplyPrefix() {
50 return [
51 [ 'User1', 'prefix', 'prefix>User1' ],
52 [ 'User1', 'prefix:>', 'prefix>User1' ],
53 [ 'User1', 'prefix:', 'prefix>User1' ],
54 ];
55 }
56
61 public function testApplyPrefix( $username, $prefix, $expected ) {
62 $externalUserNames = new ExternalUserNames( $prefix, true );
63
64 $this->assertSame(
65 $expected,
66 $externalUserNames->applyPrefix( $username )
67 );
68 }
69
70 public function provideAddPrefix() {
71 return [
72 [ 'User1', 'prefix', 'prefix>User1' ],
73 [ 'User2', 'prefix2', 'prefix2>User2' ],
74 [ 'User3', 'prefix3', 'prefix3>User3' ],
75 ];
76 }
77
82 public function testAddPrefix( $username, $prefix, $expected ) {
83 $externalUserNames = new ExternalUserNames( $prefix, true );
84
85 $this->assertSame(
86 $expected,
87 $externalUserNames->addPrefix( $username )
88 );
89 }
90
91 public function provideIsExternal() {
92 return [
93 [ 'User1', false ],
94 [ '>User1', true ],
95 [ 'prefix>User1', true ],
96 [ 'prefix:>User1', true ],
97 ];
98 }
99
104 public function testIsExternal( $username, $expected ) {
105 $this->assertSame(
106 $expected,
108 );
109 }
110
111 public function provideGetLocal() {
112 return [
113 [ 'User1', 'User1' ],
114 [ '>User2', 'User2' ],
115 [ 'prefix>User3', 'User3' ],
116 [ 'prefix:>User4', 'User4' ],
117 ];
118 }
119
124 public function testGetLocal( $username, $expected ) {
125 $this->assertSame(
126 $expected,
128 );
129 }
130
131}
they could even be mouse clicks or menu items whatever suits your program You should also get your if any
Definition COPYING.txt:326
testGetUserLinkTitle( $username, $expected)
ExternalUserNames::getUserLinkTitle provideGetUserLinkTitle.
testGetLocal( $username, $expected)
ExternalUserNames::getLocal provideGetLocal.
testApplyPrefix( $username, $prefix, $expected)
ExternalUserNames::applyPrefix provideApplyPrefix.
testIsExternal( $username, $expected)
ExternalUserNames::isExternal provideIsExternal.
testAddPrefix( $username, $prefix, $expected)
ExternalUserNames::addPrefix provideAddPrefix.
Class to parse and build external user names.
static getUserLinkTitle( $userName)
Get a target Title to link a username.
static isExternal( $username)
Tells whether the username is external or not.
static getLocal( $username)
Get local part of the user name.
setService( $name, $object)
Sets a service, maintaining a stashed version of the previous service to be restored in tearDown.
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return true
Definition hooks.txt:2006
this hook is for auditing only or null if authentication failed before getting that far $username
Definition hooks.txt:785
processing should stop and the error should be shown to the user * false
Definition hooks.txt:187
const NS_MAIN
Definition Defines.php:74
const NS_SPECIAL
Definition Defines.php:63
Service interface for looking up Interwiki records.