mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Cite
synced 2024-11-28 00:40:12 +00:00
4377f0923d
Same arguments as in Iafa2412. The one reason to use more detailled per-method @covers annotations is to avoid "accidental coverage" where code is marked as being covered by tests that don't assert anything that would be meaningful for this code. This is especially a problem with older, bigger classes with lots of side effects. But all the new classes we introduced over the years are small, with predictable, local effects. That's also why we keep the more detailled @covers annotations for the original Cite class. Bug: T353227 Bug: T353269 Change-Id: I69850f4d740d8ad5a7c2368b9068dc91e47cc797
81 lines
2.3 KiB
PHP
81 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace Cite\Tests\Unit;
|
|
|
|
use Cite\Cite;
|
|
use Cite\Hooks\CiteParserHooks;
|
|
use Parser;
|
|
use ParserOptions;
|
|
use ParserOutput;
|
|
use StripState;
|
|
|
|
/**
|
|
* @covers \Cite\Hooks\CiteParserHooks
|
|
* @license GPL-2.0-or-later
|
|
*/
|
|
class CiteParserHooksTest extends \MediaWikiUnitTestCase {
|
|
|
|
public function testOnParserFirstCallInit() {
|
|
$parser = $this->createNoOpMock( Parser::class, [ 'setHook' ] );
|
|
$expectedTags = [ 'ref' => true, 'references' => true ];
|
|
$parser->expects( $this->exactly( 2 ) )
|
|
->method( 'setHook' )
|
|
->willReturnCallback( function ( $tag ) use ( &$expectedTags ) {
|
|
$this->assertArrayHasKey( $tag, $expectedTags );
|
|
unset( $expectedTags[$tag] );
|
|
} );
|
|
|
|
$citeParserHooks = new CiteParserHooks();
|
|
$citeParserHooks->onParserFirstCallInit( $parser );
|
|
}
|
|
|
|
public function testOnParserClearState() {
|
|
$parser = $this->createParser();
|
|
$parser->extCite = $this->createMock( Cite::class );
|
|
|
|
$citeParserHooks = new CiteParserHooks();
|
|
$citeParserHooks->onParserClearState( $parser );
|
|
|
|
$this->assertObjectNotHasProperty( 'extCite', $parser );
|
|
}
|
|
|
|
public function testOnParserCloned() {
|
|
$parser = $this->createParser();
|
|
$parser->extCite = $this->createMock( Cite::class );
|
|
|
|
$citeParserHooks = new CiteParserHooks();
|
|
$citeParserHooks->onParserCloned( $parser );
|
|
|
|
$this->assertObjectNotHasProperty( 'extCite', $parser );
|
|
}
|
|
|
|
public function testAfterParseHooks() {
|
|
$cite = $this->createMock( Cite::class );
|
|
$cite->expects( $this->once() )
|
|
->method( 'checkRefsNoReferences' );
|
|
|
|
$parserOptions = $this->createMock( ParserOptions::class );
|
|
$parserOptions->method( 'getIsSectionPreview' )
|
|
->willReturn( false );
|
|
|
|
$parser = $this->createParser( [ 'getOptions', 'getOutput' ] );
|
|
$parser->method( 'getOptions' )
|
|
->willReturn( $parserOptions );
|
|
$parser->method( 'getOutput' )
|
|
->willReturn( $this->createMock( ParserOutput::class ) );
|
|
$parser->extCite = $cite;
|
|
|
|
$text = '';
|
|
$citeParserHooks = new CiteParserHooks();
|
|
$citeParserHooks->onParserAfterParse( $parser, $text, $this->createMock( StripState::class ) );
|
|
}
|
|
|
|
private function createParser( array $configurableMethods = [] ): Parser {
|
|
return $this->getMockBuilder( Parser::class )
|
|
->disableOriginalConstructor()
|
|
->onlyMethods( $configurableMethods )
|
|
->getMock();
|
|
}
|
|
|
|
}
|