2022-08-30 19:19:53 +00:00
|
|
|
<?php
|
|
|
|
|
|
2023-01-13 21:30:21 +00:00
|
|
|
namespace MediaWiki\Tests\Rest\Handler\Helper;
|
2022-08-30 19:19:53 +00:00
|
|
|
|
|
|
|
|
use Exception;
|
2023-09-15 19:22:29 +00:00
|
|
|
use Liuggio\StatsdClient\Factory\StatsdDataFactoryInterface;
|
2023-08-09 15:43:50 +00:00
|
|
|
use LogicException;
|
2024-05-19 18:33:58 +00:00
|
|
|
use MediaWiki\Content\TextContent;
|
2024-08-06 13:40:20 +00:00
|
|
|
use MediaWiki\Content\WikitextContent;
|
2023-11-06 15:22:44 +00:00
|
|
|
use MediaWiki\Edit\ParsoidRenderID;
|
2022-10-29 18:52:23 +00:00
|
|
|
use MediaWiki\Edit\SelserContext;
|
2022-08-30 19:19:53 +00:00
|
|
|
use MediaWiki\MainConfigNames;
|
|
|
|
|
use MediaWiki\MainConfigSchema;
|
|
|
|
|
use MediaWiki\Message\Converter;
|
|
|
|
|
use MediaWiki\Message\TextFormatter;
|
2024-06-05 15:49:49 +00:00
|
|
|
use MediaWiki\Page\PageIdentity;
|
2022-08-30 19:19:53 +00:00
|
|
|
use MediaWiki\Page\PageIdentityValue;
|
2023-12-14 19:20:33 +00:00
|
|
|
use MediaWiki\Parser\ParserOutput;
|
2022-10-16 21:44:53 +00:00
|
|
|
use MediaWiki\Parser\Parsoid\HtmlToContentTransform;
|
|
|
|
|
use MediaWiki\Parser\Parsoid\HtmlTransformFactory;
|
2022-10-14 15:44:57 +00:00
|
|
|
use MediaWiki\Parser\Parsoid\PageBundleParserOutputConverter;
|
2023-01-13 21:30:21 +00:00
|
|
|
use MediaWiki\Rest\Handler\Helper\HtmlInputTransformHelper;
|
|
|
|
|
use MediaWiki\Rest\Handler\Helper\ParsoidFormatHelper;
|
2022-09-09 09:32:17 +00:00
|
|
|
use MediaWiki\Rest\HttpException;
|
2022-08-30 19:19:53 +00:00
|
|
|
use MediaWiki\Rest\LocalizedHttpException;
|
|
|
|
|
use MediaWiki\Rest\ResponseFactory;
|
|
|
|
|
use MediaWiki\Revision\MutableRevisionRecord;
|
2022-10-14 15:44:57 +00:00
|
|
|
use MediaWiki\Revision\RevisionRecord;
|
2022-08-30 19:19:53 +00:00
|
|
|
use MediaWiki\Revision\SlotRecord;
|
|
|
|
|
use MediaWikiIntegrationTestCase;
|
2022-09-09 09:32:17 +00:00
|
|
|
use ParserOptions;
|
2022-08-30 19:19:53 +00:00
|
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
2024-06-05 15:49:49 +00:00
|
|
|
use Wikimedia\Bcp47Code\Bcp47Code;
|
2022-08-30 19:19:53 +00:00
|
|
|
use Wikimedia\Message\MessageValue;
|
|
|
|
|
use Wikimedia\Parsoid\Core\ClientError;
|
2022-09-09 09:32:17 +00:00
|
|
|
use Wikimedia\Parsoid\Core\PageBundle;
|
2022-08-30 19:19:53 +00:00
|
|
|
use Wikimedia\Parsoid\Core\ResourceLimitExceededException;
|
|
|
|
|
use Wikimedia\Parsoid\Parsoid;
|
2022-10-14 15:44:57 +00:00
|
|
|
use Wikimedia\Parsoid\Utils\ContentUtils;
|
2024-09-27 18:21:33 +00:00
|
|
|
use Wikimedia\Stats\BufferingStatsdDataFactory;
|
|
|
|
|
use Wikimedia\Stats\NullStatsdDataFactory;
|
2022-08-30 19:19:53 +00:00
|
|
|
|
|
|
|
|
/**
|
2023-01-13 21:30:21 +00:00
|
|
|
* @covers \MediaWiki\Rest\Handler\Helper\HtmlInputTransformHelper
|
2022-08-30 19:19:53 +00:00
|
|
|
* @group Database
|
|
|
|
|
*/
|
|
|
|
|
class HtmlInputTransformHelperTest extends MediaWikiIntegrationTestCase {
|
|
|
|
|
private const CACHE_EPOCH = '20001111010101';
|
|
|
|
|
|
|
|
|
|
protected function setUp(): void {
|
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
|
|
$this->overrideConfigValue( MainConfigNames::CacheEpoch, self::CACHE_EPOCH );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param array $methodOverrides
|
|
|
|
|
*
|
2022-10-16 21:44:53 +00:00
|
|
|
* @return MockObject|HtmlTransformFactory
|
2022-08-30 19:19:53 +00:00
|
|
|
*/
|
2022-10-16 21:44:53 +00:00
|
|
|
public function newMockHtmlTransformFactory( $methodOverrides = [] ): HtmlTransformFactory {
|
|
|
|
|
$factory = $this->createNoOpMock( HtmlTransformFactory::class, [ 'getHtmlToContentTransform' ] );
|
2022-08-30 19:19:53 +00:00
|
|
|
|
2022-10-16 21:44:53 +00:00
|
|
|
$factory->method( 'getHtmlToContentTransform' )->willReturnCallback(
|
2022-08-30 19:19:53 +00:00
|
|
|
function ( $html ) use ( $methodOverrides ) {
|
2022-10-16 21:44:53 +00:00
|
|
|
return $this->newHtmlToContentTransform( $html, $methodOverrides );
|
2022-08-30 19:19:53 +00:00
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return $factory;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param array $transformMethodOverrides
|
2023-09-15 19:22:29 +00:00
|
|
|
* @param StatsdDataFactoryInterface|null $stats
|
2024-06-05 15:49:49 +00:00
|
|
|
* @param ?PageIdentity $page
|
|
|
|
|
* @param array|string $body Body structure, or an HTML string
|
|
|
|
|
* @param array $parameters
|
|
|
|
|
* @param RevisionRecord|null $originalRevision
|
|
|
|
|
* @param Bcp47Code|null $pageLanguage
|
2022-08-30 19:19:53 +00:00
|
|
|
*
|
|
|
|
|
* @return HtmlInputTransformHelper
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
2022-10-19 15:26:02 +00:00
|
|
|
private function newHelper(
|
2024-06-05 15:49:49 +00:00
|
|
|
array $transformMethodOverrides = [],
|
|
|
|
|
?StatsdDataFactoryInterface $stats = null,
|
|
|
|
|
?PageIdentity $page = null,
|
|
|
|
|
$body = '',
|
|
|
|
|
array $parameters = [],
|
|
|
|
|
?RevisionRecord $originalRevision = null,
|
|
|
|
|
?Bcp47Code $pageLanguage = null
|
2022-10-19 15:26:02 +00:00
|
|
|
): HtmlInputTransformHelper {
|
2022-08-30 19:19:53 +00:00
|
|
|
// TODO: $cache = $cache ?: new EmptyBagOStuff();
|
|
|
|
|
// TODO: $stash = new SimpleParsoidOutputStash( $cache, 1 );
|
|
|
|
|
|
|
|
|
|
$helper = new HtmlInputTransformHelper(
|
2022-10-19 15:26:02 +00:00
|
|
|
$stats ?: new NullStatsdDataFactory(),
|
2022-10-16 21:44:53 +00:00
|
|
|
$this->newMockHtmlTransformFactory( $transformMethodOverrides ),
|
2022-09-13 15:52:44 +00:00
|
|
|
$this->getServiceContainer()->getParsoidOutputStash(),
|
2024-05-15 17:21:13 +00:00
|
|
|
$this->getServiceContainer()->getParserOutputAccess(),
|
|
|
|
|
$this->getServiceContainer()->getPageStore(),
|
2024-06-05 15:49:49 +00:00
|
|
|
$this->getServiceContainer()->getRevisionLookup(),
|
|
|
|
|
[], /* envOptions */
|
|
|
|
|
$page,
|
|
|
|
|
$body,
|
|
|
|
|
$parameters,
|
|
|
|
|
$originalRevision,
|
|
|
|
|
$pageLanguage
|
2022-08-30 19:19:53 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return $helper;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function getTextFromFile( string $name ): string {
|
2023-01-13 21:30:21 +00:00
|
|
|
return trim( file_get_contents( __DIR__ . "/../data/Transform/$name" ) );
|
2022-08-30 19:19:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function getJsonFromFile( string $name ): array {
|
|
|
|
|
$text = $this->getTextFromFile( $name );
|
|
|
|
|
return json_decode( $text, JSON_OBJECT_AS_ARRAY );
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-29 18:52:23 +00:00
|
|
|
public function provideRequests() {
|
2022-08-30 19:19:53 +00:00
|
|
|
$profileVersion = '2.4.0';
|
|
|
|
|
$wikitextProfileUri = 'https://www.mediawiki.org/wiki/Specs/wikitext/1.0.0';
|
|
|
|
|
$htmlProfileUri = 'https://www.mediawiki.org/wiki/Specs/HTML/' . $profileVersion;
|
|
|
|
|
$dataParsoidProfileUri = 'https://www.mediawiki.org/wiki/Specs/data-parsoid/' . $profileVersion;
|
|
|
|
|
|
|
|
|
|
$wikiTextContentType = "text/plain; charset=utf-8; profile=\"$wikitextProfileUri\"";
|
|
|
|
|
$htmlContentType = "text/html;profile=\"$htmlProfileUri\"";
|
|
|
|
|
$dataParsoidContentType = "application/json;profile=\"$dataParsoidProfileUri\"";
|
|
|
|
|
|
|
|
|
|
$htmlHeaders = [
|
|
|
|
|
'content-type' => $htmlContentType,
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
// NOTE: profile version 999 is a placeholder for a future feature, see T78676
|
|
|
|
|
$htmlContentType999 = 'text/html;profile="https://www.mediawiki.org/wiki/Specs/HTML/999.0.0"';
|
|
|
|
|
$htmlHeaders999 = [
|
|
|
|
|
'content-type' => $htmlContentType999,
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
// should convert html to wikitext ///////////////////////////////////
|
|
|
|
|
$html = $this->getTextFromFile( 'MainPage-data-parsoid.html' );
|
|
|
|
|
$expectedText = [
|
|
|
|
|
'MediaWiki has been successfully installed',
|
|
|
|
|
'== Getting started ==',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$params = [];
|
|
|
|
|
$body = [ 'html' => $html ];
|
|
|
|
|
yield 'should convert html to wikitext' => [
|
|
|
|
|
$body,
|
|
|
|
|
$params,
|
|
|
|
|
$expectedText,
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
// should load original wikitext by revision id ////////////////////
|
|
|
|
|
$params = [
|
|
|
|
|
'oldid' => 1, // will be replaced by the actual revid
|
|
|
|
|
];
|
|
|
|
|
$body = [ 'html' => $html ];
|
|
|
|
|
yield 'should load original wikitext by revision id' => [
|
|
|
|
|
$body,
|
|
|
|
|
$params,
|
|
|
|
|
$expectedText,
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
// should accept original wikitext in body ////////////////////
|
|
|
|
|
$originalWikitext = $this->getTextFromFile( 'OriginalMainPage.wikitext' );
|
|
|
|
|
$params = [];
|
|
|
|
|
$body = [
|
|
|
|
|
'html' => $html,
|
|
|
|
|
'original' => [
|
|
|
|
|
'wikitext' => [
|
|
|
|
|
'headers' => [
|
|
|
|
|
'content-type' => $wikiTextContentType,
|
|
|
|
|
],
|
|
|
|
|
'body' => $originalWikitext,
|
|
|
|
|
]
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
yield 'should accept original wikitext in body' => [
|
|
|
|
|
$body,
|
|
|
|
|
$params,
|
|
|
|
|
$expectedText, // TODO: ensure it's actually used!
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
// should use original html for selser (default) //////////////////////
|
|
|
|
|
$originalDataParsoid = $this->getJsonFromFile( 'MainPage-original.data-parsoid' );
|
|
|
|
|
$params = [
|
|
|
|
|
'from' => ParsoidFormatHelper::FORMAT_PAGEBUNDLE,
|
|
|
|
|
];
|
|
|
|
|
$body = [
|
|
|
|
|
'html' => $html,
|
|
|
|
|
'original' => [
|
|
|
|
|
'html' => [
|
|
|
|
|
'headers' => $htmlHeaders,
|
|
|
|
|
'body' => $this->getTextFromFile( 'MainPage-original.html' ),
|
|
|
|
|
],
|
|
|
|
|
'data-parsoid' => [
|
|
|
|
|
'headers' => [
|
|
|
|
|
'content-type' => $dataParsoidContentType,
|
|
|
|
|
],
|
|
|
|
|
'body' => $originalDataParsoid
|
|
|
|
|
]
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
yield 'should use original html for selser (default)' => [
|
|
|
|
|
$body,
|
|
|
|
|
$params,
|
|
|
|
|
$expectedText,
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
// should use original html for selser (1.1.1, meta) ///////////////////
|
|
|
|
|
$params = [];
|
|
|
|
|
$body = [
|
|
|
|
|
'html' => $html,
|
|
|
|
|
'original' => [
|
|
|
|
|
'html' => [
|
|
|
|
|
'headers' => [
|
|
|
|
|
// XXX: If this is required anyway, how do we know we are using the
|
|
|
|
|
// version given in the HTML?
|
|
|
|
|
'content-type' => 'text/html; profile="mediawiki.org/specs/html/1.1.1"',
|
|
|
|
|
],
|
|
|
|
|
'body' => $this->getTextFromFile( 'MainPage-data-parsoid-1.1.1.html' ),
|
|
|
|
|
],
|
|
|
|
|
'data-parsoid' => [
|
|
|
|
|
'headers' => [
|
|
|
|
|
'content-type' => $dataParsoidContentType,
|
|
|
|
|
],
|
|
|
|
|
'body' => $originalDataParsoid
|
|
|
|
|
]
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
yield 'should use original html for selser (1.1.1, meta)' => [
|
|
|
|
|
$body,
|
|
|
|
|
$params,
|
|
|
|
|
$expectedText,
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
// should accept original html for selser (1.1.1, headers) ////////////
|
|
|
|
|
$params = [
|
|
|
|
|
'from' => ParsoidFormatHelper::FORMAT_PAGEBUNDLE,
|
|
|
|
|
];
|
|
|
|
|
$body = [
|
|
|
|
|
'html' => $html,
|
|
|
|
|
'original' => [
|
|
|
|
|
'html' => [
|
|
|
|
|
'headers' => [
|
|
|
|
|
// Set the schema version to 1.1.1!
|
|
|
|
|
'content-type' => 'text/html; profile="mediawiki.org/specs/html/1.1.1"',
|
|
|
|
|
],
|
|
|
|
|
// No schema version in HTML
|
|
|
|
|
'body' => $this->getTextFromFile( 'MainPage-original.html' ),
|
|
|
|
|
],
|
|
|
|
|
'data-parsoid' => [
|
|
|
|
|
'headers' => [
|
|
|
|
|
'content-type' => $dataParsoidContentType,
|
|
|
|
|
],
|
|
|
|
|
'body' => $originalDataParsoid
|
|
|
|
|
]
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
yield 'should use original html for selser (1.1.1, headers)' => [
|
|
|
|
|
$body,
|
|
|
|
|
$params,
|
|
|
|
|
$expectedText,
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
// Return original wikitext when HTML doesn't change ////////////////////////////
|
|
|
|
|
// New and old html are identical, which should produce no diffs
|
|
|
|
|
// and reuse the original wikitext.
|
|
|
|
|
$html = '<html><body id="mwAA"><div id="mwBB">Selser test</div></body></html>';
|
|
|
|
|
$dataParsoid = [
|
|
|
|
|
'ids' => [
|
|
|
|
|
'mwAA' => [],
|
|
|
|
|
'mwBB' => [ 'autoInsertedEnd' => true, 'stx' => 'html' ]
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$params = [
|
|
|
|
|
'oldid' => 1, // Will be replaced by the revision ID of the default test page
|
|
|
|
|
];
|
|
|
|
|
$body = [
|
|
|
|
|
'html' => $html,
|
|
|
|
|
'original' => [
|
|
|
|
|
'html' => [
|
|
|
|
|
'headers' => $htmlHeaders,
|
|
|
|
|
// original HTML is the same as the new HTML
|
|
|
|
|
'body' => $html
|
|
|
|
|
],
|
|
|
|
|
'data-parsoid' => [
|
|
|
|
|
'body' => $dataParsoid,
|
|
|
|
|
]
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
yield 'should use selser, return original wikitext because the HTML didn\'t change' => [
|
|
|
|
|
$body,
|
|
|
|
|
$params,
|
2023-08-09 15:43:50 +00:00
|
|
|
null, // Returns original wikitext, because HTML didn't change.
|
2022-08-30 19:19:53 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
// Should fall back to non-selective serialization. //////////////////
|
|
|
|
|
// Without the original wikitext, use non-selective serialization.
|
|
|
|
|
$params = [
|
|
|
|
|
// No wikitext, no revid/oldid
|
|
|
|
|
'from' => ParsoidFormatHelper::FORMAT_PAGEBUNDLE,
|
|
|
|
|
];
|
|
|
|
|
$body = [
|
|
|
|
|
'html' => $html,
|
|
|
|
|
'original' => [
|
|
|
|
|
'html' => [
|
|
|
|
|
'headers' => $htmlHeaders,
|
|
|
|
|
// original HTML is the same as the new HTML
|
|
|
|
|
'body' => $html
|
|
|
|
|
],
|
|
|
|
|
'data-parsoid' => [
|
|
|
|
|
'body' => $dataParsoid,
|
|
|
|
|
]
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
yield 'Should fallback to non-selective serialization' => [
|
|
|
|
|
$body,
|
|
|
|
|
$params,
|
|
|
|
|
[ '<div>Selser test' ],
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
// should apply data-parsoid to duplicated ids /////////////////////////
|
|
|
|
|
$html = '<html><body id="mwAA"><div id="mwBB">data-parsoid test</div>' .
|
|
|
|
|
'<div id="mwBB">data-parsoid test</div></body></html>';
|
|
|
|
|
$originalHtml = '<html><body id="mwAA"><div id="mwBB">data-parsoid test</div></body></html>';
|
|
|
|
|
|
|
|
|
|
$params = [];
|
|
|
|
|
$body = [
|
|
|
|
|
'html' => $html,
|
|
|
|
|
'original' => [
|
|
|
|
|
'html' => [
|
|
|
|
|
'headers' => $htmlHeaders,
|
|
|
|
|
'body' => $originalHtml
|
|
|
|
|
],
|
|
|
|
|
'data-parsoid' => [
|
|
|
|
|
'body' => $dataParsoid,
|
|
|
|
|
]
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
yield 'should apply data-parsoid to duplicated ids' => [
|
|
|
|
|
$body,
|
|
|
|
|
$params,
|
|
|
|
|
[ '<div>data-parsoid test<div>data-parsoid test' ],
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
// should ignore data-parsoid if the input format is given but not pagebundle //////////////
|
|
|
|
|
$html = '<html><body id="mwAA"><div id="mwBB">data-parsoid test</div>' .
|
|
|
|
|
'<div id="mwBB">data-parsoid test</div></body></html>';
|
|
|
|
|
$originalHtml = '<html><body id="mwAA"><div id="mwBB">data-parsoid test</div></body></html>';
|
|
|
|
|
|
|
|
|
|
$params = [
|
|
|
|
|
'from' => ParsoidFormatHelper::FORMAT_HTML,
|
|
|
|
|
];
|
|
|
|
|
$body = [
|
|
|
|
|
'html' => $html,
|
|
|
|
|
'original' => [
|
|
|
|
|
'html' => [
|
|
|
|
|
'headers' => $htmlHeaders,
|
|
|
|
|
'body' => $originalHtml
|
|
|
|
|
],
|
|
|
|
|
'data-parsoid' => [
|
|
|
|
|
// This has 'autoInsertedEnd' => true, which would cause
|
|
|
|
|
// closing </div> tags to be omitted.
|
|
|
|
|
'body' => $dataParsoid,
|
|
|
|
|
]
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
yield 'should ignore data-parsoid if the input format is not pagebundle' => [
|
|
|
|
|
$body,
|
|
|
|
|
$params,
|
|
|
|
|
[ '<div>data-parsoid test</div><div>data-parsoid test</div>' ],
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
// should apply original data-mw ///////////////////////////////////////
|
|
|
|
|
$html = '<p about="#mwt1" typeof="mw:Transclusion" id="mwAQ">hi</p>';
|
|
|
|
|
$originalHtml = '<p about="#mwt1" typeof="mw:Transclusion" id="mwAQ">ho</p>';
|
|
|
|
|
$dataParsoid = [ 'ids' => [ 'mwAQ' => [ 'pi' => [ [ [ 'k' => '1' ] ] ] ] ] ];
|
|
|
|
|
$dataMediaWiki = [
|
|
|
|
|
'ids' => [
|
|
|
|
|
'mwAQ' => [
|
|
|
|
|
'parts' => [ [
|
|
|
|
|
'template' => [
|
|
|
|
|
'target' => [ 'wt' => '1x', 'href' => './Template:1x' ],
|
|
|
|
|
'params' => [ '1' => [ 'wt' => 'hi' ] ],
|
|
|
|
|
'i' => 0
|
|
|
|
|
]
|
|
|
|
|
] ]
|
|
|
|
|
]
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
$params = [];
|
|
|
|
|
$body = [
|
|
|
|
|
'html' => $html,
|
|
|
|
|
'original' => [
|
|
|
|
|
'html' => [
|
|
|
|
|
'headers' => $htmlHeaders,
|
|
|
|
|
'body' => $originalHtml,
|
|
|
|
|
],
|
|
|
|
|
'data-parsoid' => [
|
|
|
|
|
'body' => $dataParsoid,
|
|
|
|
|
],
|
|
|
|
|
'data-mw' => [
|
|
|
|
|
'body' => $dataMediaWiki,
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
];
|
|
|
|
|
yield 'should apply original data-mw' => [
|
|
|
|
|
$body,
|
|
|
|
|
$params,
|
|
|
|
|
[ '{{1x|hi}}' ],
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
// should give precedence to inline data-mw over original ////////
|
|
|
|
|
$html = '<p about="#mwt1" typeof="mw:Transclusion" data-mw=\'{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"hi"}},"i":0}}]}\' id="mwAQ">hi</p>';
|
|
|
|
|
$originalHtml = '<p about="#mwt1" typeof="mw:Transclusion" id="mwAQ">ho</p>';
|
|
|
|
|
$dataParsoid = [ 'ids' => [ 'mwAQ' => [ 'pi' => [ [ [ 'k' => '1' ] ] ] ] ] ];
|
|
|
|
|
$dataMediaWiki = [ 'ids' => [ 'mwAQ' => [] ] ]; // Missing data-mw.parts!
|
|
|
|
|
$params = [];
|
|
|
|
|
$body = [
|
|
|
|
|
'html' => $html,
|
|
|
|
|
'original' => [
|
|
|
|
|
'html' => [
|
|
|
|
|
'headers' => $htmlHeaders,
|
|
|
|
|
'body' => $originalHtml
|
|
|
|
|
],
|
|
|
|
|
'data-parsoid' => [
|
|
|
|
|
'body' => $dataParsoid,
|
|
|
|
|
],
|
|
|
|
|
'data-mw' => [
|
|
|
|
|
'body' => $dataMediaWiki,
|
|
|
|
|
],
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
yield 'should give precedence to inline data-mw over original' => [
|
|
|
|
|
$body,
|
|
|
|
|
$params,
|
|
|
|
|
[ '{{1x|hi}}' ],
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
// should not apply original data-mw if modified is supplied ///////////
|
|
|
|
|
$html = '<p about="#mwt1" typeof="mw:Transclusion" id="mwAQ">hi</p>';
|
|
|
|
|
$originalHtml = '<p about="#mwt1" typeof="mw:Transclusion" id="mwAQ">ho</p>';
|
|
|
|
|
$dataParsoid = [ 'ids' => [ 'mwAQ' => [ 'pi' => [ [ [ 'k' => '1' ] ] ] ] ] ];
|
|
|
|
|
$dataMediaWiki = [ 'ids' => [ 'mwAQ' => [] ] ]; // Missing data-mw.parts!
|
|
|
|
|
$dataMediaWikiModified = [
|
|
|
|
|
'ids' => [
|
|
|
|
|
'mwAQ' => [
|
|
|
|
|
'parts' => [ [
|
|
|
|
|
'template' => [
|
|
|
|
|
'target' => [ 'wt' => '1x', 'href' => './Template:1x' ],
|
|
|
|
|
'params' => [ '1' => [ 'wt' => 'hi' ] ],
|
|
|
|
|
'i' => 0
|
|
|
|
|
]
|
|
|
|
|
] ]
|
|
|
|
|
]
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
$params = [];
|
|
|
|
|
$body = [
|
|
|
|
|
'html' => $html,
|
|
|
|
|
'data-mw' => [ // modified data
|
|
|
|
|
'body' => $dataMediaWikiModified,
|
|
|
|
|
],
|
|
|
|
|
'original' => [
|
|
|
|
|
'html' => [
|
|
|
|
|
'headers' => $htmlHeaders999,
|
|
|
|
|
'body' => $originalHtml
|
|
|
|
|
],
|
|
|
|
|
'data-parsoid' => [
|
|
|
|
|
'body' => $dataParsoid,
|
|
|
|
|
],
|
|
|
|
|
'data-mw' => [ // original data
|
|
|
|
|
'body' => $dataMediaWiki,
|
|
|
|
|
],
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
yield 'should not apply original data-mw if modified is supplied' => [
|
|
|
|
|
$body,
|
|
|
|
|
$params,
|
|
|
|
|
[ '{{1x|hi}}' ],
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
// should apply original data-mw when modified is absent (captions 1) ///////////
|
|
|
|
|
$html = $this->getTextFromFile( 'Image.html' );
|
|
|
|
|
$dataParsoid = [ 'ids' => [
|
|
|
|
|
'mwAg' => [ 'optList' => [ [ 'ck' => 'caption', 'ak' => 'Testing 123' ] ] ],
|
|
|
|
|
'mwAw' => [ 'a' => [ 'href' => './File:Foobar.jpg' ], 'sa' => [] ],
|
|
|
|
|
'mwBA' => [
|
|
|
|
|
'a' => [ 'resource' => './File:Foobar.jpg', 'height' => '28', 'width' => '240' ],
|
|
|
|
|
'sa' => [ 'resource' => 'File:Foobar.jpg' ]
|
|
|
|
|
]
|
|
|
|
|
] ];
|
|
|
|
|
$dataMediaWiki = [ 'ids' => [ 'mwAg' => [ 'caption' => 'Testing 123' ] ] ];
|
|
|
|
|
|
|
|
|
|
$params = [];
|
|
|
|
|
$body = [
|
|
|
|
|
'html' => $html,
|
|
|
|
|
'original' => [
|
|
|
|
|
'data-parsoid' => [
|
|
|
|
|
'body' => $dataParsoid,
|
|
|
|
|
],
|
|
|
|
|
'data-mw' => [ // original data
|
|
|
|
|
'body' => $dataMediaWiki,
|
|
|
|
|
],
|
|
|
|
|
'html' => [
|
|
|
|
|
'headers' => $htmlHeaders999,
|
|
|
|
|
'body' => $html
|
|
|
|
|
],
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
yield 'should apply original data-mw when modified is absent (captions 1)' => [
|
|
|
|
|
$body,
|
|
|
|
|
$params,
|
|
|
|
|
[ '[[File:Foobar.jpg|Testing 123]]' ],
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
// should give precedence to inline data-mw over modified (captions 2) /////////////
|
|
|
|
|
$htmlModified = $this->getTextFromFile( 'Image-data-mw.html' );
|
|
|
|
|
$dataMediaWikiModified = [
|
|
|
|
|
'ids' => [
|
|
|
|
|
'mwAg' => [ 'caption' => 'Testing 123' ]
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$params = [];
|
|
|
|
|
$body = [
|
|
|
|
|
'html' => $htmlModified, // modified HTML
|
|
|
|
|
'data-mw' => [
|
|
|
|
|
'body' => $dataMediaWikiModified,
|
|
|
|
|
],
|
|
|
|
|
'original' => [
|
|
|
|
|
'data-parsoid' => [
|
|
|
|
|
'body' => $dataParsoid,
|
|
|
|
|
],
|
|
|
|
|
'data-mw' => [ // original data
|
|
|
|
|
'body' => $dataMediaWiki,
|
|
|
|
|
],
|
|
|
|
|
'html' => [
|
|
|
|
|
'headers' => $htmlHeaders999,
|
|
|
|
|
'body' => $html
|
|
|
|
|
],
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
yield 'should give precedence to inline data-mw over modified (captions 2)' => [
|
|
|
|
|
$body,
|
|
|
|
|
$params,
|
|
|
|
|
[ '[[File:Foobar.jpg]]' ],
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
// should give precedence to modified data-mw over original (captions 3) /////////////
|
|
|
|
|
$dataMediaWikiModified = [
|
|
|
|
|
'ids' => [
|
|
|
|
|
'mwAg' => []
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$params = [];
|
|
|
|
|
$body = [
|
|
|
|
|
'html' => $html,
|
|
|
|
|
'data-mw' => [
|
|
|
|
|
'body' => $dataMediaWikiModified,
|
|
|
|
|
],
|
|
|
|
|
'original' => [
|
|
|
|
|
'data-parsoid' => [
|
|
|
|
|
'body' => $dataParsoid,
|
|
|
|
|
],
|
|
|
|
|
'data-mw' => [ // original data
|
|
|
|
|
'body' => $dataMediaWiki,
|
|
|
|
|
],
|
|
|
|
|
'html' => [
|
|
|
|
|
'headers' => $htmlHeaders999,
|
|
|
|
|
'body' => $html
|
|
|
|
|
],
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
yield 'should give precedence to modified data-mw over original (captions 3)' => [
|
|
|
|
|
$body,
|
|
|
|
|
$params,
|
|
|
|
|
[ '[[File:Foobar.jpg]]' ],
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
// should apply extra normalizations ///////////////////
|
|
|
|
|
$htmlModified = 'Foo<h2></h2>Bar';
|
|
|
|
|
$params = [
|
|
|
|
|
'opts' => [
|
|
|
|
|
'original' => []
|
|
|
|
|
],
|
|
|
|
|
];
|
|
|
|
|
$body = [ 'html' => $htmlModified ]; // modified HTML
|
|
|
|
|
yield 'should apply extra normalizations' => [
|
|
|
|
|
$body,
|
|
|
|
|
$params,
|
|
|
|
|
[ 'FooBar' ], // empty tag was stripped
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
// should apply version downgrade ///////////
|
|
|
|
|
$htmlOfMinimal = $this->getTextFromFile( 'Minimal.html' ); // Uses profile version 2.4.0
|
|
|
|
|
$params = [
|
|
|
|
|
'from' => ParsoidFormatHelper::FORMAT_PAGEBUNDLE,
|
|
|
|
|
];
|
|
|
|
|
$body = [
|
|
|
|
|
'html' => $htmlOfMinimal,
|
|
|
|
|
'original' => [
|
|
|
|
|
'html' => [
|
|
|
|
|
'headers' => [
|
|
|
|
|
// Specify newer profile version for original HTML
|
|
|
|
|
'content-type' => 'text/html;profile="https://www.mediawiki.org/wiki/Specs/HTML/999.0.0"'
|
|
|
|
|
],
|
|
|
|
|
// The profile version given inline in the original HTML doesn't matter, it's ignored
|
|
|
|
|
'body' => $htmlOfMinimal,
|
|
|
|
|
],
|
|
|
|
|
'data-parsoid' => [ 'body' => [ 'ids' => [] ] ],
|
|
|
|
|
'data-mw' => [ 'body' => [ 'ids' => [] ] ], // required by version 999.0.0
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
yield 'should apply version downgrade' => [
|
|
|
|
|
$body,
|
|
|
|
|
$params,
|
|
|
|
|
[ '123' ]
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
// should not apply version downgrade if versions are the same ///////////
|
|
|
|
|
$htmlOfMinimal = $this->getTextFromFile( 'Minimal.html' ); // Uses profile version 2.4.0
|
|
|
|
|
$params = [];
|
|
|
|
|
$body = [
|
|
|
|
|
'html' => $htmlOfMinimal,
|
|
|
|
|
'original' => [
|
|
|
|
|
'html' => [
|
|
|
|
|
'headers' => [
|
|
|
|
|
// Specify the exact same version specified inline in Minimal.html 2.4.0
|
|
|
|
|
'content-type' => 'text/html;profile="https://www.mediawiki.org/wiki/Specs/HTML/2.4.0"'
|
|
|
|
|
],
|
|
|
|
|
// The profile version given inline in the original HTML doesn't matter, it's ignored
|
|
|
|
|
'body' => $htmlOfMinimal,
|
|
|
|
|
],
|
|
|
|
|
'data-parsoid' => [ 'body' => [ 'ids' => [] ] ],
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
yield 'should not apply version downgrade if versions are the same' => [
|
|
|
|
|
$body,
|
|
|
|
|
$params,
|
|
|
|
|
[ '123' ]
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
// should convert html to json ///////////////////////////////////
|
|
|
|
|
$html = $this->getTextFromFile( 'JsonConfig.html' );
|
|
|
|
|
$expectedText = [
|
|
|
|
|
'{"a":4,"b":3}',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$params = [
|
|
|
|
|
'contentmodel' => CONTENT_MODEL_JSON,
|
|
|
|
|
];
|
|
|
|
|
$body = [ 'html' => $html ];
|
|
|
|
|
yield 'should convert html to json' => [
|
|
|
|
|
$body,
|
|
|
|
|
$params,
|
|
|
|
|
$expectedText,
|
|
|
|
|
[ 'content-type' => 'application/json' ],
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
// page bundle input should work with no original data present ///////////
|
|
|
|
|
$htmlOfMinimal = $this->getTextFromFile( 'Minimal.html' ); // Uses profile version 2.4.0
|
|
|
|
|
$params = [];
|
|
|
|
|
$body = [
|
|
|
|
|
'html' => $htmlOfMinimal,
|
|
|
|
|
'original' => [],
|
|
|
|
|
];
|
|
|
|
|
yield 'page bundle input should work with no original data present' => [
|
|
|
|
|
$body,
|
|
|
|
|
$params,
|
|
|
|
|
[ '123' ]
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function createResponse() {
|
|
|
|
|
$responseFactory = new ResponseFactory( [ new TextFormatter( 'qqx', new Converter() ) ] );
|
|
|
|
|
$response = $responseFactory->create();
|
|
|
|
|
return $response;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2023-08-09 15:43:50 +00:00
|
|
|
* @param array $body
|
|
|
|
|
* @param array $params
|
|
|
|
|
* @param string|string[]|null $expectedText Null means use the original content.
|
|
|
|
|
* @param array $expectedHeaders
|
2022-10-29 18:52:23 +00:00
|
|
|
* @dataProvider provideRequests()
|
2023-01-13 21:30:21 +00:00
|
|
|
* @covers \MediaWiki\Rest\Handler\Helper\HtmlInputTransformHelper
|
2022-10-16 21:44:53 +00:00
|
|
|
* @covers \MediaWiki\Parser\Parsoid\HtmlToContentTransform
|
2022-08-30 19:19:53 +00:00
|
|
|
*/
|
|
|
|
|
public function testResponse( $body, $params, $expectedText, array $expectedHeaders = [] ) {
|
|
|
|
|
if ( !empty( $params['oldid'] ) ) {
|
|
|
|
|
// If an oldid is set, run the test with an actual existing revision ID
|
2023-08-09 15:43:50 +00:00
|
|
|
$originalContent = __METHOD__ . ' original content';
|
|
|
|
|
$page = $this->getNonexistingTestPage();
|
|
|
|
|
$this->editPage( $page, new WikitextContent( $originalContent ) );
|
|
|
|
|
$page = $page->getTitle();
|
2022-08-30 19:19:53 +00:00
|
|
|
$params['oldid'] = $page->getLatestRevID();
|
|
|
|
|
} else {
|
|
|
|
|
$page = PageIdentityValue::localIdentity( 7, NS_MAIN, $body['pageName'] ?? 'HtmlInputTransformHelperTest' );
|
2023-08-09 15:43:50 +00:00
|
|
|
$originalContent = '';
|
2022-08-30 19:19:53 +00:00
|
|
|
}
|
|
|
|
|
|
2022-10-19 15:26:02 +00:00
|
|
|
$stats = new BufferingStatsdDataFactory( '' );
|
|
|
|
|
|
2022-08-30 19:19:53 +00:00
|
|
|
// TODO: find a way to test $pageLanguage
|
2024-06-05 15:49:49 +00:00
|
|
|
$helper = $this->newHelper( [], $stats, $page, $body, $params );
|
2022-08-30 19:19:53 +00:00
|
|
|
|
|
|
|
|
$response = $this->createResponse();
|
|
|
|
|
$helper->putContent( $response );
|
|
|
|
|
|
|
|
|
|
foreach ( $expectedHeaders as $name => $value ) {
|
|
|
|
|
$this->assertSame( $value, $response->getHeaderLine( $name ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$body = $response->getBody();
|
|
|
|
|
$body->rewind();
|
|
|
|
|
$text = $body->getContents();
|
|
|
|
|
|
2023-08-09 15:43:50 +00:00
|
|
|
$expectedText ??= $originalContent;
|
2022-08-30 19:19:53 +00:00
|
|
|
foreach ( (array)$expectedText as $exp ) {
|
|
|
|
|
$this->assertStringContainsString( $exp, $text );
|
|
|
|
|
}
|
2022-10-19 15:26:02 +00:00
|
|
|
|
|
|
|
|
// Ensure that exactly one key with the given prefix is set.
|
|
|
|
|
// This ensures that the number of keys set always adds up to 100%,
|
|
|
|
|
// for any set of keys under this prefix.
|
|
|
|
|
$this->assertMetricsCount( 1, $stats, 'html_input_transform.original_html.' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function assertMetricsCount( $expected, BufferingStatsdDataFactory $metrics, $prefix = '' ) {
|
|
|
|
|
$keys = [];
|
|
|
|
|
foreach ( $metrics->getData() as $datum ) {
|
|
|
|
|
if ( str_starts_with( $datum->getKey(), $prefix ) ) {
|
|
|
|
|
$keys[] = $datum->getKey();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->addToAssertionCount( 1 );
|
|
|
|
|
if ( count( $keys ) !== $expected ) {
|
|
|
|
|
$this->fail(
|
|
|
|
|
"Failed to assert that the number of metrics keys starting with '$prefix' is $expected. Keys: \n\t"
|
|
|
|
|
. implode( "\n\t", $keys )
|
|
|
|
|
);
|
|
|
|
|
}
|
2022-08-30 19:19:53 +00:00
|
|
|
}
|
|
|
|
|
|
2022-10-14 15:44:57 +00:00
|
|
|
public function provideOriginal() {
|
|
|
|
|
$unchangedPB = new PageBundle(
|
|
|
|
|
$this->getTextFromFile( 'MainPage-original.html' ),
|
|
|
|
|
$this->getJsonFromFile( 'MainPage-original.data-parsoid' ),
|
|
|
|
|
null,
|
|
|
|
|
Parsoid::defaultHTMLVersion()
|
|
|
|
|
);
|
|
|
|
|
|
2022-10-29 18:52:23 +00:00
|
|
|
$originalContent = new WikitextContent( 'Goats are great!' );
|
|
|
|
|
$selserContext = new SelserContext( $unchangedPB, 0, $originalContent );
|
|
|
|
|
|
2022-10-14 15:44:57 +00:00
|
|
|
$unchangedPO = PageBundleParserOutputConverter::parserOutputFromPageBundle( $unchangedPB );
|
|
|
|
|
|
|
|
|
|
$renderID = new ParsoidRenderID( 0, 'testing' );
|
|
|
|
|
|
|
|
|
|
yield 'no original data' => [
|
2022-10-29 18:52:23 +00:00
|
|
|
$selserContext,
|
2022-10-14 15:44:57 +00:00
|
|
|
null,
|
|
|
|
|
null,
|
|
|
|
|
[
|
|
|
|
|
'MediaWiki has been successfully installed',
|
|
|
|
|
'== Getting started ==',
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
// should load original wikitext by revision id ////////////////////
|
|
|
|
|
yield 'should load original wikitext by revision id' => [
|
2022-10-29 18:52:23 +00:00
|
|
|
$selserContext,
|
2022-10-14 15:44:57 +00:00
|
|
|
1, // will be replaced by the actual revid
|
|
|
|
|
$unchangedPB, // Expect selser, since HTML didn't change.
|
2023-08-09 15:43:50 +00:00
|
|
|
null, // Selser should preserve the original content.
|
2022-10-14 15:44:57 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
// should use wikitext from fake revision ////////////////////
|
|
|
|
|
$page = PageIdentityValue::localIdentity( 7, NS_MAIN, 'HtmlInputTransformHelperTest' );
|
|
|
|
|
$rev = new MutableRevisionRecord( $page );
|
|
|
|
|
$rev->setContent( SlotRecord::MAIN, new WikitextContent( 'Goats are great!' ) );
|
|
|
|
|
|
|
|
|
|
yield 'should use wikitext from fake revision' => [
|
2022-10-29 18:52:23 +00:00
|
|
|
$selserContext,
|
|
|
|
|
$rev,
|
2022-10-14 15:44:57 +00:00
|
|
|
$unchangedPO, // Expect selser, since HTML didn't change.
|
|
|
|
|
'Goats are great!', // Text from the fake revision. Selser should preserve it.
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
// should get original HTML from stash ////////////////////
|
|
|
|
|
yield 'should get original HTML from stash' => [
|
2022-10-29 18:52:23 +00:00
|
|
|
$selserContext,
|
|
|
|
|
$rev,
|
2022-10-14 15:44:57 +00:00
|
|
|
$renderID, // Expect selser, since HTML didn't change.
|
|
|
|
|
'Goats are great!', // Text from the fake revision. Selser should preserve it.
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provideOriginal()
|
|
|
|
|
*
|
2022-10-29 18:52:23 +00:00
|
|
|
* @param SelserContext|null $stashed
|
2022-10-14 15:44:57 +00:00
|
|
|
* @param RevisionRecord|int|null $rev
|
|
|
|
|
* @param ParsoidRenderID|PageBundle|ParserOutput|null $originalRendering
|
2023-08-09 15:43:50 +00:00
|
|
|
* @param string|string[]|null $expectedText Null means use the original content
|
2022-10-14 15:44:57 +00:00
|
|
|
*
|
2023-09-29 10:35:16 +00:00
|
|
|
* @covers \MediaWiki\Rest\Handler\Helper\HtmlInputTransformHelper::setOriginal
|
2022-10-14 15:44:57 +00:00
|
|
|
*/
|
2022-10-29 18:52:23 +00:00
|
|
|
public function testSetOriginal( ?SelserContext $stashed, $rev, $originalRendering, $expectedText ) {
|
2022-10-14 15:44:57 +00:00
|
|
|
if ( is_int( $rev ) && $rev > 0 ) {
|
|
|
|
|
// If a revision ID is given, run the test with an actual existing revision ID
|
2023-08-09 15:43:50 +00:00
|
|
|
$originalContent = __METHOD__ . ' original content';
|
|
|
|
|
$page = $this->getNonexistingTestPage();
|
|
|
|
|
$this->editPage( $page, new WikitextContent( $originalContent ) );
|
2022-10-29 18:52:23 +00:00
|
|
|
$page = $page->getTitle();
|
|
|
|
|
$revId = $page->getLatestRevID() ?: 0;
|
2023-08-09 15:43:50 +00:00
|
|
|
$rev = $revId;
|
2022-10-29 18:52:23 +00:00
|
|
|
} elseif ( $rev instanceof RevisionRecord ) {
|
2023-08-09 15:43:50 +00:00
|
|
|
$originalContentObj = $rev->getContent( SlotRecord::MAIN );
|
|
|
|
|
if ( !$originalContentObj instanceof TextContent ) {
|
|
|
|
|
throw new LogicException( 'Not implemented' );
|
|
|
|
|
}
|
|
|
|
|
$originalContent = $originalContentObj->getText();
|
2022-10-29 18:52:23 +00:00
|
|
|
$page = $rev->getPage();
|
|
|
|
|
$revId = $rev->getId() ?: 0;
|
2022-10-14 15:44:57 +00:00
|
|
|
} else {
|
2023-08-09 15:43:50 +00:00
|
|
|
$originalContent = '';
|
2022-10-14 15:44:57 +00:00
|
|
|
$page = PageIdentityValue::localIdentity( 7, NS_MAIN, 'HtmlInputTransformHelperTest' );
|
2022-10-29 18:52:23 +00:00
|
|
|
$revId = 0;
|
2022-10-14 15:44:57 +00:00
|
|
|
}
|
|
|
|
|
|
2022-10-29 18:52:23 +00:00
|
|
|
if ( $stashed ) {
|
|
|
|
|
$renderID = new ParsoidRenderID( $revId, 'testing' );
|
|
|
|
|
$stash = $this->getServiceContainer()->getParsoidOutputStash();
|
|
|
|
|
$stash->set( $renderID, $stashed );
|
|
|
|
|
}
|
2022-10-14 15:44:57 +00:00
|
|
|
|
|
|
|
|
$html = $this->getTextFromFile( 'MainPage-original.html' );
|
|
|
|
|
|
|
|
|
|
$params = [];
|
|
|
|
|
$body = [
|
|
|
|
|
'html' => $html
|
|
|
|
|
];
|
|
|
|
|
|
2022-10-19 15:26:02 +00:00
|
|
|
$stats = new BufferingStatsdDataFactory( '' );
|
|
|
|
|
|
2024-06-05 15:49:49 +00:00
|
|
|
$helper = $this->newHelper( [], $stats, $page, $body, $params );
|
2022-10-14 15:44:57 +00:00
|
|
|
|
|
|
|
|
$helper->setOriginal( $rev, $originalRendering );
|
|
|
|
|
|
|
|
|
|
$response = $this->createResponse();
|
|
|
|
|
$helper->putContent( $response );
|
|
|
|
|
|
|
|
|
|
$body = $response->getBody();
|
|
|
|
|
$body->rewind();
|
|
|
|
|
$text = $body->getContents();
|
|
|
|
|
|
2023-08-09 15:43:50 +00:00
|
|
|
$expectedText ??= $originalContent;
|
2022-10-14 15:44:57 +00:00
|
|
|
foreach ( (array)$expectedText as $exp ) {
|
|
|
|
|
$this->assertStringContainsString( $exp, $text );
|
|
|
|
|
}
|
2022-10-19 15:26:02 +00:00
|
|
|
|
|
|
|
|
// Ensure that exactly one key with the given prefix is set.
|
|
|
|
|
// This ensures that the number of keys set always adds up to 100%,
|
|
|
|
|
// for any set of keys under this prefix.
|
|
|
|
|
if ( $rev || $originalRendering ) {
|
|
|
|
|
$this->assertMetricsCount( 1, $stats, 'html_input_transform.original_html.given' );
|
|
|
|
|
} else {
|
|
|
|
|
$this->assertMetricsCount( 1, $stats, 'html_input_transform.original_html.not_given' );
|
|
|
|
|
}
|
2022-10-14 15:44:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2023-09-29 10:35:16 +00:00
|
|
|
* @covers \MediaWiki\Rest\Handler\Helper\HtmlInputTransformHelper::getTransform
|
2022-10-14 15:44:57 +00:00
|
|
|
*/
|
|
|
|
|
public function testGetTransform() {
|
|
|
|
|
$page = PageIdentityValue::localIdentity( 7, NS_MAIN, 'HtmlInputTransformHelperTest' );
|
|
|
|
|
$html = '<p>kittens are cute</p>';
|
|
|
|
|
|
|
|
|
|
$params = [];
|
|
|
|
|
$body = [
|
|
|
|
|
'html' => $html
|
|
|
|
|
];
|
|
|
|
|
|
2024-06-05 15:49:49 +00:00
|
|
|
$helper = $this->newHelper( [], null, $page, $body, $params );
|
2022-10-14 15:44:57 +00:00
|
|
|
|
|
|
|
|
$transform = $helper->getTransform();
|
|
|
|
|
|
|
|
|
|
$this->assertStringContainsString( 'kittens', ContentUtils::toXML( $transform->getModifiedDocument() ) );
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-30 19:19:53 +00:00
|
|
|
/**
|
2023-01-13 21:30:21 +00:00
|
|
|
* @covers \MediaWiki\Rest\Handler\Helper\HtmlInputTransformHelper
|
2022-10-16 21:44:53 +00:00
|
|
|
* @covers \MediaWiki\Parser\Parsoid\HtmlToContentTransform
|
2022-08-30 19:19:53 +00:00
|
|
|
*/
|
|
|
|
|
public function testResponseForFakeRevision() {
|
|
|
|
|
$wikitext = 'Unsaved Revision Content';
|
|
|
|
|
|
|
|
|
|
$html = $this->getTextFromFile( 'Minimal.html' );
|
|
|
|
|
$page = PageIdentityValue::localIdentity( 7, NS_MAIN, $body['pageName'] ?? 'HtmlInputTransformHelperTest' );
|
|
|
|
|
|
|
|
|
|
// Create a fake revision. Since the HTML didn't change, we expect to get back the content
|
|
|
|
|
// we defined for this revision.
|
|
|
|
|
$revision = new MutableRevisionRecord( $page );
|
|
|
|
|
$revision->setContent( SlotRecord::MAIN, new WikitextContent( $wikitext ) );
|
|
|
|
|
|
|
|
|
|
$params = [];
|
|
|
|
|
$body = [
|
|
|
|
|
'html' => $html,
|
|
|
|
|
'original' => [
|
|
|
|
|
'html' => [
|
|
|
|
|
'headers' => [ 'content-type' => 'text/html;profile="https://www.mediawiki.org/wiki/Specs/HTML/2.4.0"' ],
|
|
|
|
|
// original HTML is the same as the new HTML
|
|
|
|
|
'body' => $html
|
|
|
|
|
],
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$page = PageIdentityValue::localIdentity( 7, NS_MAIN, $body['pageName'] ?? 'HtmlInputTransformHelperTest' );
|
|
|
|
|
|
2024-06-05 15:49:49 +00:00
|
|
|
$helper = $this->newHelper( [], null, $page, $body, $params, $revision );
|
2022-08-30 19:19:53 +00:00
|
|
|
|
|
|
|
|
$response = $this->createResponse();
|
|
|
|
|
$helper->putContent( $response );
|
|
|
|
|
|
|
|
|
|
$body = $response->getBody();
|
|
|
|
|
$body->rewind();
|
|
|
|
|
|
|
|
|
|
// Since the HTML didn't change, we expect to get back the content of the fake revision.
|
|
|
|
|
$this->assertSame( $wikitext, $body->getContents() );
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-29 18:52:23 +00:00
|
|
|
public function testResponseWithRenderIdForExistingRevision() {
|
2022-09-09 09:32:17 +00:00
|
|
|
$profileVersion = '2.4.0';
|
|
|
|
|
$htmlProfileUri = 'https://www.mediawiki.org/wiki/Specs/HTML/' . $profileVersion;
|
|
|
|
|
$htmlContentType = "text/html;profile=\"$htmlProfileUri\"";
|
|
|
|
|
|
|
|
|
|
$htmlHeaders = [
|
|
|
|
|
'content-type' => $htmlContentType,
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$page = $this->getExistingTestPage();
|
|
|
|
|
$oldWikitext = $page->getContent()->serialize();
|
|
|
|
|
|
|
|
|
|
$html = $this->getTextFromFile( 'MainPage-original.html' );
|
|
|
|
|
$dataParsoid = $this->getJsonFromFile( 'MainPage-original.data-parsoid' );
|
|
|
|
|
|
|
|
|
|
$pb = new PageBundle(
|
|
|
|
|
$html,
|
|
|
|
|
$dataParsoid,
|
|
|
|
|
[],
|
|
|
|
|
$profileVersion,
|
|
|
|
|
$htmlHeaders,
|
|
|
|
|
CONTENT_MODEL_WIKITEXT
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$eTag = '"' . $page->getLatest() . '/just-a-test/edit"';
|
|
|
|
|
|
|
|
|
|
// Load the original data based on the ETag
|
|
|
|
|
$body = [ 'html' => $html, 'original' => [ 'renderid' => $eTag ] ];
|
|
|
|
|
$params = [];
|
|
|
|
|
|
|
|
|
|
$stash = $this->getServiceContainer()->getParsoidOutputStash();
|
2022-10-29 18:52:23 +00:00
|
|
|
$stash->set(
|
|
|
|
|
ParsoidRenderID::newFromETag( $eTag ),
|
|
|
|
|
new SelserContext( $pb, $page->getLatest() ),
|
|
|
|
|
);
|
|
|
|
|
|
2024-06-05 15:49:49 +00:00
|
|
|
$helper = $this->newHelper( [], null, $page, $body, $params );
|
2022-10-29 18:52:23 +00:00
|
|
|
|
|
|
|
|
$content = $helper->getContent();
|
|
|
|
|
|
|
|
|
|
// Assert that we get back the old wikitext, not wikitext derived from the HTML.
|
|
|
|
|
// Since the supplied HTML is the same as the HTML in the stash, selser should
|
|
|
|
|
// decide that there is nothing to do and return the wikitext unchanged.
|
|
|
|
|
$this->assertSame( $oldWikitext, $content->serialize() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testResponseWithRenderIdForUnsavedWikitext() {
|
|
|
|
|
$profileVersion = '2.4.0';
|
|
|
|
|
$htmlProfileUri = 'https://www.mediawiki.org/wiki/Specs/HTML/' . $profileVersion;
|
|
|
|
|
$htmlContentType = "text/html;profile=\"$htmlProfileUri\"";
|
|
|
|
|
|
|
|
|
|
$htmlHeaders = [
|
|
|
|
|
'content-type' => $htmlContentType,
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$page = $this->getNonexistingTestPage();
|
|
|
|
|
|
|
|
|
|
$html = $this->getTextFromFile( 'MainPage-original.html' );
|
|
|
|
|
$dataParsoid = $this->getJsonFromFile( 'MainPage-original.data-parsoid' );
|
|
|
|
|
$oldWikitext = 'Fake old wikitext';
|
|
|
|
|
|
|
|
|
|
$content = new WikitextContent( $oldWikitext );
|
|
|
|
|
$pb = new PageBundle(
|
|
|
|
|
$html,
|
|
|
|
|
$dataParsoid,
|
|
|
|
|
[],
|
|
|
|
|
$profileVersion,
|
|
|
|
|
$htmlHeaders,
|
|
|
|
|
CONTENT_MODEL_WIKITEXT
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// NOTE: Using 0 as the prefix in the ETag indicates that the content does
|
|
|
|
|
// not correspond to a saved revision. Since we don't have a revision
|
|
|
|
|
// ID that we could use to load the wikitext from the database,
|
|
|
|
|
// the wikitext should be taken from the stash.
|
|
|
|
|
// That is the behavior asserted by this test case.
|
|
|
|
|
$eTag = '"0/just-a-test/edit"';
|
|
|
|
|
|
|
|
|
|
// Load the original data based on the ETag
|
|
|
|
|
$body = [ 'html' => $html, 'original' => [ 'renderid' => $eTag ] ];
|
|
|
|
|
$params = [];
|
|
|
|
|
|
|
|
|
|
$stash = $this->getServiceContainer()->getParsoidOutputStash();
|
|
|
|
|
$stash->set(
|
|
|
|
|
ParsoidRenderID::newFromETag( $eTag ),
|
|
|
|
|
new SelserContext( $pb, 0, $content )
|
|
|
|
|
);
|
2022-09-09 09:32:17 +00:00
|
|
|
|
2024-06-05 15:49:49 +00:00
|
|
|
$helper = $this->newHelper( [], null, $page, $body, $params );
|
2022-09-09 09:32:17 +00:00
|
|
|
|
|
|
|
|
$content = $helper->getContent();
|
|
|
|
|
|
|
|
|
|
// Assert that we get back the old wikitext, not wikitext derived from the HTML.
|
|
|
|
|
// Since the supplied HTML is the same as the HTML in the stash, selser should
|
|
|
|
|
// decide that there is nothing to do and return the wikitext unchanged.
|
|
|
|
|
$this->assertSame( $oldWikitext, $content->serialize() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testETagWithBadUUIDFails() {
|
|
|
|
|
$page = $this->getExistingTestPage();
|
|
|
|
|
$html = 'whatever';
|
|
|
|
|
|
2022-09-13 15:52:44 +00:00
|
|
|
// Call getParserOutput() to make sure a rendering is in the ParserCache.
|
|
|
|
|
// Even though we find a rendering, it should be discarded because it doesn't match
|
|
|
|
|
// the ETag.
|
2024-05-15 17:21:13 +00:00
|
|
|
$access = $this->getServiceContainer()->getParserOutputAccess();
|
|
|
|
|
$pageLookup = $this->getServiceContainer()->getPageStore();
|
2022-09-13 15:52:44 +00:00
|
|
|
$popt = ParserOptions::newFromAnon();
|
2024-05-15 17:21:13 +00:00
|
|
|
$popt->setUseParsoid();
|
|
|
|
|
$access->getParserOutput( $pageLookup->getPageByReference( $page ), $popt )->getValue();
|
2022-09-13 15:52:44 +00:00
|
|
|
|
2022-09-09 09:32:17 +00:00
|
|
|
$revid = $page->getLatest();
|
|
|
|
|
$eTag = "\"$revid/nope-nope-nope\"";
|
|
|
|
|
|
|
|
|
|
$body = [ 'html' => $html, 'original' => [ 'renderid' => $eTag ] ];
|
|
|
|
|
$params = [];
|
|
|
|
|
|
|
|
|
|
$this->expectException( HttpException::class );
|
|
|
|
|
$this->expectExceptionCode( 412 );
|
2024-06-05 15:49:49 +00:00
|
|
|
$helper = $this->newHelper( [], null, $page, $body, $params );
|
2022-09-09 09:32:17 +00:00
|
|
|
$helper->getContent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testETagWithBadRevIDFails() {
|
|
|
|
|
$page = $this->getExistingTestPage();
|
|
|
|
|
$html = 'whatever';
|
|
|
|
|
|
|
|
|
|
// Non-Existing revision
|
|
|
|
|
$eTag = "\"1111111/nope-nope-nope\"";
|
|
|
|
|
|
|
|
|
|
$body = [ 'html' => $html, 'original' => [ 'renderid' => $eTag ] ];
|
|
|
|
|
$params = [];
|
|
|
|
|
|
|
|
|
|
$this->expectException( HttpException::class );
|
|
|
|
|
$this->expectExceptionCode( 412 );
|
2024-06-05 15:49:49 +00:00
|
|
|
$helper = $this->newHelper( [], null, $page, $body, $params );
|
2022-09-09 09:32:17 +00:00
|
|
|
$helper->getContent();
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-13 15:52:44 +00:00
|
|
|
public function testResponseWithRenderIDFallbackToParserCache() {
|
2022-09-27 20:53:02 +00:00
|
|
|
// use wikitext that would be normalized without selser.
|
|
|
|
|
$oldWikitext = '<p >testing</P>';
|
|
|
|
|
$rev = $this->editPage( __METHOD__, $oldWikitext )->value['revision-record'];
|
|
|
|
|
$page = $rev->getPage();
|
2022-09-09 09:32:17 +00:00
|
|
|
|
2024-05-15 17:21:13 +00:00
|
|
|
$access = $this->getServiceContainer()->getParserOutputAccess();
|
|
|
|
|
$pageLookup = $this->getServiceContainer()->getPageStore();
|
2022-09-09 09:32:17 +00:00
|
|
|
|
|
|
|
|
$popt = ParserOptions::newFromAnon();
|
2024-05-15 17:21:13 +00:00
|
|
|
$popt->setUseParsoid();
|
|
|
|
|
$pout = $access->getParserOutput( $pageLookup->getPageByReference( $page ), $popt )->getValue();
|
2022-09-09 09:32:17 +00:00
|
|
|
|
Add ParserOutput::{get,set}RenderId() and set render id in ContentRenderer
Set the render ID for each parse stored into cache so that we are able
to identify a specific parse when there are dependencies (for example
in an edit based on that parse). This is recorded as a property added
to the ParserOutput, not the parent CacheTime interface. Even though
the render ID is /related/ to the CacheTime interface, CacheTime is
also used directly as a parser cache key, and the UUID should not be
part of the lookup key.
In general we are trying to move the location where these cache
properties are set as early as possible, so we check at each location
to ensure we don't overwrite a previously-set value. Eventually we
can convert most of these checks into assertions that the cache
properties have already been set (T350538). The primary location for
setting cache properties is the ContentRenderer.
Moved setting the revision timestamp into ContentRenderer as well, as
it was set along the same code paths. An extra parameter was added to
ContentRenderer::getParserOutput() to support this.
Added merge code to ParserOutput::mergeInternalMetaDataFrom() which
should ensure that cache time, revision, timestamp, and render id are
all set properly when multiple slots are combined together in MCR.
In order to ensure the render ID is set on all codepaths we needed to
plumb the GlobalIdGenerator service into ContentRenderer, ParserCache,
ParserCacheFactory, and RevisionOutputCache. Eventually (T350538) it
should only be necessary in the ContentRenderer.
Bug: T350538
Bug: T349868
Followup-To: Ic9b7cc0fcf365e772b7d080d76a065e3fd585f80
Change-Id: I72c5e6f86b7f081ab5ce7a56f5365d2f75067a78
2023-09-14 16:11:20 +00:00
|
|
|
$key = ParsoidRenderID::newFromParserOutput( $pout )->getKey();
|
2022-09-09 09:32:17 +00:00
|
|
|
$html = $pout->getRawText();
|
|
|
|
|
|
|
|
|
|
// Load the original data based on the ETag
|
2022-09-13 15:52:44 +00:00
|
|
|
$body = [ 'html' => $html, 'original' => [ 'renderid' => $key ] ];
|
|
|
|
|
$params = [];
|
2022-09-09 09:32:17 +00:00
|
|
|
|
|
|
|
|
// We are asking for a stash key that is not in the stash.
|
|
|
|
|
// However, a rendering with the corresponding key is in the ParserCache.
|
|
|
|
|
// Because of this, the code below will not throw to trigger a 412 response.
|
2024-06-05 15:49:49 +00:00
|
|
|
$helper = $this->newHelper( [], null, $page, $body, $params );
|
2022-09-09 09:32:17 +00:00
|
|
|
$content = $helper->getContent();
|
|
|
|
|
|
2022-09-27 20:53:02 +00:00
|
|
|
// The wikitext should not have been normalized by re-serialization
|
|
|
|
|
$this->assertSame( $oldWikitext, $content->serialize() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testResponseWithRevisionIDFallbackToRendering() {
|
|
|
|
|
// use wikitext that would be normalized without selser.
|
|
|
|
|
$oldWikitext = '<p >testing</P>';
|
|
|
|
|
$rev = $this->editPage( __METHOD__, $oldWikitext )->value['revision-record'];
|
|
|
|
|
$page = $rev->getPage();
|
|
|
|
|
|
2024-05-15 17:21:13 +00:00
|
|
|
$access = $this->getServiceContainer()->getParserOutputAccess();
|
|
|
|
|
$pageLookup = $this->getServiceContainer()->getPageStore();
|
2022-09-27 20:53:02 +00:00
|
|
|
|
|
|
|
|
$popt = ParserOptions::newFromAnon();
|
2024-05-15 17:21:13 +00:00
|
|
|
$popt->setUseParsoid();
|
|
|
|
|
$pout = $access->getParserOutput( $pageLookup->getPageByReference( $page ), $popt )->getValue();
|
2022-09-27 20:53:02 +00:00
|
|
|
$html = $pout->getRawText();
|
|
|
|
|
|
|
|
|
|
// Load the original data based on the ETag
|
|
|
|
|
$body = [ 'html' => $html, 'original' => [ 'revid' => $rev->getId() ] ];
|
|
|
|
|
$params = [];
|
|
|
|
|
|
|
|
|
|
// We are asking for a stash key that is not in the stash.
|
|
|
|
|
// However, a rendering with the corresponding key is in the ParserCache.
|
2022-10-14 15:44:57 +00:00
|
|
|
// Because of this, the code below will not trigger a 412 response.
|
2024-06-05 15:49:49 +00:00
|
|
|
$helper = $this->newHelper( [], null, $page, $body, $params );
|
2022-09-27 20:53:02 +00:00
|
|
|
$content = $helper->getContent();
|
|
|
|
|
|
|
|
|
|
// The wikitext should not have been normalized by re-serialization
|
2022-09-09 09:32:17 +00:00
|
|
|
$this->assertSame( $oldWikitext, $content->serialize() );
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-23 11:36:19 +00:00
|
|
|
public static function provideHandlesParsoidError() {
|
2022-08-30 19:19:53 +00:00
|
|
|
yield 'ClientError' => [
|
|
|
|
|
new ClientError( 'TEST_TEST' ),
|
|
|
|
|
new LocalizedHttpException(
|
|
|
|
|
new MessageValue( 'rest-html-backend-error' ),
|
|
|
|
|
400,
|
|
|
|
|
[
|
|
|
|
|
'reason' => 'TEST_TEST'
|
|
|
|
|
]
|
|
|
|
|
)
|
|
|
|
|
];
|
|
|
|
|
yield 'ResourceLimitExceededException' => [
|
|
|
|
|
new ResourceLimitExceededException( 'TEST_TEST' ),
|
|
|
|
|
new LocalizedHttpException(
|
|
|
|
|
new MessageValue( 'rest-resource-limit-exceeded' ),
|
|
|
|
|
413,
|
|
|
|
|
[
|
|
|
|
|
'reason' => 'TEST_TEST'
|
|
|
|
|
]
|
|
|
|
|
)
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provideHandlesParsoidError
|
|
|
|
|
*/
|
|
|
|
|
public function testHandlesParsoidError(
|
|
|
|
|
Exception $parsoidException,
|
|
|
|
|
Exception $expectedException
|
|
|
|
|
) {
|
|
|
|
|
$page = $this->getExistingTestPage( __METHOD__ );
|
|
|
|
|
|
2024-06-05 15:49:49 +00:00
|
|
|
$body = [ 'html' => 'hi', ];
|
|
|
|
|
$params = [];
|
|
|
|
|
|
2022-08-30 19:19:53 +00:00
|
|
|
$helper = $this->newHelper( [
|
|
|
|
|
'htmlToContent' => static function () use ( $parsoidException ) {
|
|
|
|
|
throw $parsoidException;
|
|
|
|
|
}
|
2024-06-05 15:49:49 +00:00
|
|
|
], null, $page, $body, $params );
|
2022-08-30 19:19:53 +00:00
|
|
|
|
|
|
|
|
$this->expectExceptionObject( $expectedException );
|
|
|
|
|
$helper->getContent();
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-16 21:44:53 +00:00
|
|
|
private function newHtmlToContentTransform( $html, $methodOverrides = [] ): HtmlToContentTransform {
|
|
|
|
|
$transform = $this->getMockBuilder( HtmlToContentTransform::class )
|
2022-08-30 19:19:53 +00:00
|
|
|
->onlyMethods( array_keys( $methodOverrides ) )
|
|
|
|
|
->setConstructorArgs( [
|
|
|
|
|
$html,
|
|
|
|
|
$this->getExistingTestPage(),
|
|
|
|
|
new Parsoid(
|
|
|
|
|
$this->getServiceContainer()->getParsoidSiteConfig(),
|
|
|
|
|
$this->getServiceContainer()->getParsoidDataAccess()
|
|
|
|
|
),
|
|
|
|
|
MainConfigSchema::getDefaultValue( MainConfigNames::ParsoidSettings ),
|
|
|
|
|
$this->getServiceContainer()->getParsoidPageConfigFactory(),
|
|
|
|
|
$this->getServiceContainer()->getContentHandlerFactory()
|
|
|
|
|
] )
|
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
|
|
foreach ( $methodOverrides as $method => $callback ) {
|
|
|
|
|
$transform->method( $method )->willReturnCallback( $callback );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $transform;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|