mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Math
synced 2024-12-15 01:01:56 +00:00
16d1fdacf4
* Cache results for checked tex and MathML string in one cache. * Remove access to parsetree * Introduce run method to speed up service wiring Note that the indirection table used in previous versions was abandoned here. texvc does only little unification's of the input string so that it is not expected that the overall savings in space and compute time warrant the additional table. Change-Id: Ib9ce3d2ab02bd9a2a0f9926db6b937435b7e5458
107 lines
3.4 KiB
PHP
107 lines
3.4 KiB
PHP
<?php
|
|
|
|
namespace phpunit\InputCheck;
|
|
|
|
use MediaWiki\Config\ServiceOptions;
|
|
use MediaWiki\Extension\Math\InputCheck\InputCheckFactory;
|
|
use MediaWiki\Extension\Math\InputCheck\LocalChecker;
|
|
use MediaWiki\Extension\Math\InputCheck\MathoidChecker;
|
|
use MediaWiki\Extension\Math\InputCheck\RestbaseChecker;
|
|
use MediaWiki\Http\HttpRequestFactory;
|
|
use MediaWiki\Logger\LoggerFactory;
|
|
use MediaWiki\Tests\Unit\MockServiceDependenciesTrait;
|
|
use MediaWikiIntegrationTestCase;
|
|
use Message;
|
|
use WANObjectCache;
|
|
|
|
/**
|
|
* @method InputCheckFactory newServiceInstance(string $serviceClass, array $parameterOverrides)
|
|
* @covers \MediaWiki\Extension\Math\InputCheck\InputCheckFactory
|
|
*/
|
|
class InputCheckFactoryTest extends MediaWikiIntegrationTestCase {
|
|
|
|
use MockServiceDependenciesTrait;
|
|
|
|
private $fakeHTTP;
|
|
private $fakeWAN;
|
|
|
|
protected function setUp(): void {
|
|
parent::setUp();
|
|
$this->fakeHTTP = $this->createMock( HttpRequestFactory::class );
|
|
$this->fakeWAN = $this->createMock( WANObjectCache::class );
|
|
}
|
|
|
|
public function testNewMathoidChecker() {
|
|
$checker = $this->newServiceInstance( InputCheckFactory::class, [] )
|
|
->newMathoidChecker( 'FORMULA', 'TYPE' );
|
|
$this->assertInstanceOf( MathoidChecker::class, $checker );
|
|
}
|
|
|
|
public function testNewRestbaseChecker() {
|
|
$checker = $this->newServiceInstance( InputCheckFactory::class, [] )
|
|
->newRestbaseChecker( 'FORMULA', 'TYPE' );
|
|
$this->assertInstanceOf( RestbaseChecker::class, $checker );
|
|
}
|
|
|
|
public function testNewLocalChecker() {
|
|
$checker = $this->newServiceInstance( InputCheckFactory::class, [] )
|
|
->newLocalChecker( 'FORMULA', 'tex' );
|
|
$this->assertInstanceOf( LocalChecker::class, $checker );
|
|
}
|
|
|
|
public function testInvalidLocalChecker() {
|
|
$myFactory = new InputCheckFactory(
|
|
new ServiceOptions( InputCheckFactory::CONSTRUCTOR_OPTIONS, [
|
|
'MathMathMLUrl' => 'something',
|
|
'MathTexVCService' => 'local',
|
|
'MathLaTeXMLTimeout' => 240
|
|
] ),
|
|
$this->fakeWAN,
|
|
$this->fakeHTTP,
|
|
LoggerFactory::getInstance( 'Math' )
|
|
);
|
|
$checker = $myFactory->newLocalChecker( 'FORMULA', 'INVALIDTYPE' );
|
|
$this->assertInstanceOf( LocalChecker::class, $checker );
|
|
$this->assertInstanceOf( Message::class, $checker->getError() );
|
|
$this->assertFalse( $checker->isValid() );
|
|
}
|
|
|
|
public function testNewDefaultChecker() {
|
|
$checker = $this->newServiceInstance( InputCheckFactory::class, [] )
|
|
->newDefaultChecker( 'FORMULA', 'TYPE' );
|
|
$this->assertInstanceOf( RestbaseChecker::class, $checker );
|
|
}
|
|
|
|
public function testNewMLocalCheckerDefault() {
|
|
$myFactory = new InputCheckFactory(
|
|
new ServiceOptions( InputCheckFactory::CONSTRUCTOR_OPTIONS, [
|
|
'MathMathMLUrl' => 'something',
|
|
'MathTexVCService' => 'local',
|
|
'MathLaTeXMLTimeout' => 240
|
|
] ),
|
|
$this->fakeWAN,
|
|
$this->fakeHTTP,
|
|
LoggerFactory::getInstance( 'Math' )
|
|
);
|
|
|
|
$checker = $myFactory->newDefaultChecker( 'FORMULA', 'tex' );
|
|
$this->assertInstanceOf( LocalChecker::class, $checker );
|
|
}
|
|
|
|
public function testMathoidCheckerInDefault() {
|
|
$myFactory = new InputCheckFactory(
|
|
new ServiceOptions( InputCheckFactory::CONSTRUCTOR_OPTIONS, [
|
|
'MathMathMLUrl' => 'something',
|
|
'MathTexVCService' => 'mathoid',
|
|
'MathLaTeXMLTimeout' => 240
|
|
] ),
|
|
$this->fakeWAN,
|
|
$this->fakeHTTP,
|
|
LoggerFactory::getInstance( 'Math' )
|
|
);
|
|
|
|
$checker = $myFactory->newDefaultChecker( 'FORMULA', 'TYPE' );
|
|
$this->assertInstanceOf( MathoidChecker::class, $checker );
|
|
}
|
|
}
|