wiki.techinc.nl/tests/phpunit/includes/poolcounter/PoolWorkArticleViewCurrentTest.php
Petr Pchelko cd66d7c335 Convert ParserOutputAccess to PageRecord.
Still needs to downcast to WikiPage in 2 places:

1. To check get a ContentHandler and check if content model
is cacheable. We probably should just make all content models
cacheable.
2. To call WikiPage::triggerOpportunisticLinksUpdate. I have
an elaborate plan for this one, but it will be done separately.

Change-Id: Ifd9ab0155dc1fad0c1608dafea05d16292afd057
2021-04-05 07:46:34 -06:00

84 lines
2.1 KiB
PHP

<?php
use MediaWiki\Json\JsonCodec;
use MediaWiki\Revision\RevisionRecord;
use Psr\Log\NullLogger;
/**
* @covers PoolWorkArticleViewCurrent
* @group Database
*/
class PoolWorkArticleViewCurrentTest extends PoolWorkArticleViewTest {
/** @var ParserCache */
private $parserCache = null;
/**
* @param WikiPage $page
* @param RevisionRecord|null $rev
* @param ParserOptions|null $options
*
* @return PoolWorkArticleView
*/
protected function newPoolWorkArticleView(
WikiPage $page,
RevisionRecord $rev = null,
$options = null
) {
if ( !$options ) {
$options = ParserOptions::newCanonical( 'canonical' );
}
if ( !$rev ) {
$rev = $page->getRevisionRecord();
}
$parserCache = $this->parserCache ?: $this->installParserCache();
$lbFactory = $this->getServiceContainer()->getDBLoadBalancerFactory();
$revisionRenderer = $this->getServiceContainer()->getRevisionRenderer();
return new PoolWorkArticleViewCurrent(
'test:' . $rev->getId(),
$page,
$rev,
$options,
$revisionRenderer,
$parserCache,
$lbFactory,
$this->getLoggerSpi(),
$this->getServiceContainer()->getWikiPageFactory()
);
}
private function installParserCache( $bag = null ) {
$this->parserCache = new ParserCache(
'test',
$bag ?: new HashBagOStuff(),
'',
$this->getServiceContainer()->getHookContainer(),
new JsonCodec(),
$this->getServiceContainer()->getStatsdDataFactory(),
new NullLogger(),
$this->getServiceContainer()->getTitleFactory(),
$this->getServiceContainer()->getWikiPageFactory()
);
return $this->parserCache;
}
public function testUpdateCachedOutput() {
$options = ParserOptions::newCanonical( 'canonical' );
$page = $this->getExistingTestPage( __METHOD__ );
$parserCache = $this->installParserCache();
// rendering of a deleted revision should work, audience checks are bypassed
$work = $this->newPoolWorkArticleView( $page, null, $options );
$this->assertTrue( $work->execute() );
$cachedOutput = $parserCache->get( $page, $options );
$this->assertNotEmpty( $cachedOutput );
$this->assertSame( $work->getParserOutput()->getText(), $cachedOutput->getText() );
}
}