diff --git a/src/Hooks/OutputPageParserOutput.php b/src/Hooks/OutputPageParserOutput.php index 7dd7350..dc4bbbc 100644 --- a/src/Hooks/OutputPageParserOutput.php +++ b/src/Hooks/OutputPageParserOutput.php @@ -82,6 +82,12 @@ public function __construct( * @return void */ public function process(): void { + $this->getOutputPage()->addModules( [ + 'ext.bootstrapComponents.tooltip.fix', + 'ext.bootstrapComponents.popover.fix', + 'ext.bootstrapComponents.carousel.fix', + ] ); + if ( $this->getBootstrapComponentsService()->vectorSkinInUse() ) { $this->getOutputPage()->addModules( [ 'ext.bootstrapComponents.vector-fix' ] ); } diff --git a/tests/phpunit/Unit/Hooks/OutputPageParserOutputTest.php b/tests/phpunit/Unit/Hooks/OutputPageParserOutputTest.php index 99f4bd6..61baa53 100644 --- a/tests/phpunit/Unit/Hooks/OutputPageParserOutputTest.php +++ b/tests/phpunit/Unit/Hooks/OutputPageParserOutputTest.php @@ -39,14 +39,16 @@ public function testCanConstruct() { ); } - public function testHookOutputPageParserOutputLoadsVectorFixUnderVector() { + public function testProcessLoadsPerComponentInitModulesAndVectorFix() { + $loadedModules = []; + $outputPage = $this->createMock( OutputPage::class ); $outputPage->expects( $this->never() )->method( 'addHTML' ); - $outputPage->expects( $this->once() ) + $outputPage->expects( $this->atLeastOnce() ) ->method( 'addModules' ) - ->with( - $this->equalTo( [ 'ext.bootstrapComponents.vector-fix' ] ) - ); + ->will( $this->returnCallback( function( $modules ) use ( &$loadedModules ) { + $loadedModules = array_merge( $loadedModules, (array)$modules ); + } ) ); $bootstrapService = $this->createMock( BootstrapComponentsService::class ); $bootstrapService->expects( $this->once() ) @@ -59,12 +61,28 @@ public function testHookOutputPageParserOutputLoadsVectorFixUnderVector() { $bootstrapService ); $instance->process(); + + $expected = [ + 'ext.bootstrapComponents.tooltip.fix', + 'ext.bootstrapComponents.popover.fix', + 'ext.bootstrapComponents.carousel.fix', + 'ext.bootstrapComponents.vector-fix', + ]; + sort( $loadedModules ); + sort( $expected ); + $this->assertEquals( $expected, $loadedModules ); } - public function testHookDoesNothingWhenNotVector() { + public function testProcessSkipsVectorFixWhenNotVector() { + $loadedModules = []; + $outputPage = $this->createMock( OutputPage::class ); $outputPage->expects( $this->never() )->method( 'addHTML' ); - $outputPage->expects( $this->never() )->method( 'addModules' ); + $outputPage->expects( $this->atLeastOnce() ) + ->method( 'addModules' ) + ->will( $this->returnCallback( function( $modules ) use ( &$loadedModules ) { + $loadedModules = array_merge( $loadedModules, (array)$modules ); + } ) ); $bootstrapService = $this->createMock( BootstrapComponentsService::class ); $bootstrapService->expects( $this->once() ) @@ -77,5 +95,7 @@ public function testHookDoesNothingWhenNotVector() { $bootstrapService ); $instance->process(); + + $this->assertNotContains( 'ext.bootstrapComponents.vector-fix', $loadedModules ); } }