Add info about failed tests to MathStatus

* Prints expected and real results for failed tests.
* Adopts to the new LaTeXML naming conventions.

Bug: T94434
Change-Id: I72bc6df7e9a85ae5c14cc7f82df072adfa65b67e
This commit is contained in:
physikerwelt 2015-03-30 11:33:19 -04:00 committed by Physikerwelt
parent bc52c77d24
commit 40c6bb69af
3 changed files with 26 additions and 5 deletions

View File

@ -1,4 +1,5 @@
<?php
use MediaWiki\Logger\LoggerFactory;
/**
* MediaWiki math extension
*
@ -116,8 +117,8 @@ class SpecialMathStatus extends SpecialPage {
public function testLaTeXMLIntegration() {
$renderer = MathRenderer::getRenderer( "a+b", array(), 'latexml' );
$this->assertTrue( $renderer->render( true ), "Rendering of a+b in LaTeXML mode" );
$expected = '<math xmlns="http://www.w3.org/1998/Math/MathML" id="p1.1.m1.1" class="ltx_Math" alttext="{\displaystyle a+b}" xref="p1.1.m1.1.cmml"><semantics id="p1.1.m1.1a" xref="p1.1.m1.1.cmml"><mrow id="p1.1.m1.1.4" xref="p1.1.m1.1.4.cmml"><mi id="p1.1.m1.1.1" xref="p1.1.m1.1.1.cmml">a</mi><mo id="p1.1.m1.1.2" xref="p1.1.m1.1.2.cmml">+</mo><mi id="p1.1.m1.1.3" xref="p1.1.m1.1.3.cmml">b</mi></mrow><annotation-xml encoding="MathML-Content" id="p1.1.m1.1.cmml" xref="p1.1.m1.1"><apply id="p1.1.m1.1.4.cmml" xref="p1.1.m1.1.4"><plus id="p1.1.m1.1.2.cmml" xref="p1.1.m1.1.2"/><ci id="p1.1.m1.1.1.cmml" xref="p1.1.m1.1.1">a</ci><ci id="p1.1.m1.1.3.cmml" xref="p1.1.m1.1.3">b</ci></apply></annotation-xml><annotation encoding="application/x-tex" id="p1.1.m1.1b" xref="p1.1.m1.1.cmml">{\displaystyle a+b}</annotation></semantics></math>';
$real = preg_replace( "/\n\s*/", '', $renderer->getHtmlOutput() );
$expected = '<math xmlns="http://www.w3.org/1998/Math/MathML" id="p1.1.m1.1" class="ltx_Math" alttext="{\displaystyle a+b}" ><semantics id="p1.1.m1.1a"><mrow id="p1.1.m1.1.4" xref="p1.1.m1.1.4.cmml"><mi id="p1.1.m1.1.1" xref="p1.1.m1.1.1.cmml">a</mi><mo id="p1.1.m1.1.2" xref="p1.1.m1.1.2.cmml">+</mo><mi id="p1.1.m1.1.3" xref="p1.1.m1.1.3.cmml">b</mi></mrow><annotation-xml encoding="MathML-Content" id="p1.1.m1.1b"><apply id="p1.1.m1.1.4.cmml" xref="p1.1.m1.1.4"><plus id="p1.1.m1.1.2.cmml" xref="p1.1.m1.1.2"/><ci id="p1.1.m1.1.1.cmml" xref="p1.1.m1.1.1">a</ci><ci id="p1.1.m1.1.3.cmml" xref="p1.1.m1.1.3">b</ci></apply></annotation-xml><annotation encoding="application/x-tex" id="p1.1.m1.1c">{\displaystyle a+b}</annotation></semantics></math>';
$real = preg_replace( "/\n\\s*/", '', $renderer->getHtmlOutput() );
$this->assertContains( $expected, $real
, "Comparing the output to the MathML reference rendering" .
$renderer->getLastError() );
@ -126,20 +127,36 @@ class SpecialMathStatus extends SpecialPage {
private function assertTrue( $expression, $message = '' ) {
if ( $expression ){
$this->getOutput()->addWikiMsgArray( 'math-test-success' , $message );
return true;
} else {
$this->getOutput()->addWikiMsgArray( 'math-test-fail' , $message );
return false;
}
}
private function assertContains( $expected, $real, $message = '' ) {
$this->assertTrue( strpos( $real, $expected ) !== false, $message );
if ( ! $this->assertTrue( strpos( $real, $expected ) !== false, $message ) ) {
$this->printDiff( $expected, $real, 'math-test-contains-diff' );
}
}
private function assertEquals( $expected, $real, $message = '' ) {
$this->assertTrue( $expected == $real, $message );
if ( !$this->assertTrue( $expected == $real, $message ) ) {
$this->printDiff( $expected, $real, 'math-test-equals-diff' );
}
}
private function printDiff( $expected, $real, $message = '' ) {
if ( ExtensionRegistry::getInstance()->isLoaded( "SyntaxHighlight" ) ) {
$expected = "<syntaxhighlight lang=\"xml\">$expected</syntaxhighlight>";
$real = "<syntaxhighlight lang=\"xml\">$real</syntaxhighlight>";
$this->getOutput()->addWikiMsgArray( $message, array( $real, $expected ) );
} else {
LoggerFactory::getInstance( 'Math' )->warning( 'Can not display expected and real value.'.
'SyntaxHighlight is not installed.' );
}
}
protected function getGroupName() {
return 'other';
}
}
}

View File

@ -28,6 +28,8 @@
"math-test-fail": "Test ''$1'' <span style=\"color:red\">failed</span>.",
"math-test-start": "Running backend tests for rendering mode ''$1''.",
"math-test-success": "Test ''$1'' <span style=\"color:green\">succeeded</span>.",
"math-test-contains-diff" : "Returned string $1 does not contain expected string $2.",
"math-test-equals-diff" : "Returned string $1 is different from expected string $2",
"math_tip": "Mathematical formula (LaTeX)",
"math_unknown_error": "unknown error",
"math_unknown_function": "unknown function \"$1\"",

View File

@ -39,6 +39,8 @@
"math-test-fail": "Used as special-page text.\n\nParameters:\n* $1 test name",
"math-test-start": "Used as special-page text.\n\nParameters:\n* $1 rendering mode",
"math-test-success": "Used as special-page text.\n\nParameters:\n* $1 test name",
"math-test-contains-diff" : "Used as special-page wikitext.\n\nParameters:\n* $1 syntax highlight element of the returned string \n* $2 syntax highlight element of the expected string",
"math-test-equals-diff" : "Used as special-page wikitext.\n\nParameters:\n* $1 syntax highlight element of the returned string \n* $2 syntax highlight element of the expected string",
"math_tip": "This is the text that appears when you hover the mouse over the fourth button from the right on the edit toolbar.",
"math_unknown_error": "Used as error message for unknown texvc error.\n\nThis message follows the message {{msg-mw|Math failure}}.\n{{Identical|Unknown error}}",
"math_unknown_function": "Used as error message when texvc encounters an unknown function.\n\nPreceded by the message {{msg-mw|Math failure}}.\n\nParameters:\n* $1 - name of unknown function",