diff options
author | Michael Klier <chi@chimeric.de> | 2010-03-30 11:15:08 +0200 |
---|---|---|
committer | Michael Klier <chi@chimeric.de> | 2010-03-30 11:15:08 +0200 |
commit | 08d7babffe1bded4620d0a3624bdd80522283138 (patch) | |
tree | 0e5368bff1ab25457cd9b1150ac1d1fc2f2fea92 /_test/lib | |
parent | 2a98590b375e0acfd24fb0da343eb09a3ff76ff3 (diff) | |
download | rpg-08d7babffe1bded4620d0a3624bdd80522283138.tar.gz rpg-08d7babffe1bded4620d0a3624bdd80522283138.tar.bz2 |
added support for plugin unittests
This patch adds support to include plugin tests in the
DokuWiki testsuite. Plugin tests are located in a dedicated
directory _test/within a plugin directory. The naming
convention of the test files follows the one used in
DokuWikis testsuite.
<plugin>/_test/*.test.php -> single test
<plugin>/_test/*.group.php -> group test
The plugin tests are accessible via the web interface
of the test suite and via the cli interface. It is recommend
to bundle plugin test in a plugin group test. The webinterface
also allows to run all plugin tests at once.
Test files must include:
<dokuwiki>/_test/lib/unittest.php
Example Test:
require_once(DOKU_INC.'_test/lib/unittest.php');
class plugin_test extends Doku_UnitTestCase {
function test() {
$this->assertEqual(1,1);
}
}
Example Group Test:
require_once(DOKU_INC.'_test/lib/unittest.php');
class plugin_group_test extends Doku_GroupTest {
function group_test() {
$dir = dirname(__FILE__).'/';
$this->GroupTest('plugin_grouptest');
$this->addTestFile($dir . 'plugin.test1.php');
$this->addTestFile($dir . 'plugin.test2.php');
$this->addTestFile($dir . 'plugin.test3.php');
}
}
At the moment unittest.php contains only two
meta classes so plugins tests don't have to inherit
from the simpletest classes.
This patch should be treated as intermediate step to
allow for plugin tests. The testsuite wasn't designed
to include plugin tests. It should probably be refactored
at a later point.
Diffstat (limited to '_test/lib')
-rw-r--r-- | _test/lib/testmanager.php | 91 | ||||
-rw-r--r-- | _test/lib/unittest.php | 5 |
2 files changed, 91 insertions, 5 deletions
diff --git a/_test/lib/testmanager.php b/_test/lib/testmanager.php index 14cc20bf3..96c9a57a2 100644 --- a/_test/lib/testmanager.php +++ b/_test/lib/testmanager.php @@ -5,6 +5,7 @@ define('TEST_GROUPS',realpath(dirname(__FILE__).'/../cases')); define('TEST_CASES',realpath(dirname(__FILE__).'/../cases')); +define('TEST_PLUGINS',realpath(dirname(__FILE__).'/../../lib/plugins')); // try to load runkit extension if (!extension_loaded('runkit') && function_exists('dl')) { @@ -59,6 +60,17 @@ class TestManager { $test->run($reporter); } + function runAllPluginTests(&$reporter) { + $manager =& new TestManager(); + $test_cases =& $manager->_getTestFileList(TEST_PLUGINS); + $test =& new GroupTest('All Plugin Tests'); + foreach ($test_cases as $test_case) { + $test->addTestFile($test_case); + } + $test->run($reporter); + } + + function runTestCase($testcase_name, $test_case_directory, &$reporter) { $manager =& new TestManager(); @@ -125,12 +137,12 @@ class TestManager { } function &_getTestCaseList($directory = '.') { - $base = TEST_GROUPS . DIRECTORY_SEPARATOR; $file_list =& $this->_getTestFileList($directory); $testcases = array(); foreach ($file_list as $testcase_file) { $case = str_replace($this->_testcase_extension, '',$testcase_file); - $case = str_replace($base, '', $case); + $case = str_replace(TEST_GROUPS . DIRECTORY_SEPARATOR, '', $case); + $case = str_replace(TEST_PLUGINS . DIRECTORY_SEPARATOR, '', $case); $case = str_replace(DIRECTORY_SEPARATOR, ':', $case); $testcases[$testcase_file] = $case; } @@ -142,6 +154,16 @@ class TestManager { array(&$this, '_isTestCaseFile')); } + function &getPluginTestCaseList($directory = '.') { + $manager =& new TestManager(); + return $manager->_getTestCaseList($directory); + } + + function &getPluginGroupTestList($directory = '.') { + $manager =& new TestManager(); + return $manager->_getTestGroupList($directory); + } + function &getGroupTestList($directory = '.') { $manager =& new TestManager(); return $manager->_getTestGroupList($directory); @@ -153,12 +175,12 @@ class TestManager { } function &_getTestGroupList($directory = '.') { - $base = TEST_GROUPS . DIRECTORY_SEPARATOR; $file_list =& $this->_getTestGroupFileList($directory); $grouptests = array(); foreach ($file_list as $grouptest_file) { $group = str_replace($this->_grouptest_extension, '',$grouptest_file); - $group = str_replace($base, '', $group); + $group = str_replace(TEST_GROUPS . DIRECTORY_SEPARATOR, '', $group); + $group = str_replace(TEST_PLUGINS . DIRECTORY_SEPARATOR, '', $group); $group = str_replace(DIRECTORY_SEPARATOR, ':', $group); $grouptests[$grouptest_file] = $group; } @@ -168,7 +190,7 @@ class TestManager { function &_getGroupTestClassNames($grouptest_file) { $file = implode("\n", file($grouptest_file)); - preg_match("~lass\s+?(.*)\s+?extends GroupTest~", $file, $matches); + preg_match("~lass\s+?(.*)\s+?extends .*?GroupTest~", $file, $matches); if (! empty($matches)) { unset($matches[0]); return $matches; @@ -242,6 +264,29 @@ class CLITestManager extends TestManager { } return $buffer . "\n"; } + + function &getPluginTestCaseList($directory = '.') { + $manager =& new CLITestManager(); + $test_cases =& $manager->_getTestCaseList($directory); + + $buffer = "Available test cases:\n"; + foreach ($test_cases as $test_case) { + $buffer .= " " . $test_case . "\n"; + } + return $buffer . "\n"; + } + + function &getPluginGroupTestList($directory = '.') { + $manager =& new CLITestManager(); + $test_cases =& $manager->_getTestGroupList($directory); + + $buffer = "Available test cases:\n"; + foreach ($test_cases as $test_case) { + $buffer .= " " . $test_case . "\n"; + } + return $buffer . "\n"; + } + } class HTMLTestManager extends TestManager { @@ -289,6 +334,42 @@ class HTMLTestManager extends TestManager { $buffer .= "</ul>\n"; return $buffer; } + + function &getPluginTestCaseList($directory = '.') { + $manager =& new HTMLTestManager(); + $testcases =& $manager->_getTestCaseList($directory); + + if (1 > count($testcases)) { + return "<p>No plugin test cases set up!</p>"; + } + $buffer = "<p>Available plugin test cases:</p>\n<ul>"; + foreach ($testcases as $testcase) { + $buffer .= "<li><a href='" . $manager->getBaseURL() . + "?plugin_case=" . urlencode($testcase) . "'>" . + $testcase . "</a></li>\n"; + } + + $buffer .= "</ul>\n"; + return $buffer; + } + + function &getPluginGroupTestList($directory = '.') { + $manager =& new HTMLTestManager(); + $group_tests =& $manager->_getTestGroupList($directory); + if (1 > count($group_tests)) { + return "<p>No plugin test groups set up!</p>"; + } + $buffer = "<p>Available plugin groups:</p>\n<ul>"; + $buffer .= "<li><a href='" . $manager->getBaseURL() . "?plugin_group=all'>All tests</a></li>\n"; + foreach ($group_tests as $group_test) { + $buffer .= "<li><a href='" . $manager->getBaseURL() . "?plugin_group={$group_test}'>" . + $group_test . "</a></li>\n"; + } + + $buffer .= "</ul>\n"; + return $buffer; + } + } /** diff --git a/_test/lib/unittest.php b/_test/lib/unittest.php new file mode 100644 index 000000000..220aa6c1b --- /dev/null +++ b/_test/lib/unittest.php @@ -0,0 +1,5 @@ +<?php +class Doku_UnitTestCase extends UnitTestCase { +} +class Doku_GroupTest extends GroupTest { +} |