mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Math
synced 2024-12-12 16:05:09 +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
58 lines
1.5 KiB
PHP
58 lines
1.5 KiB
PHP
<?php
|
|
|
|
use MediaWiki\Extension\Math\InputCheck\RestbaseChecker;
|
|
use MediaWiki\Extension\Math\Tests\MathMockHttpTrait;
|
|
|
|
/**
|
|
* @group Math
|
|
*
|
|
* @license GPL-2.0-or-later
|
|
*
|
|
* @covers \MediaWiki\Extension\Math\InputCheck\RestbaseChecker
|
|
*/
|
|
class RestbaseCheckerTest extends MediaWikiTestCase {
|
|
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()
|
|
);
|
|
}
|
|
}
|