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 }
ExternalUserNames\getLocal
static getLocal( $username)
Get local part of the user name.
Definition: ExternalUserNames.php:125
ExternalUserNamesTest
ExternalUserNames.
Definition: ExternalUserNamesTest.php:8
use
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
Definition: APACHE-LICENSE-2.0.txt:10
ExternalUserNamesTest\testApplyPrefix
testApplyPrefix( $username, $prefix, $expected)
ExternalUserNames::applyPrefix provideApplyPrefix.
Definition: ExternalUserNamesTest.php:61
ExternalUserNamesTest\provideIsExternal
provideIsExternal()
Definition: ExternalUserNamesTest.php:91
ExternalUserNames
Class to parse and build external user names.
Definition: ExternalUserNames.php:29
true
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
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:37
ExternalUserNamesTest\testAddPrefix
testAddPrefix( $username, $prefix, $expected)
ExternalUserNames::addPrefix provideAddPrefix.
Definition: ExternalUserNamesTest.php:82
ExternalUserNamesTest\provideAddPrefix
provideAddPrefix()
Definition: ExternalUserNamesTest.php:70
NS_MAIN
const NS_MAIN
Definition: Defines.php:74
NS_SPECIAL
const NS_SPECIAL
Definition: Defines.php:63
ExternalUserNamesTest\provideGetLocal
provideGetLocal()
Definition: ExternalUserNamesTest.php:111
MediaWikiTestCase
Definition: MediaWikiTestCase.php:17
MediaWiki\Interwiki\InterwikiLookup
Service interface for looking up Interwiki records.
Definition: InterwikiLookup.php:31
Title\makeTitle
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:534
ExternalUserNames\getUserLinkTitle
static getUserLinkTitle( $userName)
Get a target Title to link a username.
Definition: ExternalUserNames.php:50
ExternalUserNamesTest\testGetLocal
testGetLocal( $username, $expected)
ExternalUserNames::getLocal provideGetLocal.
Definition: ExternalUserNamesTest.php:124
ExternalUserNamesTest\testIsExternal
testIsExternal( $username, $expected)
ExternalUserNames::isExternal provideIsExternal.
Definition: ExternalUserNamesTest.php:104
ExternalUserNamesTest\testGetUserLinkTitle
testGetUserLinkTitle( $username, $expected)
ExternalUserNames::getUserLinkTitle provideGetUserLinkTitle.
Definition: ExternalUserNamesTest.php:29
ExternalUserNamesTest\provideGetUserLinkTitle
provideGetUserLinkTitle()
Definition: ExternalUserNamesTest.php:10
$username
this hook is for auditing only or null if authentication failed before getting that far $username
Definition: hooks.txt:785
ExternalUserNamesTest\provideApplyPrefix
provideApplyPrefix()
Definition: ExternalUserNamesTest.php:49
class
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:56
MediaWikiTestCase\setService
setService( $name, $object)
Sets a service, maintaining a stashed version of the previous service to be restored in tearDown.
Definition: MediaWikiTestCase.php:628
ExternalUserNames\isExternal
static isExternal( $username)
Tells whether the username is external or not.
Definition: ExternalUserNames.php:115
false
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:187