3 use Wikimedia\TestingAccessWrapper;
15 'wgCentralIdLookupProviders' => [
18 'mock' => [
'factory' =>
function ()
use ( $mock ) {
23 'wgCentralIdLookupProvider' =>
'mock',
28 $this->assertSame(
'mock', $mock->getProviderId() );
31 $this->assertNotSame( $mock, $local );
34 $this->assertSame(
'local', $local->getProviderId() );
37 $this->assertNotSame( $local, $local2 );
39 $this->assertSame(
'local2', $local2->getProviderId() );
46 $mock = TestingAccessWrapper::newFromObject(
50 $user = static::getTestSysop()->getUser();
51 $this->assertSame(
$user, $mock->checkAudience(
$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() );
69 $mock->expects( $this->once() )->method(
'lookupCentralIds' )
71 $this->equalTo( [ 15 =>
null ] ),
73 $this->equalTo( CentralIdLookup::READ_LATEST )
75 ->will( $this->returnValue( [ 15 =>
'FooBar' ] ) );
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(
107 $this->assertNull(
$user );
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 ],
137 $mock->expects( $this->once() )->method(
'lookupUserNames' )
139 $this->equalTo( [
'FooBar' => 0 ] ),
141 $this->equalTo( CentralIdLookup::READ_LATEST )
143 ->will( $this->returnValue( [
'FooBar' => 23 ] ) );
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(
171 $mock->expects( $this->
any() )->method(
'isAttached' )
172 ->will( $this->returnValue(
false ) );
173 $mock->expects( $this->never() )->method(
'lookupUserNames' );
177 $mock->centralIdFromLocalUser(