$wt ] ); $pageConfig = new MockPageConfig( $opts, $pageContent ); $out = $parsoid->wikitext2html( $pageConfig, $parserOpts ); if ( !empty( $parserOpts['pageBundle'] ) ) { $this->assertTrue( $out instanceof PageBundle ); $this->assertEquals( $expected, $out->html ); } else { $this->assertEquals( $expected, $out ); } } public function provideWt2Html() { return [ [ "'''hi ho'''", "
hi ho
", [ 'body_only' => true, 'wrapSections' => false, ] ], [ "'''hi ho'''", "hi ho
", [ 'body_only' => true, 'wrapSections' => false, 'pageBundle' => true, ] ], ]; } /** * @covers ::wikitext2lint * @dataProvider provideWt2Lint */ public function testWt2Lint( $wt, $expected, $parserOpts = [] ) { $opts = [ 'linting' => true, ]; $siteConfig = new MockSiteConfig( $opts ); $dataAccess = new MockDataAccess( $opts ); $parsoid = new Parsoid( $siteConfig, $dataAccess ); $pageContent = new MockPageContent( [ 'main' => $wt ] ); $pageConfig = new MockPageConfig( $opts, $pageContent ); $lint = $parsoid->wikitext2lint( $pageConfig, $parserOpts ); $this->assertEquals( $expected, $lint ); } public function provideWt2Lint() { return [ [ "[http://google.com This is [[Google]]'s search page]", [ [ 'type' => 'wikilink-in-extlink', 'dsr' => [ 0, 52, 19, 1 ], 'params' => [], ] ] ] ]; } /** * @covers ::html2wikitext * @dataProvider provideHtml2Wt */ public function testHtml2Wt( $input, $expected, $parserOpts = [] ) { $opts = []; $siteConfig = new MockSiteConfig( $opts ); $dataAccess = new MockDataAccess( $opts ); $parsoid = new Parsoid( $siteConfig, $dataAccess ); $pageContent = new MockPageContent( [ 'main' => '' ] ); $pageConfig = new MockPageConfig( $opts, $pageContent ); $wt = $parsoid->html2wikitext( $pageConfig, $input, $parserOpts ); $this->assertEquals( $expected, $wt ); } public function provideHtml2Wt() { return [ [ "hi\n
Special:Version Doesnotexist Redirected
', 'Special:Version Doesnotexist Redirected
', [ 'body_only' => true, ] ], [ 'variant', // bogus w/ a data-parsoid attribute, just to verify // that data-parsoid attributes are preserved and not erased. 'абвг abcd x
', 'abvg abcd x
', [ 'body_only' => true, 'pageLanguage' => 'sr', 'variant' => [ 'source' => null, 'target' => 'sr-el', ] ] ], [ 'variant', 'абвг abcd x
', 'abvg abcd x
', [ 'body_only' => true, 'pageLanguage' => 'sr', 'variant' => [ 'source' => 'sr-ec', 'target' => 'sr-el', ] ] ], [ 'variant', 'абвг abcd x
', 'абвг абцд x
', [ 'body_only' => true, 'pageLanguage' => 'sr', 'variant' => [ 'source' => 'sr-el', 'target' => 'sr-ec', ] ] ] ]; // phpcs:enable Generic.Files.LineLength.TooLong } /** * @covers ::pb2pb * @dataProvider providePb2Pb */ public function testPb2Pb( $update, $input, $expected, $testOpts = [] ) { $opts = []; $siteConfig = new MockSiteConfig( $opts ); $dataAccess = new MockDataAccess( $opts ); $parsoid = new Parsoid( $siteConfig, $dataAccess ); $pageContent = new MockPageContent( [ 'main' => '' ] ); $pageConfig = new MockPageConfig( [ 'pageLanguage' => $testOpts['pageLanguage'] ?? 'en' ], $pageContent ); $pb = new PageBundle( $input['html'], PHPUtils::jsonDecode( $input['parsoid'] ?? 'null' ), PHPUtils::jsonDecode( $input['mw'] ?? 'null' ), $input['version'] ?? null, $input['headers'] ?? null, $input['contentmodel'] ?? null ); $out = $parsoid->pb2pb( $pageConfig, $update, $pb, $testOpts ); $this->assertTrue( $out instanceof PageBundle ); $this->assertEquals( $expected['html'], $out->html ); $this->assertEquals( $expected['parsoid'] ?? 'null', PHPUtils::jsonEncode( $out->parsoid ) ); $this->assertEquals( $expected['mw'] ?? 'null', PHPUtils::jsonEncode( $out->mw ) ); $this->assertEquals( $expected['version'] ?? null, $out->version ); if ( isset( $expected['headers'] ) ) { $this->assertEquals( $expected['headers'] ?? null, $out->headers ); } } public function providePb2Pb() { // phpcs:disable Generic.Files.LineLength.TooLong return [ [ 'variant', [ 'html' => 'abcd
', 'parsoid' => '{"counter":2,"ids":{"mwAA":{"dsr":[0,11,0,0]},"mwAQ":{"dsr":[0,10,0,0]},"mwAg":{"dsr":[0,10,3,3]}},"offsetType":"byte"}', 'mw' => '{"ids":[]}', ], [ 'html' => 'абцд
', 'parsoid' => '{"counter":-1,"ids":{"mwAA":{"dsr":[0,11,0,0]},"mwAQ":{"dsr":[0,10,0,0]},"mwAg":{"dsr":[0,10,3,3]}},"offsetType":"byte"}', 'mw' => '{"ids":[]}', 'version' => '2.1.0', ], [ 'body_only' => true, 'pageLanguage' => 'sr', 'variant' => [ 'source' => 'sr-el', 'target' => 'sr-ec', ] ] ], // Note that id attributes are preserved, even if no data-parsoid // is provided. [ 'variant', [ 'html' => 'abcd
', 'parsoid' => null, 'mw' => null, ], [ 'html' => 'абцд
', 'parsoid' => '{"counter":-1,"ids":[],"offsetType":"byte"}', 'mw' => '{"ids":[]}', 'version' => '2.1.0', ], [ 'body_only' => true, 'pageLanguage' => 'sr', 'variant' => [ 'source' => 'sr-el', 'target' => 'sr-ec', ] ] ], ]; // phpcs:enable Generic.Files.LineLength.TooLong } }