| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Tests\Unit\Edit; |
| 4 |
|
| 5 |
use MediaWiki\Content\WikitextContent; |
| 6 |
use MediaWiki\Edit\ParsoidRenderID; |
| 7 |
use MediaWiki\Edit\SelserContext; |
| 8 |
use MediaWiki\Edit\SimpleParsoidOutputStash; |
| 9 |
use MediaWiki\Json\JsonCodec; |
| 10 |
use Wikimedia\ObjectCache\HashBagOStuff; |
| 11 |
use Wikimedia\Parsoid\Core\PageBundle; |
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
class SimpleParsoidOutputStashTest extends \MediaWikiIntegrationTestCase { |
| 18 |
|
| 19 |
public function testSetAndGetWithNoContent() { |
| 20 |
$codec = new JsonCodec( $this->getServiceContainer() ); |
| 21 |
$stash = new SimpleParsoidOutputStash( $codec, new HashBagOStuff(), 12 ); |
| 22 |
|
| 23 |
$key = new ParsoidRenderID( 7, 'acme' ); |
| 24 |
$pageBundle = new PageBundle( '<p>Hello World</p>' ); |
| 25 |
$selserContext = new SelserContext( $pageBundle, 7 ); |
| 26 |
|
| 27 |
$stash->set( $key, $selserContext ); |
| 28 |
$this->assertEquals( $selserContext, $stash->get( $key ) ); |
| 29 |
} |
| 30 |
|
| 31 |
public function testSetAndGetWithContent() { |
| 32 |
$codec = new JsonCodec( $this->getServiceContainer() ); |
| 33 |
$stash = new SimpleParsoidOutputStash( $codec, new HashBagOStuff(), 12 ); |
| 34 |
|
| 35 |
$key = new ParsoidRenderID( 7, 'acme' ); |
| 36 |
$pageBundle = new PageBundle( '<p>Hello World</p>' ); |
| 37 |
|
| 38 |
$content = new WikitextContent( 'Hello World' ); |
| 39 |
|
| 40 |
$selserContext = new SelserContext( $pageBundle, 7, $content ); |
| 41 |
|
| 42 |
$stash->set( $key, $selserContext ); |
| 43 |
|
| 44 |
$actual = $stash->get( $key ); |
| 45 |
$this->assertEquals( $pageBundle, $actual->getPageBundle() ); |
| 46 |
$this->assertEquals( 'Hello World', $actual->getContent()->getText() ); |
| 47 |
$this->assertEquals( 7, $actual->getRevisionID() ); |
| 48 |
} |
| 49 |
} |