wiki.techinc.nl/tests/phpunit/integration/includes/Rest/Handler/HTMLHandlerTestTrait.php
Derick Alangi d62f97d5e0 Rest: Return different eTags for different output modes
This patch enables the response from PageHTMLHandler and
RevisionHTMLHandler to have different eTags for different
output modes and varying flavors.

Before, the only difference we got was when the stashing
option is set or not, but we need more flavors.

Bug: T308744
Change-Id: I2e9679e46a31955a2106a52af4eb612b32799c8c
2022-05-25 11:15:47 +00:00

79 lines
2 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;
/**
* 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 ) {
$this->parsoidOutputStash = new SimpleParsoidOutputStash( new HashBagOStuff() );
}
return $this->parsoidOutputStash;
}
/**
* @param string $page
* @param array $queryParams
* @param array $config
*
* @return array
* @throws \Exception
*/
private function executePageHTMLRequest(
string $page,
array $queryParams = [],
array $config = []
): array {
$handler = $this->newHandler();
$request = new RequestData( [
'pathParams' => [ 'title' => $page ],
'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 ];
}
}