| 1 |
<?php |
| 2 |
|
| 3 |
use MediaWiki\Extension\Math\MathMathMLCli; |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
class MathoidCliTest extends MediaWikiIntegrationTestCase { |
| 13 |
|
| 14 |
private $goodInput = '\sin\left(\frac12x\right)'; |
| 15 |
|
| 16 |
private $badInput = '\newcommand{\text{do evil things}}'; |
| 17 |
|
| 18 |
protected static $hasMathoidCli; |
| 19 |
|
| 20 |
public static function setUpBeforeClass(): void { |
| 21 |
global $wgMathoidCli; |
| 22 |
if ( is_array( $wgMathoidCli ) && is_executable( $wgMathoidCli[0] ) ) { |
| 23 |
self::$hasMathoidCli = true; |
| 24 |
} |
| 25 |
} |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
protected function setUp(): void { |
| 32 |
parent::setUp(); |
| 33 |
if ( !self::$hasMathoidCli ) { |
| 34 |
$this->markTestSkipped( "No mathoid cli configured on server" ); |
| 35 |
} |
| 36 |
} |
| 37 |
|
| 38 |
public function testGood() { |
| 39 |
$mml = new MathMathMLCli( $this->goodInput ); |
| 40 |
$input = [ 'good' => $mml ]; |
| 41 |
MathMathMLCli::batchEvaluate( $input ); |
| 42 |
$this->assertTrue( $mml->render(), 'assert that renders' ); |
| 43 |
$this->assertStringContainsString( '</mo>', $mml->getMathml() ); |
| 44 |
} |
| 45 |
|
| 46 |
public function testUndefinedFunctionError() { |
| 47 |
$mml = new MathMathMLCli( $this->badInput ); |
| 48 |
$input = [ 'bad' => $mml ]; |
| 49 |
MathMathMLCli::batchEvaluate( $input ); |
| 50 |
$this->assertFalse( $mml->render(), 'assert that fails' ); |
| 51 |
$this->assertStringContainsString( 'newcommand', $mml->getLastError() ); |
| 52 |
} |
| 53 |
|
| 54 |
public function testSyntaxError() { |
| 55 |
$mml = new MathMathMLCli( '^' ); |
| 56 |
$input = [ 'bad' => $mml ]; |
| 57 |
MathMathMLCli::batchEvaluate( $input ); |
| 58 |
$this->assertFalse( $mml->render(), 'assert that fails' ); |
| 59 |
$this->assertStringContainsString( 'SyntaxError', $mml->getLastError() ); |
| 60 |
} |
| 61 |
|
| 62 |
public function testCeError() { |
| 63 |
$mml = new MathMathMLCli( '\ce{H2O}' ); |
| 64 |
$input = [ 'bad' => $mml ]; |
| 65 |
MathMathMLCli::batchEvaluate( $input ); |
| 66 |
$this->assertFalse( $mml->render(), 'assert that fails' ); |
| 67 |
$this->assertStringContainsString( 'SyntaxError', $mml->getLastError() ); |
| 68 |
} |
| 69 |
|
| 70 |
public function testEmpty() { |
| 71 |
$mml = new MathMathMLCli( '' ); |
| 72 |
$input = [ 'bad' => $mml ]; |
| 73 |
MathMathMLCli::batchEvaluate( $input ); |
| 74 |
$this->assertFalse( $mml->render(), 'assert that renders' ); |
| 75 |
$this->assertFalse( $mml->isTexSecure() ); |
| 76 |
$this->assertStringContainsString( 'empty', $mml->getLastError() ); |
| 77 |
} |
| 78 |
|
| 79 |
} |