2021-08-11 13:38:51 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
use MediaWiki\Extension\Math\InputCheck\RestbaseChecker;
|
|
|
|
use MediaWiki\Extension\Math\Tests\MathMockHttpTrait;
|
2024-06-09 16:48:28 +00:00
|
|
|
use MediaWiki\Message\Message;
|
2021-08-11 13:38:51 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @group Math
|
|
|
|
*
|
|
|
|
* @license GPL-2.0-or-later
|
|
|
|
*
|
|
|
|
* @covers \MediaWiki\Extension\Math\InputCheck\RestbaseChecker
|
|
|
|
*/
|
2021-10-11 22:51:10 +00:00
|
|
|
class RestbaseCheckerTest extends MediaWikiIntegrationTestCase {
|
2021-08-11 13:38:51 +00:00
|
|
|
use MathMockHttpTrait;
|
|
|
|
|
|
|
|
public function testValid() {
|
|
|
|
$this->setupGoodMathRestBaseMockHttp();
|
|
|
|
|
|
|
|
$checker = new RestbaseChecker( '\sin x^2' );
|
|
|
|
$this->assertNull( $checker->getError() );
|
|
|
|
$this->assertTrue( $checker->isValid() );
|
|
|
|
$this->assertNull( $checker->getError() );
|
|
|
|
$this->assertSame( '\\sin x^{2}', $checker->getValidTex() );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testInvalid() {
|
|
|
|
$this->setupBadMathRestBaseMockHttp();
|
|
|
|
|
|
|
|
$checker = new RestbaseChecker( '\sin\newcommand' );
|
|
|
|
$this->assertNull( $checker->getError() );
|
|
|
|
$this->assertFalse( $checker->isValid() );
|
|
|
|
$this->assertStringContainsString(
|
|
|
|
Message::newFromKey( 'math_unknown_function', '\newcommand' )
|
|
|
|
->inContentLanguage()
|
|
|
|
->escaped(),
|
|
|
|
$checker->getError()
|
|
|
|
->inContentLanguage()
|
|
|
|
->escaped()
|
|
|
|
);
|
|
|
|
$this->assertNull( $checker->getValidTex() );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testErrorSyntax() {
|
|
|
|
$this->setupSyntaxErrorRestBaseMockHttp();
|
|
|
|
|
|
|
|
$checker = new RestbaseChecker( '\left(' );
|
|
|
|
$this->assertFalse( $checker->isValid() );
|
|
|
|
$this->assertStringContainsString(
|
|
|
|
Message::newFromKey( 'math_syntax_error' )
|
|
|
|
->inContentLanguage()
|
|
|
|
->escaped(),
|
|
|
|
$checker->getError()
|
|
|
|
->inContentLanguage()
|
|
|
|
->escaped()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|