aboutsummaryrefslogtreecommitdiffstats
path: root/tests/phpunit/unit/includes/parser/ParserObserverTest.php
blob: 8f978b45f534ebd20d988dab1e3324b9b25c049e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php

namespace MediaWiki\Tests\Parser;

use DummyContentForTesting;
use MediaWiki\Parser\ParserObserver;
use MediaWiki\Parser\ParserOutput;
use MediaWiki\Title\Title;
use MediaWikiUnitTestCase;
use ParserOptions;
use TestLogger;

/**
 * @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 );

		$content = new DummyContentForTesting( "hello world" );

		$output = new ParserOutput();
		$observer = new ParserObserver( $logger );
		$observer->notifyParse( $title, null, $options, $content, $output );
		$observer->notifyParse( $title, null, $options, $content, $output );

		$this->assertArrayEquals( $expects, $logger->getBuffer() );
	}

	public static function provideDuplicateParse() {
		yield [
			'foo',
			'bar',
			[]
		];
		yield [
			'foo',
			'foo',
			[
				[
					'debug',
					'MediaWiki\Parser\ParserObserver::notifyParse: Possibly redundant parse!'
				]
			]
		];
	}
}