Debian Codegraph @

skins/Vector/tests/phpunit/unit/components/VectorComponentPageToolsTest.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.35
20 */
21
22 namespace MediaWiki\Skins\Vector\Tests\Unit\Components;
23
24 use MediaWiki\Message\Message;
25 use MediaWiki\Skins\Vector\Components\VectorComponentPageTools;
26 use MediaWiki\Skins\Vector\FeatureManagement\FeatureManager;
27 use MessageLocalizer;
28
29 /**
30 * @group Vector
31 * @group Components
32 * @coversDefaultClass \MediaWiki\Skins\Vector\Components\VectorComponentPageTools
33 */
34 class VectorComponentPageToolsTest extends \MediaWikiUnitTestCase {
35 public static function getPinnableHeaderData( $data = [] ) {
36 return array_merge( [
37 'is-pinned' => false,
38 'label' => 'vector-page-tools-label',
39 'label-tag-name' => 'div',
40 'pin-label' => 'vector-pin-element-label',
41 'unpin-label' => 'vector-unpin-element-label',
42 'data-feature-name' => 'page-tools-pinned',
43 'data-pinnable-element-id' => 'vector-page-tools',
44 'data-unpinned-container-id' => 'vector-page-tools-unpinned-container',
45 'data-pinned-container-id' => 'vector-page-tools-pinned-container',
46 ], $data );
47 }
48
49 public static function provideConstructorData() {
50 $menus = [ [
51 'id' => 'p-cactions',
52 'array-items' => [ [
53 'id' => 'ca-delete',
54 'html-item' => "<li><a><span>Delete</span></a></li>"
55 ] ]
56 ], [
57 'id' => 'p-tb',
58 'array-items' => [ [
59 'id' => 't-whatlinkshere',
60 'html-item' => "<li><a><span>What links here</span></a></li>"
61 ] ]
62 ] ];
63
64 $expectedMenus = $menus;
65 $expectedMenus[ 0 ][ 'label' ] = 'vector-page-tools-actions-label';
66 $expectedMenus[ 1 ][ 'label' ] = 'vector-page-tools-general-label';
67
68 return [
69 [
70 $menus,
71 false,
72 false,
73 [
74 'id' => 'vector-page-tools',
75 'is-pinned' => false,
76 'data-pinnable-header' => self::getPinnableHeaderData(),
77 'data-menus' => $expectedMenus
78 ]
79 ],
80 [
81 $menus,
82 false,
83 true,
84 [
85 'id' => 'vector-page-tools',
86 'is-pinned' => true,
87 'data-pinnable-header' => self::getPinnableHeaderData( [
88 'is-pinned' => true,
89 ] ),
90 'data-menus' => $expectedMenus
91 ]
92 ],
93 [
94 $menus,
95 true,
96 false,
97 [
98 'id' => 'vector-page-tools',
99 'is-pinned' => false,
100 'data-pinnable-header' => self::getPinnableHeaderData(),
101 'data-menus' => $expectedMenus
102 ]
103 ]
104 ];
105 }
106
107 /**
108 * @covers ::getTemplateData
109 * @dataProvider provideConstructorData
110 */
111 public function testGetTemplateData(
112 array $menus,
113 bool $isRegistered,
114 bool $isPinned,
115 array $expected
116 ) {
117 $localizer = $this->createMock( MessageLocalizer::class );
118 $localizer->method( 'msg' )->willReturnCallback( function ( $key, ...$params ) {
119 $msg = $this->createMock( Message::class );
120 $msg->method( '__toString' )->willReturn( $key );
121 $msg->method( 'text' )->willReturn( $key );
122 return $msg;
123 } );
124 $featureManager = $this->createMock( FeatureManager::class );
125 $featureManager->method( 'isFeatureEnabled' )->willReturn( $isPinned );
126
127 $pageTools = new VectorComponentPageTools(
128 $menus,
129 $localizer,
130 $featureManager
131 );
132 $this->assertEquals( $expected, $pageTools->getTemplateData() );
133 }
134 }