2019-11-04 16:23:29 +00:00
|
|
|
<?php
|
|
|
|
|
2019-11-12 10:45:13 +00:00
|
|
|
namespace Cite\Tests\Unit;
|
2019-11-04 16:23:29 +00:00
|
|
|
|
2019-11-19 14:12:11 +00:00
|
|
|
use Cite\Cite;
|
|
|
|
use Cite\Hooks\CiteParserHooks;
|
2019-11-04 16:23:29 +00:00
|
|
|
use Parser;
|
2019-11-12 10:45:13 +00:00
|
|
|
use ParserOptions;
|
2019-11-12 11:52:55 +00:00
|
|
|
use ParserOutput;
|
2019-11-12 10:45:13 +00:00
|
|
|
use StripState;
|
2019-11-04 16:23:29 +00:00
|
|
|
|
|
|
|
/**
|
2019-11-19 14:12:11 +00:00
|
|
|
* @coversDefaultClass \Cite\Hooks\CiteParserHooks
|
2019-11-19 10:31:08 +00:00
|
|
|
*
|
|
|
|
* @license GPL-2.0-or-later
|
2019-11-04 16:23:29 +00:00
|
|
|
*/
|
|
|
|
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' ) ]
|
|
|
|
);
|
|
|
|
|
2020-12-28 15:40:47 +00:00
|
|
|
$citeParserHooks = new CiteParserHooks();
|
|
|
|
$citeParserHooks->onParserFirstCallInit( $parser );
|
2019-11-04 16:23:29 +00:00
|
|
|
}
|
|
|
|
|
2019-11-12 10:45:13 +00:00
|
|
|
/**
|
2020-12-28 15:40:47 +00:00
|
|
|
* @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
|
2019-11-12 10:45:13 +00:00
|
|
|
*/
|
|
|
|
public function testOnParserCloned() {
|
|
|
|
$parser = $this->createMock( Parser::class );
|
2019-12-11 10:01:05 +00:00
|
|
|
$parser->extCite = $this->createMock( Cite::class );
|
2019-11-12 10:45:13 +00:00
|
|
|
|
2020-12-28 15:40:47 +00:00
|
|
|
$citeParserHooks = new CiteParserHooks();
|
2019-12-11 10:01:05 +00:00
|
|
|
/** @var Parser $parser */
|
2020-12-28 15:40:47 +00:00
|
|
|
$citeParserHooks->onParserCloned( $parser );
|
2019-11-12 10:45:13 +00:00
|
|
|
|
2019-12-11 10:01:05 +00:00
|
|
|
$this->assertFalse( isset( $parser->extCite ) );
|
2019-11-12 10:45:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers ::onParserAfterParse
|
|
|
|
*/
|
2019-11-12 11:52:55 +00:00
|
|
|
public function testAfterParseHooks() {
|
2019-11-12 10:45:13 +00:00
|
|
|
$cite = $this->createMock( Cite::class );
|
2019-12-04 15:49:56 +00:00
|
|
|
$cite->expects( $this->once() )
|
2019-11-12 10:45:13 +00:00
|
|
|
->method( 'checkRefsNoReferences' );
|
|
|
|
|
2019-11-28 10:15:19 +00:00
|
|
|
$parserOptions = $this->createMock( ParserOptions::class );
|
|
|
|
$parserOptions->method( 'getIsSectionPreview' )
|
|
|
|
->willReturn( false );
|
|
|
|
|
2019-11-12 10:45:13 +00:00
|
|
|
$parser = $this->createMock( Parser::class );
|
|
|
|
$parser->method( 'getOptions' )
|
2019-11-28 10:15:19 +00:00
|
|
|
->willReturn( $parserOptions );
|
2019-11-12 11:52:55 +00:00
|
|
|
$parser->method( 'getOutput' )
|
|
|
|
->willReturn( $this->createMock( ParserOutput::class ) );
|
2019-11-12 10:45:13 +00:00
|
|
|
$parser->extCite = $cite;
|
|
|
|
|
2019-11-28 10:15:19 +00:00
|
|
|
$text = '';
|
2020-12-28 15:40:47 +00:00
|
|
|
$citeParserHooks = new CiteParserHooks();
|
|
|
|
$citeParserHooks->onParserAfterParse( $parser, $text, $this->createMock( StripState::class ) );
|
2019-11-12 10:45:13 +00:00
|
|
|
}
|
|
|
|
|
2019-11-04 16:23:29 +00:00
|
|
|
}
|