| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
use MediaWiki\Extension\OATHAuth\OATHAuthModuleRegistry; |
| 22 |
use Wikimedia\ObjectFactory\ObjectFactory; |
| 23 |
use Wikimedia\Rdbms\IConnectionProvider; |
| 24 |
|
| 25 |
|
| 26 |
tf> |
| 27 |
|
| 28 |
|
| 29 |
class OATHAuthModuleRegistryTest extends MediaWikiIntegrationTestCase { |
| 30 |
private function makeTestRegistry(): OATHAuthModuleRegistry { |
| 31 |
$this->getDb()->newInsertQueryBuilder() |
| 32 |
->insertInto( 'oathauth_types' ) |
| 33 |
->row( [ 'oat_name' => 'first' ] ) |
| 34 |
->caller( __METHOD__ ) |
| 35 |
->execute(); |
| 36 |
|
| 37 |
$database = $this->createMock( IConnectionProvider::class ); |
| 38 |
$database->method( 'getPrimaryDatabase' )->with( 'virtual-oathauth' )->willReturn( $this->getDb() ); |
| 39 |
$database->method( 'getReplicaDatabase' )->with( 'virtual-oathauth' )->willReturn( $this->getDb() ); |
| 40 |
|
| 41 |
return new OATHAuthModuleRegistry( |
| 42 |
$database, |
| 43 |
$this->createNoOpMock( ObjectFactory::class ), |
| 44 |
[ |
| 45 |
'first' => 'does not matter', |
| 46 |
'second' => 'does not matter', |
| 47 |
'third' => 'does not matter', |
| 48 |
] |
| 49 |
); |
| 50 |
} |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
public function testModuleExists() { |
| 56 |
$registry = $this->makeTestRegistry(); |
| 57 |
$this->assertTrue( $registry->moduleExists( 'first' ) ); |
| 58 |
$this->assertFalse( $registry->moduleExists( 'nonexistent' ) ); |
| 59 |
} |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
public function testGetModuleIds() { |
| 65 |
$registry = $this->makeTestRegistry(); |
| 66 |
|
| 67 |
$this->assertEquals( |
| 68 |
[ 'first', 'second', 'third' ], |
| 69 |
array_keys( $registry->getModuleIds() ) |
| 70 |
); |
| 71 |
} |
| 72 |
} |