mediawiki-extensions-Cite/tests/phpunit/CiteDbTest.php
gerritbot 198ae5b21c Replace some moved Title class uses, now MediaWiki\Title\Title
Bug: T321681
Change-Id: Idde5511e075fcec40cad12c7369abec3ee4d096c
2023-08-19 04:13:55 +00:00

49 lines
1.2 KiB
PHP

<?php
namespace Cite\Tests;
use MediaWiki\MediaWikiServices;
use MediaWiki\Title\Title;
use ParserOptions;
/**
* @group Database
*
* @license GPL-2.0-or-later
*/
class CiteDbTest extends \MediaWikiIntegrationTestCase {
/** @inheritDoc */
protected $tablesUsed = [ 'page' ];
/**
* Edge case where a parser call within `<ref>` parse clears the original parser state.
* @see https://phabricator.wikimedia.org/T240248
* @covers \Cite\ReferenceStack::pushRef
*/
public function testReferenceStackError() {
$this->insertPage( 'Cite-tracking-category-cite-error', '{{PAGENAME}}', NS_MEDIAWIKI );
$services = MediaWikiServices::getInstance();
// Reset the MessageCache in order to force it to clone a new parser.
$services->resetServiceForTesting( 'MessageCache' );
$services->getMessageCache()->enable();
$parserOutput = $services->getParser()->parse(
'
<ref name="a">text #1</ref>
<ref name="a">text #2</ref>
<ref>text #3</ref>
',
Title::makeTitle( NS_MAIN, mt_rand() ),
ParserOptions::newFromAnon()
);
$this->assertStringContainsString(
'cite_ref-2',
$parserOutput->getText(),
'Internal counter should not reset to 1 for text #3'
);
}
}