2017-08-16 05:50:44 +00:00
|
|
|
<?php
|
|
|
|
|
2021-04-07 22:22:05 +00:00
|
|
|
use MediaWiki\Extension\Math\MathMathMLCli;
|
|
|
|
|
2017-08-16 05:50:44 +00:00
|
|
|
/**
|
2021-04-07 22:22:05 +00:00
|
|
|
* @covers \MediaWiki\Extension\Math\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
|
|
|
*/
|
2021-10-11 22:51:10 +00:00
|
|
|
class MathoidCliTest extends MediaWikiIntegrationTestCase {
|
2024-08-25 12:22:07 +00:00
|
|
|
/** @var string */
|
2017-08-16 05:50:44 +00:00
|
|
|
private $goodInput = '\sin\left(\frac12x\right)';
|
2024-08-25 12:22:07 +00:00
|
|
|
/** @var string */
|
2017-08-16 05:50:44 +00:00
|
|
|
private $badInput = '\newcommand{\text{do evil things}}';
|
2024-08-25 12:22:07 +00:00
|
|
|
/** @var true|null */
|
2017-08-16 05:50:44 +00:00
|
|
|
protected static $hasMathoidCli;
|
|
|
|
|
2021-07-22 11:56:28 +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.
|
|
|
|
*/
|
2021-07-22 11:56:28 +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 );
|
2021-08-04 19:49:10 +00:00
|
|
|
$input = [ 'good' => $mml ];
|
2017-08-16 05:50:44 +00:00
|
|
|
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 );
|
2021-08-04 19:49:10 +00:00
|
|
|
$input = [ 'bad' => $mml ];
|
2017-08-16 05:50:44 +00:00
|
|
|
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( '^' );
|
2021-08-04 19:49:10 +00:00
|
|
|
$input = [ 'bad' => $mml ];
|
2017-08-16 05:50:44 +00:00
|
|
|
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}' );
|
2021-08-04 19:49:10 +00:00
|
|
|
$input = [ 'bad' => $mml ];
|
2017-08-16 05:50:44 +00:00
|
|
|
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( '' );
|
2021-08-04 19:49:10 +00:00
|
|
|
$input = [ 'bad' => $mml ];
|
2017-08-16 05:50:44 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
}
|