diff --git a/tests/phpunit/unit/TexVC/Mhchem/MMLmhchemTest.php b/tests/phpunit/unit/TexVC/Mhchem/MMLmhchemTest.php index a6cf01b41..ecbfc10bc 100644 --- a/tests/phpunit/unit/TexVC/Mhchem/MMLmhchemTest.php +++ b/tests/phpunit/unit/TexVC/Mhchem/MMLmhchemTest.php @@ -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" + . "| " . $tex . " \n" + . "|" . $tex . " \n" + . "|" . $tex . ""; + 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"] ) : " error texvc "; 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 );