| 1 |
<?php |
| 2 |
|
| 3 |
use MediaWiki\Config\HashConfig; |
| 4 |
use MediaWiki\MainConfigNames; |
| 5 |
use MediaWiki\Message\Message; |
| 6 |
use MediaWiki\Skin\SkinComponentSearch; |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
class SkinComponentSearchTest extends MediaWikiUnitTestCase { |
| 13 |
use MockTitleTrait; |
| 14 |
|
| 15 |
public function testGetTemplateData() { |
| 16 |
$config = new HashConfig( [ |
| 17 |
MainConfigNames::Script => '/w/index.php', |
| 18 |
MainConfigNames::CapitalLinks => true, |
| 19 |
MainConfigNames::WatchlistExpiry => false, |
| 20 |
] ); |
| 21 |
$msg = $this->createMock( Message::class ); |
| 22 |
$msg->method( 'isDisabled' )->willReturn( false ); |
| 23 |
$msg->method( 'text' )->willReturn( 'text' ); |
| 24 |
|
| 25 |
$skin = $this->createMock( SkinTemplate::class ); |
| 26 |
$skin->method( 'getConfig' )->willReturn( $config ); |
| 27 |
$skin->method( 'msg' )->willReturn( $msg ); |
| 28 |
$localizer = $this->createMock( MessageLocalizer::class ); |
| 29 |
$localizer->method( 'msg' )->willReturn( |
| 30 |
$msg |
| 31 |
); |
| 32 |
$searchTitle = $this->makeMockTitle( 'Special:Search' ); |
| 33 |
$component = new SkinComponentSearch( |
| 34 |
$config, $localizer, $searchTitle |
| 35 |
); |
| 36 |
|
| 37 |
$data = $component->getTemplateData(); |
| 38 |
$expectedKeys = [ |
| 39 |
'page-title', 'html-button-search-fallback', 'html-button-search', |
| 40 |
'html-input', 'array-button-go-attributes', |
| 41 |
'html-button-fulltext-attributes', 'array-input-attributes', |
| 42 |
'html-input-attributes' |
| 43 |
]; |
| 44 |
foreach ( $expectedKeys as $key ) { |
| 45 |
$this->assertArrayHasKey( $key, $data, $key . ' is in array' ); |
| 46 |
} |
| 47 |
$this->assertEquals( 'Search', $data['search-special-page-title'] ); |
| 48 |
$this->assertEquals( '/w/index.php', $data['form-action'] ); |
| 49 |
} |
| 50 |
} |