Debian Codegraph @

skins/Vector/tests/phpunit/unit/components/VectorComponentDropdownTest.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\VectorComponentDropdown;
25 use MediaWikiUnitTestCase;
26
27 /**
28 * @group Vector
29 * @group Components
30 * @coversDefaultClass \MediaWiki\Skins\Vector\Components\VectorComponentDropdown
31 */
32 class VectorComponentDropdownTest extends MediaWikiUnitTestCase {
33
34 /**
35 * @return array[]
36 */
37 public function provideDropdownData(): array {
38 return [
39 'Dropdown' => [
40 'id' => 'mock-dropdown',
41 'label' => 'Mock Dropdown',
42 'class' => 'some-class',
43 'icon' => null,
44 'tooltip' => 'A tooltip for the dropdown',
45 'expectedClasses' => 'some-class',
46 'expectedIconButtonClasses' => '',
47 ],
48 'Dropdown with icon' => [
49 'id' => 'mock-icon-dropdown',
50 'label' => 'Mock Icon Dropdown',
51 'class' => 'some-icon-class',
52 'icon' => 'icon-some',
53 'tooltip' => 'A tooltip for the icon dropdown',
54 'expectedClasses' => 'some-icon-class',
55 'expectedIconButtonClasses' => 'cdx-button--icon-only',
56 ],
57 ];
58 }
59
60 /**
61 * @covers ::getTemplateData
62 * @dataProvider provideDropdownData
63 */
64 public function testGetTemplateData( string $id, string $label, string $class, $icon, string $tooltip,
65 string $expectedClasses, string $expectedIconButtonClasses ) {
66 // Create a new VectorComponentDropdown object
67 $dropdown = new VectorComponentDropdown( $id, $label, $class, $icon, $tooltip );
68 // Call the getTemplateData method
69 $templateData = $dropdown->getTemplateData();
70
71 // Verifying that the template data is constructed as expected
72 $this->assertEquals( $id, $templateData['id'] );
73 $this->assertEquals( $label, $templateData['label'] );
74 $this->assertEquals( $expectedClasses, $templateData['class'] );
75 $this->assertEquals( $icon, $templateData['icon'] );
76 $this->assertEquals( $tooltip, $templateData['html-tooltip'] );
77 // Verifying that the label-class is constructed as expected
78 $this->assertStringContainsString( $expectedIconButtonClasses, $templateData['label-class'] );
79 }
80 }