mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Cite
synced 2024-12-12 15:15:12 +00:00
c71109b97b
- Avoid withConsecutive() Bug: T342110 Change-Id: Icb951b461c5e6ea1ced2ab8a183c53265d4a2b4f
98 lines
2.5 KiB
PHP
98 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace Cite\Tests\Unit;
|
|
|
|
use Cite\Cite;
|
|
use Cite\Hooks\CiteParserHooks;
|
|
use Parser;
|
|
use ParserOptions;
|
|
use ParserOutput;
|
|
use StripState;
|
|
|
|
/**
|
|
* @coversDefaultClass \Cite\Hooks\CiteParserHooks
|
|
*
|
|
* @license GPL-2.0-or-later
|
|
*/
|
|
class CiteParserHooksTest extends \MediaWikiUnitTestCase {
|
|
|
|
/**
|
|
* @covers ::onParserFirstCallInit
|
|
*/
|
|
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 );
|
|
}
|
|
|
|
/**
|
|
* @covers ::onParserClearState
|
|
*/
|
|
public function testOnParserClearState() {
|
|
$parser = $this->createParser();
|
|
$parser->extCite = $this->createMock( Cite::class );
|
|
|
|
$citeParserHooks = new CiteParserHooks();
|
|
$citeParserHooks->onParserClearState( $parser );
|
|
|
|
$this->assertFalse( isset( $parser->extCite ) );
|
|
}
|
|
|
|
/**
|
|
* @covers ::onParserCloned
|
|
*/
|
|
public function testOnParserCloned() {
|
|
$parser = $this->createParser();
|
|
$parser->extCite = $this->createMock( Cite::class );
|
|
|
|
$citeParserHooks = new CiteParserHooks();
|
|
$citeParserHooks->onParserCloned( $parser );
|
|
|
|
$this->assertFalse( isset( $parser->extCite ) );
|
|
}
|
|
|
|
/**
|
|
* @covers ::onParserAfterParse
|
|
*/
|
|
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 ) );
|
|
}
|
|
|
|
/**
|
|
* @param array $configurableMethods
|
|
* @return Parser
|
|
*/
|
|
private function createParser( $configurableMethods = [] ) {
|
|
return $this->getMockBuilder( Parser::class )
|
|
->disableOriginalConstructor()
|
|
->onlyMethods( $configurableMethods )
|
|
->getMock();
|
|
}
|
|
|
|
}
|