MediaWiki  master
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  $this->setContentLang( 'en' );
31 
32  $interwikiLookupMock = $this->getMockBuilder( InterwikiLookup::class )
33  ->getMock();
34 
35  $interwikiValueMap = [
36  [ 'valid', true ],
37  [ 'invalid', false ]
38  ];
39  $interwikiLookupMock->expects( $this->any() )
40  ->method( 'isValidInterwiki' )
41  ->will( $this->returnValueMap( $interwikiValueMap ) );
42 
43  $this->setService( 'InterwikiLookup', $interwikiLookupMock );
44 
45  $this->assertEquals(
46  $expected,
48  );
49  }
50 
51  public function provideApplyPrefix() {
52  return [
53  [ 'User1', 'prefix', 'prefix>User1' ],
54  [ 'User1', 'prefix:>', 'prefix>User1' ],
55  [ 'User1', 'prefix:', 'prefix>User1' ],
56  ];
57  }
58 
63  public function testApplyPrefix( $username, $prefix, $expected ) {
64  $externalUserNames = new ExternalUserNames( $prefix, true );
65 
66  $this->assertSame(
67  $expected,
68  $externalUserNames->applyPrefix( $username )
69  );
70  }
71 
72  public function provideAddPrefix() {
73  return [
74  [ 'User1', 'prefix', 'prefix>User1' ],
75  [ 'User2', 'prefix2', 'prefix2>User2' ],
76  [ 'User3', 'prefix3', 'prefix3>User3' ],
77  ];
78  }
79 
84  public function testAddPrefix( $username, $prefix, $expected ) {
85  $externalUserNames = new ExternalUserNames( $prefix, true );
86 
87  $this->assertSame(
88  $expected,
89  $externalUserNames->addPrefix( $username )
90  );
91  }
92 
93  public function provideIsExternal() {
94  return [
95  [ 'User1', false ],
96  [ '>User1', true ],
97  [ 'prefix>User1', true ],
98  [ 'prefix:>User1', true ],
99  ];
100  }
101 
106  public function testIsExternal( $username, $expected ) {
107  $this->assertSame(
108  $expected,
110  );
111  }
112 
113  public function provideGetLocal() {
114  return [
115  [ 'User1', 'User1' ],
116  [ '>User2', 'User2' ],
117  [ 'prefix>User3', 'User3' ],
118  [ 'prefix:>User4', 'User4' ],
119  ];
120  }
121 
126  public function testGetLocal( $username, $expected ) {
127  $this->assertSame(
128  $expected,
130  );
131  }
132 
133 }
const NS_MAIN
Definition: Defines.php:60
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:187
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
testAddPrefix( $username, $prefix, $expected)
ExternalUserNames::addPrefix provideAddPrefix.
const NS_SPECIAL
Definition: Defines.php:49
testGetUserLinkTitle( $username, $expected)
ExternalUserNames::getUserLinkTitle provideGetUserLinkTitle.
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:1982
testApplyPrefix( $username, $prefix, $expected)
ExternalUserNames::applyPrefix provideApplyPrefix.
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not null
Definition: hooks.txt:780
static getUserLinkTitle( $userName)
Get a target Title to link a username.
setService( $name, $object)
Sets a service, maintaining a stashed version of the previous service to be restored in tearDown...
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:589
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:35
this hook is for auditing only or null if authentication failed before getting that far $username
Definition: hooks.txt:780
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:52
testIsExternal( $username, $expected)
ExternalUserNames::isExternal provideIsExternal.
Class to parse and build external user names.
testGetLocal( $username, $expected)
ExternalUserNames::getLocal provideGetLocal.
static getLocal( $username)
Get local part of the user name.
static isExternal( $username)
Tells whether the username is external or not.