mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Math
synced 2024-11-15 03:34:10 +00:00
b189280467
Some mentioned a "__constructor", which should be "__construct". The leading backslash is not strictly needed by all tools. But some need it. I learned it's best practice to always have it. Change-Id: I22fe3a3b4828c02ab5a457aba9af5af1c72567ea
68 lines
1.7 KiB
PHP
68 lines
1.7 KiB
PHP
<?php
|
|
|
|
use DataValues\StringValue;
|
|
use DataValues\NumberValue;
|
|
|
|
/**
|
|
* @covers \MathValidator
|
|
*
|
|
* @group Math
|
|
*
|
|
* @license GPL-2.0-or-later
|
|
*/
|
|
class MathValidatorTest extends MediaWikiTestCase {
|
|
const VADLID_TEX = "a^2+b^2=c^2";
|
|
const INVADLID_TEX = "\\notExists";
|
|
|
|
protected static $hasRestbase;
|
|
|
|
public static function setUpBeforeClass() : void {
|
|
$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.
|
|
*/
|
|
protected function setUp() : void {
|
|
parent::setUp();
|
|
|
|
if ( !self::$hasRestbase ) {
|
|
$this->markTestSkipped( "Can not connect to Restbase Math interface." );
|
|
}
|
|
}
|
|
|
|
protected function tearDown() : void {
|
|
parent::tearDown();
|
|
}
|
|
|
|
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() {
|
|
$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() );
|
|
}
|
|
}
|