mirror of
https://github.com/StarCitizenTools/mediawiki-skins-Citizen.git
synced 2024-11-28 16:21:11 +00:00
60 lines
1.9 KiB
PHP
60 lines
1.9 KiB
PHP
|
<?php
|
||
|
|
||
|
declare( strict_types=1 );
|
||
|
|
||
|
namespace MediaWiki\Skins\Citizen\Tests\Unit\Components;
|
||
|
|
||
|
use MediaWiki\Skins\Citizen\Components\CitizenComponentLink;
|
||
|
use MediaWikiUnitTestCase;
|
||
|
use Message;
|
||
|
use MessageLocalizer;
|
||
|
|
||
|
/**
|
||
|
* @group Citizen
|
||
|
* @group Components
|
||
|
* @coversDefaultClass \MediaWiki\Skins\Citizen\Components\CitizenComponentLink
|
||
|
*/
|
||
|
class CitizenComponentLinkTest extends MediaWikiUnitTestCase {
|
||
|
|
||
|
/**
|
||
|
* @covers ::getTemplateData
|
||
|
*/
|
||
|
public function testGetTemplateData() {
|
||
|
$href = '/mock-link';
|
||
|
$text = 'Mock Text';
|
||
|
$icon = 'mock-icon';
|
||
|
$accessKeyHint = 'sample-accesskey';
|
||
|
|
||
|
$localizer = $this->createMock( MessageLocalizer::class );
|
||
|
// Adjusting mock to prevent calling the service container.
|
||
|
$localizer->method( 'msg' )
|
||
|
->willReturnCallback( function ( $key ) use ( $accessKeyHint ) {
|
||
|
// Directly create Message object without accessing real message texts
|
||
|
// to avoid 'Premature access to service container' error.
|
||
|
return $this->createConfiguredMock( Message::class, [
|
||
|
'exists' => true,
|
||
|
'text' => $key === $accessKeyHint . '-label' ? 'Mock aria label' : $key,
|
||
|
'__toString' => 'Mock aria label',
|
||
|
] );
|
||
|
} );
|
||
|
|
||
|
// Create the component
|
||
|
$linkComponent = new CitizenComponentLink( $href, $text, $icon, $localizer, $accessKeyHint );
|
||
|
$actual = $linkComponent->getTemplateData();
|
||
|
|
||
|
// Assert the expected values
|
||
|
$this->assertEquals( $icon, $actual['icon'] );
|
||
|
$this->assertEquals( $text, $actual['text'] );
|
||
|
$this->assertEquals( $href, $actual['href'] );
|
||
|
|
||
|
// New assertions for HTML attributes
|
||
|
$expectedTitle = "tooltip-sample-accesskeyword-separatorbrackets";
|
||
|
$expectedAriaLabel = "Mock aria label";
|
||
|
$attributesString = $actual['html-attributes'];
|
||
|
|
||
|
// Assert that the expected attributes are present in the string
|
||
|
$this->assertStringContainsString( 'title="' . $expectedTitle . '"', $attributesString );
|
||
|
$this->assertStringContainsString( 'aria-label="' . $expectedAriaLabel . '"', $attributesString );
|
||
|
}
|
||
|
}
|