diff --git a/src/HooksHandler.php b/src/HooksHandler.php index 7ff5bac..91fbef5 100644 --- a/src/HooksHandler.php +++ b/src/HooksHandler.php @@ -226,7 +226,7 @@ public function onParserAfterParse( $parser, &$text, $stripState ): bool { if ( !$this->getComponentLibrary()->isRegistered( $activeComponent ) ) { continue; } - foreach ( $this->getComponentLibrary()->getModulesFor( $activeComponent ) as $module ) { + foreach ( $this->getComponentLibrary()->getModulesFor( $activeComponent, 'vector' ) as $module ) { $parser->getOutput()->addModuleStyles( [ $module ] ); $parser->getOutput()->addModules( [ $module ] ); } diff --git a/tests/phpunit/Unit/HooksHandlerTest.php b/tests/phpunit/Unit/HooksHandlerTest.php index 3d9867e..18aa2fb 100644 --- a/tests/phpunit/Unit/HooksHandlerTest.php +++ b/tests/phpunit/Unit/HooksHandlerTest.php @@ -6,8 +6,6 @@ use MediaWiki\Extension\BootstrapComponents\ComponentLibrary; use MediaWiki\Extension\BootstrapComponents\HooksHandler; use MediaWiki\Extension\BootstrapComponents\NestingController; -use Parser; -use ParserOutput; use PHPUnit\Framework\TestCase; /** @@ -75,49 +73,4 @@ public function testOnOutputPageParserOutput() { $this->assertTrue( true ); } - public function testOnParserAfterParseLoadsActiveComponentScriptsAndStyles() { - $loadedStyles = []; - $loadedModules = []; - - $parserOutput = $this->createMock( ParserOutput::class ); - $parserOutput->method( 'addModuleStyles' ) - ->willReturnCallback( function ( $m ) use ( &$loadedStyles ) { - $loadedStyles = array_merge( $loadedStyles, (array)$m ); - } ); - $parserOutput->method( 'addModules' ) - ->willReturnCallback( function ( $m ) use ( &$loadedModules ) { - $loadedModules = array_merge( $loadedModules, (array)$m ); - } ); - - $parser = $this->createMock( Parser::class ); - $parser->method( 'getOutput' )->willReturn( $parserOutput ); - - $service = $this->createMock( BootstrapComponentsService::class ); - $service->method( 'getNameOfActiveSkin' )->willReturn( 'vector' ); - $service->method( 'getActiveComponents' )->willReturn( [ 'tooltip', 'popover' ] ); - - $library = $this->createMock( ComponentLibrary::class ); - $library->method( 'isRegistered' )->willReturn( true ); - $library->method( 'getModulesFor' ) - ->willReturnCallback( function ( $name ) { - return [ 'ext.bootstrapComponents.' . $name . '.fix' ]; - } ); - - $handler = new HooksHandler( - $service, - $library, - $this->createMock( NestingController::class ) - ); - - $text = ''; - $handler->onParserAfterParse( $parser, $text, null ); - - // Per-component fix modules must reach BOTH addModuleStyles and addModules - // (style-only modules treat addModules as a no-op; modules with a scripts - // entry get their JS init via that call). - $this->assertContains( 'ext.bootstrapComponents.tooltip.fix', $loadedStyles ); - $this->assertContains( 'ext.bootstrapComponents.popover.fix', $loadedStyles ); - $this->assertContains( 'ext.bootstrapComponents.tooltip.fix', $loadedModules ); - $this->assertContains( 'ext.bootstrapComponents.popover.fix', $loadedModules ); - } }