Debian Codegraph @

skins/Vector/tests/phpunit/unit/components/VectorComponentMenuTest.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\VectorComponentMenu;
26 use MediaWikiUnitTestCase;
27
28 /**
29 * @group Vector
30 * @group Components
31 * @coversDefaultClass \MediaWiki\Skins\Vector\Components\VectorComponentMenu
32 */
33 class VectorComponentMenuTest extends MediaWikiUnitTestCase {
34
35 /**
36 * @return array[]
37 */
38 public function provideMenuData(): array {
39 return [
40 [
41 [
42 'class' => 'some-class',
43 'label' => 'Some label',
44 'html-tooltip' => 'Some tooltip',
45 'label-class' => 'some-label-class',
46 'html-before-portal' => 'Some before portal',
47 'html-items' => 'Some items',
48 'html-after-portal' => 'Some after portal',
49 'array-list-items' => [ 'some-item-one', 'some-item-2', 'some-item-3' ]
50 ]
51 ]
52 ];
53 }
54
55 /**
56 * @return array[]
57 */
58 public function provideCountData(): array {
59 return [
60 [
61 [
62 'array-list-items' => [ 'some-item-one', 'some-item-2', 'some-item-3' ]
63 ],
64 3
65 ],
66 [
67 [
68 'html-items' => '<li>Some item</li><li>Some item</li><li>Some item</li>'
69 ],
70 3
71 ]
72 ];
73 }
74
75 /**
76 * This test checks if the VectorComponentMenu class can be instantiated
77 * @covers ::__construct
78 */
79 public function testConstruct() {
80 // Create a new VectorComponentMenu object
81 $menu = new VectorComponentMenu( [] );
82
83 // Check if the object is an instance of VectorComponent
84 $this->assertInstanceOf( VectorComponent::class, $menu );
85 }
86
87 /**
88 * This test checks if the count method returns the correct number of items
89 * @covers ::count
90 * @dataProvider provideCountData
91 */
92 public function testCount( array $data, int $expected ) {
93 // Create a new VectorComponentMenu object
94 $menu = new VectorComponentMenu( $data );
95
96 // Check if the count method returns the correct number of items
97 $this->assertSame( $expected, $menu->count() );
98 }
99
100 /**
101 * This test checks if the getTemplateData method returns the correct data
102 * @covers ::getTemplateData
103 * @dataProvider provideMenuData
104 */
105 public function testGetTemplateData( array $data ) {
106 // Create a new VectorComponentMenu object
107 $menu = new VectorComponentMenu( $data );
108
109 // Call the getTemplateData method
110 $actualData = $menu->getTemplateData();
111
112 // Check if the getTemplateData method returns the correct data
113 $this->assertSame( $data, $actualData );
114 }
115 }