2017-08-16 05:50:44 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
2019-11-26 09:59:54 +00:00
|
|
|
* @covers \MathMathMLCli
|
2017-08-16 05:50:44 +00:00
|
|
|
*
|
|
|
|
* @group Math
|
|
|
|
*
|
2018-04-13 14:06:39 +00:00
|
|
|
* @license GPL-2.0-or-later
|
2017-08-16 05:50:44 +00:00
|
|
|
*/
|
|
|
|
class MathoidCliTest extends MediaWikiTestCase {
|
|
|
|
private $goodInput = '\sin\left(\frac12x\right)';
|
|
|
|
private $badInput = '\newcommand{\text{do evil things}}';
|
|
|
|
protected static $hasMathoidCli;
|
|
|
|
|
2019-11-02 00:18:33 +00:00
|
|
|
public static function setUpBeforeClass() : void {
|
2017-08-16 05:50:44 +00:00
|
|
|
global $wgMathoidCli;
|
|
|
|
if ( is_array( $wgMathoidCli ) && is_executable( $wgMathoidCli[0] ) ) {
|
|
|
|
self::$hasMathoidCli = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets up the fixture, for example, opens a network connection.
|
|
|
|
* This method is called before a test is executed.
|
|
|
|
*/
|
2019-10-11 17:45:11 +00:00
|
|
|
protected function setUp() : void {
|
2017-08-16 05:50:44 +00:00
|
|
|
parent::setUp();
|
|
|
|
if ( !self::$hasMathoidCli ) {
|
|
|
|
$this->markTestSkipped( "No mathoid cli configured on server" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGood() {
|
|
|
|
$mml = new MathMathMLCli( $this->goodInput );
|
|
|
|
$input = [ 'good' => [ $mml ] ];
|
|
|
|
MathMathMLCli::batchEvaluate( $input );
|
|
|
|
$this->assertTrue( $mml->render(), 'assert that renders' );
|
2020-04-05 11:38:45 +00:00
|
|
|
$this->assertStringContainsString( '</mo>', $mml->getMathml() );
|
2017-08-16 05:50:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testUndefinedFunctionError() {
|
|
|
|
$mml = new MathMathMLCli( $this->badInput );
|
|
|
|
$input = [ 'bad' => [ $mml ] ];
|
|
|
|
MathMathMLCli::batchEvaluate( $input );
|
|
|
|
$this->assertFalse( $mml->render(), 'assert that fails' );
|
2020-04-05 11:38:45 +00:00
|
|
|
$this->assertStringContainsString( 'newcommand', $mml->getLastError() );
|
2017-08-16 05:50:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testSyntaxError() {
|
|
|
|
$mml = new MathMathMLCli( '^' );
|
|
|
|
$input = [ 'bad' => [ $mml ] ];
|
|
|
|
MathMathMLCli::batchEvaluate( $input );
|
|
|
|
$this->assertFalse( $mml->render(), 'assert that fails' );
|
2020-04-05 11:38:45 +00:00
|
|
|
$this->assertStringContainsString( 'SyntaxError', $mml->getLastError() );
|
2017-08-16 05:50:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testCeError() {
|
|
|
|
$mml = new MathMathMLCli( '\ce{H2O}' );
|
|
|
|
$input = [ 'bad' => [ $mml ] ];
|
|
|
|
MathMathMLCli::batchEvaluate( $input );
|
|
|
|
$this->assertFalse( $mml->render(), 'assert that fails' );
|
2020-04-05 11:38:45 +00:00
|
|
|
$this->assertStringContainsString( 'SyntaxError', $mml->getLastError() );
|
2017-08-16 05:50:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testEmpty() {
|
|
|
|
$mml = new MathMathMLCli( '' );
|
|
|
|
$input = [ 'bad' => [ $mml ] ];
|
|
|
|
MathMathMLCli::batchEvaluate( $input );
|
|
|
|
$this->assertFalse( $mml->render(), 'assert that renders' );
|
|
|
|
$this->assertFalse( $mml->isTexSecure() );
|
2020-04-05 11:38:45 +00:00
|
|
|
$this->assertStringContainsString( 'empty', $mml->getLastError() );
|
2017-08-16 05:50:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|