12 $mock = $this->getMockForAbstractClass( CentralIdLookup::class );
15 'wgCentralIdLookupProviders' => [
16 'local' => [
'class' => LocalIdLookup::class ],
17 'local2' => [
'class' => LocalIdLookup::class ],
18 'mock' => [
'factory' =>
function ()
use ( $mock ) {
21 'bad' => [
'class' => stdClass::class ],
23 'wgCentralIdLookupProvider' =>
'mock',
26 $this->assertSame( $mock, CentralIdLookup::factory() );
27 $this->assertSame( $mock, CentralIdLookup::factory(
'mock' ) );
28 $this->assertSame(
'mock', $mock->getProviderId() );
30 $local = CentralIdLookup::factory(
'local' );
31 $this->assertNotSame( $mock, $local );
32 $this->assertInstanceOf( LocalIdLookup::class, $local );
33 $this->assertSame( $local, CentralIdLookup::factory(
'local' ) );
34 $this->assertSame(
'local', $local->getProviderId() );
36 $local2 = CentralIdLookup::factory(
'local2' );
37 $this->assertNotSame( $local, $local2 );
38 $this->assertInstanceOf( LocalIdLookup::class, $local2 );
39 $this->assertSame(
'local2', $local2->getProviderId() );
41 $this->assertNull( CentralIdLookup::factory(
'unconfigured' ) );
42 $this->assertNull( CentralIdLookup::factory(
'bad' ) );
46 $mock = TestingAccessWrapper::newFromObject(
47 $this->getMockForAbstractClass( CentralIdLookup::class )
50 $user = static::getTestSysop()->getUser();
51 $this->assertSame(
$user, $mock->checkAudience(
$user ) );
53 $user = $mock->checkAudience( CentralIdLookup::AUDIENCE_PUBLIC );
54 $this->assertInstanceOf( User::class,
$user );
55 $this->assertSame( 0,
$user->getId() );
57 $this->assertNull( $mock->checkAudience( CentralIdLookup::AUDIENCE_RAW ) );
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::class );
69 $mock->expects( $this->once() )->method(
'lookupCentralIds' )
71 $this->equalTo( [ 15 =>
null ] ),
72 $this->equalTo( CentralIdLookup::AUDIENCE_RAW ),
73 $this->equalTo( CentralIdLookup::READ_LATEST )
75 ->will( $this->returnValue( [ 15 =>
'FooBar' ] ) );
79 $mock->nameFromCentralId( 15, CentralIdLookup::AUDIENCE_RAW, CentralIdLookup::READ_LATEST )
89 $mock = $this->getMockForAbstractClass( CentralIdLookup::class );
90 $mock->expects( $this->any() )->method(
'isAttached' )
91 ->will( $this->returnValue(
true ) );
92 $mock->expects( $this->once() )->method(
'lookupCentralIds' )
94 $this->equalTo( [ 42 =>
null ] ),
95 $this->equalTo( CentralIdLookup::AUDIENCE_RAW ),
96 $this->equalTo( CentralIdLookup::READ_LATEST )
98 ->will( $this->returnValue( [ 42 =>
$name ] ) );
100 $user = $mock->localUserFromCentralId(
101 42, CentralIdLookup::AUDIENCE_RAW, CentralIdLookup::READ_LATEST
104 $this->assertInstanceOf( User::class,
$user );
107 $this->assertNull(
$user );
110 $mock = $this->getMockForAbstractClass( CentralIdLookup::class );
111 $mock->expects( $this->any() )->method(
'isAttached' )
112 ->will( $this->returnValue(
false ) );
113 $mock->expects( $this->once() )->method(
'lookupCentralIds' )
115 $this->equalTo( [ 42 =>
null ] ),
116 $this->equalTo( CentralIdLookup::AUDIENCE_RAW ),
117 $this->equalTo( CentralIdLookup::READ_LATEST )
119 ->will( $this->returnValue( [ 42 =>
$name ] ) );
121 $mock->localUserFromCentralId( 42, CentralIdLookup::AUDIENCE_RAW, CentralIdLookup::READ_LATEST )
136 $mock = $this->getMockForAbstractClass( CentralIdLookup::class );
137 $mock->expects( $this->once() )->method(
'lookupUserNames' )
139 $this->equalTo( [
'FooBar' => 0 ] ),
140 $this->equalTo( CentralIdLookup::AUDIENCE_RAW ),
141 $this->equalTo( CentralIdLookup::READ_LATEST )
143 ->will( $this->returnValue( [
'FooBar' => 23 ] ) );
147 $mock->centralIdFromName(
'FooBar', CentralIdLookup::AUDIENCE_RAW, CentralIdLookup::READ_LATEST )
152 $mock = $this->getMockForAbstractClass( CentralIdLookup::class );
153 $mock->expects( $this->any() )->method(
'isAttached' )
154 ->will( $this->returnValue(
true ) );
155 $mock->expects( $this->once() )->method(
'lookupUserNames' )
157 $this->equalTo( [
'FooBar' => 0 ] ),
158 $this->equalTo( CentralIdLookup::AUDIENCE_RAW ),
159 $this->equalTo( CentralIdLookup::READ_LATEST )
161 ->will( $this->returnValue( [
'FooBar' => 23 ] ) );
165 $mock->centralIdFromLocalUser(
166 User::newFromName(
'FooBar' ), CentralIdLookup::AUDIENCE_RAW, CentralIdLookup::READ_LATEST
170 $mock = $this->getMockForAbstractClass( CentralIdLookup::class );
171 $mock->expects( $this->any() )->method(
'isAttached' )
172 ->will( $this->returnValue(
false ) );
173 $mock->expects( $this->never() )->method(
'lookupUserNames' );
177 $mock->centralIdFromLocalUser(
178 User::newFromName(
'FooBar' ), CentralIdLookup::AUDIENCE_RAW, CentralIdLookup::READ_LATEST