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

This class contains helper functions which should not be directly used outside of Parsoid. More...

Static Public Member Functions

static encodeXml (string $str)
 Little helper function for encoding XML entities.
 
static normalizeAbout (string $str)
 Strip the actual about id from the string.
 
static normalizeOut ( $domBody, array $options=[])
 Specialized normalization of the PHP parser & Parsoid output, to ignore a few known-ok differences in parser test runs.
 
static stripParsoidIds (string $s)
 Strip Parsoid ID attributes (id="mwXX", used to associate NodeData) from an HTML string.
 
static unwrapSpansAndNormalizeIEW (Element $body, ?string $stripSpanTypeof=null, bool $parsoidOnly=false, bool $preserveIEW=false)
 Normalize newlines in IEW to spaces instead.
 
static normalizePhpOutput (string $html)
 Strip some php output we aren't generating.
 
static normalizeHTML (string $source)
 Normalize the expected parser output by parsing it using a HTML5 parser and re-serializing it to HTML.
 
static colorString (string $string, string $color, bool $inverse=false)
 

Detailed Description

This class contains helper functions which should not be directly used outside of Parsoid.

Per T332457, most of the code in Wikimedia\Parsoid\ParserTests is "for use in parser test runners only", including the core parser test runner, but this file is "more internal" than that: core's parser test runner should not use these helpers directly.

Member Function Documentation

◆ colorString()

static Wikimedia\Parsoid\ParserTests\TestUtils::colorString ( string $string,
string $color,
bool $inverse = false )
static
Parameters
string$string
string$color
bool$inverse
Returns
string @suppress PhanUndeclaredClassMethod @suppress UnusedSuppression

◆ encodeXml()

static Wikimedia\Parsoid\ParserTests\TestUtils::encodeXml ( string $str)
static

Little helper function for encoding XML entities.

Parameters
string$str
Returns
string

◆ normalizeAbout()

static Wikimedia\Parsoid\ParserTests\TestUtils::normalizeAbout ( string $str)
static

Strip the actual about id from the string.

Parameters
string$str
Returns
string

◆ normalizeHTML()

static Wikimedia\Parsoid\ParserTests\TestUtils::normalizeHTML ( string $source)
static

Normalize the expected parser output by parsing it using a HTML5 parser and re-serializing it to HTML.

Ideally, the parser would normalize inter-tag whitespace for us. For now, we fake that by simply stripping all newlines.

Parameters
string$source
Returns
string

◆ normalizeOut()

static Wikimedia\Parsoid\ParserTests\TestUtils::normalizeOut ( $domBody,
array $options = [] )
static

Specialized normalization of the PHP parser & Parsoid output, to ignore a few known-ok differences in parser test runs.

This code is also used by the Parsoid round-trip testing code.

If parsoidOnly is true-ish, we allow more markup through (like property and typeof attributes), for better checking of parsoid-only test cases.

Parameters
Element | string$domBody
array$options
  • parsoidOnly (bool) Is this test Parsoid Only? Optional. Default: false
  • preserveIEW (bool) Should inter-element WS be preserved? Optional. Default: false
  • hackyNormalize (bool) Apply the normalizer to the html. Optional. Default: false
Returns
string

◆ normalizePhpOutput()

static Wikimedia\Parsoid\ParserTests\TestUtils::normalizePhpOutput ( string $html)
static

Strip some php output we aren't generating.

Parameters
string$html
Returns
string

◆ stripParsoidIds()

static Wikimedia\Parsoid\ParserTests\TestUtils::stripParsoidIds ( string $s)
static

Strip Parsoid ID attributes (id="mwXX", used to associate NodeData) from an HTML string.

Parameters
string$s
Returns
string

◆ unwrapSpansAndNormalizeIEW()

static Wikimedia\Parsoid\ParserTests\TestUtils::unwrapSpansAndNormalizeIEW ( Element $body,
?string $stripSpanTypeof = null,
bool $parsoidOnly = false,
bool $preserveIEW = false )
static

Normalize newlines in IEW to spaces instead.

Parameters
Element$bodyThe document body node to normalize.
?string$stripSpanTypeofRegular expression to strip typeof attributes
bool$parsoidOnly
bool$preserveIEW
Returns
Element

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