mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Cite
synced 2024-12-03 19:16:09 +00:00
7157c7f494
Note this codebase appears to be dual-licensed. Some files mention MIT, but extension.json and some other files mention GPL. Since WMDE typically uses GPL, I will continue to mark the files we created as such. Change-Id: I126da10f7fb13a6d4c99e96e72d024b2e5ecee06
87 lines
2 KiB
PHP
87 lines
2 KiB
PHP
<?php
|
|
|
|
namespace Cite\Tests\Unit;
|
|
|
|
use Cite;
|
|
use CiteParserHooks;
|
|
use Parser;
|
|
use ParserOptions;
|
|
use ParserOutput;
|
|
use StripState;
|
|
|
|
/**
|
|
* @coversDefaultClass \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::onParserFirstCallInit( $parser );
|
|
|
|
$this->assertInstanceOf( Cite::class, $parser->extCite );
|
|
}
|
|
|
|
/**
|
|
* @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
|
|
*/
|
|
public function testAfterParseHooks() {
|
|
$cite = $this->createMock( Cite::class );
|
|
$cite->expects( $this->exactly( 2 ) )
|
|
->method( 'checkRefsNoReferences' );
|
|
|
|
$parser = $this->createMock( Parser::class );
|
|
$parser->method( 'getOptions' )
|
|
->willReturn( $this->createMock( ParserOptions::class ) );
|
|
$parser->method( 'getOutput' )
|
|
->willReturn( $this->createMock( ParserOutput::class ) );
|
|
$parser->extCite = $cite;
|
|
|
|
CiteParserHooks::onParserAfterParse( $parser, $text, $this->createMock( StripState::class ) );
|
|
CiteParserHooks::onParserBeforeTidy( $parser, $text );
|
|
}
|
|
|
|
}
|