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
|
|
|
|
|
|
|
/**
|
2023-12-15 11:12:16 +00:00
|
|
|
* @covers \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 {
|
|
|
|
|
|
|
|
public function testOnParserFirstCallInit() {
|
2023-07-27 09:39:46 +00:00
|
|
|
$parser = $this->createNoOpMock( Parser::class, [ 'setHook' ] );
|
2023-11-21 23:15:20 +00:00
|
|
|
$expectedTags = [ 'ref' => true, 'references' => true ];
|
2019-11-04 16:23:29 +00:00
|
|
|
$parser->expects( $this->exactly( 2 ) )
|
|
|
|
->method( 'setHook' )
|
2023-11-21 23:15:20 +00:00
|
|
|
->willReturnCallback( function ( $tag ) use ( &$expectedTags ) {
|
|
|
|
$this->assertArrayHasKey( $tag, $expectedTags );
|
|
|
|
unset( $expectedTags[$tag] );
|
|
|
|
} );
|
2019-11-04 16:23:29 +00:00
|
|
|
|
2020-12-28 15:40:47 +00:00
|
|
|
$citeParserHooks = new CiteParserHooks();
|
|
|
|
$citeParserHooks->onParserFirstCallInit( $parser );
|
2019-11-04 16:23:29 +00:00
|
|
|
}
|
|
|
|
|
2020-12-28 15:40:47 +00:00
|
|
|
public function testOnParserClearState() {
|
2023-12-15 11:43:49 +00:00
|
|
|
$parser = $this->createNoOpMock( Parser::class );
|
2020-12-28 15:40:47 +00:00
|
|
|
$parser->extCite = $this->createMock( Cite::class );
|
|
|
|
|
|
|
|
$citeParserHooks = new CiteParserHooks();
|
|
|
|
$citeParserHooks->onParserClearState( $parser );
|
|
|
|
|
2023-12-12 09:09:45 +00:00
|
|
|
$this->assertObjectNotHasProperty( 'extCite', $parser );
|
2020-12-28 15:40:47 +00:00
|
|
|
}
|
|
|
|
|
2019-11-12 10:45:13 +00:00
|
|
|
public function testOnParserCloned() {
|
2023-12-15 11:43:49 +00:00
|
|
|
$parser = $this->createNoOpMock( 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();
|
|
|
|
$citeParserHooks->onParserCloned( $parser );
|
2019-11-12 10:45:13 +00:00
|
|
|
|
2023-12-12 09:09:45 +00:00
|
|
|
$this->assertObjectNotHasProperty( 'extCite', $parser );
|
2019-11-12 10:45:13 +00:00
|
|
|
}
|
|
|
|
|
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 );
|
|
|
|
|
2023-12-15 11:43:49 +00:00
|
|
|
$parser = $this->createNoOpMock( Parser::class, [ 'getOptions', 'getOutput' ] );
|
2019-11-12 10:45:13 +00:00
|
|
|
$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
|
|
|
}
|