Debian Codegraph @

skins/Vector/tests/phpunit/unit/components/VectorComponentMainMenuTest.php

raw symbols SCIP
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @file
19 * @since 1.42
20 */
21
22 namespace MediaWiki\Skins\Vector\Tests\Unit\Components;
23
24 use MediaWiki\Skins\Vector\Components\VectorComponent;
25 use MediaWiki\Skins\Vector\Components\VectorComponentMainMenu;
26 use MediaWiki\Skins\Vector\Constants;
27 use MediaWiki\Skins\Vector\FeatureManagement\FeatureManager;
28 use MediaWiki\User\UserIdentity;
29 use MediaWikiUnitTestCase;
30 use MessageLocalizer;
31 use Skin;
32
33 /**
34 * @group Vector
35 * @group Components
36 * @coversDefaultClass \MediaWiki\Skins\Vector\Components\VectorComponentMainMenu
37 */
38 class VectorComponentMainMenuTest extends MediaWikiUnitTestCase {
39
40 /**
41 * This test checks if the VectorComponentMainMenu class can be instantiated
42 * @covers ::__construct
43 */
44 public function testConstruct() {
45 // Mock the sidebar data, number of languages, and language data
46 $sidebarData = [];
47 $languageData = [];
48
49 // Mock the MessageLocalizer, UserIdentity, FeatureManager, and Skin classes
50 $localizerMock = $this->createMock( MessageLocalizer::class );
51 $userMock = $this->createMock( UserIdentity::class );
52 $featureManagerMock = $this->createMock( FeatureManager::class );
53 $skinMock = $this->createMock( Skin::class );
54
55 // Create a new VectorComponentMainMenu object
56 $mainMenu = new VectorComponentMainMenu(
57 $sidebarData,
58 $languageData,
59 $localizerMock,
60 $userMock,
61 $featureManagerMock,
62 $skinMock
63 );
64
65 // Assert that the object is an instance of VectorComponent
66 $this->assertInstanceOf( VectorComponent::class, $mainMenu );
67 }
68
69 /**
70 * @return array[]
71 */
72 public function provideMainMenuScenarios(): array {
73 return [
74 'Main Menu Pinned' => [
75 'sidebarData' => [
76 'data-portlets-first' => [],
77 'array-portlets-rest' => [],
78 ],
79 'languageData' => [],
80 'isPinned' => true,
81 ],
82 'Main Menu Not Pinned' => [
83 'sidebarData' => [
84 'data-portlets-first' => [],
85 'array-portlets-rest' => [],
86 ],
87 'languageData' => [],
88 'isPinned' => false,
89 ],
90 ];
91 }
92
93 /**
94 * @covers ::getTemplateData
95 * @dataProvider provideMainMenuScenarios
96 */
97 public function testGetTemplateData( array $sidebarData, array $languageData, bool $isPinned ) {
98 // Mock the MessageLocalizer, UserIdentity, FeatureManager, and Skin classes
99 $localizerMock = $this->createMock( MessageLocalizer::class );
100 $userMock = $this->createMock( UserIdentity::class );
101 $featureManagerMock = $this->createMock( FeatureManager::class );
102
103 // Mock the isFeatureEnabled method
104 $featureManagerMock->expects( $this->once() )
105 ->method( 'isFeatureEnabled' )
106 ->with( Constants::FEATURE_MAIN_MENU_PINNED )
107 ->willReturn( $isPinned );
108
109 // Mock the Skin class
110 $skinMock = $this->createMock( Skin::class );
111
112 // Create a new VectorComponentMainMenu object
113 $mainMenu = new VectorComponentMainMenu(
114 $sidebarData,
115 $languageData,
116 $localizerMock,
117 $userMock,
118 $featureManagerMock,
119 $skinMock
120 );
121
122 // Call the getTemplateData method
123 $templateData = $mainMenu->getTemplateData();
124
125 // Assert main menu id and pin status
126 $this->assertSame( 'vector-main-menu', $templateData['id'] );
127 $this->assertSame( $isPinned, $templateData['is-pinned'] );
128
129 // Assert the structure and types of expected keys
130 $this->assertIsArray( $templateData['data-portlets-first'] );
131 $this->assertIsArray( $templateData['array-portlets-rest'] );
132 $this->assertNull( $templateData['data-main-menu-action'] );
133
134 // Assert data-pinnable-header
135 $this->assertIsArray( $templateData['data-pinnable-header'] );
136 $this->assertIsArray( $templateData['data-languages'] );
137
138 // Assert the structure and types of expected keys
139 $this->assertArrayHasKey( 'data-portlets-first', $templateData );
140 $this->assertArrayHasKey( 'array-portlets-rest', $templateData );
141 $this->assertArrayHasKey( 'data-main-menu-action', $templateData );
142 $this->assertArrayHasKey( 'data-pinnable-header', $templateData );
143 $this->assertArrayHasKey( 'data-languages', $templateData );
144 }
145 }