mediawiki-extensions-Math/tests/phpunit/unit/WikiTexVC/MMLTestUtil.php
thiemowmde 10e2e17bb1 Remove unused return values from MMLTestUtil
Just removing unused code that never did anything. Note this is only
in a test. As long as all tests still succeed this can't really cause
any problems, I believe.

Change-Id: I272803353eed9de0ecf98c55b75710df16da2c44
2024-08-12 08:50:22 +02:00

58 lines
1.6 KiB
PHP

<?php
namespace MediaWiki\Extension\Math\WikiTexVC\MMLmappings\Util;
use DOMDocument;
use InvalidArgumentException;
use MediaWiki\Extension\Math\WikiTexVC\MMLnodes\MMLmath;
/**
* This Utility class has some methods for running
* tests for the Tex to MathML converters in WikiTexVC.
* @author Johannes Stegmüller
*/
class MMLTestUtil {
public static function getJSON( $filePath ) {
if ( !file_exists( $filePath ) ) {
throw new InvalidArgumentException( "No testfile found at specified path: " . $filePath );
}
return json_decode( file_get_contents( $filePath ) );
}
public static function createJSONstartEnd( $start, $file ) {
file_put_contents( $file, $start ? "[\n" : "\n]", FILE_APPEND );
}
public static function appendToJSONFile( $dataArray, $file ) {
$jsonData = json_encode( $dataArray, JSON_PRETTY_PRINT ) . ",";
file_put_contents( $file, $jsonData, FILE_APPEND );
}
public static function deleteFile( $file ): void {
if ( file_exists( $file ) ) {
unlink( $file );
}
}
public static function prettifyXML( $xml, $replaceHeader = true ) {
$dom = new DOMDocument();
// Initial block (must before load xml string)
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;
// End initial block
$dom->loadXML( $xml );
$out = $dom->saveXML();
if ( $replaceHeader ) {
// replacing the xml header in a hacky way
return substr_replace( $out, "", 0, 22 );
}
return $out;
}
public static function getMMLwrapped( $input ) {
$math = new MMLmath();
$mml = $math->encapsulateRaw( $input->renderMML() );
return self::prettifyXML( $mml );
}
}