aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engine/lib/testing.php40
-rw-r--r--mod/diagnostics/index.php8
-rw-r--r--mod/diagnostics/languages/en.php13
-rw-r--r--mod/diagnostics/start.php28
-rw-r--r--mod/diagnostics/testreport.php45
-rw-r--r--mod/diagnostics/unittester.php43
-rw-r--r--mod/diagnostics/views/default/diagnostics/runalltests.php15
-rw-r--r--mod/diagnostics/views/default/diagnostics/test.php29
-rw-r--r--mod/diagnostics/views/default/diagnostics/testresult.php42
9 files changed, 253 insertions, 10 deletions
diff --git a/engine/lib/testing.php b/engine/lib/testing.php
index afa5dd2e2..6af96d8cf 100644
--- a/engine/lib/testing.php
+++ b/engine/lib/testing.php
@@ -52,6 +52,27 @@
$this->details = $details;
$this->debug = $debug;
}
+
+ /**
+ * Successful execution or not?
+ *
+ * @return bool
+ */
+ public function isSuccess() { return $this->successful; }
+
+ /**
+ * Retrieve details.
+ *
+ * @return string
+ */
+ public function getDetails() { return $this->details; }
+
+ /**
+ * Retrieve debug.
+ *
+ * @return string
+ */
+ public function getDebug() { return $this->debug; }
/**
* Factory function to generate a successful result.
@@ -73,10 +94,12 @@
*/
function execute_elgg_test($function)
{
- if (is_callable($function))
- return $function();
+ global $ELGG_TEST_REGISTRY;
+
+ if ((is_callable($function)) && (isset($ELGG_TEST_REGISTRY[$function]))) // must be callable, and registered (for security)
+ return array('function' => $function, 'result' => $function());
- return false;
+ return array('function' => $function, 'result' => false);
}
/**
@@ -113,4 +136,15 @@
$ELGG_TEST_REGISTRY[$function] = $description;
}
+ /**
+ * Return a list of available tests.
+ *
+ * @return array
+ */
+ function get_available_tests()
+ {
+ global $ELGG_TEST_REGISTRY;
+
+ return $ELGG_TEST_REGISTRY;
+ }
?> \ No newline at end of file
diff --git a/mod/diagnostics/index.php b/mod/diagnostics/index.php
index b9aa2e309..54c8e9c4f 100644
--- a/mod/diagnostics/index.php
+++ b/mod/diagnostics/index.php
@@ -18,11 +18,9 @@
$title = elgg_view_title(elgg_echo('diagnostics'));
- $body .= "<div class=\"contentWrapper\">";
- $body .= elgg_echo('diagnostics:description');
-
- $body .= elgg_view('diagnostics/forms/download');
- $body .= "</div>";
+ $body = elgg_view('page_elements/contentwrapper', array('body' =>
+ elgg_echo('diagnostics:description') . elgg_view('diagnostics/forms/download'))
+ );
page_draw(elgg_echo('diagnostics'),elgg_view_layout("two_column_left_sidebar", '', $title . $body));
diff --git a/mod/diagnostics/languages/en.php b/mod/diagnostics/languages/en.php
index 79d35e938..5d19824bd 100644
--- a/mod/diagnostics/languages/en.php
+++ b/mod/diagnostics/languages/en.php
@@ -12,8 +12,21 @@
$english = array(
'diagnostics' => 'System diagnostics',
+ 'diagnostics:unittester' => 'Unit tests',
'diagnostics:description' => 'The following diagnostic report is useful for diagnosing any problems with Elgg, and should be attached to any bug reports you file.',
+ 'diagnostics:unittester:description' => 'The following are diagnostic tests which are registered by plugins and may be performed in order to debug parts of the Elgg framework.',
+
+ 'diagnostics:test:executetest' => 'Execute test',
+ 'diagnostics:test:executeall' => 'Execute All',
+ 'diagnostics:unittester:notests' => 'Sorry, there are no unit test modules currently installed.',
+ 'diagnostics:unittester:testnotfound' => 'Sorry, the report could not be generated because that test was not found',
+
+ 'diagnostics:unittester:testresult:nottestclass' => 'FAIL - Result not a test class',
+ 'diagnostics:unittester:testresult:fail' => 'FAIL',
+ 'diagnostics:unittester:testresult:success' => 'FAIL',
+
+ 'diagnostics:unittester:report' => 'Test report for %s',
'diagnostics:download' => 'Download .txt',
diff --git a/mod/diagnostics/start.php b/mod/diagnostics/start.php
index 5bf2dc468..a7afe346e 100644
--- a/mod/diagnostics/start.php
+++ b/mod/diagnostics/start.php
@@ -33,6 +33,7 @@
if (get_context() == 'admin' && isadminloggedin()) {
global $CONFIG;
add_submenu_item(elgg_echo('diagnostics'), $CONFIG->wwwroot . 'pg/diagnostics/');
+ add_submenu_item(elgg_echo('diagnostics:unittester'), $CONFIG->wwwroot . 'pg/diagnostics/tests/');
}
}
@@ -45,8 +46,31 @@
{
global $CONFIG;
- // only interested in one page for now
- include($CONFIG->pluginspath . "diagnostics/index.php");
+ if (isset($page[0]))
+ {
+ switch ($page[0])
+ {
+ case 'tests' :
+ if ((isset($page[1])) && ($page[1])) {
+ switch ($page[1])
+ {
+ case 'all': break;
+ default: set_input('test_func', $page[1]);
+ }
+
+ include($CONFIG->pluginspath . "diagnostics/testreport.php");
+ }
+ else
+ include($CONFIG->pluginspath . "diagnostics/unittester.php");
+ break;
+ default: include($CONFIG->pluginspath . "diagnostics/index.php");
+ }
+ }
+ else
+ {
+ // only interested in one page for now
+ include($CONFIG->pluginspath . "diagnostics/index.php");
+ }
}
/**
diff --git a/mod/diagnostics/testreport.php b/mod/diagnostics/testreport.php
new file mode 100644
index 000000000..979cca267
--- /dev/null
+++ b/mod/diagnostics/testreport.php
@@ -0,0 +1,45 @@
+<?php
+ /**
+ * Elgg diagnostics - test report
+ *
+ * @package ElggDiagnostics
+ * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
+ * @author Curverider Ltd
+ * @copyright Curverider Ltd 2008-2009
+ * @link http://elgg.com/
+ */
+
+ require_once(dirname(dirname(dirname(__FILE__))) . "/engine/start.php");
+
+ admin_gatekeeper();
+ set_context('admin');
+ // Set admin user for user block
+ set_page_owner($_SESSION['guid']);
+
+ // Which test are we executing?
+ $test_func = get_input('test_func');
+
+ $title_txt = sprintf(elgg_echo('diagnostics:unittester:report'), $test_func ? $testfunc : elgg_echo('diagnostics:test:executeall'));
+
+ $title = elgg_view_title();
+
+ $result = null;
+ if ($test_func)
+ $result = array(execute_elgg_test($test_func));
+ else
+ $result = execute_elgg_tests();
+
+ if ($result)
+ {
+ foreach ($result as $r)
+ $body .= elgg_view('page_elements/contentwrapper', array('body' =>
+ elgg_view('diagnostics/testresult', array('function' => $r['function'], 'result' => $r['result']))
+ ));
+ }
+ else
+ $body = elgg_view('page_elements/contentwrapper', array('body' =>
+ elgg_echo('diagnostics:unittester:testnotfound' )
+ ));
+
+ page_draw($title_txt, elgg_view_layout("two_column_left_sidebar", '', $title . $body));
+?> \ No newline at end of file
diff --git a/mod/diagnostics/unittester.php b/mod/diagnostics/unittester.php
new file mode 100644
index 000000000..d0aa0c8c4
--- /dev/null
+++ b/mod/diagnostics/unittester.php
@@ -0,0 +1,43 @@
+<?php
+ /**
+ * Elgg diagnostics - unit tester
+ *
+ * @package ElggDiagnostics
+ * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
+ * @author Curverider Ltd
+ * @copyright Curverider Ltd 2008-2009
+ * @link http://elgg.com/
+ */
+
+ require_once(dirname(dirname(dirname(__FILE__))) . "/engine/start.php");
+
+ admin_gatekeeper();
+ set_context('admin');
+ // Set admin user for user block
+ set_page_owner($_SESSION['guid']);
+
+ $title = elgg_view_title(elgg_echo('diagnostics:unittester'));
+
+ $tests = get_available_tests();
+ $test_body = "";
+ if ($tests)
+ {
+ foreach ($tests as $func => $desc)
+ $test_body .= elgg_view('diagnostics/test', array('function' => $func, 'description' => $desc));
+ }
+ else
+ $test_body = elgg_echo('diagnostics:unittester:notests');
+
+ $body = elgg_view('page_elements/contentwrapper', array('body' =>
+ elgg_echo('diagnostics:unittester:description') .
+ elgg_view('diagnostics/runalltests')
+ )
+ );
+
+ $body .= elgg_view('page_elements/contentwrapper', array('body' =>
+ $test_body )
+ );
+
+
+ page_draw(elgg_echo('diagnostics:unittester'),elgg_view_layout("two_column_left_sidebar", '', $title . $body));
+?> \ No newline at end of file
diff --git a/mod/diagnostics/views/default/diagnostics/runalltests.php b/mod/diagnostics/views/default/diagnostics/runalltests.php
new file mode 100644
index 000000000..12bbf2a4a
--- /dev/null
+++ b/mod/diagnostics/views/default/diagnostics/runalltests.php
@@ -0,0 +1,15 @@
+<?php
+ /**
+ * Elgg diagnostics - unit tester
+ *
+ * @package ElggDiagnostics
+ * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
+ * @author Curverider Ltd
+ * @copyright Curverider Ltd 2008-2009
+ * @link http://elgg.com/
+ */
+
+ $form_body .= elgg_view('input/submit', array('internalname' => 'execute', 'value' => elgg_echo('diagnostics:test:executeall')));
+
+ echo elgg_view('input/form', array('action' => $vars['url'] . "pg/diagnostics/tests/all", 'body' => $form_body));
+?> \ No newline at end of file
diff --git a/mod/diagnostics/views/default/diagnostics/test.php b/mod/diagnostics/views/default/diagnostics/test.php
new file mode 100644
index 000000000..5010eb903
--- /dev/null
+++ b/mod/diagnostics/views/default/diagnostics/test.php
@@ -0,0 +1,29 @@
+<?php
+ /**
+ * Elgg diagnostics
+ *
+ * @package ElggDiagnostics
+ * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
+ * @author Curverider Ltd
+ * @copyright Curverider Ltd 2008-2009
+ * @link http://elgg.com/
+ */
+
+
+?>
+<div class="test">
+ <div class="test_header">
+ <?php echo $vars['function']; ?>
+ </div>
+ <div class="test_description">
+ <?php echo $vars['description']; ?>
+ </div>
+ <div class="test_button">
+ <?php
+
+ $form_body = elgg_view('input/submit', array('internalname' => 'execute', 'value' => elgg_echo('diagnostics:test:executetest')));
+
+ echo elgg_view('input/form', array('action' => $vars['url'] . "pg/diagnostics/tests/{$vars['function']}", 'body' => $form_body));
+ ?>
+ </div>
+</div> \ No newline at end of file
diff --git a/mod/diagnostics/views/default/diagnostics/testresult.php b/mod/diagnostics/views/default/diagnostics/testresult.php
new file mode 100644
index 000000000..ddd688e93
--- /dev/null
+++ b/mod/diagnostics/views/default/diagnostics/testresult.php
@@ -0,0 +1,42 @@
+<?php
+ /**
+ * Elgg diagnostics - test report
+ *
+ * @package ElggDiagnostics
+ * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
+ * @author Curverider Ltd
+ * @copyright Curverider Ltd 2008-2009
+ * @link http://elgg.com/
+ */
+
+ $result = $vars['result'];
+
+ $testresult_div = 'fail';
+ $successmessage = "";
+
+ if (!($result instanceof ElggTestResult))
+ {
+ $successmessage = elgg_echo('diagnostics:unittester:testresult:nottestclass');
+ $result = ElggTestResult::CreateFailResult(elgg_echo('diagnostics:unittester:testresult:fail'));
+ }
+ else
+ {
+ if ($result->isSuccess())
+ $successmessage = elgg_echo('diagnostics:unittester:testresult:success');
+ else
+ $successmessage = elgg_echo('diagnostics:unittester:testresult:fail');
+ }
+?>
+<div class="testreport">
+ <div class="testreport_<?php echo $testresult_div; ?>">
+ <div class="testreport_header">
+ <p><?php echo $vars['function']; ?> : <?php echo $successmessage; ?></p>
+ </div>
+ <div class="testreport_details">
+ <?php echo $result->getDetails(); ?>
+ </div>
+ <div class="testreport_debug">
+ <?php echo $result->getDebug(); ?>
+ </div>
+ </div>
+</div> \ No newline at end of file