mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Math
synced 2024-11-27 17:01:07 +00:00
Provide static Factory Class for Math related services
Initially we provide one service. More services will come in the future. Change-Id: I98a0f5f181f729e123a063dabf3597b5effa55b8
This commit is contained in:
parent
a274beae78
commit
73c41b4626
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
use MediaWiki\Config\ServiceOptions;
|
use MediaWiki\Config\ServiceOptions;
|
||||||
use MediaWiki\Extension\Math\InputCheck\InputCheckFactory;
|
use MediaWiki\Extension\Math\InputCheck\InputCheckFactory;
|
||||||
|
use MediaWiki\Extension\Math\Math;
|
||||||
use MediaWiki\Extension\Math\MathConfig;
|
use MediaWiki\Extension\Math\MathConfig;
|
||||||
use MediaWiki\Extension\Math\MathWikibaseConfig;
|
use MediaWiki\Extension\Math\MathWikibaseConfig;
|
||||||
use MediaWiki\Extension\Math\MathWikibaseConnector;
|
use MediaWiki\Extension\Math\MathWikibaseConnector;
|
||||||
|
@ -33,7 +34,7 @@ return [
|
||||||
RendererFactory::CONSTRUCTOR_OPTIONS,
|
RendererFactory::CONSTRUCTOR_OPTIONS,
|
||||||
$services->getMainConfig()
|
$services->getMainConfig()
|
||||||
),
|
),
|
||||||
$services->get( 'Math.Config' ),
|
Math::getMathConfig( $services ),
|
||||||
$services->getUserOptionsLookup(),
|
$services->getUserOptionsLookup(),
|
||||||
LoggerFactory::getInstance( 'Math' )
|
LoggerFactory::getInstance( 'Math' )
|
||||||
);
|
);
|
||||||
|
|
27
src/Math.php
Normal file
27
src/Math.php
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace MediaWiki\Extension\Math;
|
||||||
|
|
||||||
|
use MediaWiki\MediaWikiServices;
|
||||||
|
use Psr\Container\ContainerInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Top level factory for the Math extension.
|
||||||
|
*
|
||||||
|
* @license GPL-2.0-or-later
|
||||||
|
*/
|
||||||
|
final class Math {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @codeCoverageIgnore
|
||||||
|
*/
|
||||||
|
private function __construct() {
|
||||||
|
// should not be instantiated
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getMathConfig( ContainerInterface $services = null ): MathConfig {
|
||||||
|
return ( $services ?: MediaWikiServices::getInstance() )
|
||||||
|
->get( 'Math.Config' );
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
14
tests/phpunit/integration/MathIntegrationTest.php
Normal file
14
tests/phpunit/integration/MathIntegrationTest.php
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
<?php
|
||||||
|
namespace MediaWiki\Extension\Math\Tests;
|
||||||
|
|
||||||
|
use MediaWiki\Extension\Math\Math;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \MediaWiki\Extension\Math\Math
|
||||||
|
*/
|
||||||
|
class MathIntegrationTest extends \MediaWikiIntegrationTestCase {
|
||||||
|
public function testGetMathConfigNull() {
|
||||||
|
$config = Math::getMathConfig();
|
||||||
|
$this->assertInstanceOf( '\MediaWiki\Extension\Math\MathConfig', $config );
|
||||||
|
}
|
||||||
|
}
|
32
tests/phpunit/unit/MathTest.php
Normal file
32
tests/phpunit/unit/MathTest.php
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
<?php
|
||||||
|
namespace MediaWiki\Extension\Math\Tests;
|
||||||
|
|
||||||
|
use HashConfig;
|
||||||
|
use MediaWiki\Config\ServiceOptions;
|
||||||
|
use MediaWiki\Extension\Math\Math;
|
||||||
|
use MediaWiki\Extension\Math\MathConfig;
|
||||||
|
use MediaWiki\MediaWikiServices;
|
||||||
|
use MediaWikiUnitTestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \MediaWiki\Extension\Math\Math
|
||||||
|
*/
|
||||||
|
class MathTest extends MediaWikiUnitTestCase {
|
||||||
|
|
||||||
|
public function testGetMathConfigService() {
|
||||||
|
$config = new HashConfig( [
|
||||||
|
'MathDisableTexFilter' => MathConfig::NEW,
|
||||||
|
'MathValidModes' => [ MathConfig::MODE_SOURCE ]
|
||||||
|
] );
|
||||||
|
$services = new MediaWikiServices( $config );
|
||||||
|
$services->defineService( 'Math.Config',
|
||||||
|
static function ( MediaWikiServices $services ){
|
||||||
|
return new MathConfig(
|
||||||
|
new ServiceOptions( MathConfig::CONSTRUCTOR_OPTIONS, $services->get( 'BootstrapConfig' ) )
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
$mathConfig = Math::getMathConfig( $services );
|
||||||
|
$this->assertStringContainsString( 'new', $mathConfig->texCheckDisabled() );
|
||||||
|
}
|
||||||
|
}
|
30
tests/phpunit/unit/ServiceWiringTest.php
Normal file
30
tests/phpunit/unit/ServiceWiringTest.php
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace MediaWiki\Extension\Math\Tests;
|
||||||
|
|
||||||
|
use Generator;
|
||||||
|
use MediaWikiUnitTestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @coversNothing
|
||||||
|
*/
|
||||||
|
class ServiceWiringTest extends MediaWikiUnitTestCase {
|
||||||
|
private const EXTENSION_PREFIX = 'Math.';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider provideWiring
|
||||||
|
*/
|
||||||
|
public function testAllWiringsAreProperlyShaped( $name, $definition ): void {
|
||||||
|
$this->assertStringStartsWith( self::EXTENSION_PREFIX, $name );
|
||||||
|
$this->assertIsCallable( $definition );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function provideWiring(): Generator {
|
||||||
|
$wiring = require __DIR__ . '/../../../ServiceWiring.php';
|
||||||
|
|
||||||
|
foreach ( $wiring as $name => $definition ) {
|
||||||
|
yield $name => [ $name, $definition ];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue