| 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\Message\Message; |
| 25 |
use MediaWiki\Skins\Vector\Components\VectorComponentLink; |
| 26 |
use MediaWikiUnitTestCase; |
| 27 |
use MessageLocalizer; |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
class VectorComponentLinkTest extends MediaWikiUnitTestCase { |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
public function testGetTemplateData() { |
| 40 |
$href = '/mock-link'; |
| 41 |
$text = 'Mock Text'; |
| 42 |
$icon = 'mock-icon'; |
| 43 |
$accessKeyHint = 'sample-accesskey'; |
| 44 |
|
| 45 |
$localizer = $this->createMock( MessageLocalizer::class ); |
| 46 |
|
| 47 |
$localizer->method( 'msg' ) |
| 48 |
->willReturnCallback( function ( $key ) use ( $accessKeyHint ) { |
| 49 |
|
| 50 |
|
| 51 |
return $this->createConfiguredMock( Message::class, [ |
| 52 |
'exists' => true, |
| 53 |
'text' => $key === $accessKeyHint . '-label' ? 'Mock aria label' : $key, |
| 54 |
'__toString' => 'Mock aria label', |
| 55 |
] ); |
| 56 |
} ); |
| 57 |
|
| 58 |
|
| 59 |
$linkComponent = new VectorComponentLink( $href, $text, $icon, $localizer, $accessKeyHint ); |
| 60 |
$actual = $linkComponent->getTemplateData(); |
| 61 |
|
| 62 |
|
| 63 |
$this->assertEquals( $icon, $actual['icon'] ); |
| 64 |
$this->assertEquals( $text, $actual['text'] ); |
| 65 |
$this->assertEquals( $href, $actual['href'] ); |
| 66 |
|
| 67 |
|
| 68 |
$expectedTitle = "tooltip-sample-accesskeyword-separatorbrackets"; |
| 69 |
$expectedAriaLabel = "Mock aria label"; |
| 70 |
$attributesString = $actual['html-attributes']; |
| 71 |
|
| 72 |
|
| 73 |
$this->assertStringContainsString( 'title="' . $expectedTitle . '"', $attributesString ); |
| 74 |
$this->assertStringContainsString( 'aria-label="' . $expectedAriaLabel . '"', $attributesString ); |
| 75 |
} |
| 76 |
} |