$gadgetName, ReferencePreviewsGadgetsIntegration::CONFIG_REFERENCE_TOOLTIPS_NAME => $gadgetName, ] ); } public function testConflictsWithNavPopupsGadgetIfGadgetsExtensionIsNotLoaded() { $integration = new ReferencePreviewsGadgetsIntegration( $this->getConfig() ); $this->assertFalse( $integration->isNavPopupsGadgetEnabled( $this->createNoOpMock( User::class ) ), 'No conflict is identified.' ); } public function testConflictsWithNavPopupsGadgetIfGadgetNotExists() { $this->markTestSkippedIfExtensionNotLoaded( 'Gadgets' ); $gadgetRepoMock = $this->createMock( GadgetRepo::class ); $gadgetRepoMock->expects( $this->once() ) ->method( 'getGadgetIds' ) ->willReturn( [] ); $this->executeIsNavPopupsGadgetEnabled( $this->createNoOpMock( User::class ), $this->getConfig(), $gadgetRepoMock, self::GADGET_DISABLED ); } public function testConflictsWithNavPopupsGadgetIfGadgetExists() { $this->markTestSkippedIfExtensionNotLoaded( 'Gadgets' ); $user = $this->createMock( User::class ); $gadgetMock = $this->createMock( Gadget::class ); $gadgetMock->expects( $this->once() ) ->method( 'isEnabled' ) ->with( $user ) ->willReturn( self::GADGET_ENABLED ); $gadgetRepoMock = $this->createMock( GadgetRepo::class ); $gadgetRepoMock->expects( $this->once() ) ->method( 'getGadgetIds' ) ->willReturn( [ self::NAV_POPUPS_GADGET_NAME ] ); $gadgetRepoMock->expects( $this->once() ) ->method( 'getGadget' ) ->with( self::NAV_POPUPS_GADGET_NAME ) ->willReturn( $gadgetMock ); $this->executeIsNavPopupsGadgetEnabled( $user, $this->getConfig(), $gadgetRepoMock, self::GADGET_ENABLED ); } /** * Test the edge case when GadgetsRepo::getGadget throws an exception */ public function testConflictsWithNavPopupsGadgetWhenGadgetNotExists() { $this->markTestSkippedIfExtensionNotLoaded( 'Gadgets' ); $gadgetRepoMock = $this->createMock( GadgetRepo::class ); $gadgetRepoMock->expects( $this->once() ) ->method( 'getGadgetIds' ) ->willReturn( [ self::NAV_POPUPS_GADGET_NAME ] ); $gadgetRepoMock->expects( $this->once() ) ->method( 'getGadget' ) ->with( self::NAV_POPUPS_GADGET_NAME ) ->willThrowException( new InvalidArgumentException() ); $this->executeIsNavPopupsGadgetEnabled( $this->createNoOpMock( User::class ), $this->getConfig(), $gadgetRepoMock, self::GADGET_DISABLED ); } /** * @dataProvider provideGadgetNamesWithSanitizedVersion */ public function testConflictsWithNavPopupsGadgetNameSanitization( string $gadgetName, string $sanitized ) { $this->markTestSkippedIfExtensionNotLoaded( 'Gadgets' ); $gadgetMock = $this->createMock( Gadget::class ); $gadgetMock->expects( $this->once() ) ->method( 'isEnabled' ) ->willReturn( self::GADGET_ENABLED ); $gadgetRepoMock = $this->createMock( GadgetRepo::class ); $gadgetRepoMock->expects( $this->once() ) ->method( 'getGadgetIds' ) ->willReturn( [ $sanitized ] ); $gadgetRepoMock->expects( $this->once() ) ->method( 'getGadget' ) ->with( $sanitized ) ->willReturn( $gadgetMock ); $this->executeIsNavPopupsGadgetEnabled( $this->createNoOpMock( User::class ), $this->getConfig( $gadgetName ), $gadgetRepoMock, self::GADGET_ENABLED ); } public static function provideGadgetNamesWithSanitizedVersion() { yield [ ' Popups ', 'Popups' ]; yield [ 'Navigation_popups-API', 'Navigation_popups-API' ]; yield [ 'Navigation popups ', 'Navigation_popups' ]; } private function executeIsNavPopupsGadgetEnabled( User $user, Config $config, GadgetRepo $repoMock, bool $expected ): void { $this->setService( 'GadgetsRepo', $repoMock ); $integration = new ReferencePreviewsGadgetsIntegration( $config ); $this->assertSame( $expected, $integration->isNavPopupsGadgetEnabled( $user ), ( $expected ? 'A' : 'No' ) . ' conflict is identified.' ); } }