2015-07-22 22:10:46 +00:00
|
|
|
<?php
|
2016-02-12 16:57:37 +00:00
|
|
|
|
2015-07-22 22:10:46 +00:00
|
|
|
/**
|
2016-02-12 16:57:37 +00:00
|
|
|
* @covers MathHooks
|
2015-07-22 22:10:46 +00:00
|
|
|
*
|
|
|
|
* @group Math
|
2016-02-12 16:57:37 +00:00
|
|
|
*
|
2018-04-13 14:06:39 +00:00
|
|
|
* @license GPL-2.0-or-later
|
2015-07-22 22:10:46 +00:00
|
|
|
*/
|
2016-02-12 16:57:37 +00:00
|
|
|
class MathHooksTest extends MediaWikiTestCase {
|
2015-07-22 22:10:46 +00:00
|
|
|
|
|
|
|
public function testMathModeToString() {
|
|
|
|
$default = 'png-testing'; // use a different string for testing only
|
2016-04-12 20:53:25 +00:00
|
|
|
$testCases = [
|
2015-07-22 22:10:46 +00:00
|
|
|
'MW_MATH_SIMPLE' => $default,
|
|
|
|
'MW_MATH_HTML' => $default,
|
|
|
|
'MW_MATH_MODERN' => $default,
|
|
|
|
'MW_MATH_MATHJAX' => $default,
|
|
|
|
'MW_MATH_LATEXML_JAX' => $default,
|
|
|
|
'MW_MATH_PNG' => 'png',
|
|
|
|
'MW_MATH_SOURCE' => 'source',
|
|
|
|
'MW_MATH_MATHML' => 'mathml',
|
|
|
|
'MW_MATH_LATEXML' => 'latexml',
|
|
|
|
1 => $default,
|
|
|
|
2 => $default,
|
|
|
|
4 => $default,
|
|
|
|
6 => $default,
|
|
|
|
8 => $default,
|
|
|
|
0 => 'png',
|
|
|
|
3 => 'source',
|
|
|
|
5 => 'mathml',
|
|
|
|
7 => 'latexml',
|
|
|
|
'png' => 'png',
|
|
|
|
'source' => 'source',
|
|
|
|
'mathml' => 'mathml',
|
|
|
|
'latexml' => 'latexml',
|
2016-04-12 20:53:25 +00:00
|
|
|
];
|
2017-06-20 07:11:57 +00:00
|
|
|
foreach ( $testCases as $input => $expected ) {
|
2015-07-22 22:10:46 +00:00
|
|
|
$real = MathHooks::mathModeToString( $input, $default );
|
|
|
|
$this->assertEquals( $expected, $real, "Conversion math mode $input -> $expected" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testMathStyleToString() {
|
|
|
|
$default = 'inlineDisplaystyle-test';
|
2016-04-12 20:53:25 +00:00
|
|
|
$testCases = [
|
2015-07-22 22:10:46 +00:00
|
|
|
'MW_MATHSTYLE_INLINE_DISPLAYSTYLE' => 'inlineDisplaystyle',
|
|
|
|
'MW_MATHSTYLE_DISPLAY' => 'display',
|
|
|
|
'MW_MATHSTYLE_INLINE' => 'inline',
|
|
|
|
0 => 'inlineDisplaystyle',
|
|
|
|
1 => 'display',
|
|
|
|
2 => 'inline',
|
|
|
|
'inlineDisplaystyle' => 'inlineDisplaystyle',
|
|
|
|
'display' => 'display',
|
|
|
|
'inline' => 'inline',
|
2016-04-12 20:53:25 +00:00
|
|
|
];
|
2017-06-20 07:11:57 +00:00
|
|
|
foreach ( $testCases as $input => $expected ) {
|
2015-07-22 22:10:46 +00:00
|
|
|
$real = MathHooks::mathStyleToString( $input, $default );
|
|
|
|
$this->assertEquals( $expected, $real, "Conversion in math style" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testMathCheckToString() {
|
|
|
|
$default = 'always-default';
|
2016-04-12 20:53:25 +00:00
|
|
|
$testCases = [
|
2015-07-22 22:10:46 +00:00
|
|
|
'MW_MATH_CHECK_ALWAYS' => 'always',
|
|
|
|
'MW_MATH_CHECK_NEVER' => 'never',
|
|
|
|
'MW_MATH_CHECK_NEW' => 'new',
|
|
|
|
0 => 'always',
|
|
|
|
1 => 'never',
|
|
|
|
2 => 'new',
|
|
|
|
'always' => 'always',
|
|
|
|
'never' => 'never',
|
|
|
|
'new' => 'new',
|
|
|
|
true => 'never',
|
|
|
|
false => 'always'
|
2016-04-12 20:53:25 +00:00
|
|
|
];
|
2015-07-22 22:10:46 +00:00
|
|
|
|
2017-06-20 07:11:57 +00:00
|
|
|
foreach ( $testCases as $input => $expected ) {
|
2015-07-22 22:10:46 +00:00
|
|
|
$real = MathHooks::mathCheckToString( $input, $default );
|
|
|
|
$this->assertEquals( $expected, $real, "Conversion in math check method" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testMathModeToHash() {
|
|
|
|
$default = 0;
|
2016-04-12 20:53:25 +00:00
|
|
|
$testCases = [
|
2015-07-22 22:10:46 +00:00
|
|
|
'png' => 0,
|
|
|
|
'source' => 3,
|
|
|
|
'mathml' => 5,
|
2017-08-11 03:57:43 +00:00
|
|
|
'latexml' => 7,
|
|
|
|
'invalid' => $default
|
2016-04-12 20:53:25 +00:00
|
|
|
];
|
2015-07-22 22:10:46 +00:00
|
|
|
|
2017-06-20 07:11:57 +00:00
|
|
|
foreach ( $testCases as $input => $expected ) {
|
2015-07-22 22:10:46 +00:00
|
|
|
$real = MathHooks::mathModeToHashKey( $input, $default );
|
|
|
|
$this->assertEquals( $expected, $real, "Conversion to hash key" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetMathNames() {
|
|
|
|
$real = MathHooks::getMathNames();
|
|
|
|
$this->assertEquals( 'PNG images', $real['png'] );
|
|
|
|
}
|
|
|
|
|
2015-09-21 16:14:01 +00:00
|
|
|
}
|