wiki.techinc.nl/tests/phpunit/integration/includes/Rest/Handler/HTMLHandlerTestTrait.php
Umherirrender 503bff0b04 Rest: Add missing documentation to class properties
Add doc-typehints to class properties found by the PropertyDocumentation
sniff to improve the documentation.

Once the sniff is enabled it avoids that new code is missing type
declarations. This is focused on documentation and does not change code.

Change-Id: Idf17719c875466810313f0fbbf16bc67f3e40059
2024-09-07 21:49:56 +02:00

116 lines
2.9 KiB
PHP

<?php
namespace MediaWiki\Tests\Rest\Handler;
use Exception;
use MediaWiki\Block\BlockErrorFormatter;
use MediaWiki\Context\IContextSource;
use MediaWiki\Edit\ParsoidOutputStash;
use MediaWiki\Edit\ParsoidRenderID;
use MediaWiki\Edit\SimpleParsoidOutputStash;
use MediaWiki\Permissions\Authority;
use MediaWiki\Permissions\UserAuthority;
use MediaWiki\Request\FauxRequest;
use MediaWiki\Rest\RequestData;
use MediaWiki\User\User;
use Wikimedia\ObjectCache\HashBagOStuff;
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 {
/** @var ParsoidOutputStash|null */
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;
}
private function getAuthority(): Authority {
$services = $this->getServiceContainer();
return new UserAuthority(
// We need a newly created user because we want IP and newbie to apply.
new User(),
new FauxRequest(),
$this->createMock( IContextSource::class ),
$services->getPermissionManager(),
$services->getRateLimiter(),
$this->createMock( BlockErrorFormatter::class )
);
}
/**
* @param WikiPage $page
* @param array $queryParams
* @param array $config
*
* @return array
* @throws Exception
*/
private function executePageHTMLRequest(
WikiPage $page,
array $queryParams = [],
array $config = [],
Authority $authority = null
): array {
$handler = $this->newHandler();
$request = new RequestData( [
'pathParams' => [ 'title' => $page->getTitle()->getPrefixedDBkey() ],
'queryParams' => $queryParams,
] );
$result = $this->executeHandler(
$handler,
$request,
$config + [ 'format' => 'html' ],
[],
[],
[],
$authority
);
$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 = [],
Authority $authority = null
): array {
$handler = $this->newHandler();
$request = new RequestData( [
'pathParams' => [ 'id' => $revId ],
'queryParams' => $queryParams,
] );
$result = $this->executeHandler(
$handler,
$request,
$config + [ 'format' => 'html' ],
[],
[],
[],
$authority
);
$etag = $result->getHeaderLine( 'ETag' );
$stashKey = ParsoidRenderID::newFromETag( $etag );
return [ $result->getBody()->getContents(), $etag, $stashKey ];
}
}