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:
Moritz Schubortz 2013-02-16 23:55:39 +01:00 committed by Ori.livneh
parent 48b029fbe9
commit c869831f45
4 changed files with 44 additions and 0 deletions

View file

@ -162,4 +162,16 @@ class MathHooks {
$wgMathPath = '/images/math';
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;
}
}

View file

@ -119,6 +119,7 @@ $wgHooks['GetPreferences'][] = 'MathHooks::onGetPreferences';
$wgHooks['LoadExtensionSchemaUpdates'][] = 'MathHooks::onLoadExtensionSchemaUpdates';
$wgHooks['ParserTestTables'][] = 'MathHooks::onParserTestTables';
$wgHooks['ParserTestParser'][] = 'MathHooks::onParserTestParser';
$wgHooks['UnitTestsList'][] = 'MathHooks::onRegisterUnitTests';
$dir = dirname( __FILE__ ) . '/';
$wgAutoloadClasses['MathHooks'] = $dir . 'Math.hooks.php';

4
README
View file

@ -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
low-level conversion tools.
For testing your installation run
php tests/phpunit/phpunit.php extensions/Math/tests/
from your MediWiki home path.

27
tests/MathSourceTest.php Normal file
View file

@ -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");
}
}