mediawiki-extensions-Cite/tests/phpunit/unit/CiteParserHooksTest.php
Taavi Väänänen 9293e2d5ca Update Cite to use the new HookContainer/HookRunner system
Bug: T270875
Change-Id: Ieb29603cde24a1c52829c12ae431eca09ba37bf9
2020-12-28 17:55:34 +02:00

88 lines
2.2 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->createMock( Parser::class );
$parser->expects( $this->exactly( 2 ) )
->method( 'setHook' )
->withConsecutive(
[ 'ref', $this->isType( 'callable' ) ],
[ 'references', $this->isType( 'callable' ) ]
);
$citeParserHooks = new CiteParserHooks();
$citeParserHooks->onParserFirstCallInit( $parser );
}
/**
* @covers ::onParserClearState
*/
public function testOnParserClearState() {
$parser = $this->createMock( Parser::class );
$parser->extCite = $this->createMock( Cite::class );
$citeParserHooks = new CiteParserHooks();
/** @var Parser $parser */
$citeParserHooks->onParserClearState( $parser );
$this->assertFalse( isset( $parser->extCite ) );
}
/**
* @covers ::onParserCloned
*/
public function testOnParserCloned() {
$parser = $this->createMock( Parser::class );
$parser->extCite = $this->createMock( Cite::class );
$citeParserHooks = new CiteParserHooks();
/** @var Parser $parser */
$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->createMock( Parser::class );
$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 ) );
}
}