$pageContent ]; // Test malformed JSON handler $env = new MockEnv( $opts ); $API = new ParsoidExtensionAPI( $env ); $parsoidVersion = Parsoid::version(); $expected = # '' . "\n" . 'TestPage
'; $doc = $json->toDOM( $API ); $response = DOMCompat::getOuterHTML( $doc->documentElement ); $this->assertSame( $expected, $response ); $pageContent = '{"array":[{"foo":"bar","key":["string1",null,false,true,0,1,123,456.789]}]}'; $expected = # '' . "\n" . 'TestPage
array
foobar
key
string1
null
false
true
0
1
123
456.789
'; $opts = [ 'pageContent' => $pageContent ]; // Test complex nested JSON object using string matching $env = new MockEnv( $opts ); $API = new ParsoidExtensionAPI( $env ); $doc = $json->toDOM( $API ); $response = DOMCompat::getOuterHTML( $doc->documentElement ); $this->assertSame( $expected, $response ); } /** * Create a DOM document using HTML and convert that to JSON and verify correctness * @covers \Wikimedia\Parsoid\Ext\JSON\JSON::fromDOM */ public function testFromDOM() { $html = '' . "\n" . '
' . 'array
' . '' . '' . '' . '
foobar
key' . '' . '' . '' . '' . '' . '' . '' . '
string1
null
false
true
0
1
123
456.789
' . "\n"; $doc = DOMCompat::newDocument( true ); $doc->loadHTML( $html ); $opts = [ 'topLevelDoc' => $doc ]; $env = new MockEnv( $opts ); $API = new ParsoidExtensionAPI( $env ); $json = new JSON(); $expected = '{"array":[{"foo":"bar","key":["string1",null,false,true,0,1,123,456.789]}]}'; $response = $json->fromDOM( $API ); $this->assertSame( $expected, $response ); } }