" . $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-WikiTexVC" ], self::$GENERATEFILES ); if ( self::$GENERATEFILES ) { self::writeWikifileHeader( self::$GENERATEDWIKIFILE ); } } public static function tearDownAfterClass(): void { MMLTestUtilHTML::generateHTMLEnd( self::$GENERATEDHTMLFILE, self::$GENERATEFILES ); } /** * @dataProvider provideTestCases * @throws Exception */ 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", "skipped" ], false, self::$GENERATEFILES ); $this->addToAssertionCount( 1 ); return; } if ( self::$GENERATEFILES ) { self::writeWikifileRow( self::$GENERATEDWIKIFILE, $tc->tex ); } # Fetch result from WikiTexVC(PHP) $mhchemParser = new MhchemParser( self::$LOGMHCHEM ); $mhchemOutput = $mhchemParser->toTex( $tc->tex, $tc->typeC, true ); $warnings = []; $resTexVC = $texVC->check( $mhchemOutput, [ 'debug' => false, 'usemathrm' => true, 'oldtexvc' => false, '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::$GENERATEFILES ); if ( !self::$SKIPXMLVALIDATION ) { $this->assertEquals( $tc->texNew, $mhchemOutput ); } else { $this->addToAssertionCount( 1 ); } } public static function provideTestCases() { $fileTestcases = MMLTestUtil::getJSON( self::$FILENAMEREF ); $f = []; // Adding running indices for location of tests. $ctr = 0; foreach ( $fileTestcases as $tcF ) { $tc = [ "ctr" => $ctr, "tex" => $tcF->tex, "texNew" => $tcF->texNew, "type" => $tcF->type, "typeC" => $tcF->typeC, "mml_mathoid" => $tcF->mmlMathoid, "mml_latexml" => $tcF->mmlLaTeXML, ]; $f[] = [ "tc#" . str_pad( $ctr, 3, '0', STR_PAD_LEFT ) . " " . $tcF->description, (object)$tc ]; $ctr++; } // Filtering results by index if necessary if ( self::$APPLYFILTER ) { $f = array_slice( $f, self::$FILTERSTART, self::$FILTERLENGTH ); } return $f; } }