From c869831f45861f36cc2e6a9ef533337a4e7c3e2e Mon Sep 17 00:00:00 2001 From: Moritz Schubortz Date: Sat, 16 Feb 2013 23:55:39 +0100 Subject: [PATCH] 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 --- Math.hooks.php | 12 ++++++++++++ Math.php | 1 + README | 4 ++++ tests/MathSourceTest.php | 27 +++++++++++++++++++++++++++ 4 files changed, 44 insertions(+) create mode 100644 tests/MathSourceTest.php diff --git a/Math.hooks.php b/Math.hooks.php index ab61f10..a70da28 100644 --- a/Math.hooks.php +++ b/Math.hooks.php @@ -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; + } } diff --git a/Math.php b/Math.php index 2f6ea2b..b083a79 100644 --- a/Math.php +++ b/Math.php @@ -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'; diff --git a/README b/README index f7c6493..54123a8 100644 --- a/README +++ b/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 low-level conversion tools. +For testing your installation run +php tests/phpunit/phpunit.php extensions/Math/tests/ +from your MediWiki home path. + diff --git a/tests/MathSourceTest.php b/tests/MathSourceTest.php new file mode 100644 index 0000000..9f67ae1 --- /dev/null +++ b/tests/MathSourceTest.php @@ -0,0 +1,27 @@ +assertEquals('$ a+b $', $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('$ a b $', $real + , "converting newlines to spaces"); + } + +} \ No newline at end of file