Merge "Add a possibility for creating a test wikipage for chemical formulas"

This commit is contained in:
jenkins-bot 2023-10-30 16:22:48 +00:00 committed by Gerrit Code Review
commit 83835f19e7

View file

@ -28,18 +28,45 @@ final class MMLmhchemTest extends MediaWikiUnitTestCase {
private static bool $APPLYFILTER = false;
private static int $FILTERSTART = 92;
private static int $FILTERLENGTH = 1;
private static bool $GENERATEHTML = false;
private static bool $GENERATEFILES = false;
private static string $GENERATEDHTMLFILE = __DIR__ . "/MMLmhchemTest-Output.html";
private static string $GENERATEDWIKIFILE = __DIR__ . "/chemtest.wiki";
private static array $SKIPPEDINDICES = [ 36,40,50,51,91,92,93,94 ];
public static function writeWikifileHeader( $filename ) {
unlink( $filename );
self::writeToFile( $filename, "{| class=\"wikitable\"\n|-\n !colspan=\"3\"|\n" .
"|+ comparison of rendering for chemical formulas \n" .
"|- \n ! TeX !! Rendering(native) !! Rendering(default)}" );
}
public static function writeWikifileRow( $filename, $tex ) {
$text = "|- \n"
. "| <syntaxhighlight lang=\"latex\" enclose=\"none\">" . $tex . "</syntaxhighlight> \n"
. "|<chem forcemathmode=\"native\">" . $tex . "</chem> \n"
. "|<chem>" . $tex . "</chem>";
self::writeToFile( $filename, $text );
}
public static function writeToFile( $filename, $line ) {
$myfile = fopen( $filename, "a" );
fwrite( $myfile, $line . "\n" );
fclose( $myfile );
}
public static function setUpBeforeClass(): void {
MMLTestUtilHTML::generateHTMLstart( self::$GENERATEDHTMLFILE, [ "name","TeX-Input",
"Tex-MhchemParser","Tex-PHP-Mhchem", "MathML-LaTeXML", "MathML-TexVC" ],
self::$GENERATEHTML );
self::$GENERATEFILES );
if ( self::$GENERATEFILES ) {
self::writeWikifileHeader( self::$GENERATEDWIKIFILE );
}
}
public static function tearDownAfterClass(): void {
MMLTestUtilHTML::generateHTMLEnd( self::$GENERATEDHTMLFILE, self::$GENERATEHTML );
MMLTestUtilHTML::generateHTMLEnd( self::$GENERATEDHTMLFILE, self::$GENERATEFILES );
}
/**
@ -51,10 +78,13 @@ final class MMLmhchemTest extends MediaWikiUnitTestCase {
if ( in_array( $tc->ctr, self::$SKIPPEDINDICES ) ) {
MMLTestUtilHTML::generateHTMLtableRow( self::$GENERATEDHTMLFILE, [ $tc->ctr, $tc->tex,
"skipped", "skipped", "skipped", "skipped" ], false, self::$GENERATEHTML );
"skipped", "skipped", "skipped", "skipped" ], false, self::$GENERATEFILES );
$this->assertTrue( true );
return;
}
if ( self::$GENERATEFILES ) {
self::writeWikifileRow( self::$GENERATEDWIKIFILE, $tc->tex );
}
# Fetch result from TexVC(PHP)
$mhchemParser = new MhchemParser( self::$LOGMHCHEM );
@ -68,14 +98,13 @@ final class MMLmhchemTest extends MediaWikiUnitTestCase {
'usemhchem' => true,
"usemhchemtexified" => true
], $warnings, false );
$mathMLtexVC = isset( $resTexVC["input"] ) ? MMLTestUtil::getMMLwrapped( $resTexVC["input"] ) :
"<math> error texvc </math>";
MMLTestUtilHTML::generateHTMLtableRow(
self::$GENERATEDHTMLFILE, [ $title, $tc->tex, $tc->texNew, $mhchemOutput, $tc->mml_latexml ?? "no mathml",
$mathMLtexVC ],
false, self::$GENERATEHTML );
false, self::$GENERATEFILES );
if ( !self::$SKIPXMLVALIDATION ) {
$this->assertEquals( $tc->texNew, $mhchemOutput );