When visual editor switches from source mode to visual mode, we need to stash the wikitext. Otherwise, we later lack the proper context to convert the modified HTML back to wikitext. Bug: T321862 Change-Id: Id611e6e022bf8d9d774ca1a3a214220ada713285
64 lines
2.2 KiB
PHP
64 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace MediaWiki\Tests\Unit\Edit;
|
|
|
|
use HashBagOStuff;
|
|
use MediaWiki\Content\IContentHandlerFactory;
|
|
use MediaWiki\Edit\SelserContext;
|
|
use MediaWiki\Edit\SimpleParsoidOutputStash;
|
|
use MediaWiki\Parser\Parsoid\ParsoidRenderID;
|
|
use TextContentHandler;
|
|
use Wikimedia\Parsoid\Core\PageBundle;
|
|
use WikitextContent;
|
|
|
|
/**
|
|
* @covers \MediaWiki\Edit\SimpleParsoidOutputStash
|
|
* @covers \MediaWiki\Edit\SelserContext
|
|
*/
|
|
class SimpleParsoidOutputStashTest extends \MediaWikiUnitTestCase {
|
|
|
|
public function testSetAndGetWithNoContent() {
|
|
$chFactory = $this->createNoOpMock( IContentHandlerFactory::class );
|
|
$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->createNoOpMock( IContentHandlerFactory::class, [ 'getContentHandler' ] );
|
|
$chFactory->method( 'getContentHandler' )
|
|
->with( CONTENT_MODEL_WIKITEXT )
|
|
->willReturn(
|
|
$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() );
|
|
}
|
|
|
|
}
|