wiki.techinc.nl/tests/phpunit/unit/includes/parser/Parsoid/ParsoidRenderIdTest.php
Derick Alangi 13f6ec9e1b Rest: Migrate parsoid stashing logic from RESTbase
Add stash option to /page/html & /revision/html endpoints.
When this option is set, the PageBundle returned by Parsoid is
stashed and an etag is returned that can later be used to
make use of the stashed PageBundle.

The stash is for now backed by the BagOStuff returned by
ObjectCache::getLocalClusterInstance().

This patch adds additional data to the ParserOutput stored in ParserCache.
Old entries lacking that data will be ignored.

Bug: T267990
Co-Authored-by: Nikki <nnikkhoui@wikimedia.org>
Change-Id: Id35f1423a69e3ff63e4f9883b3f7e3f9521d81d5
2022-05-23 17:28:29 +01:00

48 lines
1.4 KiB
PHP

<?php
namespace MediaWiki\Tests\Unit\Parser\Parsoid;
use MediaWiki\Parser\Parsoid\ParsoidRenderID;
use MediaWikiUnitTestCase;
class ParsoidRenderIdTest extends MediaWikiUnitTestCase {
/**
* @covers \MediaWiki\Parser\Parsoid\ParsoidRenderID
*/
public function testConstruction() {
$renderID = new ParsoidRenderID( 1, '123-abc' );
$this->assertSame( 1, $renderID->getRevisionID() );
$this->assertEquals( '123-abc', $renderID->getUniqueID() );
$this->assertEquals( '1/123-abc', $renderID->__toString() );
}
/**
* @covers \MediaWiki\Parser\Parsoid\ParsoidRenderID::newFromKey
*/
public function testRoundTrip() {
$renderID = new ParsoidRenderID( 1, '123-abc' );
$stringRenderID = $renderID->__toString();
$backToRenderID = $renderID::newFromKey( $stringRenderID );
$this->assertSame( $stringRenderID, $backToRenderID->__toString() );
}
/**
* @dataProvider provideETags
*
* @param string $eTag
* @param ParsoidRenderID $renderId
*
* @covers \MediaWiki\Parser\Parsoid\ParsoidRenderID::newFromETag
*/
public function testNewFromETag( $eTag, $renderId ) {
$actual = ParsoidRenderID::newFromETag( $eTag );
$this->assertSame( $renderId->getKey(), $actual->getKey() );
}
public function provideETags() {
yield [ '"1/abc/stash"', new ParsoidRenderID( 1, 'abc' ) ];
yield [ '"1/abc"', new ParsoidRenderID( 1, 'abc' ) ];
yield [ '"1/abc/stash/stash"', new ParsoidRenderID( 1, 'abc' ) ];
}
}