mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Math
synced 2024-11-28 01:10:09 +00:00
Add Full-Coverage Test TexVC-MMLGeneration for Mathoid-LateXML
* Implemented multiple-column generation for the HTML-Generator * Items can be skipped in test by defining index Bug: T327386 Change-Id: I13148d58246ddcc1f2e6dcd14fa5b4255a1fb8e7
This commit is contained in:
parent
8ca418578c
commit
ada1d6e3db
123
tests/phpunit/unit/TexVC/MMLFullCoverageTest.php
Normal file
123
tests/phpunit/unit/TexVC/MMLFullCoverageTest.php
Normal file
|
@ -0,0 +1,123 @@
|
|||
<?php
|
||||
namespace MediaWiki\Extension\Math\TexVC;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use MediaWiki\Extension\Math\TexVC\MMLmappings\Util\MMLTestUtil;
|
||||
use MediaWiki\Extension\Math\TexVC\MMLmappings\Util\MMLTestUtilHTML;
|
||||
|
||||
use MediaWikiUnitTestCase;
|
||||
|
||||
/**
|
||||
* This is a test which checks the TexVC (LaTeX to MathML) converter capabilities
|
||||
* It uses the Full-Coverage definition of tests from:
|
||||
* https://www.mediawiki.org/wiki/Extension:Math/CoverageTest
|
||||
*
|
||||
* The json test-files for this can be updated with:
|
||||
* 'MathSearch-Extension/maintenance/UpdateMath.php --mode mathml --exportmml /var/www/html/extensions/MathSearch'
|
||||
*
|
||||
* WIP:
|
||||
* Currently this is just checking that texVC can generate MathML
|
||||
* for the specified tests, not how the MathML looks like.
|
||||
*
|
||||
* @covers \MediaWiki\Extension\Math\TexVC\TexVC
|
||||
* @group stub
|
||||
*/
|
||||
final class MMLFullCoverageTest extends MediaWikiUnitTestCase {
|
||||
private static $FILENAMELATEXML = __DIR__ . "/mmlRes-latexml-FullCoverage.json";
|
||||
private static $FILENAMEMATHOID = __DIR__ . "/mmlRes-mathml-FullCoverage.json";
|
||||
private static $APPLYFILTER = false;
|
||||
private static $FILTERSTART = 0;
|
||||
private static $FILTERLENGTH = 60;
|
||||
private static $GENERATEHTML = true;
|
||||
private static $GENERATEDHTMLFILE = __DIR__ . "/MMLFullCoverageTest-Output.html";
|
||||
private static $SKIPPEDINDICES = [ 0,58, 380, 388 ];
|
||||
|
||||
private static $FILTERMML = true;
|
||||
|
||||
public static function setUpBeforeClass(): void {
|
||||
MMLTestUtilHTML::generateHTMLstart( self::$GENERATEDHTMLFILE, [ "name","TeX-Input","MathML(LaTeXML)",
|
||||
"MathML(Mathoid)", "MathML(TexVC)" ], self::$GENERATEHTML );
|
||||
}
|
||||
|
||||
public static function tearDownAfterClass(): void {
|
||||
MMLTestUtilHTML::generateHTMLEnd( self::$GENERATEDHTMLFILE, self::$GENERATEHTML );
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideTestCases
|
||||
*/
|
||||
public function testTexVC( $title, $tc ) {
|
||||
$texVC = new TexVC();
|
||||
|
||||
if ( in_array( $tc->ctr, self::$SKIPPEDINDICES ) ) {
|
||||
MMLTestUtilHTML::generateHTMLtableRow( self::$GENERATEDHTMLFILE, [ $tc->ctr, $tc->tex,
|
||||
"skipped", "skipped", "skipped" ], false, self::$GENERATEHTML );
|
||||
$this->assertTrue( true );
|
||||
return;
|
||||
}
|
||||
# Fetch result from TexVC(PHP)
|
||||
$resultT = $texVC->check( $tc->tex, [
|
||||
'debug' => false,
|
||||
'usemathrm' => $tc->usemathrm ?? false,
|
||||
'oldtexvc' => $tc->oldtexvc ?? false
|
||||
] );
|
||||
|
||||
$mml_latexml = self::$FILTERMML ? self::loadXMLandDeleteAttrs( $tc->mml_latexml ) : $tc->mml_latexml;
|
||||
$mathMLtexVC = MMLTestUtil::getMMLwrapped( $resultT["input"] );
|
||||
MMLTestUtilHTML::generateHTMLtableRow( self::$GENERATEDHTMLFILE, [ $tc->ctr, $tc->tex, $mml_latexml,
|
||||
$tc->mml_mathoid, $mathMLtexVC ], false, self::$GENERATEHTML );
|
||||
$this->assertTrue( true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes some attributes from the mathml which are not necessary for comparisons.
|
||||
* @param string $mml mathml as string
|
||||
* @return bool|string false if problem, mathml as xml string without the specified attributes if ok
|
||||
*/
|
||||
public static function loadXMLandDeleteAttrs( $mml ) {
|
||||
$xml = simplexml_load_string( $mml );
|
||||
self::unsetAttrs( $xml );
|
||||
// Recursive call deleting attributes
|
||||
self::deleteAttributes( $xml );
|
||||
return $xml->asXML();
|
||||
}
|
||||
|
||||
public static function deleteAttributes( &$xml ) {
|
||||
foreach ( $xml as $node ) {
|
||||
self::unsetAttrs( $node );
|
||||
self::deleteAttributes( $node );
|
||||
}
|
||||
}
|
||||
|
||||
public static function unsetAttrs( $node ): void {
|
||||
$attrs = $node->attributes();
|
||||
unset( $attrs['id'] );
|
||||
unset( $attrs['xref'] );
|
||||
}
|
||||
|
||||
public static function provideTestCases() {
|
||||
$resMathoid = MMLTestUtil::getJSON( self::$FILENAMEMATHOID );
|
||||
$resLaTeXML = MMLTestUtil::getJSON( self::$FILENAMELATEXML );
|
||||
if ( count( $resMathoid ) != count( $resLaTeXML ) ) {
|
||||
throw new InvalidArgumentException( "Test files dont have the same number of entries." );
|
||||
}
|
||||
$f = [];
|
||||
// Adding running indices for location of tests.
|
||||
foreach ( $resMathoid as $index => $tcMathoid ) {
|
||||
$tcLaTeXML = $resLaTeXML[$index];
|
||||
$tc = [
|
||||
"ctr" => $index,
|
||||
"tex" => $tcMathoid->tex,
|
||||
"type" => $tcMathoid->type,
|
||||
"mml_mathoid" => $tcMathoid->mml,
|
||||
"mml_latexml" => $tcLaTeXML->mml,
|
||||
];
|
||||
array_push( $f, [ "title N/A", (object)$tc ] );
|
||||
}
|
||||
// Filtering results by index if necessary
|
||||
if ( self::$APPLYFILTER ) {
|
||||
$f = array_slice( $f, self::$FILTERSTART, self::$FILTERLENGTH );
|
||||
}
|
||||
return $f;
|
||||
}
|
||||
}
|
|
@ -156,12 +156,12 @@ class MMLGenerationTest extends MediaWikiUnitTestCase {
|
|||
$resMML3latexml = $mmlLatexML[$input] ?? "merror";
|
||||
if ( str_contains( $resMML3latexml, "merror" ) ) {
|
||||
$errorMessage = "Error Rendering in MathJax";
|
||||
MMLTestUtilHTML::generateHTMLtableRow( self::$GENERATEDHTMLFILE, $title, $input, $errorMessage,
|
||||
$mathMLtexVC, false, self::$GENERATEHTML );
|
||||
MMLTestUtilHTML::generateHTMLtableRow( self::$GENERATEDHTMLFILE, [ $title, $input, $errorMessage,
|
||||
$mathMLtexVC ], false, self::$GENERATEHTML );
|
||||
$this->assertTrue( true );
|
||||
} else {
|
||||
MMLTestUtilHTML::generateHTMLtableRow( self::$GENERATEDHTMLFILE, $title, $input, $resMML3latexml,
|
||||
$mathMLtexVC, false, self::$GENERATEHTML );
|
||||
MMLTestUtilHTML::generateHTMLtableRow( self::$GENERATEDHTMLFILE, [ $title, $input, $resMML3latexml,
|
||||
$mathMLtexVC ], false, self::$GENERATEHTML );
|
||||
$resMML3latexml = $resMML3latexml ?: "<math> no MML3 from Lookup </math>";
|
||||
if ( !self::$SKIPXMLVALIDATION ) {
|
||||
$this->assertXmlStringEqualsXmlString( $resMML3latexml, $mathMLtexVC );
|
||||
|
@ -172,7 +172,8 @@ class MMLGenerationTest extends MediaWikiUnitTestCase {
|
|||
}
|
||||
|
||||
public static function setUpBeforeClass(): void {
|
||||
MMLTestUtilHTML::generateHTMLstart( self::$GENERATEDHTMLFILE, "MathML(MathJax3)", self::$GENERATEHTML );
|
||||
MMLTestUtilHTML::generateHTMLstart( self::$GENERATEDHTMLFILE, [ "name","Tex-Input",
|
||||
"MathML(MathJax3)","MathML(TexVC)" ], self::$GENERATEHTML );
|
||||
}
|
||||
|
||||
public static function tearDownAfterClass(): void {
|
||||
|
|
|
@ -22,7 +22,7 @@ final class MMLGenerationTest2 extends MediaWikiUnitTestCase {
|
|||
private static $FILTERSTART = 0;
|
||||
private static $FILTERLENGTH = 1;
|
||||
|
||||
private static $GENERATEHTML = true;
|
||||
private static $GENERATEHTML = false;
|
||||
private static $GENERATEDHTMLFILE = __DIR__ . "/MMLGenerationTest2-Output.html";
|
||||
|
||||
protected function setUp(): void {
|
||||
|
@ -34,7 +34,8 @@ final class MMLGenerationTest2 extends MediaWikiUnitTestCase {
|
|||
}
|
||||
|
||||
public static function setUpBeforeClass(): void {
|
||||
MMLTestUtilHTML::generateHTMLstart( self::$GENERATEDHTMLFILE, self::$GENERATEHTML );
|
||||
MMLTestUtilHTML::generateHTMLstart( self::$GENERATEDHTMLFILE, [ "name","Tex-Input",
|
||||
"MathML(MathJax3)","MathML(TexVC)" ], self::$GENERATEHTML );
|
||||
}
|
||||
|
||||
public static function tearDownAfterClass(): void {
|
||||
|
@ -48,8 +49,8 @@ final class MMLGenerationTest2 extends MediaWikiUnitTestCase {
|
|||
$texVC = new TexVC();
|
||||
|
||||
if ( $tc->skipped ?? false ) {
|
||||
MMLTestUtilHTML::generateHTMLtableRow( self::$GENERATEDHTMLFILE, $tc->ctr, $tc->input,
|
||||
"skipped", "skipped", false, self::$GENERATEHTML );
|
||||
MMLTestUtilHTML::generateHTMLtableRow( self::$GENERATEDHTMLFILE, [ $tc->ctr, $tc->input,
|
||||
"skipped", "skipped" ], false, self::$GENERATEHTML );
|
||||
$this->assertTrue( true );
|
||||
return;
|
||||
}
|
||||
|
@ -60,8 +61,8 @@ final class MMLGenerationTest2 extends MediaWikiUnitTestCase {
|
|||
'oldtexvc' => $tc->oldtexvc ?? false
|
||||
] );
|
||||
$mathMLtexVC = MMLTestUtil::getMMLwrapped( $resultT["input"] );
|
||||
MMLTestUtilHTML::generateHTMLtableRow( self::$GENERATEDHTMLFILE, $tc->ctr, $tc->input, "tbd",
|
||||
$mathMLtexVC, false, self::$GENERATEHTML );
|
||||
MMLTestUtilHTML::generateHTMLtableRow( self::$GENERATEDHTMLFILE, [ $tc->ctr, $tc->input, "tbd",
|
||||
$mathMLtexVC ], false, self::$GENERATEHTML );
|
||||
$this->assertTrue( true );
|
||||
}
|
||||
|
||||
|
|
|
@ -27,78 +27,80 @@ class MMLTestUtilHTML {
|
|||
fclose( $file );
|
||||
}
|
||||
|
||||
public static function generateHTMLtableRow( $filePath, $id, $inputTex, $mmlMj3, $mmlGen,
|
||||
$bold = false, $active = true ) {
|
||||
public static function generateHTMLtableRow( $filePath, $rows, $bold = false, $active = true ) {
|
||||
if ( !$active ) {
|
||||
return;
|
||||
}
|
||||
$file = fopen( $filePath, 'a' );
|
||||
|
||||
$stringData = "<tr>"
|
||||
. self::generateHTMLtableItem( $id, $bold )
|
||||
. self::generateHTMLtableItem( $inputTex, $bold )
|
||||
. self::generateHTMLtableItem( $mmlMj3, $bold )
|
||||
. self::generateHTMLtableItem( $mmlGen, $bold ) .
|
||||
"</tr>";
|
||||
$stringData = "<tr>";
|
||||
foreach ( $rows as $row ) {
|
||||
$stringData .= self::generateHTMLtableItem( $row, $bold );
|
||||
}
|
||||
$stringData .= "</tr>";
|
||||
|
||||
fwrite( $file, $stringData );
|
||||
|
||||
fclose( $file ); // tbd only open close once for all tests
|
||||
}
|
||||
|
||||
public static function generateHTMLstart( $filePath, $name, $active = true ) {
|
||||
public static function generateHTMLstart( $filePath, $headrows = [ "name","Tex-Input",
|
||||
"MathML(MathJax3)","MathML(TexVC)" ], $active = true ) {
|
||||
if ( !$active ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$htmlRows = "";
|
||||
foreach ( $headrows as $header ) {
|
||||
$htmlRows .= "<th class=\"tg-0lax\"><b>" . $header . "</b></th>";
|
||||
}
|
||||
|
||||
$file = fopen( $filePath, 'w' ); // or die("error");
|
||||
$stringData = /** @lang HTML */
|
||||
<<<HTML
|
||||
<style>
|
||||
.tg {
|
||||
border-collapse: collapse;
|
||||
border-spacing: 0;
|
||||
}
|
||||
|
||||
.tg td {
|
||||
border-color: black;
|
||||
border-style: solid;
|
||||
border-width: 1px;
|
||||
font-family: Arial, sans-serif;
|
||||
font-size: 14px;
|
||||
overflow: hidden;
|
||||
padding: 10px 5px;
|
||||
word-break: normal;
|
||||
}
|
||||
|
||||
.tg th {
|
||||
border-color: black;
|
||||
border-style: solid;
|
||||
border-width: 1px;
|
||||
font-family: Arial,
|
||||
sans-serif;
|
||||
font-size: 14px;
|
||||
font-weight: normal;
|
||||
overflow: hidden;
|
||||
padding: 10px 5px;
|
||||
word-break: normal;
|
||||
}
|
||||
|
||||
.tg .tg-0lax {
|
||||
text-align: left;
|
||||
vertical-align: top
|
||||
}
|
||||
</style>
|
||||
<table class="tg">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="tg-0lax"><b>name</b></th>
|
||||
<th class="tg-0lax"><b>Tex-Input</b></th>
|
||||
<th class="tg-0lax"><b>MathML(MathJax3)</b></th>
|
||||
<th class="tg-0lax"><b>MathML(TexVC)</b></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
HTML;
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
</head>
|
||||
<style>
|
||||
.tg {
|
||||
border-collapse: collapse;
|
||||
border-spacing: 0;
|
||||
}
|
||||
.tg td {
|
||||
border-color: black;
|
||||
border-style: solid;
|
||||
border-width: 1px;
|
||||
font-family: Arial, sans-serif;
|
||||
font-size: 14px;
|
||||
overflow: hidden;
|
||||
padding: 10px 5px;
|
||||
word-break: normal;
|
||||
}
|
||||
.tg th {
|
||||
border-color: black;
|
||||
border-style: solid;
|
||||
border-width: 1px;
|
||||
font-family: Arial,
|
||||
sans-serif;
|
||||
font-size: 14px;
|
||||
font-weight: normal;
|
||||
overflow: hidden;
|
||||
padding: 10px 5px;
|
||||
word-break: normal;
|
||||
}
|
||||
.tg .tg-0lax {
|
||||
text-align: left;
|
||||
vertical-align: top
|
||||
}
|
||||
</style>
|
||||
<table class="tg">
|
||||
<thead>
|
||||
<tr>{$htmlRows}</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
HTML;
|
||||
fwrite( $file, $stringData );
|
||||
fclose( $file );
|
||||
}
|
||||
|
|
2122
tests/phpunit/unit/TexVC/mmlRes-latexml-FullCoverage.json
Normal file
2122
tests/phpunit/unit/TexVC/mmlRes-latexml-FullCoverage.json
Normal file
File diff suppressed because one or more lines are too long
2122
tests/phpunit/unit/TexVC/mmlRes-mathml-FullCoverage.json
Normal file
2122
tests/phpunit/unit/TexVC/mmlRes-mathml-FullCoverage.json
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue