getServiceContainer(); $repo = TestingAccessWrapper::newFromObject( new MediaWikiGadgetsDefinitionRepo( $services->getMainWANObjectCache(), $services->getRevisionLookup() ) ); $gadgetsDef = <<object ); /** @var MediaWikiGadgetsDefinitionRepo $repo */ $gadgets = $repo->fetchStructuredList( $gadgetsDef ); $this->assertGreaterThanOrEqual( 2, count( $gadgets ), "Gadget list parsed" ); $repo->definitions = $gadgets; $user = $this->createMock( User::class ); $user->method( 'isAllowedAll' ) ->willReturnCallback( static function ( ...$rights ) use ( $testRightNotAllowed ): bool { return !in_array( $testRightNotAllowed, $rights, true ); } ); $hooks->onGetPreferences( $user, $prefs ); $this->assertEquals( 'check', $prefs['gadget-bar']['type'] ); $this->assertEquals( 'api', $prefs['gadget-baz']['type'], 'Must not show unavailable gadgets' ); $this->assertEquals( 'gadgets/gadget-section-keep-section2', $prefs['gadget-quux']['section'] ); } }