2022-06-17 14:00:27 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
use MediaWiki\Config\ServiceOptions;
|
|
|
|
|
use MediaWiki\Json\JsonCodec;
|
|
|
|
|
use MediaWiki\Parser\ParserCacheFactory;
|
2022-09-26 06:18:43 +00:00
|
|
|
use MediaWiki\Parser\Parsoid\PageBundleParserOutputConverter;
|
2022-06-17 14:00:27 +00:00
|
|
|
use MediaWiki\Parser\Parsoid\ParsoidOutputAccess;
|
2022-08-30 10:26:39 +00:00
|
|
|
use MediaWiki\Revision\MutableRevisionRecord;
|
2022-06-17 14:00:27 +00:00
|
|
|
use MediaWiki\Revision\RevisionAccessException;
|
|
|
|
|
use MediaWiki\Revision\SlotRecord;
|
|
|
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
|
|
|
|
use Psr\Log\NullLogger;
|
|
|
|
|
use Wikimedia\Parsoid\Config\PageConfig;
|
|
|
|
|
use Wikimedia\Parsoid\Core\PageBundle;
|
|
|
|
|
use Wikimedia\Parsoid\Parsoid;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers \MediaWiki\Parser\Parsoid\ParsoidOutputAccess
|
|
|
|
|
* @group Database
|
|
|
|
|
*/
|
|
|
|
|
class ParsoidOutputAccessTest extends MediaWikiIntegrationTestCase {
|
|
|
|
|
private const WIKITEXT = 'Hello \'\'\'Parsoid\'\'\'!';
|
|
|
|
|
private const MOCKED_HTML = 'mocked HTML';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param int $expectedCalls
|
|
|
|
|
*
|
|
|
|
|
* @return MockObject|Parsoid
|
|
|
|
|
*/
|
|
|
|
|
private function newMockParsoid( $expectedCalls = 1 ) {
|
|
|
|
|
$parsoid = $this->createNoOpMock( Parsoid::class, [ 'wikitext2html' ] );
|
|
|
|
|
$parsoid->expects( $this->exactly( $expectedCalls ) )->method( 'wikitext2html' )->willReturnCallback(
|
|
|
|
|
static function ( PageConfig $pageConfig ) {
|
|
|
|
|
$wikitext = $pageConfig->getRevisionContent()->getContent( SlotRecord::MAIN );
|
2022-09-09 09:32:17 +00:00
|
|
|
|
|
|
|
|
return new PageBundle(
|
|
|
|
|
self::MOCKED_HTML . ' of ' . $wikitext,
|
|
|
|
|
[ 'parsoid-data' ],
|
|
|
|
|
[ 'mw-data' ],
|
|
|
|
|
Parsoid::defaultHTMLVersion(),
|
|
|
|
|
[ 'content-language' => 'en' ],
|
|
|
|
|
$pageConfig->getContentModel()
|
|
|
|
|
);
|
2022-06-17 14:00:27 +00:00
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return $parsoid;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param int $expectedParses
|
|
|
|
|
* @param array $parsoidCacheConfig
|
|
|
|
|
*
|
|
|
|
|
* @return ParsoidOutputAccess
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
|
|
|
|
private function getParsoidOutputAccessWithCache( $expectedParses, $parsoidCacheConfig = [] ) {
|
|
|
|
|
$stats = new NullStatsdDataFactory();
|
|
|
|
|
$services = $this->getServiceContainer();
|
|
|
|
|
|
|
|
|
|
$parsoidCacheConfig += [
|
|
|
|
|
'CacheThresholdTime' => 0,
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$parserCacheFactoryOptions = new ServiceOptions( ParserCacheFactory::CONSTRUCTOR_OPTIONS, [
|
|
|
|
|
'CacheEpoch' => '20200202112233',
|
|
|
|
|
'OldRevisionParserCacheExpireTime' => 60 * 60,
|
|
|
|
|
] );
|
|
|
|
|
|
|
|
|
|
$parserCacheFactory = new ParserCacheFactory(
|
|
|
|
|
new HashBagOStuff(),
|
|
|
|
|
new WANObjectCache( [ 'cache' => new HashBagOStuff(), ] ),
|
|
|
|
|
$this->createHookContainer(),
|
|
|
|
|
new JsonCodec(),
|
|
|
|
|
new NullStatsdDataFactory(),
|
|
|
|
|
new NullLogger(),
|
|
|
|
|
$parserCacheFactoryOptions,
|
|
|
|
|
$services->getTitleFactory(),
|
|
|
|
|
$services->getWikiPageFactory()
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return new ParsoidOutputAccess(
|
|
|
|
|
new ServiceOptions(
|
|
|
|
|
ParsoidOutputAccess::CONSTRUCTOR_OPTIONS,
|
|
|
|
|
[ 'ParsoidCacheConfig' => $parsoidCacheConfig ]
|
|
|
|
|
),
|
|
|
|
|
$parserCacheFactory,
|
2022-09-13 15:52:44 +00:00
|
|
|
$services->getPageStore(),
|
2022-06-17 14:00:27 +00:00
|
|
|
$services->getRevisionLookup(),
|
|
|
|
|
$services->getGlobalIdGenerator(),
|
|
|
|
|
$stats,
|
|
|
|
|
$this->newMockParsoid( $expectedParses ),
|
2022-06-29 17:01:21 +00:00
|
|
|
$services->getParsoidSiteConfig(),
|
2022-06-17 14:00:27 +00:00
|
|
|
$services->getParsoidPageConfigFactory()
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return ParserOptions
|
|
|
|
|
*/
|
|
|
|
|
private function getParserOptions() {
|
|
|
|
|
return ParserOptions::newFromAnon();
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-28 10:30:44 +00:00
|
|
|
private function getHtml( $value ) {
|
|
|
|
|
if ( $value instanceof StatusValue ) {
|
|
|
|
|
$value = $value->getValue();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( $value instanceof ParserOutput ) {
|
|
|
|
|
$value = $value->getRawText();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$html = preg_replace( '/<!--.*?-->/s', '', $value );
|
|
|
|
|
$html = trim( preg_replace( '/[\r\n]{2,}/s', "\n", $html ) );
|
|
|
|
|
$html = trim( preg_replace( '/\s{2,}/s', ' ', $html ) );
|
|
|
|
|
return $html;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function assertContainsHtml( $needle, $actual, $msg = '' ) {
|
|
|
|
|
$this->assertNotNull( $actual );
|
|
|
|
|
|
|
|
|
|
if ( $actual instanceof StatusValue ) {
|
|
|
|
|
$this->assertStatusOK( $actual, 'isOK' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->assertStringContainsString( $needle, $this->getHtml( $actual ), $msg );
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-17 14:00:27 +00:00
|
|
|
/**
|
|
|
|
|
* @covers \MediaWiki\Parser\Parsoid\ParsoidOutputAccess::getParserOutput
|
|
|
|
|
*/
|
|
|
|
|
public function testGetParserOutputThrowsIfRevisionNotFound() {
|
|
|
|
|
$access = $this->getParsoidOutputAccessWithCache( 0 );
|
|
|
|
|
$parserOptions = $this->getParserOptions();
|
|
|
|
|
|
|
|
|
|
$page = $this->getNonexistingTestPage( __METHOD__ );
|
|
|
|
|
|
|
|
|
|
$this->expectException( RevisionAccessException::class );
|
|
|
|
|
$access->getParserOutput( $page, $parserOptions );
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-29 17:01:21 +00:00
|
|
|
/**
|
|
|
|
|
* @covers \MediaWiki\Parser\Parsoid\ParsoidOutputAccess::getParserOutput
|
|
|
|
|
*/
|
|
|
|
|
public function testGetParserOutputThrowsIfNotWikitext() {
|
|
|
|
|
$access = $this->getParsoidOutputAccessWithCache( 0 );
|
|
|
|
|
$parserOptions = $this->getParserOptions();
|
|
|
|
|
|
|
|
|
|
$page = $this->getNonexistingTestPage( __METHOD__ );
|
|
|
|
|
$updater = $page->newPageUpdater( $this->getTestUser()->getUserIdentity() );
|
|
|
|
|
$updater->setContent( SlotRecord::MAIN, new JavaScriptContent( '{}' ) );
|
|
|
|
|
$updater->saveRevision( CommentStoreComment::newUnsavedComment( 'testing' ) );
|
|
|
|
|
|
|
|
|
|
$this->expectException( UnexpectedValueException::class );
|
|
|
|
|
$access->getParserOutput( $page, $parserOptions );
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-17 14:00:27 +00:00
|
|
|
/**
|
|
|
|
|
* Tests that getParserOutput() will return output.
|
|
|
|
|
*
|
|
|
|
|
* @covers \MediaWiki\Parser\Parsoid\ParsoidOutputAccess::getParserOutput
|
|
|
|
|
* @covers \MediaWiki\Parser\Parsoid\ParsoidOutputAccess::getParsoidRenderID
|
|
|
|
|
*/
|
|
|
|
|
public function testGetParserOutput() {
|
|
|
|
|
$access = $this->getParsoidOutputAccessWithCache( 1 );
|
|
|
|
|
$parserOptions = $this->getParserOptions();
|
|
|
|
|
|
|
|
|
|
$page = $this->getNonexistingTestPage( __METHOD__ );
|
|
|
|
|
$this->editPage( $page, self::WIKITEXT );
|
|
|
|
|
|
2022-06-28 10:30:44 +00:00
|
|
|
$status = $access->getParserOutput( $page, $parserOptions );
|
|
|
|
|
$this->assertContainsHtml( self::MOCKED_HTML . ' of ' . self::WIKITEXT, $status );
|
|
|
|
|
|
|
|
|
|
$output = $status->getValue();
|
2022-06-17 14:00:27 +00:00
|
|
|
|
|
|
|
|
// check that getParsoidRenderID() doesn't throw
|
|
|
|
|
$this->assertNotNull( $access->getParsoidRenderID( $output ) );
|
2022-06-28 09:49:36 +00:00
|
|
|
|
2022-09-26 06:18:43 +00:00
|
|
|
// Ensure that we can still create a valid instance of PageBundle from the ParserOutput
|
|
|
|
|
$pageBundle = PageBundleParserOutputConverter::pageBundleFromParserOutput( $output );
|
2022-06-28 09:49:36 +00:00
|
|
|
$this->assertSame( $output->getRawText(), $pageBundle->html );
|
|
|
|
|
|
2022-09-26 06:18:43 +00:00
|
|
|
// Ensure that the expected mw and parsoid fields are set in the PageBundle
|
2022-06-28 09:49:36 +00:00
|
|
|
$this->assertNotEmpty( $pageBundle->mw );
|
|
|
|
|
$this->assertNotEmpty( $pageBundle->parsoid );
|
2022-09-09 09:32:17 +00:00
|
|
|
$this->assertNotEmpty( $pageBundle->headers );
|
|
|
|
|
$this->assertNotEmpty( $pageBundle->version );
|
2022-06-17 14:00:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Tests that getParserOutput() will place the generated output for the latest revision
|
|
|
|
|
* in the parsoid parser cache.
|
|
|
|
|
*
|
|
|
|
|
* @covers \MediaWiki\Parser\Parsoid\ParsoidOutputAccess::getParserOutput
|
2022-09-13 15:52:44 +00:00
|
|
|
* @covers \MediaWiki\Parser\Parsoid\ParsoidOutputAccess::getCachedParserOutputInternal
|
2022-06-17 14:00:27 +00:00
|
|
|
*/
|
|
|
|
|
public function testLatestRevisionIsCached() {
|
|
|
|
|
$access = $this->getParsoidOutputAccessWithCache( 1 );
|
|
|
|
|
$parserOptions = $this->getParserOptions();
|
|
|
|
|
|
|
|
|
|
$page = $this->getNonexistingTestPage( __METHOD__ );
|
|
|
|
|
$this->editPage( $page, self::WIKITEXT );
|
|
|
|
|
|
2022-06-28 10:30:44 +00:00
|
|
|
$status = $access->getParserOutput( $page, $parserOptions );
|
|
|
|
|
$this->assertContainsHtml( self::MOCKED_HTML . ' of ' . self::WIKITEXT, $status );
|
2022-06-17 14:00:27 +00:00
|
|
|
|
2022-09-13 15:52:44 +00:00
|
|
|
// Get the ParserOutput from cache
|
|
|
|
|
$status = $access->getCachedParserOutput( $page, $parserOptions );
|
|
|
|
|
$this->assertContainsHtml( self::MOCKED_HTML . ' of ' . self::WIKITEXT, $status );
|
|
|
|
|
|
|
|
|
|
// Get the ParserOutput from cache, without supplying a PageRecord
|
|
|
|
|
$status = $access->getCachedParserOutput( $page->getTitle(), $parserOptions );
|
|
|
|
|
$this->assertContainsHtml( self::MOCKED_HTML . ' of ' . self::WIKITEXT, $status );
|
|
|
|
|
|
2022-06-17 14:00:27 +00:00
|
|
|
// Get the ParserOutput again, this should not trigger a new parse.
|
2022-06-28 10:30:44 +00:00
|
|
|
$status = $access->getParserOutput( $page, $parserOptions );
|
|
|
|
|
$this->assertContainsHtml( self::MOCKED_HTML . ' of ' . self::WIKITEXT, $status );
|
2022-06-17 14:00:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Tests that getParserOutput() will force a parse since we know that
|
|
|
|
|
* the revision is not in the cache.
|
|
|
|
|
*
|
|
|
|
|
* @covers \MediaWiki\Parser\Parsoid\ParsoidOutputAccess::getParserOutput
|
|
|
|
|
*/
|
|
|
|
|
public function testLatestRevisionWithForceParse() {
|
|
|
|
|
$access = $this->getParsoidOutputAccessWithCache( 2 );
|
|
|
|
|
$parserOptions = $this->getParserOptions();
|
|
|
|
|
|
|
|
|
|
$page = $this->getNonexistingTestPage( __METHOD__ );
|
|
|
|
|
$this->editPage( $page, self::WIKITEXT );
|
|
|
|
|
|
2022-06-28 10:30:44 +00:00
|
|
|
$status = $access->getParserOutput( $page, $parserOptions );
|
|
|
|
|
$this->assertContainsHtml( self::MOCKED_HTML . ' of ' . self::WIKITEXT, $status );
|
2022-06-17 14:00:27 +00:00
|
|
|
|
|
|
|
|
// Get the ParserOutput again, this should trigger a new parse
|
|
|
|
|
// since we're forcing it to.
|
2022-06-28 10:30:44 +00:00
|
|
|
$status = $access->getParserOutput(
|
2022-06-17 14:00:27 +00:00
|
|
|
$page,
|
|
|
|
|
$parserOptions,
|
|
|
|
|
null,
|
|
|
|
|
ParsoidOutputAccess::OPT_FORCE_PARSE
|
|
|
|
|
);
|
2022-06-28 10:30:44 +00:00
|
|
|
$this->assertContainsHtml( self::MOCKED_HTML . ' of ' . self::WIKITEXT, $status );
|
2022-06-17 14:00:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function provideCacheThresholdData() {
|
|
|
|
|
return [
|
|
|
|
|
yield "fast parse" => [ 1, 2 ], // high threshold, no caching
|
|
|
|
|
yield "slow parse" => [ 0, 1 ], // low threshold, caching
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provideCacheThresholdData()
|
|
|
|
|
*/
|
|
|
|
|
public function testHtmlWithCacheThreshold(
|
|
|
|
|
$cacheThresholdTime,
|
|
|
|
|
$expectedCalls
|
|
|
|
|
) {
|
|
|
|
|
$page = $this->getExistingTestPage( __METHOD__ );
|
|
|
|
|
$parsoidCacheConfig = [
|
|
|
|
|
'CacheThresholdTime' => $cacheThresholdTime
|
|
|
|
|
];
|
|
|
|
|
$parserOptions = $this->getParserOptions();
|
|
|
|
|
|
|
|
|
|
$access = $this->getParsoidOutputAccessWithCache( $expectedCalls, $parsoidCacheConfig );
|
2022-06-28 10:30:44 +00:00
|
|
|
$status = $access->getParserOutput( $page, $parserOptions );
|
|
|
|
|
$this->assertContainsHtml( self::MOCKED_HTML, $status );
|
2022-06-17 14:00:27 +00:00
|
|
|
|
2022-06-28 10:30:44 +00:00
|
|
|
$status = $access->getParserOutput( $page, $parserOptions );
|
|
|
|
|
$this->assertContainsHtml( self::MOCKED_HTML, $status );
|
2022-06-17 14:00:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testOldRevisionIsCached() {
|
|
|
|
|
$access = $this->getParsoidOutputAccessWithCache( 1 );
|
|
|
|
|
$parserOptions = $this->getParserOptions();
|
|
|
|
|
|
|
|
|
|
$page = $this->getNonexistingTestPage( __METHOD__ );
|
|
|
|
|
$status1 = $this->editPage( $page, self::WIKITEXT );
|
|
|
|
|
$rev = $status1->getValue()['revision-record'];
|
|
|
|
|
|
|
|
|
|
// Make an edit so that the revision we're getting output
|
|
|
|
|
// for below is not the current revision.
|
|
|
|
|
$this->editPage( $page, 'Second revision' );
|
|
|
|
|
|
|
|
|
|
$access->getParserOutput( $page, $parserOptions, $rev );
|
|
|
|
|
|
2022-09-13 15:52:44 +00:00
|
|
|
// Get the ParserOutput from cache, using revision object
|
|
|
|
|
$status = $access->getCachedParserOutput( $page, $parserOptions, $rev );
|
|
|
|
|
$this->assertContainsHtml( self::MOCKED_HTML . ' of ' . self::WIKITEXT, $status );
|
|
|
|
|
|
|
|
|
|
// Get the ParserOutput from cache, using revision ID
|
|
|
|
|
$status = $access->getCachedParserOutput( $page->getTitle(), $parserOptions, $rev->getId() );
|
|
|
|
|
$this->assertContainsHtml( self::MOCKED_HTML . ' of ' . self::WIKITEXT, $status );
|
|
|
|
|
|
2022-06-17 14:00:27 +00:00
|
|
|
// Get the ParserOutput again, this should not trigger a new parse.
|
2022-06-28 10:30:44 +00:00
|
|
|
$status = $access->getParserOutput( $page, $parserOptions, $rev );
|
|
|
|
|
$this->assertContainsHtml( self::MOCKED_HTML . ' of ' . self::WIKITEXT, $status );
|
2022-06-17 14:00:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testGetParserOutputWithOldRevision() {
|
|
|
|
|
$access = $this->getParsoidOutputAccessWithCache( 2 );
|
|
|
|
|
$parserOptions = $this->getParserOptions();
|
|
|
|
|
|
|
|
|
|
$page = $this->getNonexistingTestPage( __METHOD__ );
|
|
|
|
|
$status1 = $this->editPage( $page, self::WIKITEXT );
|
|
|
|
|
$rev1 = $status1->getValue()['revision-record'];
|
|
|
|
|
|
|
|
|
|
$this->editPage( $page, 'Second revision' );
|
|
|
|
|
|
2022-06-28 10:30:44 +00:00
|
|
|
$status2 = $access->getParserOutput( $page, $parserOptions );
|
|
|
|
|
$this->assertContainsHtml( self::MOCKED_HTML . ' of Second revision', $status2 );
|
2022-06-17 14:00:27 +00:00
|
|
|
|
2022-06-28 10:30:44 +00:00
|
|
|
$status1 = $access->getParserOutput( $page, $parserOptions, $rev1 );
|
|
|
|
|
$this->assertContainsHtml( self::MOCKED_HTML . ' of ' . self::WIKITEXT, $status1 );
|
2022-09-13 15:52:44 +00:00
|
|
|
|
|
|
|
|
// Again, using just the revision ID
|
|
|
|
|
$status1 = $access->getParserOutput( $page, $parserOptions, $rev1->getId() );
|
|
|
|
|
$this->assertContainsHtml( self::MOCKED_HTML . ' of ' . self::WIKITEXT, $status1 );
|
2022-06-17 14:00:27 +00:00
|
|
|
|
|
|
|
|
// check that getParsoidRenderID() doesn't throw
|
2022-06-28 10:30:44 +00:00
|
|
|
$output1 = $status1->getValue();
|
2022-06-17 14:00:27 +00:00
|
|
|
$this->assertNotNull( $access->getParsoidRenderID( $output1 ) );
|
|
|
|
|
}
|
2022-06-29 17:01:21 +00:00
|
|
|
|
|
|
|
|
public function provideSupportsContentModels() {
|
|
|
|
|
yield [ CONTENT_MODEL_WIKITEXT, true ];
|
|
|
|
|
yield [ CONTENT_MODEL_JSON, true ];
|
|
|
|
|
yield [ CONTENT_MODEL_JAVASCRIPT, false ];
|
|
|
|
|
yield [ 'xyzzy', false ];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provideSupportsContentModels
|
|
|
|
|
*/
|
|
|
|
|
public function testSupportsContentModel( $model, $expected ) {
|
|
|
|
|
$access = $this->getParsoidOutputAccessWithCache( 0 );
|
|
|
|
|
$this->assertSame( $expected, $access->supportsContentModel( $model ) );
|
|
|
|
|
}
|
2022-08-30 10:26:39 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers \MediaWiki\Parser\Parsoid\ParsoidOutputAccess::parse
|
|
|
|
|
* @covers \MediaWiki\Parser\Parsoid\ParsoidOutputAccess::parseInternal
|
|
|
|
|
*/
|
|
|
|
|
public function testParseWithPageRecordAndNoRevision() {
|
|
|
|
|
$pageRecord = $this->getExistingTestPage( __METHOD__ )->toPageRecord();
|
|
|
|
|
$pOpts = ParserOptions::newFromAnon();
|
|
|
|
|
|
|
|
|
|
$parsoidOutputAccess = $this->getServiceContainer()->getParsoidOutputAccess();
|
|
|
|
|
$status = $parsoidOutputAccess->parse( $pageRecord, $pOpts, null );
|
|
|
|
|
|
|
|
|
|
$this->assertInstanceOf( Status::class, $status );
|
|
|
|
|
$this->assertTrue( $status->isOK() );
|
|
|
|
|
$this->assertInstanceOf( ParserOutput::class, $status->getValue() );
|
|
|
|
|
|
|
|
|
|
/** @var ParserOutput $parserOutput */
|
|
|
|
|
$parserOutput = $status->getValue();
|
|
|
|
|
$this->assertStringContainsString( __METHOD__, $parserOutput->getText() );
|
|
|
|
|
$this->assertNotEmpty( $parserOutput->getExtensionData( 'parsoid-render-id' ) );
|
|
|
|
|
$this->assertNotEmpty( $parserOutput->getCacheRevisionId() );
|
|
|
|
|
$this->assertNotEmpty( $parserOutput->getCacheTime() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers \MediaWiki\Parser\Parsoid\ParsoidOutputAccess::parse
|
|
|
|
|
* @covers \MediaWiki\Parser\Parsoid\ParsoidOutputAccess::parseInternal
|
|
|
|
|
*/
|
|
|
|
|
public function testParseWithPageRecordAndRevision() {
|
|
|
|
|
$page = $this->getExistingTestPage( __METHOD__ );
|
|
|
|
|
$pageRecord = $page->toPageRecord();
|
|
|
|
|
$pOpts = ParserOptions::newFromAnon();
|
|
|
|
|
$revRecord = $page->getRevisionRecord();
|
|
|
|
|
|
|
|
|
|
$parsoidOutputAccess = $this->getServiceContainer()->getParsoidOutputAccess();
|
|
|
|
|
$status = $parsoidOutputAccess->parse( $pageRecord, $pOpts, $revRecord );
|
|
|
|
|
|
|
|
|
|
$this->assertInstanceOf( Status::class, $status );
|
|
|
|
|
$this->assertTrue( $status->isOK() );
|
|
|
|
|
$this->assertInstanceOf( ParserOutput::class, $status->getValue() );
|
|
|
|
|
|
|
|
|
|
/** @var ParserOutput $parserOutput */
|
|
|
|
|
$parserOutput = $status->getValue();
|
|
|
|
|
$this->assertStringContainsString( __METHOD__, $parserOutput->getText() );
|
|
|
|
|
$this->assertNotEmpty( $parserOutput->getExtensionData( 'parsoid-render-id' ) );
|
|
|
|
|
$this->assertNotEmpty( $parserOutput->getCacheRevisionId() );
|
|
|
|
|
$this->assertNotEmpty( $parserOutput->getCacheTime() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers \MediaWiki\Parser\Parsoid\ParsoidOutputAccess::parse
|
|
|
|
|
* @covers \MediaWiki\Parser\Parsoid\ParsoidOutputAccess::parseInternal
|
|
|
|
|
*/
|
|
|
|
|
public function testParseWithNonExistingPageAndFakeRevision() {
|
|
|
|
|
$page = $this->getNonexistingTestPage( __METHOD__ );
|
|
|
|
|
$pOpts = ParserOptions::newFromAnon();
|
|
|
|
|
|
|
|
|
|
// Create a fake revision record
|
|
|
|
|
$revRecord = new MutableRevisionRecord( $page->getTitle() );
|
|
|
|
|
$revRecord->setId( 0 );
|
|
|
|
|
$revRecord->setPageId( $page->getId() );
|
|
|
|
|
$revRecord->setContent(
|
|
|
|
|
SlotRecord::MAIN,
|
|
|
|
|
new WikitextContent( 'test' )
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$parsoidOutputAccess = $this->getServiceContainer()->getParsoidOutputAccess();
|
2022-09-21 17:12:39 +00:00
|
|
|
$status = $parsoidOutputAccess->parse( $page->getTitle(), $pOpts, $revRecord );
|
2022-08-30 10:26:39 +00:00
|
|
|
|
|
|
|
|
$this->assertInstanceOf( Status::class, $status );
|
|
|
|
|
$this->assertTrue( $status->isOK() );
|
|
|
|
|
$this->assertInstanceOf( ParserOutput::class, $status->getValue() );
|
|
|
|
|
|
|
|
|
|
/** @var ParserOutput $parserOutput */
|
|
|
|
|
$parserOutput = $status->getValue();
|
|
|
|
|
$this->assertStringContainsString( __METHOD__, $parserOutput->getText() );
|
|
|
|
|
$this->assertNotEmpty( $parserOutput->getExtensionData( 'parsoid-render-id' ) );
|
|
|
|
|
// The revision ID is set to 0, so that's what is in the cache.
|
|
|
|
|
$this->assertSame( 0, $parserOutput->getCacheRevisionId() );
|
|
|
|
|
$this->assertNotEmpty( $parserOutput->getCacheTime() );
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-17 14:00:27 +00:00
|
|
|
}
|