2018-01-04 02:41:02 +00:00
|
|
|
<?php
|
|
|
|
|
|
2023-02-16 19:27:21 +00:00
|
|
|
use MediaWiki\Html\ListToggle;
|
2023-03-14 18:24:11 +00:00
|
|
|
use MediaWiki\Tests\Unit\FakeQqxMessageLocalizer;
|
2023-02-16 19:27:21 +00:00
|
|
|
|
2018-01-04 02:41:02 +00:00
|
|
|
/**
|
2023-05-27 09:43:12 +00:00
|
|
|
* @covers MediaWiki\Html\ListToggle
|
2018-01-04 02:41:02 +00:00
|
|
|
*/
|
2021-03-01 18:13:23 +00:00
|
|
|
class ListToggleTest extends MediaWikiUnitTestCase {
|
2018-01-04 02:41:02 +00:00
|
|
|
|
|
|
|
|
/**
|
2023-05-27 09:43:12 +00:00
|
|
|
* @covers MediaWiki\Html\ListToggle::__construct
|
2018-01-04 02:41:02 +00:00
|
|
|
*/
|
|
|
|
|
public function testConstruct() {
|
2021-03-01 18:13:23 +00:00
|
|
|
$output = $this->createMock( OutputPage::class );
|
|
|
|
|
$output->expects( $this->once() )
|
|
|
|
|
->method( 'addModules' )
|
|
|
|
|
->with( 'mediawiki.checkboxtoggle' );
|
|
|
|
|
$output->expects( $this->once() )
|
|
|
|
|
->method( 'addModuleStyles' )
|
|
|
|
|
->with( 'mediawiki.checkboxtoggle.styles' );
|
2018-01-04 02:41:02 +00:00
|
|
|
|
2021-03-01 18:13:23 +00:00
|
|
|
new ListToggle( $output );
|
2018-01-04 02:41:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2023-05-27 09:43:12 +00:00
|
|
|
* @covers MediaWiki\Html\ListToggle::getHTML
|
2018-01-04 02:41:02 +00:00
|
|
|
*/
|
|
|
|
|
public function testGetHTML() {
|
2021-03-01 18:13:23 +00:00
|
|
|
$language = $this->createMock( Language::class );
|
|
|
|
|
$language->method( 'commaList' )
|
|
|
|
|
->willReturnCallback( static function ( array $list ) {
|
|
|
|
|
return implode( '(comma-separator)', $list );
|
|
|
|
|
} );
|
|
|
|
|
|
2018-01-13 00:02:09 +00:00
|
|
|
$output = $this->createMock( OutputPage::class );
|
2021-04-22 08:40:46 +00:00
|
|
|
$output->method( 'msg' )
|
2023-03-14 18:24:11 +00:00
|
|
|
->willReturnCallback( [ new FakeQqxMessageLocalizer(), 'msg' ] );
|
2018-01-04 02:41:02 +00:00
|
|
|
$output->expects( $this->once() )
|
|
|
|
|
->method( 'getLanguage' )
|
2021-03-01 18:13:23 +00:00
|
|
|
->willReturn( $language );
|
2018-01-04 02:41:02 +00:00
|
|
|
|
|
|
|
|
$listToggle = new ListToggle( $output );
|
|
|
|
|
|
|
|
|
|
$html = $listToggle->getHTML();
|
|
|
|
|
$this->assertEquals( '<div class="mw-checkbox-toggle-controls">' .
|
|
|
|
|
'(checkbox-select: <a class="mw-checkbox-all" role="button"' .
|
|
|
|
|
' tabindex="0">(checkbox-all)</a>(comma-separator)' .
|
|
|
|
|
'<a class="mw-checkbox-none" role="button" tabindex="0">' .
|
|
|
|
|
'(checkbox-none)</a>(comma-separator)<a class="mw-checkbox-invert" ' .
|
|
|
|
|
'role="button" tabindex="0">(checkbox-invert)</a>)</div>',
|
|
|
|
|
$html );
|
|
|
|
|
}
|
|
|
|
|
}
|