| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 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 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
class VectorComponentLanguageDropdownTest extends MediaWikiUnitTestCase { |
| 34 |
|
| 35 |
|
| 36 |
|
| 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 |
|
| 85 |
|
| 86 |
|
| 87 |
public function testGetTemplateData( $label, $ariaLabel, $class, $numLanguages, $itemHTML, $titleExists, |
| 88 |
$expectedIcon, $isSubjectPage ) { |
| 89 |
|
| 90 |
$titleMock = $this->createMock( Title::class ); |
| 91 |
|
| 92 |
$titleMock->method( 'exists' )->willReturn( $titleExists ); |
| 93 |
$titleMock->method( 'isTalkPage' )->willReturn( !$titleExists ); |
| 94 |
|
| 95 |
|
| 96 |
$languageDropdown = new VectorComponentLanguageDropdown( |
| 97 |
$label, $ariaLabel, $class, $numLanguages, $itemHTML, '', '', $titleMock |
| 98 |
); |
| 99 |
|
| 100 |
|
| 101 |
$templateData = $languageDropdown->getTemplateData(); |
| 102 |
|
| 103 |
|
| 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 |
|
| 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 |
} |