2022-05-16 16:56:20 +00:00
|
|
|
<?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;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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 ) {
|
2022-06-02 18:15:36 +00:00
|
|
|
$this->parsoidOutputStash = new SimpleParsoidOutputStash( new HashBagOStuff(), 120 );
|
2022-05-16 16:56:20 +00:00
|
|
|
}
|
|
|
|
|
return $this->parsoidOutputStash;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param string $page
|
|
|
|
|
* @param array $queryParams
|
2022-05-24 21:13:42 +00:00
|
|
|
* @param array $config
|
2022-05-16 16:56:20 +00:00
|
|
|
*
|
|
|
|
|
* @return array
|
2022-05-24 21:13:42 +00:00
|
|
|
* @throws \Exception
|
2022-05-16 16:56:20 +00:00
|
|
|
*/
|
2022-05-24 21:13:42 +00:00
|
|
|
private function executePageHTMLRequest(
|
|
|
|
|
string $page,
|
|
|
|
|
array $queryParams = [],
|
|
|
|
|
array $config = []
|
|
|
|
|
): array {
|
2022-05-16 16:56:20 +00:00
|
|
|
$handler = $this->newHandler();
|
|
|
|
|
$request = new RequestData( [
|
|
|
|
|
'pathParams' => [ 'title' => $page ],
|
|
|
|
|
'queryParams' => $queryParams,
|
|
|
|
|
] );
|
|
|
|
|
$result = $this->executeHandler( $handler,
|
|
|
|
|
$request,
|
2022-05-24 21:13:42 +00:00
|
|
|
$config + [ 'format' => 'html' ] );
|
2022-05-16 16:56:20 +00:00
|
|
|
$etag = $result->getHeaderLine( 'ETag' );
|
|
|
|
|
$stashKey = ParsoidRenderID::newFromETag( $etag );
|
|
|
|
|
|
|
|
|
|
return [ $result->getBody()->getContents(), $etag, $stashKey ];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param int $revId
|
|
|
|
|
* @param array $queryParams
|
2022-05-24 21:13:42 +00:00
|
|
|
* @param array $config
|
2022-05-16 16:56:20 +00:00
|
|
|
*
|
|
|
|
|
* @return array
|
2022-05-24 21:13:42 +00:00
|
|
|
* @throws \Exception
|
2022-05-16 16:56:20 +00:00
|
|
|
*/
|
2022-05-24 21:13:42 +00:00
|
|
|
private function executeRevisionHTMLRequest(
|
|
|
|
|
int $revId,
|
|
|
|
|
array $queryParams = [],
|
|
|
|
|
array $config = []
|
|
|
|
|
): array {
|
2022-05-16 16:56:20 +00:00
|
|
|
$handler = $this->newHandler();
|
|
|
|
|
$request = new RequestData( [
|
|
|
|
|
'pathParams' => [ 'id' => $revId ],
|
|
|
|
|
'queryParams' => $queryParams,
|
|
|
|
|
] );
|
|
|
|
|
$result = $this->executeHandler( $handler,
|
|
|
|
|
$request,
|
2022-05-24 21:13:42 +00:00
|
|
|
$config + [ 'format' => 'html' ] );
|
2022-05-16 16:56:20 +00:00
|
|
|
$etag = $result->getHeaderLine( 'ETag' );
|
|
|
|
|
$stashKey = ParsoidRenderID::newFromETag( $etag );
|
|
|
|
|
|
|
|
|
|
return [ $result->getBody()->getContents(), $etag, $stashKey ];
|
|
|
|
|
}
|
|
|
|
|
}
|