Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/Hooks/OutputPageParserOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ] );
}
Expand Down
34 changes: 27 additions & 7 deletions tests/phpunit/Unit/Hooks/OutputPageParserOutputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() )
Expand All @@ -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() )
Expand All @@ -77,5 +95,7 @@ public function testHookDoesNothingWhenNotVector() {
$bootstrapService
);
$instance->process();

$this->assertNotContains( 'ext.bootstrapComponents.vector-fix', $loadedModules );
}
}
Loading