1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
<?php
namespace MediaWiki\Tests\Unit\Edit;
use HashBagOStuff;
use MediaWiki\Content\TextContentHandler;
use MediaWiki\Edit\ParsoidRenderID;
use MediaWiki\Edit\SelserContext;
use MediaWiki\Edit\SimpleParsoidOutputStash;
use MediaWiki\Tests\Unit\DummyServicesTrait;
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() );
}
}
|