Debian Codegraph @

skins/Vector/tests/phpunit/unit/components/VectorComponentLanguageDropdownTest.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\VectorComponentLanguageDropdown;
25 use MediaWiki\Title\Title;
26 use MediaWikiUnitTestCase;
27
28 /**
29 * @group Vector
30 * @group Components
31 * @coversDefaultClass \MediaWiki\Skins\Vector\Components\VectorComponentLanguageDropdown
32 */
33 class VectorComponentLanguageDropdownTest extends MediaWikiUnitTestCase {
34
35 /**
36 * @return array[]
37 */
38 public function provideLanguageDropdownData(): array {
39 return [
40 'Subject page with languages' => [
41 'label' => 'Languages',
42 'ariaLabel' => 'Choose language',
43 'class' => 'some-class',
44 'numLanguages' => 5,
45 'itemHTML' => '<li>Language Mock</li>',
46 'titleExists' => true,
47 'expectedIcon' => 'language-progressive',
48 'isSubjectPage' => true,
49 ],
50 'Talk page without languages' => [
51 'label' => 'Languages',
52 'ariaLabel' => 'Choose language',
53 'class' => 'some-class',
54 'numLanguages' => 0,
55 'itemHTML' => '',
56 'titleExists' => false,
57 'expectedIcon' => 'language',
58 'isSubjectPage' => false,
59 ],
60 'Subject page without languages' => [
61 'label' => 'Languages',
62 'ariaLabel' => 'Choose language',
63 'class' => 'some-class',
64 'numLanguages' => 0,
65 'itemHTML' => '',
66 'titleExists' => true,
67 'expectedIcon' => 'language-progressive',
68 'isSubjectPage' => true,
69 ],
70 'Talk page with languages' => [
71 'label' => 'Languages',
72 'ariaLabel' => 'Choose language',
73 'class' => 'some-class',
74 'numLanguages' => 5,
75 'itemHTML' => '<li>Language Mock</li>',
76 'titleExists' => false,
77 'expectedIcon' => 'language',
78 'isSubjectPage' => false,
79 ],
80 ];
81 }
82
83 /**
84 * @covers ::getTemplateData
85 * @dataProvider provideLanguageDropdownData
86 */
87 public function testGetTemplateData( $label, $ariaLabel, $class, $numLanguages, $itemHTML, $titleExists,
88 $expectedIcon, $isSubjectPage ) {
89 // Mock Title
90 $titleMock = $this->createMock( Title::class );
91 // Mock Title methods
92 $titleMock->method( 'exists' )->willReturn( $titleExists );
93 $titleMock->method( 'isTalkPage' )->willReturn( !$titleExists );
94
95 // Create a new VectorComponentLanguageDropdown object
96 $languageDropdown = new VectorComponentLanguageDropdown(
97 $label, $ariaLabel, $class, $numLanguages, $itemHTML, '', '', $titleMock
98 );
99
100 // Call the getTemplateData method
101 $templateData = $languageDropdown->getTemplateData();
102
103 // Verifying that the template data is constructed as expected
104 $this->assertEquals( $label, $templateData['label'] );
105 $this->assertEquals( $ariaLabel, $templateData['aria-label'] );
106 $this->assertEquals( $expectedIcon, $templateData['icon'] );
107 $this->assertStringContainsString( 'cdx-button--fake-button', $templateData['label-class'] );
108 $this->assertEquals( $itemHTML, $templateData['html-items'] );
109 $this->assertSame( !$titleExists, $templateData['is-language-selector-empty'] );
110
111 // Verifying that the template data is constructed as expected
112 if ( !$isSubjectPage ) {
113 $this->assertStringContainsString( 'cdx-button--fake-button', $templateData['label-class'] );
114 $this->assertStringContainsString( 'cdx-button--icon-only', $templateData['label-class'] );
115 $this->assertStringContainsString( 'mw-portlet-lang-heading-empty', $templateData['label-class'] );
116 $this->assertStringContainsString( 'mw-interlanguage-selector-empty', $templateData['checkbox-class'] );
117 $this->assertStringContainsString( 'mw-portlet-lang-icon-only', $templateData['class'] );
118
119 } else {
120 $this->assertStringContainsString( 'cdx-button--fake-button', $templateData['label-class'] );
121 $this->assertStringNotContainsString( 'cdx-button--icon-only', $templateData['label-class'] );
122 $this->assertStringNotContainsString( 'mw-portlet-lang-heading-empty', $templateData['label-class'] );
123 $this->assertStringNotContainsString( 'mw-interlanguage-selector-empty', $templateData['checkbox-class'] );
124 $this->assertStringNotContainsString( 'mw-portlet-lang-icon-only', $templateData['class'] );
125 }
126 }
127 }