mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Math
synced 2024-11-15 11:48:23 +00:00
c27f7edef9
Bug: T312528 Change-Id: I0eda7d4213a5f703ab7ae7887aa364af9e576dbe
96 lines
3 KiB
PHP
96 lines
3 KiB
PHP
<?php
|
|
|
|
namespace phpunit\InputCheck;
|
|
|
|
use InvalidArgumentException;
|
|
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 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() {
|
|
$this->expectException( InvalidArgumentException::class );
|
|
$this->newServiceInstance( InputCheckFactory::class, [] )
|
|
->newLocalChecker( 'FORMULA', 'invalidtype' );
|
|
}
|
|
|
|
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 );
|
|
}
|
|
}
|