| 1 |
<?php |
| 2 |
namespace MediaWiki\Extension\Math\WikiTexVC; |
| 3 |
|
| 4 |
use MediaWiki\Config\Config; |
| 5 |
use MediaWiki\Config\HashConfig; |
| 6 |
use MediaWiki\Config\ServiceOptions; |
| 7 |
use MediaWiki\Extension\Math\MathConfig; |
| 8 |
use MediaWiki\Extension\Math\MathNativeMML; |
| 9 |
use MediaWiki\HookContainer\HookContainer; |
| 10 |
use MediaWiki\Registration\ExtensionRegistry; |
| 11 |
use MediaWikiUnitTestCase; |
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
final class ChangesTest extends MediaWikiUnitTestCase { |
| 22 |
private MathConfig $mathConfig; |
| 23 |
private HookContainer $hookContainer; |
| 24 |
private Config $mainConfig; |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
public function testChanges( $tc ) { |
| 30 |
$old = $tc['output']; |
| 31 |
unset( $tc['output'] ); |
| 32 |
MathNativeMML::renderReferenceEntry( $tc, $this->mathConfig, $this->hookContainer, $this->mainConfig ); |
| 33 |
$this->assertEquals( $old, $tc['output'] ); |
| 34 |
} |
| 35 |
|
| 36 |
public static function provideTestCases() { |
| 37 |
$file = file_get_contents( __DIR__ . "/data/reference.json" ); |
| 38 |
$json = json_decode( $file, true ); |
| 39 |
$i = -1; |
| 40 |
foreach ( $json as $entry ) { |
| 41 |
$i++; |
| 42 |
yield "Testcase $i: " . substr( $entry['input'], 0, 20 ) => [ $entry ]; |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
private function getMathConfig() { |
| 47 |
return new MathConfig( |
| 48 |
new ServiceOptions( MathConfig::CONSTRUCTOR_OPTIONS, [ |
| 49 |
'MathDisableTexFilter' => MathConfig::ALWAYS, |
| 50 |
'MathValidModes' => [ MathConfig::MODE_NATIVE_MML ], |
| 51 |
'MathEntitySelectorFallbackUrl' => '\\urs', |
| 52 |
] ), |
| 53 |
$this->createMock( ExtensionRegistry::class ) |
| 54 |
|
| 55 |
); |
| 56 |
} |
| 57 |
|
| 58 |
protected function setUp(): void { |
| 59 |
parent::setUp(); |
| 60 |
$this->mathConfig = $this->getMathConfig(); |
| 61 |
$this->hookContainer = $this->createHookContainer(); |
| 62 |
$this->mainConfig = new HashConfig(); |
| 63 |
$this->mainConfig->set( 'MathEnableFormulaLinks', false ); |
| 64 |
} |
| 65 |
} |