Debian Codegraph @

extensions/Math/tests/phpunit/MathoidCliTest.php

raw symbols SCIP
1 <?php
2
3 use MediaWiki\Extension\Math\MathMathMLCli;
4
5 /**
6 * @covers \MediaWiki\Extension\Math\MathMathMLCli
7 *
8 * @group Math
9 *
10 * @license GPL-2.0-or-later
11 */
12 class MathoidCliTest extends MediaWikiIntegrationTestCase {
13 /** @var string */
14 private $goodInput = '\sin\left(\frac12x\right)';
15 /** @var string */
16 private $badInput = '\newcommand{\text{do evil things}}';
17 /** @var true|null */
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 * Sets up the fixture, for example, opens a network connection.
29 * This method is called before a test is executed.
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 }