diff --git a/includes/MediaWikiServices.php b/includes/MediaWikiServices.php index 1306d8cd668..5b21b57cb24 100644 --- a/includes/MediaWikiServices.php +++ b/includes/MediaWikiServices.php @@ -100,7 +100,7 @@ use MediaWiki\Page\UndeletePageFactory; use MediaWiki\Page\WikiPageFactory; use MediaWiki\Parser\ParserCacheFactory; use MediaWiki\Parser\Parsoid\Config\PageConfigFactory; -use MediaWiki\Parser\Parsoid\HTMLTransformFactory; +use MediaWiki\Parser\Parsoid\HtmlTransformFactory; use MediaWiki\Parser\Parsoid\ParsoidOutputAccess; use MediaWiki\Permissions\GrantsInfo; use MediaWiki\Permissions\GrantsLocalization; @@ -1065,11 +1065,11 @@ class MediaWikiServices extends ServiceContainer { } /** - * @return HTMLTransformFactory + * @return HtmlTransformFactory * @since 1.39 */ - public function getHTMLTransformFactory(): HTMLTransformFactory { - return $this->getService( 'HTMLTransformFactory' ); + public function getHtmlTransformFactory(): HtmlTransformFactory { + return $this->getService( 'HtmlTransformFactory' ); } /** diff --git a/includes/Rest/Handler/HtmlInputTransformHelper.php b/includes/Rest/Handler/HtmlInputTransformHelper.php index 24b7c4f2e05..78e6f7e6e60 100644 --- a/includes/Rest/Handler/HtmlInputTransformHelper.php +++ b/includes/Rest/Handler/HtmlInputTransformHelper.php @@ -29,8 +29,8 @@ use Liuggio\StatsdClient\Factory\StatsdDataFactoryInterface; use MediaWiki\Edit\ParsoidOutputStash; use MediaWiki\MainConfigNames; use MediaWiki\Page\PageIdentity; -use MediaWiki\Parser\Parsoid\HTMLTransform; -use MediaWiki\Parser\Parsoid\HTMLTransformFactory; +use MediaWiki\Parser\Parsoid\HtmlToContentTransform; +use MediaWiki\Parser\Parsoid\HtmlTransformFactory; use MediaWiki\Parser\Parsoid\PageBundleParserOutputConverter; use MediaWiki\Parser\Parsoid\ParsoidOutputAccess; use MediaWiki\Parser\Parsoid\ParsoidRenderID; @@ -66,7 +66,7 @@ class HtmlInputTransformHelper { MainConfigNames::ParsoidCacheConfig ]; - /** @var HTMLTransformFactory */ + /** @var HtmlTransformFactory */ private $htmlTransformFactory; /** @var PageIdentity|null */ @@ -79,7 +79,7 @@ class HtmlInputTransformHelper { private $parameters = null; /** - * @var HTMLTransform + * @var HtmlToContentTransform */ private $transform; @@ -100,14 +100,14 @@ class HtmlInputTransformHelper { /** * @param StatsdDataFactoryInterface $statsDataFactory - * @param HTMLTransformFactory $htmlTransformFactory + * @param HtmlTransformFactory $htmlTransformFactory * @param ParsoidOutputStash $parsoidOutputStash * @param ParsoidOutputAccess $parsoidOutputAccess * @param array $envOptions */ public function __construct( StatsdDataFactoryInterface $statsDataFactory, - HTMLTransformFactory $htmlTransformFactory, + HtmlTransformFactory $htmlTransformFactory, ParsoidOutputStash $parsoidOutputStash, ParsoidOutputAccess $parsoidOutputAccess, array $envOptions = [] @@ -304,7 +304,7 @@ class HtmlInputTransformHelper { $html = is_array( $body['html'] ) ? $body['html']['body'] : $body['html']; // TODO: validate $body against a proper schema. - $this->transform = $this->htmlTransformFactory->getHTMLTransform( + $this->transform = $this->htmlTransformFactory->getHtmlToContentTransform( $html, $this->page ); diff --git a/includes/Rest/Handler/HtmlOutputRendererHelper.php b/includes/Rest/Handler/HtmlOutputRendererHelper.php index df320abfcc5..c960267baf4 100644 --- a/includes/Rest/Handler/HtmlOutputRendererHelper.php +++ b/includes/Rest/Handler/HtmlOutputRendererHelper.php @@ -29,7 +29,7 @@ use MediaWiki\Edit\ParsoidOutputStash; use MediaWiki\MainConfigNames; use MediaWiki\Page\PageIdentity; use MediaWiki\Page\PageRecord; -use MediaWiki\Parser\Parsoid\HTMLTransformFactory; +use MediaWiki\Parser\Parsoid\HtmlTransformFactory; use MediaWiki\Parser\Parsoid\PageBundleParserOutputConverter; use MediaWiki\Parser\Parsoid\ParsoidOutputAccess; use MediaWiki\Parser\Parsoid\ParsoidRenderID; @@ -98,7 +98,7 @@ class HtmlOutputRendererHelper { /** @var ParserOutput */ private $processedParserOutput; - /** @var HTMLTransformFactory */ + /** @var HtmlTransformFactory */ private $htmlTransformFactory; /** @var string|null */ @@ -111,13 +111,13 @@ class HtmlOutputRendererHelper { * @param ParsoidOutputStash $parsoidOutputStash * @param IBufferingStatsdDataFactory $statsDataFactory * @param ParsoidOutputAccess $parsoidOutputAccess - * @param HTMLTransformFactory $htmlTransformFactory + * @param HtmlTransformFactory $htmlTransformFactory */ public function __construct( ParsoidOutputStash $parsoidOutputStash, IBufferingStatsdDataFactory $statsDataFactory, ParsoidOutputAccess $parsoidOutputAccess, - HTMLTransformFactory $htmlTransformFactory + HtmlTransformFactory $htmlTransformFactory ) { $this->parsoidOutputStash = $parsoidOutputStash; $this->stats = $statsDataFactory; diff --git a/includes/Rest/Handler/PageHTMLHandler.php b/includes/Rest/Handler/PageHTMLHandler.php index b5dfc7da284..7aeef2a1445 100644 --- a/includes/Rest/Handler/PageHTMLHandler.php +++ b/includes/Rest/Handler/PageHTMLHandler.php @@ -8,7 +8,7 @@ use LogicException; use MediaWiki\Edit\ParsoidOutputStash; use MediaWiki\MediaWikiServices; use MediaWiki\Page\PageLookup; -use MediaWiki\Parser\Parsoid\HTMLTransformFactory; +use MediaWiki\Parser\Parsoid\HtmlTransformFactory; use MediaWiki\Parser\Parsoid\ParsoidOutputAccess; use MediaWiki\Rest\LocalizedHttpException; use MediaWiki\Rest\Response; @@ -41,7 +41,7 @@ class PageHTMLHandler extends SimpleHandler { ParsoidOutputStash $parsoidOutputStash, IBufferingStatsdDataFactory $statsDataFactory, ParsoidOutputAccess $parsoidOutputAccess, - HTMLTransformFactory $htmlTransformFactory + HtmlTransformFactory $htmlTransformFactory ) { $this->contentHelper = new PageContentHelper( $config, diff --git a/includes/Rest/Handler/ParsoidHandler.php b/includes/Rest/Handler/ParsoidHandler.php index 38ff696f073..5bdf924f590 100644 --- a/includes/Rest/Handler/ParsoidHandler.php +++ b/includes/Rest/Handler/ParsoidHandler.php @@ -307,7 +307,7 @@ abstract class ParsoidHandler extends Handler { $helper = new HtmlInputTransformHelper( $this->siteConfig->metrics() ?: $services->getStatsdDataFactory(), - $services->getHTMLTransformFactory(), + $services->getHtmlTransformFactory(), $services->getParsoidOutputStash(), $services->getParsoidOutputAccess(), $attribs['envOptions'] @@ -891,7 +891,7 @@ abstract class ParsoidHandler extends Handler { ) { if ( $page instanceof PageConfig ) { // TODO: Deprecate passing a PageConfig. - // Ideally, callers would use HTMLTransform directly. + // Ideally, callers would use HtmlToContentTransform directly. // XXX: This is slow, and we already have the parsed title and ID inside the PageConfig... $page = Title::newFromTextThrow( $page->getTitle() ); } @@ -1085,7 +1085,7 @@ abstract class ParsoidHandler extends Handler { ); $languageVariantConverter = MediaWikiServices::getInstance() - ->getHTMLTransformFactory() + ->getHtmlTransformFactory() ->getLanguageVariantConverter( $pageIdentity ); $languageVariantConverter->setPageConfig( $pageConfig ); $httpContentLanguage = $attribs['pagelanguage' ] ?? null; diff --git a/includes/Rest/Handler/RevisionHTMLHandler.php b/includes/Rest/Handler/RevisionHTMLHandler.php index be47de6b138..168f9de5d60 100644 --- a/includes/Rest/Handler/RevisionHTMLHandler.php +++ b/includes/Rest/Handler/RevisionHTMLHandler.php @@ -8,7 +8,7 @@ use LogicException; use MediaWiki\Edit\ParsoidOutputStash; use MediaWiki\MediaWikiServices; use MediaWiki\Page\PageLookup; -use MediaWiki\Parser\Parsoid\HTMLTransformFactory; +use MediaWiki\Parser\Parsoid\HtmlTransformFactory; use MediaWiki\Parser\Parsoid\ParsoidOutputAccess; use MediaWiki\Rest\LocalizedHttpException; use MediaWiki\Rest\Response; @@ -42,7 +42,7 @@ class RevisionHTMLHandler extends SimpleHandler { ParsoidOutputStash $parsoidOutputStash, IBufferingStatsdDataFactory $statsDataFactory, ParsoidOutputAccess $parsoidOutputAccess, - HTMLTransformFactory $htmlTransformFactory + HtmlTransformFactory $htmlTransformFactory ) { $this->contentHelper = new RevisionContentHelper( $config, diff --git a/includes/Rest/coreRoutes.json b/includes/Rest/coreRoutes.json index afd3808e9a0..3f67445d2e7 100644 --- a/includes/Rest/coreRoutes.json +++ b/includes/Rest/coreRoutes.json @@ -54,7 +54,7 @@ "ParsoidOutputStash", "StatsdDataFactory", "ParsoidOutputAccess", - "HTMLTransformFactory" + "HtmlTransformFactory" ], "format": "html" }, @@ -69,7 +69,7 @@ "ParsoidOutputStash", "StatsdDataFactory", "ParsoidOutputAccess", - "HTMLTransformFactory" + "HtmlTransformFactory" ], "format": "with_html" }, @@ -158,7 +158,7 @@ "ParsoidOutputStash", "StatsdDataFactory", "ParsoidOutputAccess", - "HTMLTransformFactory" + "HtmlTransformFactory" ], "format": "html" }, @@ -173,7 +173,7 @@ "ParsoidOutputStash", "StatsdDataFactory", "ParsoidOutputAccess", - "HTMLTransformFactory" + "HtmlTransformFactory" ], "format": "with_html" }, diff --git a/includes/ServiceWiring.php b/includes/ServiceWiring.php index 168273002f5..7e05620f9ea 100644 --- a/includes/ServiceWiring.php +++ b/includes/ServiceWiring.php @@ -119,7 +119,7 @@ use MediaWiki\Parser\ParserObserver; use MediaWiki\Parser\Parsoid\Config\DataAccess as MWDataAccess; use MediaWiki\Parser\Parsoid\Config\PageConfigFactory as MWPageConfigFactory; use MediaWiki\Parser\Parsoid\Config\SiteConfig as MWSiteConfig; -use MediaWiki\Parser\Parsoid\HTMLTransformFactory; +use MediaWiki\Parser\Parsoid\HtmlTransformFactory; use MediaWiki\Parser\Parsoid\ParsoidOutputAccess; use MediaWiki\Permissions\GrantsInfo; use MediaWiki\Permissions\GrantsLocalization; @@ -736,8 +736,8 @@ return [ ); }, - 'HTMLTransformFactory' => static function ( MediaWikiServices $services ): HTMLTransformFactory { - return new HTMLTransformFactory( + 'HtmlTransformFactory' => static function ( MediaWikiServices $services ): HtmlTransformFactory { + return new HtmlTransformFactory( $services->getService( '_Parsoid' ), $services->getMainConfig()->get( MainConfigNames::ParsoidSettings ), $services->getParsoidPageConfigFactory(), diff --git a/includes/parser/Parsoid/HTMLTransform.php b/includes/parser/Parsoid/HtmlToContentTransform.php similarity index 99% rename from includes/parser/Parsoid/HTMLTransform.php rename to includes/parser/Parsoid/HtmlToContentTransform.php index f1f048e1878..5e7c90703da 100644 --- a/includes/parser/Parsoid/HTMLTransform.php +++ b/includes/parser/Parsoid/HtmlToContentTransform.php @@ -34,7 +34,7 @@ use Wikimedia\Parsoid\Utils\Timing; * @since 1.40 * @unstable should be stable before 1.40 release */ -class HTMLTransform { +class HtmlToContentTransform { /** @var array */ private $options = []; diff --git a/includes/parser/Parsoid/HTMLTransformFactory.php b/includes/parser/Parsoid/HtmlTransformFactory.php similarity index 92% rename from includes/parser/Parsoid/HTMLTransformFactory.php rename to includes/parser/Parsoid/HtmlTransformFactory.php index a5d7c419061..2690a71dad8 100644 --- a/includes/parser/Parsoid/HTMLTransformFactory.php +++ b/includes/parser/Parsoid/HtmlTransformFactory.php @@ -14,7 +14,7 @@ use Wikimedia\Parsoid\Parsoid; * @since 1.40 * @unstable should be marked stable before 1.40 release */ -class HTMLTransformFactory { +class HtmlTransformFactory { /** @var Parsoid */ private $parsoid; @@ -71,10 +71,10 @@ class HTMLTransformFactory { * @param string $modifiedHTML * @param PageIdentity $page * - * @return HTMLTransform + * @return HtmlToContentTransform */ - public function getHTMLTransform( string $modifiedHTML, PageIdentity $page ) { - return new HTMLTransform( + public function getHtmlToContentTransform( string $modifiedHTML, PageIdentity $page ) { + return new HtmlToContentTransform( $modifiedHTML, $page, $this->parsoid, diff --git a/tests/phpunit/integration/includes/Rest/Handler/HtmlInputTransformHelperTest.php b/tests/phpunit/integration/includes/Rest/Handler/HtmlInputTransformHelperTest.php index a3e53409a71..79bfe25c126 100644 --- a/tests/phpunit/integration/includes/Rest/Handler/HtmlInputTransformHelperTest.php +++ b/tests/phpunit/integration/includes/Rest/Handler/HtmlInputTransformHelperTest.php @@ -8,8 +8,8 @@ use MediaWiki\MainConfigSchema; use MediaWiki\Message\Converter; use MediaWiki\Message\TextFormatter; use MediaWiki\Page\PageIdentityValue; -use MediaWiki\Parser\Parsoid\HTMLTransform; -use MediaWiki\Parser\Parsoid\HTMLTransformFactory; +use MediaWiki\Parser\Parsoid\HtmlToContentTransform; +use MediaWiki\Parser\Parsoid\HtmlTransformFactory; use MediaWiki\Parser\Parsoid\ParsoidRenderID; use MediaWiki\Rest\Handler\HtmlInputTransformHelper; use MediaWiki\Rest\Handler\ParsoidFormatHelper; @@ -54,14 +54,14 @@ class HtmlInputTransformHelperTest extends MediaWikiIntegrationTestCase { /** * @param array $methodOverrides * - * @return MockObject|HTMLTransformFactory + * @return MockObject|HtmlTransformFactory */ - public function newMockHTMLTransformFactory( $methodOverrides = [] ): HTMLTransformFactory { - $factory = $this->createNoOpMock( HTMLTransformFactory::class, [ 'getHTMLTransform' ] ); + public function newMockHtmlTransformFactory( $methodOverrides = [] ): HtmlTransformFactory { + $factory = $this->createNoOpMock( HtmlTransformFactory::class, [ 'getHtmlToContentTransform' ] ); - $factory->method( 'getHTMLTransform' )->willReturnCallback( + $factory->method( 'getHtmlToContentTransform' )->willReturnCallback( function ( $html ) use ( $methodOverrides ) { - return $this->newHTMLTransform( $html, $methodOverrides ); + return $this->newHtmlToContentTransform( $html, $methodOverrides ); } ); @@ -80,7 +80,7 @@ class HtmlInputTransformHelperTest extends MediaWikiIntegrationTestCase { $helper = new HtmlInputTransformHelper( new NullStatsdDataFactory(), - $this->newMockHTMLTransformFactory( $transformMethodOverrides ), + $this->newMockHtmlTransformFactory( $transformMethodOverrides ), $this->getServiceContainer()->getParsoidOutputStash(), $this->getServiceContainer()->getParsoidOutputAccess() ); @@ -666,7 +666,7 @@ class HtmlInputTransformHelperTest extends MediaWikiIntegrationTestCase { /** * @dataProvider provideResponse() * @covers \MediaWiki\Rest\Handler\HtmlInputTransformHelper - * @covers \MediaWiki\Parser\Parsoid\HTMLTransform + * @covers \MediaWiki\Parser\Parsoid\HtmlToContentTransform */ public function testResponse( $body, $params, $expectedText, array $expectedHeaders = [] ) { if ( !empty( $params['oldid'] ) ) { @@ -699,7 +699,7 @@ class HtmlInputTransformHelperTest extends MediaWikiIntegrationTestCase { /** * @covers \MediaWiki\Rest\Handler\HtmlInputTransformHelper - * @covers \MediaWiki\Parser\Parsoid\HTMLTransform + * @covers \MediaWiki\Parser\Parsoid\HtmlToContentTransform */ public function testResponseForFakeRevision() { $wikitext = 'Unsaved Revision Content'; @@ -931,8 +931,8 @@ class HtmlInputTransformHelperTest extends MediaWikiIntegrationTestCase { $helper->getContent(); } - private function newHTMLTransform( $html, $methodOverrides = [] ): HTMLTransform { - $transform = $this->getMockBuilder( HTMLTransform::class ) + private function newHtmlToContentTransform( $html, $methodOverrides = [] ): HtmlToContentTransform { + $transform = $this->getMockBuilder( HtmlToContentTransform::class ) ->onlyMethods( array_keys( $methodOverrides ) ) ->setConstructorArgs( [ $html, diff --git a/tests/phpunit/integration/includes/Rest/Handler/HtmlOutputRendererHelperTest.php b/tests/phpunit/integration/includes/Rest/Handler/HtmlOutputRendererHelperTest.php index 7d0f4f87bb9..33f90ac7546 100644 --- a/tests/phpunit/integration/includes/Rest/Handler/HtmlOutputRendererHelperTest.php +++ b/tests/phpunit/integration/includes/Rest/Handler/HtmlOutputRendererHelperTest.php @@ -227,7 +227,7 @@ class HtmlOutputRendererHelperTest extends MediaWikiIntegrationTestCase { $stash, new NullStatsdDataFactory(), $access ?? $this->newMockParsoidOutputAccess(), - $this->getServiceContainer()->getHTMLTransformFactory() + $this->getServiceContainer()->getHtmlTransformFactory() ); return $helper; diff --git a/tests/phpunit/integration/includes/Rest/Handler/PageHTMLHandlerTest.php b/tests/phpunit/integration/includes/Rest/Handler/PageHTMLHandlerTest.php index 56a886da79d..a214ae2932c 100644 --- a/tests/phpunit/integration/includes/Rest/Handler/PageHTMLHandlerTest.php +++ b/tests/phpunit/integration/includes/Rest/Handler/PageHTMLHandlerTest.php @@ -117,7 +117,7 @@ class PageHTMLHandlerTest extends MediaWikiIntegrationTestCase { $this->getParsoidOutputStash(), $services->getStatsdDataFactory(), $parsoidOutputAccess, - $services->getHTMLTransformFactory() + $services->getHtmlTransformFactory() ); return $handler; diff --git a/tests/phpunit/integration/includes/Rest/Handler/ParsoidHandlerTest.php b/tests/phpunit/integration/includes/Rest/Handler/ParsoidHandlerTest.php index 37e97a885f1..3853ab13d8a 100644 --- a/tests/phpunit/integration/includes/Rest/Handler/ParsoidHandlerTest.php +++ b/tests/phpunit/integration/includes/Rest/Handler/ParsoidHandlerTest.php @@ -8,8 +8,8 @@ use MediaWiki\MainConfigNames; use MediaWiki\MainConfigSchema; use MediaWiki\Page\PageIdentity; use MediaWiki\Parser\Parsoid\Config\PageConfigFactory; -use MediaWiki\Parser\Parsoid\HTMLTransform; -use MediaWiki\Parser\Parsoid\HTMLTransformFactory; +use MediaWiki\Parser\Parsoid\HtmlToContentTransform; +use MediaWiki\Parser\Parsoid\HtmlTransformFactory; use MediaWiki\Permissions\UltimateAuthority; use MediaWiki\Rest\Handler\HtmlInputTransformHelper; use MediaWiki\Rest\Handler\ParsoidFormatHelper; @@ -39,7 +39,7 @@ use Wikimedia\Parsoid\Parsoid; /** * @group Database * @covers \MediaWiki\Rest\Handler\ParsoidHandler - * @covers \MediaWiki\Parser\Parsoid\HTMLTransform + * @covers \MediaWiki\Parser\Parsoid\HtmlToContentTransform */ class ParsoidHandlerTest extends MediaWikiIntegrationTestCase { use RestTestTrait; @@ -1325,10 +1325,10 @@ class ParsoidHandlerTest extends MediaWikiIntegrationTestCase { $parsoid = $this->createNoOpMock( Parsoid::class, [ 'dom2wikitext' ] ); $parsoid->method( 'dom2wikitext' )->willThrowException( $throw ); - // Make a fake HTMLTransformFactory that returns an HTMLTransform that uses the fake Parsoid. - /** @var HTMLTransformFactory|MockObject $factory */ - $factory = $this->createNoOpMock( HTMLTransformFactory::class, [ 'getHTMLTransform' ] ); - $factory->method( 'getHTMLTransform' )->willReturn( new HTMLTransform( + // Make a fake HtmlTransformFactory that returns an HtmlToContentTransform that uses the fake Parsoid. + /** @var HtmlTransformFactory|MockObject $factory */ + $factory = $this->createNoOpMock( HtmlTransformFactory::class, [ 'getHtmlToContentTransform' ] ); + $factory->method( 'getHtmlToContentTransform' )->willReturn( new HtmlToContentTransform( $html, $page, $parsoid, @@ -1337,8 +1337,8 @@ class ParsoidHandlerTest extends MediaWikiIntegrationTestCase { $this->getServiceContainer()->getContentHandlerFactory() ) ); - // Use an HtmlInputTransformHelper that uses the fake HTMLTransformFactory, so it ends up - // using the HTMLTransform that has the fake Parsoid which throws an exception. + // Use an HtmlInputTransformHelper that uses the fake HtmlTransformFactory, so it ends up + // using the HtmlToContentTransform that has the fake Parsoid which throws an exception. $handler = $this->newParsoidHandler( [ 'getHtmlInputHelper' => function () use ( $factory, $page, $html ) { $helper = new HtmlInputTransformHelper( diff --git a/tests/phpunit/integration/includes/Rest/Handler/RevisionHTMLHandlerTest.php b/tests/phpunit/integration/includes/Rest/Handler/RevisionHTMLHandlerTest.php index 8fe57e33165..ee620e38a35 100644 --- a/tests/phpunit/integration/includes/Rest/Handler/RevisionHTMLHandlerTest.php +++ b/tests/phpunit/integration/includes/Rest/Handler/RevisionHTMLHandlerTest.php @@ -129,7 +129,7 @@ class RevisionHTMLHandlerTest extends MediaWikiIntegrationTestCase { $this->getParsoidOutputStash(), $services->getStatsdDataFactory(), $parsoidOutputAccess, - $services->getHTMLTransformFactory() + $services->getHtmlTransformFactory() ); return $handler; diff --git a/tests/phpunit/integration/includes/parser/Parsoid/HTMLTransformFactoryTest.php b/tests/phpunit/integration/includes/parser/Parsoid/HTMLTransformFactoryTest.php deleted file mode 100644 index 430c6bedf16..00000000000 --- a/tests/phpunit/integration/includes/parser/Parsoid/HTMLTransformFactoryTest.php +++ /dev/null @@ -1,42 +0,0 @@ -getServiceContainer()->getHTMLTransformFactory(); - $this->assertInstanceOf( HTMLTransformFactory::class, $factory ); - } - - /** - * @covers ::getHTMLTransform - */ - public function testGetHTMLTransform() { - $factory = $this->getServiceContainer()->getHTMLTransformFactory(); - $modifiedHTML = '

Hello World

'; - - $transform = $factory->getHTMLTransform( - $modifiedHTML, - PageIdentityValue::localIdentity( 0, NS_MAIN, 'Test' ) - ); - - $this->assertInstanceOf( HTMLTransform::class, $transform ); - - $actualHTML = ContentUtils::toXML( DOMCompat::getBody( $transform->getModifiedDocument() ) ); - $this->assertStringContainsString( $modifiedHTML, $actualHTML ); - } - -} diff --git a/tests/phpunit/integration/includes/parser/Parsoid/HTMLTransformTest.php b/tests/phpunit/integration/includes/parser/Parsoid/HtmlToContentTransformTest.php similarity index 82% rename from tests/phpunit/integration/includes/parser/Parsoid/HTMLTransformTest.php rename to tests/phpunit/integration/includes/parser/Parsoid/HtmlToContentTransformTest.php index e8f781e1691..9313801a61e 100644 --- a/tests/phpunit/integration/includes/parser/Parsoid/HTMLTransformTest.php +++ b/tests/phpunit/integration/includes/parser/Parsoid/HtmlToContentTransformTest.php @@ -8,7 +8,7 @@ use Liuggio\StatsdClient\Factory\StatsdDataFactoryInterface; use LogicException; use MediaWiki\Page\PageIdentityValue; use MediaWiki\Parser\Parsoid\Config\PageConfigFactory; -use MediaWiki\Parser\Parsoid\HTMLTransform; +use MediaWiki\Parser\Parsoid\HtmlToContentTransform; use MediaWiki\Revision\MutableRevisionRecord; use MediaWikiIntegrationTestCase; use PHPUnit\Framework\MockObject\MockObject; @@ -19,9 +19,9 @@ use Wikimedia\Parsoid\Utils\ContentUtils; use WikitextContent; /** - * @covers \MediaWiki\Parser\Parsoid\HTMLTransform + * @covers \MediaWiki\Parser\Parsoid\HtmlToContentTransform */ -class HTMLTransformTest extends MediaWikiIntegrationTestCase { +class HtmlToContentTransformTest extends MediaWikiIntegrationTestCase { private const MODIFIED_HTML = '' . '' . 'Modified HTML'; @@ -40,7 +40,7 @@ class HTMLTransformTest extends MediaWikiIntegrationTestCase { ] ] ] ] ]; - private function setOriginalData( HTMLTransform $transform ) { + private function setOriginalData( HtmlToContentTransform $transform ) { $transform->setOriginalRevisionId( 1 ); $transform->setOriginalSchemaVersion( '2.4.0' ); $transform->setOriginalHtml( self::ORIG_HTML ); @@ -48,12 +48,12 @@ class HTMLTransformTest extends MediaWikiIntegrationTestCase { $transform->setOriginalDataParsoid( self::ORIG_DATA_PARSOID ); } - private function createHTMLTransform( $html = '' ) { + private function createHtmlToContentTransform( $html = '' ) { /** @var PageConfigFactory|MockObject $pageConfigFactory */ $pageConfigFactory = $this->createNoOpMock( PageConfigFactory::class, [ 'create' ] ); $pageConfigFactory->method( 'create' )->willReturn( new MockPageConfig( [], null ) ); - return new HTMLTransform( + return new HtmlToContentTransform( $html ?? self::ORIG_HTML, PageIdentityValue::localIdentity( 7, NS_MAIN, 'Test' ), new Parsoid( @@ -66,8 +66,8 @@ class HTMLTransformTest extends MediaWikiIntegrationTestCase { ); } - private function createHTMLTransformWithOriginalData( $html = '' ) { - $transform = $this->createHTMLTransform( $html ); + private function createHtmlToContentTransformWithOriginalData( $html = '' ) { + $transform = $this->createHtmlToContentTransform( $html ); // Set some options to assert on $transform object. $transform->setOptions( [ @@ -81,7 +81,7 @@ class HTMLTransformTest extends MediaWikiIntegrationTestCase { } public function testGetOriginalBodyRequiresValidDataParsoid() { - $transform = $this->createHTMLTransform( self::ORIG_HTML ); + $transform = $this->createHtmlToContentTransform( self::ORIG_HTML ); $transform->setOriginalSchemaVersion( '2.4.0' ); $transform->setOriginalHtml( self::ORIG_HTML ); @@ -100,7 +100,7 @@ class HTMLTransformTest extends MediaWikiIntegrationTestCase { } public function testHasOriginalHtml() { - $transform = $this->createHTMLTransform( self::MODIFIED_HTML ); + $transform = $this->createHtmlToContentTransform( self::MODIFIED_HTML ); $this->assertFalse( $transform->hasOriginalHtml() ); $transform->setOriginalDataParsoid( self::ORIG_DATA_PARSOID ); @@ -111,10 +111,10 @@ class HTMLTransformTest extends MediaWikiIntegrationTestCase { } public function testGetOriginalSchemaVersion() { - $transform = $this->createHTMLTransform( self::ORIG_HTML ); // no version inline + $transform = $this->createHtmlToContentTransform( self::ORIG_HTML ); // no version inline $this->assertSame( Parsoid::defaultHTMLVersion(), $transform->getOriginalSchemaVersion() ); - $transform = $this->createHTMLTransform( self::MODIFIED_HTML ); // has version inline + $transform = $this->createHtmlToContentTransform( self::MODIFIED_HTML ); // has version inline $this->assertSame( '2.4.0', $transform->getOriginalSchemaVersion() ); $transform->setOriginalSchemaVersion( '2.3.0' ); @@ -122,14 +122,14 @@ class HTMLTransformTest extends MediaWikiIntegrationTestCase { } public function testGetSchemaVersion() { - $transform = $this->createHTMLTransform( self::ORIG_HTML ); // no version inline + $transform = $this->createHtmlToContentTransform( self::ORIG_HTML ); // no version inline $this->assertSame( Parsoid::defaultHTMLVersion(), $transform->getSchemaVersion() ); // Should have an effect, since the HTML has no version specified inline $transform->setOriginalSchemaVersion( '2.3.0' ); $this->assertSame( '2.3.0', $transform->getSchemaVersion() ); - $transform = $this->createHTMLTransform( self::MODIFIED_HTML ); // has version inline + $transform = $this->createHtmlToContentTransform( self::MODIFIED_HTML ); // has version inline $this->assertSame( '2.4.0', $transform->getSchemaVersion() ); // Should have no impact, since the HTML has a version specified inline @@ -138,7 +138,7 @@ class HTMLTransformTest extends MediaWikiIntegrationTestCase { } public function testHasOriginalDataParsoid() { - $transform = $this->createHTMLTransform( self::MODIFIED_HTML ); + $transform = $this->createHtmlToContentTransform( self::MODIFIED_HTML ); $this->assertFalse( $transform->hasOriginalDataParsoid() ); $transform->setOriginalDataParsoid( self::ORIG_DATA_PARSOID ); @@ -146,7 +146,7 @@ class HTMLTransformTest extends MediaWikiIntegrationTestCase { } public function testGetOriginalHtml() { - $transform = $this->createHTMLTransform( self::MODIFIED_HTML ); + $transform = $this->createHtmlToContentTransform( self::MODIFIED_HTML ); $this->assertFalse( $transform->hasOriginalHtml() ); @@ -158,7 +158,7 @@ class HTMLTransformTest extends MediaWikiIntegrationTestCase { } public function testGetOriginalBody() { - $transform = $this->createHTMLTransform( self::MODIFIED_HTML ); + $transform = $this->createHtmlToContentTransform( self::MODIFIED_HTML ); $transform->setOriginalSchemaVersion( '2.4.0' ); $transform->setOriginalHtml( self::ORIG_HTML ); @@ -169,7 +169,7 @@ class HTMLTransformTest extends MediaWikiIntegrationTestCase { } public function testOldId() { - $transform = $this->createHTMLTransformWithOriginalData(); + $transform = $this->createHtmlToContentTransformWithOriginalData(); $this->assertSame( 1, $transform->getOriginalRevisionId() ); $this->assertTrue( $transform->knowsOriginalRevision() ); } @@ -179,19 +179,19 @@ class HTMLTransformTest extends MediaWikiIntegrationTestCase { $rev = new MutableRevisionRecord( $page ); $rev->setId( 1337 ); - $transform = $this->createHTMLTransformWithOriginalData(); + $transform = $this->createHtmlToContentTransformWithOriginalData(); $transform->setOriginalRevision( $rev ); $this->assertTrue( $transform->knowsOriginalRevision() ); $this->assertSame( $rev->getId(), $transform->getOriginalRevisionId() ); } public function testGetContentModel() { - $transform = $this->createHTMLTransformWithOriginalData(); + $transform = $this->createHtmlToContentTransformWithOriginalData(); $this->assertSame( 'wikitext', $transform->getContentModel() ); } public function testGetEnvOpts() { - $transform = $this->createHTMLTransformWithOriginalData(); + $transform = $this->createHtmlToContentTransformWithOriginalData(); $this->assertSame( 'byte', $transform->getOffsetType() ); } @@ -201,7 +201,7 @@ class HTMLTransformTest extends MediaWikiIntegrationTestCase { public function testDowngrade() { $html = $this->getTextFromFile( 'Minimal.html' ); // Uses profile version 2.4.0 - $transform = $this->createHTMLTransform( $html ); + $transform = $this->createHtmlToContentTransform( $html ); $transform->setOriginalSchemaVersion( '999.0.0' ); $transform->setOriginalHtml( $html ); @@ -219,7 +219,7 @@ class HTMLTransformTest extends MediaWikiIntegrationTestCase { public function testModifiedDataMW() { $html = $this->getTextFromFile( 'Minimal-999.html' ); // Uses profile version 2.4.0 - $transform = $this->createHTMLTransform( $html ); + $transform = $this->createHtmlToContentTransform( $html ); $transform->setOriginalHtml( self::ORIG_HTML ); $transform->setOriginalDataParsoid( self::ORIG_DATA_PARSOID ); @@ -234,7 +234,7 @@ class HTMLTransformTest extends MediaWikiIntegrationTestCase { public function testMetrics() { $html = 'xyz'; // no schema version! - $transform = $this->createHTMLTransform( $html ); + $transform = $this->createHtmlToContentTransform( $html ); $metrics = $this->createNoOpMock( StatsdDataFactoryInterface::class, [ 'increment' ] ); $metrics->expects( $this->atLeastOnce() )->method( 'increment' ); @@ -247,7 +247,7 @@ class HTMLTransformTest extends MediaWikiIntegrationTestCase { public function testHtmlSize() { $html = 'hällö'; // use some multi-byte characters - $transform = $this->createHTMLTransform( $html ); + $transform = $this->createHtmlToContentTransform( $html ); // make sure it counts characters, not bytes $this->assertSame( 31, $transform->getModifiedHtmlSize() ); @@ -255,7 +255,7 @@ class HTMLTransformTest extends MediaWikiIntegrationTestCase { public function testSetOriginalHTML() { $html = 'xyz'; // no schema version! - $transform = $this->createHTMLTransform( $html ); + $transform = $this->createHtmlToContentTransform( $html ); // mainly check that this doesn't explode. $transform->setOriginalSchemaVersion( '999.0.0' ); @@ -269,7 +269,7 @@ class HTMLTransformTest extends MediaWikiIntegrationTestCase { // Use HTML that contains a schema version! // Otherwise, we won't trigger the right error. $html = $this->getTextFromFile( 'Minimal.html' ); - $transform = $this->createHTMLTransform( $html ); + $transform = $this->createHtmlToContentTransform( $html ); $transform->getModifiedDocument(); @@ -280,7 +280,7 @@ class HTMLTransformTest extends MediaWikiIntegrationTestCase { } public function testOffsetTypeMismatch() { - $transform = $this->createHTMLTransform( self::ORIG_HTML ); + $transform = $this->createHtmlToContentTransform( self::ORIG_HTML ); $this->setOriginalData( $transform ); // Set some options to assert on $transform. @@ -299,7 +299,7 @@ class HTMLTransformTest extends MediaWikiIntegrationTestCase { } public function testHtmlToWikitextContent() { - $transform = $this->createHTMLTransform( self::ORIG_HTML ); + $transform = $this->createHtmlToContentTransform( self::ORIG_HTML ); // Set some options to assert on $transform. $transform->setOptions( [ @@ -314,7 +314,7 @@ class HTMLTransformTest extends MediaWikiIntegrationTestCase { public function testHtmlToJsonContent() { $jsonConfigHtml = $this->getTextFromFile( 'JsonConfig.html' ); - $transform = $this->createHTMLTransform( $jsonConfigHtml ); + $transform = $this->createHtmlToContentTransform( $jsonConfigHtml ); // Set some options to assert on $transform. $transform->setOptions( [ diff --git a/tests/phpunit/integration/includes/parser/Parsoid/HtmlTransformFactoryTest.php b/tests/phpunit/integration/includes/parser/Parsoid/HtmlTransformFactoryTest.php new file mode 100644 index 00000000000..bf2fc18a0c1 --- /dev/null +++ b/tests/phpunit/integration/includes/parser/Parsoid/HtmlTransformFactoryTest.php @@ -0,0 +1,42 @@ +getServiceContainer()->getHtmlTransformFactory(); + $this->assertInstanceOf( HtmlTransformFactory::class, $factory ); + } + + /** + * @covers ::getHtmlToContentTransform + */ + public function testGetHtmlToContentTransform() { + $factory = $this->getServiceContainer()->getHtmlTransformFactory(); + $modifiedHTML = '

Hello World

'; + + $transform = $factory->getHtmlToContentTransform( + $modifiedHTML, + PageIdentityValue::localIdentity( 0, NS_MAIN, 'Test' ) + ); + + $this->assertInstanceOf( HtmlToContentTransform::class, $transform ); + + $actualHTML = ContentUtils::toXML( DOMCompat::getBody( $transform->getModifiedDocument() ) ); + $this->assertStringContainsString( $modifiedHTML, $actualHTML ); + } + +}