| 1 |
<?php |
| 2 |
|
| 3 |
use MediaWiki\Html\ListToggle; |
| 4 |
use MediaWiki\Language\Language; |
| 5 |
use MediaWiki\Output\OutputPage; |
| 6 |
use MediaWiki\Tests\Unit\FakeQqxMessageLocalizer; |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
class ListToggleTest extends MediaWikiUnitTestCase { |
| 12 |
|
| 13 |
public function testConstruct() { |
| 14 |
$output = $this->createMock( OutputPage::class ); |
| 15 |
$output->expects( $this->once() ) |
| 16 |
->method( 'addModules' ) |
| 17 |
->with( 'mediawiki.checkboxtoggle' ); |
| 18 |
$output->expects( $this->once() ) |
| 19 |
->method( 'addModuleStyles' ) |
| 20 |
->with( 'mediawiki.checkboxtoggle.styles' ); |
| 21 |
|
| 22 |
new ListToggle( $output ); |
| 23 |
} |
| 24 |
|
| 25 |
public function testGetHTML() { |
| 26 |
$language = $this->createMock( Language::class ); |
| 27 |
$language->method( 'commaList' ) |
| 28 |
->willReturnCallback( static function ( array $list ) { |
| 29 |
return implode( '(comma-separator)', $list ); |
| 30 |
} ); |
| 31 |
|
| 32 |
$output = $this->createMock( OutputPage::class ); |
| 33 |
$output->method( 'msg' ) |
| 34 |
->willReturnCallback( [ new FakeQqxMessageLocalizer(), 'msg' ] ); |
| 35 |
$output->expects( $this->once() ) |
| 36 |
->method( 'getLanguage' ) |
| 37 |
->willReturn( $language ); |
| 38 |
|
| 39 |
$listToggle = new ListToggle( $output ); |
| 40 |
|
| 41 |
$html = $listToggle->getHTML(); |
| 42 |
$this->assertEquals( '<div class="mw-checkbox-toggle-controls">' . |
| 43 |
'(checkbox-select: <a class="mw-checkbox-all" role="button"' . |
| 44 |
' tabindex="0">(checkbox-all)</a>(comma-separator)' . |
| 45 |
'<a class="mw-checkbox-none" role="button" tabindex="0">' . |
| 46 |
'(checkbox-none)</a>(comma-separator)<a class="mw-checkbox-invert" ' . |
| 47 |
'role="button" tabindex="0">(checkbox-invert)</a>)</div>', |
| 48 |
$html ); |
| 49 |
} |
| 50 |
} |