ctr, self::$SKIPPEDINDICES, true ) ) { 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"] ); $mmlComparator = new MMLComparator(); $compRes = $mmlComparator->compareMathML( $tc->mml_mathoid, $mathMLtexVC ); MMLTestUtilHTML::generateHTMLtableRow( self::$GENERATEDHTMLFILE, [ $tc->ctr, $tc->tex, $mml_latexml, $tc->mml_mathoid, $mathMLtexVC, $compRes['similarityF'] ], false, self::$GENERATEHTML ); if ( !self::$SKIPXMLVALIDATION ) { if ( !$tc->mml_mathoid ) { $this->fail( "No Mathoid reference found for: " . $tc->tex ); } if ( $compRes['similarityF'] >= self::$SIMILARITYTRESH ) { $this->assertTrue( true ); } else { $this->assertXmlStringEqualsXmlString( $tc->mml_mathoid, $mathMLtexVC ); } } else { $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; } }