wiki.techinc.nl/tests/phpunit/unit/includes/parser/ParserObserverTest.php
Cindy Cicalese eed48e402b Detect and monitor against multiple Parser invocation during edit requests
Bug: T288707
Change-Id: I0cca8f9bcf1d6e964b8b06c0c4490e83f4fb1de5
2021-09-23 16:12:40 -05:00

53 lines
1.2 KiB
PHP

<?php
use MediaWiki\Parser\ParserObserver;
/**
* @covers \MediaWiki\Parser\ParserObserver
*/
class ParserObserverTest extends MediaWikiUnitTestCase {
/**
* @param string $hashOne
* @param string $hashTwo
* @param array $expects
*
* @dataProvider provideDuplicateParse
*/
public function testDuplicateParse( string $hashOne, string $hashTwo, array $expects ) {
$logger = new TestLogger( true );
// ::makeTitle allows us to create a title without needing any services
$title = Title::makeTitle(
NS_PROJECT,
'Duplicate Parse Test'
);
$options = $this->createNoOpMock( ParserOptions::class, [ 'optionsHash' ] );
$options->method( 'optionsHash' )->willReturnOnConsecutiveCalls( $hashOne, $hashTwo );
$output = new ParserOutput();
$observer = new ParserObserver( $logger );
$observer->notifyParse( $title, null, $options, $output );
$observer->notifyParse( $title, null, $options, $output );
$this->assertArrayEquals( $expects, $logger->getBuffer() );
}
public function provideDuplicateParse() {
yield [
'foo',
'bar',
[]
];
yield [
'foo',
'foo',
[
[
'debug',
'MediaWiki\Parser\ParserObserver::notifyParse: Possibly redundant parse!'
]
]
];
}
}