wiki.techinc.nl/tests/phpunit/includes/parser/PageBundleJsonTraitTest.php
thiemowmde 7e70b8042c Use the instanceof and ::class features instead of strings
This makes it much easier for IDEs and tools like Phan to understand
what's going on. Note this syntax is perfectly valid even if a class
is undefined. Language features like `use`, `instanceof`, and
`class_exists` work perfectly fine. We do this a lot in existing
code.

Change-Id: I4d397621ebcc6a7e842150f7641c1b23d082b730
2024-02-02 14:50:15 +00:00

45 lines
1.3 KiB
PHP

<?php
use MediaWiki\Parser\Parsoid\PageBundleJsonTrait;
use Wikimedia\Parsoid\Core\PageBundle;
/**
* @covers MediaWiki\Parser\Parsoid\PageBundleJsonTrait
*/
class PageBundleJsonTraitTest extends MediaWikiIntegrationTestCase {
private $bundleData = [
'html' => '<h1>woohoo</h1>',
'parsoid' => [ 'metadata' => 'foo' ],
'mw' => null,
'version' => '1.0',
'headers' => [ 'bar' => 'baz' ],
'contentmodel' => 'default'
];
public function testNewPageBundleFromJson() {
$trait = new class {
use PageBundleJsonTrait {
newPageBundleFromJson as public;
}
};
$bundle = $trait->newPageBundleFromJson( $this->bundleData );
$this->assertInstanceOf( PageBundle::class, $bundle );
$this->assertEquals( '<h1>woohoo</h1>', $bundle->html );
$this->assertEquals( 'default', $bundle->contentmodel );
$this->assertNull( $bundle->mw );
}
public function testJsonSerializePageBundle() {
$trait = new class {
use PageBundleJsonTrait {
jsonSerializePageBundle as public;
}
};
$bundle = new PageBundle( ...array_values( $this->bundleData ) );
$json = $trait->jsonSerializePageBundle( $bundle );
$this->assertEquals( PageBundle::class, $json['_type_'] );
$this->assertEquals( '<h1>woohoo</h1>', $json['html'] );
$this->assertNull( $json['mw'] );
}
}