wiki.techinc.nl/tests/phpunit/unit/includes/edit/SimpleParsoidOutputStashTest.php
C. Scott Ananian 52320c0902 Move ParsoidRenderID to MediaWiki\Edit
This class belongs with the rest of the Parsoid output stash code.

This class has been marked @unstable since 1.39 and thus the move
does not need release notes.

Change-Id: I16061c0c28b1549fbe90ea082cc717fee4a09a6e
2024-02-07 21:22:06 -05:00

62 lines
2 KiB
PHP

<?php
namespace MediaWiki\Tests\Unit\Edit;
use HashBagOStuff;
use MediaWiki\Edit\ParsoidRenderID;
use MediaWiki\Edit\SelserContext;
use MediaWiki\Edit\SimpleParsoidOutputStash;
use MediaWiki\Tests\Unit\DummyServicesTrait;
use TextContentHandler;
use Wikimedia\Parsoid\Core\PageBundle;
use WikitextContent;
/**
* @covers \MediaWiki\Edit\SimpleParsoidOutputStash
* @covers \MediaWiki\Edit\SelserContext
*/
class SimpleParsoidOutputStashTest extends \MediaWikiUnitTestCase {
use DummyServicesTrait;
public function testSetAndGetWithNoContent() {
$chFactory = $this->getDummyContentHandlerFactory();
$stash = new SimpleParsoidOutputStash( $chFactory, new HashBagOStuff(), 12 );
$key = new ParsoidRenderID( 7, 'acme' );
$pageBundle = new PageBundle( '<p>Hello World</p>' );
$selserContext = new SelserContext( $pageBundle, 7 );
$stash->set( $key, $selserContext );
$this->assertEquals( $selserContext, $stash->get( $key ) );
}
public function testSetAndGetWithContent() {
$contentHandler = $this->createNoOpMock( TextContentHandler::class, [ 'unserializeContent' ] );
$contentHandler->method( 'unserializeContent' )->willReturnCallback( static function ( $data ) {
return new WikitextContent( $data );
} );
$chFactory = $this->getDummyContentHandlerFactory(
[ CONTENT_MODEL_WIKITEXT => $contentHandler ]
);
$stash = new SimpleParsoidOutputStash( $chFactory, new HashBagOStuff(), 12 );
$key = new ParsoidRenderID( 7, 'acme' );
$pageBundle = new PageBundle( '<p>Hello World</p>' );
$content = $this->createNoOpMock( WikitextContent::class, [ 'getModel', 'serialize' ] );
$content->method( 'getModel' )->willReturn( CONTENT_MODEL_WIKITEXT );
$content->method( 'serialize' )->willReturn( 'Hello World' );
$selserContext = new SelserContext( $pageBundle, 7, $content );
$stash->set( $key, $selserContext );
$actual = $stash->get( $key );
$this->assertEquals( $pageBundle, $actual->getPageBundle() );
$this->assertEquals( 'Hello World', $actual->getContent()->getText() );
$this->assertEquals( 7, $actual->getRevisionID() );
}
}