createMock( MessageLocalizer::class ); $userMock = $this->createMock( UserIdentity::class ); $featureManagerMock = $this->createMock( FeatureManager::class ); $skinMock = $this->createMock( Skin::class ); // Create a new VectorComponentMainMenu object $mainMenu = new VectorComponentMainMenu( $sidebarData, $languageData, $localizerMock, $userMock, $featureManagerMock, $skinMock ); // Assert that the object is an instance of VectorComponent $this->assertInstanceOf( VectorComponent::class, $mainMenu ); } /** * @return array[] */ public function provideMainMenuScenarios(): array { return [ 'Main Menu Pinned' => [ 'sidebarData' => [ 'data-portlets-first' => [], 'array-portlets-rest' => [], ], 'languageData' => [], 'isPinned' => true, ], 'Main Menu Not Pinned' => [ 'sidebarData' => [ 'data-portlets-first' => [], 'array-portlets-rest' => [], ], 'languageData' => [], 'isPinned' => false, ], ]; } /** * @covers ::getTemplateData * @dataProvider provideMainMenuScenarios */ public function testGetTemplateData( array $sidebarData, array $languageData, bool $isPinned ) { // Mock the MessageLocalizer, UserIdentity, FeatureManager, and Skin classes $localizerMock = $this->createMock( MessageLocalizer::class ); $userMock = $this->createMock( UserIdentity::class ); $featureManagerMock = $this->createMock( FeatureManager::class ); // Mock the isFeatureEnabled method $featureManagerMock->expects( $this->once() ) ->method( 'isFeatureEnabled' ) ->with( Constants::FEATURE_MAIN_MENU_PINNED ) ->willReturn( $isPinned ); // Mock the Skin class $skinMock = $this->createMock( Skin::class ); // Create a new VectorComponentMainMenu object $mainMenu = new VectorComponentMainMenu( $sidebarData, $languageData, $localizerMock, $userMock, $featureManagerMock, $skinMock ); // Call the getTemplateData method $templateData = $mainMenu->getTemplateData(); // Assert main menu id and pin status $this->assertSame( 'vector-main-menu', $templateData['id'] ); $this->assertSame( $isPinned, $templateData['is-pinned'] ); // Assert the structure and types of expected keys $this->assertIsArray( $templateData['data-portlets-first'] ); $this->assertIsArray( $templateData['array-portlets-rest'] ); $this->assertNull( $templateData['data-main-menu-action'] ); // Assert data-pinnable-header $this->assertIsArray( $templateData['data-pinnable-header'] ); $this->assertIsArray( $templateData['data-languages'] ); // Assert the structure and types of expected keys $this->assertArrayHasKey( 'data-portlets-first', $templateData ); $this->assertArrayHasKey( 'array-portlets-rest', $templateData ); $this->assertArrayHasKey( 'data-main-menu-action', $templateData ); $this->assertArrayHasKey( 'data-pinnable-header', $templateData ); $this->assertArrayHasKey( 'data-languages', $templateData ); } }