Parsoid
A bidirectional parser between wikitext and HTML5
Loading...
Searching...
No Matches
Wikimedia\Parsoid\ParserTests\MockApiHelper Class Reference

This class supports the implementation of Parser Tests in a standalone mode and without network access. More...

+ Inheritance diagram for Wikimedia\Parsoid\ParserTests\MockApiHelper:
+ Collaboration diagram for Wikimedia\Parsoid\ParserTests\MockApiHelper:

Public Member Functions

 __construct (?string $prefix=null)
 
 setApiPrefix (string $prefix)
 Update prefix.
 
 addArticle (string $key, Article $article)
 Register an article defined in parsertests so that we can return the proper known/missing information about that title.
 
 makeRequest (array $params)
 
- Public Member Functions inherited from Wikimedia\Parsoid\Config\Api\ApiHelper
 __construct (array $opts)
 

Static Public Member Functions

static transformHelper ( $width, $height, &$twidth, &$theight)
 Image scaling computation helper.
 
- Static Public Member Functions inherited from Wikimedia\Parsoid\Config\Api\ApiHelper
static fromSettings (array $parsoidSettings)
 

Detailed Description

This class supports the implementation of Parser Tests in a standalone mode and without network access.

In standalone mode, the config and data transformations needed by Parsoid cannot come from MediaWiki's database or its core classes.

Without network access, we cannot fetch site configs or do data transformations on a remote wiki. This class supports this by intercepting network requests and returning mock responses based on cached site configs, hardcoded network responses and config,

So, this API helper should be used with the Parsoid\Config\Api* set of config classes (and any subclasses derived from them).

A lot of the responses here are tuned to what ParserTests needed. But, presumably this can be used by PHP Unit tests as long as the specific set of mocked responses satisfies the needs of those tests. Ideally, this class should NOT be updated for anything but the needs of running parser tests.

Alternatively, PHP Unit tests could bypass the Api* classes altogether and use a (sub)set of mocked classes (Env, SiteConfig, PageConfig, DataAccess) if those classes and the data they provide satisfies the needs of those tests.

Constructor & Destructor Documentation

◆ __construct()

Wikimedia\Parsoid\ParserTests\MockApiHelper::__construct ( ?string $prefix = null)
Parameters
?string$prefix

Member Function Documentation

◆ addArticle()

Wikimedia\Parsoid\ParserTests\MockApiHelper::addArticle ( string $key,
Article $article )

Register an article defined in parsertests so that we can return the proper known/missing information about that title.

Parameters
string$keyThe normalized title of the article
Article$articleThe contents of the article

◆ makeRequest()

Wikimedia\Parsoid\ParserTests\MockApiHelper::makeRequest ( array $params)
Parameters
array$params
Returns
array

Reimplemented from Wikimedia\Parsoid\Config\Api\ApiHelper.

◆ setApiPrefix()

Wikimedia\Parsoid\ParserTests\MockApiHelper::setApiPrefix ( string $prefix)

Update prefix.

Parameters
string$prefix

◆ transformHelper()

static Wikimedia\Parsoid\ParserTests\MockApiHelper::transformHelper ( $width,
$height,
& $twidth,
& $theight )
static

Image scaling computation helper.

Linker.php in core calls File::transform(...) for each dimension (1x, 1.5x, 2x) which then scales the image dimensions, using round/ceil/floor as appropriate to yield integer dimensions. Note that the results may be unintuitive due to the conversion to integer: eg, a 442px width image may become 883px in 2x mode. Resist the temptation to "optimize" this by computing the transformed size once and then scaling that; always scale the input dimensions instead.

See also
ImageHandler::normaliseParams, MediaHandler::fitBoxWidth, File::scaleHeight, etc, in core.

Either $twidth or $theight or both will be set when called; both will be set when this function returns.

Parameters
int$widthOriginal image width
int$heightOriginal image height
int | float | null&$twidthThumbnail width (inout parameter)
int | float | null&$theightThumbnail height (inout parameter)

The documentation for this class was generated from the following file: