2018-01-04 02:41:02 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers ListToggle
|
|
|
|
|
*/
|
2021-03-01 18:13:23 +00:00
|
|
|
class ListToggleTest extends MediaWikiUnitTestCase {
|
2018-01-04 02:41:02 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers ListToggle::__construct
|
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers ListToggle::getHTML
|
|
|
|
|
*/
|
|
|
|
|
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' )
|
2021-02-07 13:10:36 +00:00
|
|
|
->will( $this->returnCallback( static function ( $key ) {
|
2021-03-01 18:13:23 +00:00
|
|
|
return new class( $key ) extends Message {
|
|
|
|
|
protected function fetchMessage() {
|
|
|
|
|
return "($this->key$*)";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function transformText( $string ) {
|
|
|
|
|
return $string;
|
|
|
|
|
}
|
|
|
|
|
};
|
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 );
|
|
|
|
|
}
|
|
|
|
|
}
|