Debian Codegraph @

skins/Vector/tests/phpunit/unit/components/VectorComponentAppearanceTest.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\VectorComponentAppearance;
25 use MediaWiki\Skins\Vector\FeatureManagement\FeatureManager;
26 use MediaWikiUnitTestCase;
27 use MessageLocalizer;
28
29 /**
30 * @group Vector
31 * @group Components
32 * @coversDefaultClass \MediaWiki\Skins\Vector\Components\VectorComponentAppearance
33 */
34 class VectorComponentAppearanceTest extends MediaWikiUnitTestCase {
35
36 /**
37 * @covers ::getTemplateData
38 */
39 public function testGetTemplateDataPinned() {
40 // Mock the MessageLocalizer and FeatureManager
41 $localizer = $this->createMock( MessageLocalizer::class );
42 $featureManager = $this->createMock( FeatureManager::class );
43 // The isFeatureEnabled method is called and returns true
44 $featureManager->method( 'isFeatureEnabled' )
45 ->willReturn( true );
46
47 // Create a new VectorComponentAppearance object
48 $appearanceMenu = new VectorComponentAppearance( $localizer, $featureManager );
49 // Call the getTemplateData method
50 $actualData = $appearanceMenu->getTemplateData();
51
52 // The expected data
53 $expectedData = [
54 // The id is set to 'vector-appearance'
55 'id' => 'vector-appearance',
56 // The is-pinned value is true
57 'is-pinned' => true,
58 // The data-pinnable-header array
59 'data-pinnable-header' => [
60 // The is-pinned value is true
61 'is-pinned' => true,
62 // The label is null
63 'label' => null,
64 // The label-tag-name is set to 'div'
65 'label-tag-name' => 'div',
66 // The pin-label is null
67 'pin-label' => null,
68 // The unpin-label is null
69 'unpin-label' => null,
70 // The data-pinnable-element-id is set to 'vector-appearance'
71 'data-pinnable-element-id' => 'vector-appearance',
72 // The data-feature-name is set to 'appearance-pinned'
73 'data-feature-name' => 'appearance-pinned',
74 // The data-unpinned-container-id is set to 'vector-appearance-unpinned-container'
75 'data-unpinned-container-id' => 'vector-appearance-unpinned-container',
76 // The data-pinned-container-id is set to 'vector-appearance-pinned-container'
77 'data-pinned-container-id' => 'vector-appearance-pinned-container',
78 ]
79 ];
80
81 // Assert that the actual data matches the expected data
82 $this->assertEquals( $expectedData, $actualData );
83 // Assert that the is-pinned value is true
84 $this->assertSame( true, $actualData['is-pinned'], 'Assertion for the pinned state failed.' );
85 }
86
87 /**
88 * @covers ::getTemplateData
89 */
90 public function testGetTemplateDataUnpinned() {
91 // Mock the MessageLocalizer and FeatureManager
92 $localizer = $this->createMock( MessageLocalizer::class );
93 $featureManager = $this->createMock( FeatureManager::class );
94 // The isFeatureEnabled method is called and returns false
95 $featureManager->method( 'isFeatureEnabled' )
96 ->willReturn( false );
97
98 // Create a new VectorComponentAppearance object
99 $clientPrefs = new VectorComponentAppearance( $localizer, $featureManager );
100 // Call the getTemplateData method
101 $actualData = $clientPrefs->getTemplateData();
102
103 // The expected data
104 $expectedData = [
105 // The id is set to 'vector-appearance'
106 'id' => 'vector-appearance',
107 // The is-pinned value is false
108 'is-pinned' => false,
109 // The data-pinnable-header array
110 'data-pinnable-header' => [
111 // The is-pinned value is false
112 'is-pinned' => false,
113 // The label is null
114 'label' => null,
115 // The label-tag-name is set to 'div'
116 'label-tag-name' => 'div',
117 // The pin-label is null
118 'pin-label' => null,
119 // The unpin-label is null
120 'unpin-label' => null,
121 // The data-pinnable-element-id is set to 'vector-appearance'
122 'data-pinnable-element-id' => 'vector-appearance',
123 // The data-feature-name is set to 'appearance-pinned'
124 'data-feature-name' => 'appearance-pinned',
125 // The data-unpinned-container-id is set to 'vector-appearance-unpinned-container'
126 'data-unpinned-container-id' => 'vector-appearance-unpinned-container',
127 // The data-pinned-container-id is set to 'vector-appearance-pinned-container'
128 'data-pinned-container-id' => 'vector-appearance-pinned-container',
129 ]
130 ];
131
132 // Assert that the actual data matches the expected data
133 $this->assertEquals( $expectedData, $actualData );
134 // Assert that the is-pinned value is false
135 $this->assertSame( false, $actualData['is-pinned'], 'Assertion for the pinned state failed.' );
136 }
137 }