mediawiki-extensions-Math/tests/phpunit/MathoidCliTest.php
libraryupgrader b409746fc6 build: Updating dependencies
composer:
* mediawiki/mediawiki-codesniffer: 36.0.0 → 37.0.0

npm:
* postcss: 7.0.35 → 7.0.36
  * https://npmjs.com/advisories/1693 (CVE-2021-23368)
* ws: 7.3.0 → 7.5.3
  * https://npmjs.com/advisories/1748 (CVE-2021-32640)
* glob-parent: 5.1.1 → 5.1.2
  * https://npmjs.com/advisories/1751 (CVE-2020-28469)
* trim-newlines: 3.0.0 → 3.0.1
  * https://npmjs.com/advisories/1753 (CVE-2021-33623)
* normalize-url: 4.5.0 → 4.5.1
  * https://npmjs.com/advisories/1755 (CVE-2021-33502)

Change-Id: Ie14979780cdbd04fa2804f5317e8b0f6b0029470
2021-07-23 02:28:22 +00:00

77 lines
2.3 KiB
PHP

<?php
use MediaWiki\Extension\Math\MathMathMLCli;
/**
* @covers \MediaWiki\Extension\Math\MathMathMLCli
*
* @group Math
*
* @license GPL-2.0-or-later
*/
class MathoidCliTest extends MediaWikiTestCase {
private $goodInput = '\sin\left(\frac12x\right)';
private $badInput = '\newcommand{\text{do evil things}}';
protected static $hasMathoidCli;
public static function setUpBeforeClass(): void {
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.
*/
protected function setUp(): void {
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' );
$this->assertStringContainsString( '</mo>', $mml->getMathml() );
}
public function testUndefinedFunctionError() {
$mml = new MathMathMLCli( $this->badInput );
$input = [ 'bad' => [ $mml ] ];
MathMathMLCli::batchEvaluate( $input );
$this->assertFalse( $mml->render(), 'assert that fails' );
$this->assertStringContainsString( 'newcommand', $mml->getLastError() );
}
public function testSyntaxError() {
$mml = new MathMathMLCli( '^' );
$input = [ 'bad' => [ $mml ] ];
MathMathMLCli::batchEvaluate( $input );
$this->assertFalse( $mml->render(), 'assert that fails' );
$this->assertStringContainsString( 'SyntaxError', $mml->getLastError() );
}
public function testCeError() {
$mml = new MathMathMLCli( '\ce{H2O}' );
$input = [ 'bad' => [ $mml ] ];
MathMathMLCli::batchEvaluate( $input );
$this->assertFalse( $mml->render(), 'assert that fails' );
$this->assertStringContainsString( 'SyntaxError', $mml->getLastError() );
}
public function testEmpty() {
$mml = new MathMathMLCli( '' );
$input = [ 'bad' => [ $mml ] ];
MathMathMLCli::batchEvaluate( $input );
$this->assertFalse( $mml->render(), 'assert that renders' );
$this->assertFalse( $mml->isTexSecure() );
$this->assertStringContainsString( 'empty', $mml->getLastError() );
}
}