wiki.techinc.nl/tests/phpunit/unit/includes/ListToggleTest.php
Thiemo Kreuz b95a07380a Remove meaningless ->expects( $this->any() ) from all tests
It is not entirely meaningless. It might be an indicator that
the number of calls to a method is intentionally unlimited.
This is similar to e.g. an @inheritDoc PHPDoc comment that
marks a method as being "intentionally undocumented".

However, what's the meaning of being "intentionally
unconstrained"? Let's just not have any constraint then.

I feel all these ->expects( $this->any() ) bloat the test
code so much that it's never worth it.

Change-Id: I9925e7706bd03e1666f6eb0b284cb42b0dd3be23
2021-04-23 11:58:58 +02:00

61 lines
1.7 KiB
PHP

<?php
/**
* @covers ListToggle
*/
class ListToggleTest extends MediaWikiUnitTestCase {
/**
* @covers ListToggle::__construct
*/
public function testConstruct() {
$output = $this->createMock( OutputPage::class );
$output->expects( $this->once() )
->method( 'addModules' )
->with( 'mediawiki.checkboxtoggle' );
$output->expects( $this->once() )
->method( 'addModuleStyles' )
->with( 'mediawiki.checkboxtoggle.styles' );
new ListToggle( $output );
}
/**
* @covers ListToggle::getHTML
*/
public function testGetHTML() {
$language = $this->createMock( Language::class );
$language->method( 'commaList' )
->willReturnCallback( static function ( array $list ) {
return implode( '(comma-separator)', $list );
} );
$output = $this->createMock( OutputPage::class );
$output->method( 'msg' )
->will( $this->returnCallback( static function ( $key ) {
return new class( $key ) extends Message {
protected function fetchMessage() {
return "($this->key$*)";
}
protected function transformText( $string ) {
return $string;
}
};
} ) );
$output->expects( $this->once() )
->method( 'getLanguage' )
->willReturn( $language );
$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 );
}
}