2015-12-14 20:26:29 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
use DataValues\StringValue;
|
|
|
|
use DataValues\NumberValue;
|
|
|
|
|
2016-02-12 16:57:37 +00:00
|
|
|
/**
|
|
|
|
* @covers MathValidator
|
|
|
|
*
|
|
|
|
* @group Math
|
|
|
|
*
|
2018-04-13 14:06:39 +00:00
|
|
|
* @license GPL-2.0-or-later
|
2016-02-12 16:57:37 +00:00
|
|
|
*/
|
2015-12-14 20:26:29 +00:00
|
|
|
class MathValidatorTest extends MediaWikiTestCase {
|
|
|
|
const VADLID_TEX = "a^2+b^2=c^2";
|
|
|
|
const INVADLID_TEX = "\\notExists";
|
|
|
|
|
|
|
|
protected static $hasRestbase;
|
|
|
|
|
2019-11-02 00:18:33 +00:00
|
|
|
public static function setUpBeforeClass() : void {
|
2015-12-14 20:26:29 +00:00
|
|
|
$rbi = new MathRestbaseInterface();
|
|
|
|
self::$hasRestbase = $rbi->checkBackend( true );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets up the fixture, for example, opens a network connection.
|
|
|
|
* This method is called before a test is executed.
|
|
|
|
*/
|
2019-10-11 17:45:11 +00:00
|
|
|
protected function setUp() : void {
|
2015-12-14 20:26:29 +00:00
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
if ( !self::$hasRestbase ) {
|
|
|
|
$this->markTestSkipped( "Can not connect to Restbase Math interface." );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-11 17:45:11 +00:00
|
|
|
protected function tearDown() : void {
|
2015-12-14 20:26:29 +00:00
|
|
|
parent::tearDown();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testNotStringValue() {
|
|
|
|
$validator = new MathValidator();
|
2019-10-16 02:28:43 +00:00
|
|
|
$this->expectException( InvalidArgumentException::class );
|
2015-12-14 20:26:29 +00:00
|
|
|
$validator->validate( new NumberValue( 0 ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testNullValue() {
|
|
|
|
$validator = new MathValidator();
|
2019-10-16 02:28:43 +00:00
|
|
|
$this->expectException( InvalidArgumentException::class );
|
2015-12-14 20:26:29 +00:00
|
|
|
$validator->validate( null );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testValidInput() {
|
|
|
|
$validator = new MathValidator();
|
|
|
|
$result = $validator->validate( new StringValue( self::VADLID_TEX ) );
|
|
|
|
// not supported by jenkins php version
|
|
|
|
// $this->assertType( \ValueValidators\Result::class, $result );
|
|
|
|
$this->assertTrue( $result->isValid() );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testInvalidInput() {
|
|
|
|
$validator = new MathValidator();
|
|
|
|
$result = $validator->validate( new StringValue( self::INVADLID_TEX ) );
|
|
|
|
// not supported by jenkins php version
|
|
|
|
// $this->assertType( \ValueValidators\Result::class, $result );
|
|
|
|
$this->assertFalse( $result->isValid() );
|
|
|
|
}
|
|
|
|
}
|