mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Math
synced 2024-11-14 19:26:08 +00:00
da8e918fb3
Additionally - remove RestbaseInterface::checkBackend. When HTTP requests are banned from unit tests this method makes no sence. MathoidCli tests were not reenabled cause it's a bit hard to mock shell acceess. Hopefully as part of Shellbox transition we can have MockShell trait in core and reenable those tests Bug: T265628 Depends-On: I350ed59af603a0504704af3265787a4be8f2dc2a Change-Id: I294d0ed905193850dc38cb3071eb9b31c8863121
50 lines
1.5 KiB
PHP
50 lines
1.5 KiB
PHP
<?php
|
|
|
|
use DataValues\NumberValue;
|
|
use DataValues\StringValue;
|
|
use MediaWiki\Extension\Math\MathValidator;
|
|
|
|
/**
|
|
* @covers \MediaWiki\Extension\Math\MathValidator
|
|
*
|
|
* @group Math
|
|
*
|
|
* @license GPL-2.0-or-later
|
|
*/
|
|
class MathValidatorTest extends MediaWikiTestCase {
|
|
use MockHttpTrait;
|
|
|
|
private const VADLID_TEX = "\sin x";
|
|
private const INVADLID_TEX = "\\notExists";
|
|
|
|
public function testNotStringValue() {
|
|
$validator = new MathValidator();
|
|
$this->expectException( InvalidArgumentException::class );
|
|
$validator->validate( new NumberValue( 0 ) );
|
|
}
|
|
|
|
public function testNullValue() {
|
|
$validator = new MathValidator();
|
|
$this->expectException( InvalidArgumentException::class );
|
|
$validator->validate( null );
|
|
}
|
|
|
|
public function testValidInput() {
|
|
$this->installMockHttp( $this->makeFakeHttpRequest( file_get_contents( __DIR__ .
|
|
'/InputCheck/data/mathoid/sinx.json' ) ) );
|
|
$validator = new MathValidator();
|
|
$result = $validator->validate( new StringValue( self::VADLID_TEX ) );
|
|
$this->assertInstanceOf( \ValueValidators\Result::class, $result );
|
|
$this->assertTrue( $result->isValid() );
|
|
}
|
|
|
|
public function testInvalidInput() {
|
|
$this->installMockHttp( $this->makeFakeHttpRequest( file_get_contents( __DIR__ .
|
|
'/InputCheck/data/mathoid/invalidF.json' ), 400 ) );
|
|
$validator = new MathValidator();
|
|
$result = $validator->validate( new StringValue( self::INVADLID_TEX ) );
|
|
$this->assertInstanceOf( \ValueValidators\Result::class, $result );
|
|
$this->assertFalse( $result->isValid() );
|
|
}
|
|
}
|