UTPage is badly named, because it doesn't give any information as to what test caused the page to be created. It also sort of encourages test authors to rely on this "UTPage" page being created by the framework for them. Both these things are dangerous, or at least very questionable. Use a random page title instead, but include the caller name in case someone needs to investigate where a test page is coming from. Do the same for summary and content, too. In getExistingTestPage, add a check to make sure that the page was created successfully. Do not use assert* to avoid adding assertions extraneous to the test. addCoreDBData is not changed because that method will be removed entirely (T342428). Fix tests that are now failing: - ParsoidOutputAccessTest was relying on the content of getExistingTestPage to be UTContent. - HTMLHandlerTestTrait did not account for spaces in the page name (also change the signature to reflect the fact that WikiPage is always passed in). - HtmlInputTransformHelperTest was relying on the fake test page to be there. - PoolWorkArticleViewTest is leaving pages behind, and for some reason that's making SpecialRecentchangesTest fail. Bug: T341344 Change-Id: I9c2dc1cf1f184c8062864756d2747ee56e886086
81 lines
2.1 KiB
PHP
81 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace MediaWiki\Tests\Rest\Handler;
|
|
|
|
use HashBagOStuff;
|
|
use MediaWiki\Edit\ParsoidOutputStash;
|
|
use MediaWiki\Edit\SimpleParsoidOutputStash;
|
|
use MediaWiki\Parser\Parsoid\ParsoidRenderID;
|
|
use MediaWiki\Rest\RequestData;
|
|
use WikiPage;
|
|
|
|
/**
|
|
* This trait is used in PageHTMLHandlerTest.php & RevisionHTMLHandlerTest.php
|
|
* to construct requests and perform stashing for the Parsoid Output stash feature.
|
|
*/
|
|
trait HTMLHandlerTestTrait {
|
|
|
|
private $parsoidOutputStash = null;
|
|
|
|
private function getParsoidOutputStash(): ParsoidOutputStash {
|
|
if ( !$this->parsoidOutputStash ) {
|
|
$chFactory = $this->getServiceContainer()->getContentHandlerFactory();
|
|
$this->parsoidOutputStash = new SimpleParsoidOutputStash( $chFactory, new HashBagOStuff(), 120 );
|
|
}
|
|
return $this->parsoidOutputStash;
|
|
}
|
|
|
|
/**
|
|
* @param WikiPage $page
|
|
* @param array $queryParams
|
|
* @param array $config
|
|
*
|
|
* @return array
|
|
* @throws \Exception
|
|
*/
|
|
private function executePageHTMLRequest(
|
|
WikiPage $page,
|
|
array $queryParams = [],
|
|
array $config = []
|
|
): array {
|
|
$handler = $this->newHandler();
|
|
$request = new RequestData( [
|
|
'pathParams' => [ 'title' => $page->getTitle()->getPrefixedDBkey() ],
|
|
'queryParams' => $queryParams,
|
|
] );
|
|
$result = $this->executeHandler( $handler,
|
|
$request,
|
|
$config + [ 'format' => 'html' ] );
|
|
$etag = $result->getHeaderLine( 'ETag' );
|
|
$stashKey = ParsoidRenderID::newFromETag( $etag );
|
|
|
|
return [ $result->getBody()->getContents(), $etag, $stashKey ];
|
|
}
|
|
|
|
/**
|
|
* @param int $revId
|
|
* @param array $queryParams
|
|
* @param array $config
|
|
*
|
|
* @return array
|
|
* @throws \Exception
|
|
*/
|
|
private function executeRevisionHTMLRequest(
|
|
int $revId,
|
|
array $queryParams = [],
|
|
array $config = []
|
|
): array {
|
|
$handler = $this->newHandler();
|
|
$request = new RequestData( [
|
|
'pathParams' => [ 'id' => $revId ],
|
|
'queryParams' => $queryParams,
|
|
] );
|
|
$result = $this->executeHandler( $handler,
|
|
$request,
|
|
$config + [ 'format' => 'html' ] );
|
|
$etag = $result->getHeaderLine( 'ETag' );
|
|
$stashKey = ParsoidRenderID::newFromETag( $etag );
|
|
|
|
return [ $result->getBody()->getContents(), $etag, $stashKey ];
|
|
}
|
|
}
|