3 use Wikimedia\TestingAccessWrapper;
12 $mock = $this->getMockForAbstractClass(
'CentralIdLookup' );
15 'wgCentralIdLookupProviders' => [
16 'local' => [
'class' =>
'LocalIdLookup' ],
17 'local2' => [
'class' =>
'LocalIdLookup' ],
18 'mock' => [
'factory' =>
function ()
use ( $mock ) {
21 'bad' => [
'class' =>
'stdClass' ],
23 'wgCentralIdLookupProvider' =>
'mock',
28 $this->assertSame(
'mock', $mock->getProviderId() );
31 $this->assertNotSame( $mock, $local );
32 $this->assertInstanceOf(
'LocalIdLookup', $local );
34 $this->assertSame(
'local', $local->getProviderId() );
37 $this->assertNotSame( $local, $local2 );
38 $this->assertInstanceOf(
'LocalIdLookup', $local2 );
39 $this->assertSame(
'local2', $local2->getProviderId() );
46 $mock = TestingAccessWrapper::newFromObject(
47 $this->getMockForAbstractClass(
'CentralIdLookup' )
50 $user = static::getTestSysop()->getUser();
51 $this->assertSame(
$user, $mock->checkAudience(
$user ) );
54 $this->assertInstanceOf(
'User',
$user );
55 $this->assertSame( 0,
$user->getId() );
60 $mock->checkAudience( 100 );
61 $this->fail(
'Expected exception not thrown' );
62 }
catch ( InvalidArgumentException $ex ) {
63 $this->assertSame(
'Invalid audience', $ex->getMessage() );
68 $mock = $this->getMockForAbstractClass(
'CentralIdLookup' );
69 $mock->expects( $this->once() )->method(
'lookupCentralIds' )
71 $this->equalTo( [ 15 =>
null ] ),
73 $this->equalTo( CentralIdLookup::READ_LATEST )
75 ->will( $this->returnValue( [ 15 =>
'FooBar' ] ) );
89 $mock = $this->getMockForAbstractClass(
'CentralIdLookup' );
90 $mock->expects( $this->
any() )->method(
'isAttached' )
91 ->will( $this->returnValue(
true ) );
92 $mock->expects( $this->once() )->method(
'lookupCentralIds' )
94 $this->equalTo( [ 42 =>
null ] ),
96 $this->equalTo( CentralIdLookup::READ_LATEST )
98 ->will( $this->returnValue( [ 42 =>
$name ] ) );
100 $user = $mock->localUserFromCentralId(
104 $this->assertInstanceOf(
'User',
$user );
107 $this->assertNull(
$user );
110 $mock = $this->getMockForAbstractClass(
'CentralIdLookup' );
111 $mock->expects( $this->
any() )->method(
'isAttached' )
112 ->will( $this->returnValue(
false ) );
113 $mock->expects( $this->once() )->method(
'lookupCentralIds' )
115 $this->equalTo( [ 42 =>
null ] ),
117 $this->equalTo( CentralIdLookup::READ_LATEST )
119 ->will( $this->returnValue( [ 42 =>
$name ] ) );
128 [
'UTDoesNotExist',
false ],
136 $mock = $this->getMockForAbstractClass(
'CentralIdLookup' );
137 $mock->expects( $this->once() )->method(
'lookupUserNames' )
139 $this->equalTo( [
'FooBar' => 0 ] ),
141 $this->equalTo( CentralIdLookup::READ_LATEST )
143 ->will( $this->returnValue( [
'FooBar' => 23 ] ) );
152 $mock = $this->getMockForAbstractClass(
'CentralIdLookup' );
153 $mock->expects( $this->
any() )->method(
'isAttached' )
154 ->will( $this->returnValue(
true ) );
155 $mock->expects( $this->once() )->method(
'lookupUserNames' )
157 $this->equalTo( [
'FooBar' => 0 ] ),
159 $this->equalTo( CentralIdLookup::READ_LATEST )
161 ->will( $this->returnValue( [
'FooBar' => 23 ] ) );
165 $mock->centralIdFromLocalUser(
170 $mock = $this->getMockForAbstractClass(
'CentralIdLookup' );
171 $mock->expects( $this->
any() )->method(
'isAttached' )
172 ->will( $this->returnValue(
false ) );
173 $mock->expects( $this->never() )->method(
'lookupUserNames' );
177 $mock->centralIdFromLocalUser(