setHeaders();
if ( ! ( $this->getUser()->isAllowed( 'purge' ) ) ) {
// The effect of loading this page is comparable to purge a page.
// If desired a dedicated right e.g. "viewmathstatus" could be used instead.
throw new PermissionsError( 'purge' );
}
$out = $this->getOutput();
$out->addWikiMsg( 'math-status-introduction' );
$enabledMathModes = MathHooks::getMathNames();
foreach ( $enabledMathModes as $modeNr => $modeName ){
$out->addWikiText( "=== $modeName ===" );
switch( $modeNr ){
case MW_MATH_MATHML:
$this->runMathMLTest( $modeName );
break;
case MW_MATH_LATEXML:
$this->runMathLaTeXMLTest( $modeName );
}
}
}
private function runMathMLTest( $modeName ) {
$this->getOutput()->addWikiMsgArray( 'math-test-start', $modeName );
$this->testSpecialCaseText();
$this->testMathMLIntegration();
$this->testPmmlInput();
$this->getOutput()->addWikiMsgArray( 'math-test-end', $modeName );
}
private function runMathLaTeXMLTest( $modeName ) {
$this->getOutput()->addWikiMsgArray( 'math-test-start', $modeName );
$this->testLaTeXMLIntegration();
$this->getOutput()->addWikiMsgArray( 'math-test-end', $modeName );
}
public function testSpecialCaseText() {
$renderer = MathRenderer::getRenderer( 'x^2+\text{a sample Text}', array(), MW_MATH_MATHML );
$expected = 'a sample Text';
$this->assertTrue( $renderer->render(), 'Rendering the input "x^2+\text{a sample Text}"' );
$this->assertContains( $expected, $renderer->getHtmlOutput(), 'Comparing to the reference rendering' );
}
/**
* Checks the basic functionality
* i.e. if the span element is generated right.
*/
public function testMathMLIntegration() {
$svgRef = '
';
$renderer = MathRenderer::getRenderer( "a+b", array(), MW_MATH_MATHML );
$this->assertTrue( $renderer->render( true ), "Rendering of a+b in plain MathML mode" );
$real = str_replace( "\n", '', $renderer->getHtmlOutput() );
$expected = '+';
$this->assertContains( $expected, $real, "Checking the presence of '+' in the MathML output" );
$this->assertEquals( $svgRef, $renderer->getSvg(), "Comparing the generated SVG with the reference" );
}
/**
* Checks the experimental option to 'render' MathML input
*/
public function testPmmlInput() {
// sample from 'Navajo Coal Combustion and Respiratory Health Near Shiprock, New Mexico' in ''Journal of Environmental and Public Health'' , vol. 2010p.
// authors Joseph E. Bunnell; Linda V. Garcia; Jill M. Furst; Harry Lerch; Ricardo A. Olea; Stephen E. Suitt; Allan Kolker
$inputSample = ' P i j = 100 d i j 6.75 r j , ';
$attribs = array( 'type' => 'pmml' );
$renderer = new MathMathML( $inputSample, $attribs );
$this->assertEquals( 'pmml', $renderer->getInputType(), 'Checking if MathML input is supported' );
$this->assertTrue( $renderer->render(), 'Rendering Presentation MathML sample' );
$real = MathRenderer::renderMath( $inputSample, $attribs, MW_MATH_MATHML );
$expected = 'hash=5628b8248b79267ecac656102334d5e3&mode=5';
$this->assertContains( $expected, $real, 'Checking if the link to SVG image is correct' );
}
/**
* Checks the basic functionality
* i.e. if the span element is generated right.
*/
public function testLaTeXMLIntegration() {
$renderer = MathRenderer::getRenderer( "a+b", array(), MW_MATH_LATEXML );
$this->assertTrue( $renderer->render( true ), "Rendering of a+b in LaTeXML mode" );
$expected = '';
$real = preg_replace( "/\n\s*/", '', $renderer->getHtmlOutput() );
$this->assertContains( $expected, $real
, "Comparing the output to the MathML reference rendering" .
$renderer->getLastError() );
}
private function assertTrue( $expression, $message = '' ) {
if ( $expression ){
$this->getOutput()->addWikiMsgArray( 'math-test-success' , $message );
} else {
$this->getOutput()->addWikiMsgArray( 'math-test-fail' , $message );
}
}
private function assertContains( $expected, $real, $message = '' ) {
$this->assertTrue( strpos( $real, $expected ) !== false, $message );
}
private function assertEquals( $expected, $real, $message = '' ) {
$this->assertTrue( $expected == $real, $message );
}
}