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' ) ]
|
|
|
|
);
|
|
|
|
|
|
|
|
CiteParserHooks::onParserFirstCallInit( $parser );
|
|
|
|
|
|
|
|
$this->assertInstanceOf( Cite::class, $parser->extCite );
|
|
|
|
}
|
|
|
|
|
2019-11-12 10:45:13 +00:00
|
|
|
/**
|
|
|
|
* @covers ::onParserClearState
|
|
|
|
*/
|
|
|
|
public function testOnParserClearState() {
|
|
|
|
$cite = $this->createMock( Cite::class );
|
|
|
|
$cite->expects( $this->once() )
|
|
|
|
->method( 'clearState' );
|
|
|
|
|
|
|
|
$parser = $this->createMock( Parser::class );
|
|
|
|
$parser->extCite = $cite;
|
|
|
|
|
|
|
|
CiteParserHooks::onParserClearState( $parser );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers ::onParserCloned
|
|
|
|
*/
|
|
|
|
public function testOnParserCloned() {
|
|
|
|
$cite = $this->createMock( Cite::class );
|
|
|
|
$cite->expects( $this->once() )
|
|
|
|
->method( 'clearState' );
|
|
|
|
|
|
|
|
$parser = $this->createMock( Parser::class );
|
|
|
|
$parser->extCite = $cite;
|
|
|
|
|
|
|
|
CiteParserHooks::onParserCloned( $parser );
|
|
|
|
|
|
|
|
$this->assertNotSame( $cite, $parser->extCite );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers ::onParserAfterParse
|
|
|
|
* @covers ::onParserBeforeTidy
|
|
|
|
*/
|
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-11-12 11:52:55 +00:00
|
|
|
$cite->expects( $this->exactly( 2 ) )
|
2019-11-12 10:45:13 +00:00
|
|
|
->method( 'checkRefsNoReferences' );
|
|
|
|
|
|
|
|
$parser = $this->createMock( Parser::class );
|
|
|
|
$parser->method( 'getOptions' )
|
|
|
|
->willReturn( $this->createMock( ParserOptions::class ) );
|
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-12 11:52:55 +00:00
|
|
|
CiteParserHooks::onParserAfterParse( $parser, $text, $this->createMock( StripState::class ) );
|
2019-11-12 10:45:13 +00:00
|
|
|
CiteParserHooks::onParserBeforeTidy( $parser, $text );
|
|
|
|
}
|
|
|
|
|
2019-11-04 16:23:29 +00:00
|
|
|
}
|