Debian Codegraph @

extensions/Math/tests/phpunit/MathValidatorTest.php

raw symbols SCIP
1 <?php
2
3 use DataValues\NumberValue;
4 use DataValues\StringValue;
5 use MediaWiki\Extension\Math\MathValidator;
6
7 /**
8 * @covers \MediaWiki\Extension\Math\MathValidator
9 *
10 * @group Math
11 *
12 * @license GPL-2.0-or-later
13 */
14 class MathValidatorTest extends MediaWikiIntegrationTestCase {
15 use MockHttpTrait;
16
17 private const VADLID_TEX = "\sin x";
18 private const INVADLID_TEX = "\\notExists";
19
20 public function testNotStringValue() {
21 $validator = new MathValidator();
22 $this->expectException( InvalidArgumentException::class );
23 $validator->validate( new NumberValue( 0 ) );
24 }
25
26 public function testNullValue() {
27 $validator = new MathValidator();
28 $this->expectException( InvalidArgumentException::class );
29 $validator->validate( null );
30 }
31
32 public function testValidInput() {
33 $this->installMockHttp( $this->makeFakeHttpRequest( file_get_contents( __DIR__ .
34 '/InputCheck/data/mathoid/sinx.json' ) ) );
35 $validator = new MathValidator();
36 $result = $validator->validate( new StringValue( self::VADLID_TEX ) );
37 $this->assertInstanceOf( \ValueValidators\Result::class, $result );
38 $this->assertTrue( $result->isValid() );
39 }
40
41 public function testInvalidInput() {
42 $this->installMockHttp( $this->makeFakeHttpRequest( file_get_contents( __DIR__ .
43 '/InputCheck/data/mathoid/invalidF.json' ), 400 ) );
44 $validator = new MathValidator();
45 $result = $validator->validate( new StringValue( self::INVADLID_TEX ) );
46 $this->assertInstanceOf( \ValueValidators\Result::class, $result );
47 $this->assertFalse( $result->isValid() );
48 }
49 }