Add and register PHP unit tests for MathSource class
This change adds test cases for the MathSource class and registers a hook for loading these tests. Also adds documentation about how to run these tests in README. Change-Id: Ie58a273326e0353dfa4437b3de21a2393adb5a87
This commit is contained in:
parent
48b029fbe9
commit
c869831f45
|
@ -162,4 +162,16 @@ class MathHooks {
|
||||||
$wgMathPath = '/images/math';
|
$wgMathPath = '/images/math';
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Links to the unit test files for the test cases.
|
||||||
|
*
|
||||||
|
* @param string $files
|
||||||
|
* @return boolean (true)
|
||||||
|
*/
|
||||||
|
static function onRegisterUnitTests( &$files ) {
|
||||||
|
$testDir = __DIR__ . '/tests/';
|
||||||
|
$files = array_merge( $files, glob( "$testDir/*Test.php" ) );
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
1
Math.php
1
Math.php
|
@ -119,6 +119,7 @@ $wgHooks['GetPreferences'][] = 'MathHooks::onGetPreferences';
|
||||||
$wgHooks['LoadExtensionSchemaUpdates'][] = 'MathHooks::onLoadExtensionSchemaUpdates';
|
$wgHooks['LoadExtensionSchemaUpdates'][] = 'MathHooks::onLoadExtensionSchemaUpdates';
|
||||||
$wgHooks['ParserTestTables'][] = 'MathHooks::onParserTestTables';
|
$wgHooks['ParserTestTables'][] = 'MathHooks::onParserTestTables';
|
||||||
$wgHooks['ParserTestParser'][] = 'MathHooks::onParserTestParser';
|
$wgHooks['ParserTestParser'][] = 'MathHooks::onParserTestParser';
|
||||||
|
$wgHooks['UnitTestsList'][] = 'MathHooks::onRegisterUnitTests';
|
||||||
|
|
||||||
$dir = dirname( __FILE__ ) . '/';
|
$dir = dirname( __FILE__ ) . '/';
|
||||||
$wgAutoloadClasses['MathHooks'] = $dir . 'Math.hooks.php';
|
$wgAutoloadClasses['MathHooks'] = $dir . 'Math.hooks.php';
|
||||||
|
|
4
README
4
README
|
@ -7,3 +7,7 @@ This version (for MediaWiki 1.19) has some changes since previous versions:
|
||||||
See the README in the math subdirectory for more info on setting up the
|
See the README in the math subdirectory for more info on setting up the
|
||||||
low-level conversion tools.
|
low-level conversion tools.
|
||||||
|
|
||||||
|
For testing your installation run
|
||||||
|
php tests/phpunit/phpunit.php extensions/Math/tests/
|
||||||
|
from your MediWiki home path.
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Test the TeX source output format.
|
||||||
|
* @group Math
|
||||||
|
*/
|
||||||
|
class MathSourceTest extends MediaWikiTestCase {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks the basic functionallity
|
||||||
|
* i.e. if the span element is generated right.
|
||||||
|
*/
|
||||||
|
public function simpleTest(){
|
||||||
|
$real=MathRenderer::renderMath("a+b",array(),MW_MATH_SOURCE);
|
||||||
|
$this->assertEquals('<span class="tex" dir="ltr">$ a+b $</span>', $real
|
||||||
|
, "Rendering of a+b in plain Text mode");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if newlines are converted to spaces correctly.
|
||||||
|
*/
|
||||||
|
public function testNewLines(){
|
||||||
|
$real=MathRenderer::renderMath("a\n b",array(),MW_MATH_SOURCE);
|
||||||
|
$this->assertSame('<span class="tex" dir="ltr">$ a b $</span>', $real
|
||||||
|
, "converting newlines to spaces");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue