Debian Codegraph @

extensions/OATHAuth/tests/phpunit/OATHAuthModuleRegistryTest.php

raw symbols SCIP
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @file
19 */
20
21 use MediaWiki\Extension\OATHAuth\OATHAuthModuleRegistry;
22 use Wikimedia\ObjectFactory\ObjectFactory;
23 use Wikimedia\Rdbms\IConnectionProvider;
24
25 /**
26 * @author Taavi Väänänen <[email protected]tf>
27 * @group Database
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 * @covers \MediaWiki\Extension\OATHAuth\OATHAuthModuleRegistry::moduleExists
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 * @covers \MediaWiki\Extension\OATHAuth\OATHAuthModuleRegistry::getModuleIds
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 }