From: brettp Date: Wed, 17 Feb 2010 15:32:23 +0000 (+0000) Subject: Fixes #1526: Big honking warning added to unit tests. Getter test also deletes its... X-Git-Url: https://gitweb.fluxo.info/?a=commitdiff_plain;h=ccb5a69319a6a367988534296c678c8abf322879;p=lorea%2Felgg.git Fixes #1526: Big honking warning added to unit tests. Getter test also deletes its subtypes now. git-svn-id: http://code.elgg.org/elgg/trunk@3945 36083f99-b078-4883-b0ff-0f9b5a30f544 --- diff --git a/engine/tests/api/entity_getter_functions.php b/engine/tests/api/entity_getter_functions.php index d09f1066d..f3f892d79 100644 --- a/engine/tests/api/entity_getter_functions.php +++ b/engine/tests/api/entity_getter_functions.php @@ -68,10 +68,25 @@ class ElggCoreEntityGetterFunctionsTest extends ElggCoreUnitTest { * Called after each test method. */ public function tearDown() { - //$this->swallowErrors(); + global $CONFIG; + + $this->swallowErrors(); foreach ($this->entities as $e) { $e->delete(); } + + // manually remove subtype entries since there is no way + // to using the API. + $subtype_arr = array(); + foreach ($this->subtypes as $type => $subtypes) { + foreach ($subtypes as $subtype) { + $subtype_arr[] = "'$subtype'"; + } + } + + $subtype_str = implode(',', $subtype_arr); + $q = "DELETE FROM {$CONFIG->dbprefix}entity_subtypes WHERE subtype IN ($subtype_str)"; + delete_data($q); } /** @@ -107,7 +122,6 @@ class ElggCoreEntityGetterFunctionsTest extends ElggCoreUnitTest { return $r; } - /** * Get a random valid subtype (that we just created) * @@ -225,16 +239,16 @@ class ElggCoreEntityGetterFunctionsTest extends ElggCoreUnitTest { $options = array( 'type' => $type, 'group_by' => 'e.type' - ); + ); - $es = elgg_get_entities($options); - $this->assertIsA($es, 'array'); + $es = elgg_get_entities($options); + $this->assertIsA($es, 'array'); - // should only ever return one object because of group by - $this->assertIdentical(count($es), 1); - foreach ($es as $e) { - $this->assertTrue(in_array($e->getType(), $type_arr)); - } + // should only ever return one object because of group by + $this->assertIdentical(count($es), 1); + foreach ($es as $e) { + $this->assertTrue(in_array($e->getType(), $type_arr)); + } } public function testElggAPIGettersValidTypeUsingTypesAsString() { @@ -243,16 +257,16 @@ class ElggCoreEntityGetterFunctionsTest extends ElggCoreUnitTest { $options = array( 'types' => $type, 'group_by' => 'e.type' - ); + ); - $es = elgg_get_entities($options); - $this->assertIsA($es, 'array'); + $es = elgg_get_entities($options); + $this->assertIsA($es, 'array'); - // should only ever return one object because of group by - $this->assertIdentical(count($es), 1); - foreach ($es as $e) { - $this->assertTrue(in_array($e->getType(), $type_arr)); - } + // should only ever return one object because of group by + $this->assertIdentical(count($es), 1); + foreach ($es as $e) { + $this->assertTrue(in_array($e->getType(), $type_arr)); + } } public function testElggAPIGettersValidTypeUsingTypesAsArray() { @@ -261,16 +275,16 @@ class ElggCoreEntityGetterFunctionsTest extends ElggCoreUnitTest { $options = array( 'types' => $type_arr, 'group_by' => 'e.type' - ); + ); - $es = elgg_get_entities($options); - $this->assertIsA($es, 'array'); + $es = elgg_get_entities($options); + $this->assertIsA($es, 'array'); - // should only ever return one object because of group by - $this->assertIdentical(count($es), 1); - foreach ($es as $e) { - $this->assertTrue(in_array($e->getType(), $type_arr)); - } + // should only ever return one object because of group by + $this->assertIdentical(count($es), 1); + foreach ($es as $e) { + $this->assertTrue(in_array($e->getType(), $type_arr)); + } } public function testElggAPIGettersValidTypeUsingTypesAsArrayPlural() { @@ -279,17 +293,17 @@ class ElggCoreEntityGetterFunctionsTest extends ElggCoreUnitTest { $options = array( 'types' => $types, 'group_by' => 'e.type' - ); + ); - $es = elgg_get_entities($options); - $this->assertIsA($es, 'array'); + $es = elgg_get_entities($options); + $this->assertIsA($es, 'array'); - // one of object and one of group - $this->assertIdentical(count($es), $num); + // one of object and one of group + $this->assertIdentical(count($es), $num); - foreach ($es as $e) { - $this->assertTrue(in_array($e->getType(), $types)); - } + foreach ($es as $e) { + $this->assertTrue(in_array($e->getType(), $types)); + } } @@ -309,14 +323,14 @@ class ElggCoreEntityGetterFunctionsTest extends ElggCoreUnitTest { $options = array( 'types' => array($invalid, $valid), 'group_by' => 'e.type' - ); + ); - $es = elgg_get_entities($options); - $this->assertIsA($es, 'array'); + $es = elgg_get_entities($options); + $this->assertIsA($es, 'array'); - // should only ever return one object because of group by - $this->assertIdentical(count($es), 1); - $this->assertIdentical($es[0]->getType(), $valid); + // should only ever return one object because of group by + $this->assertIdentical(count($es), 1); + $this->assertIdentical($es[0]->getType(), $valid); } public function testElggAPIGettersValidAndInvalidTypesPlural() { @@ -338,16 +352,16 @@ class ElggCoreEntityGetterFunctionsTest extends ElggCoreUnitTest { $options = array( 'types' => $types, 'group_by' => 'e.type' - ); + ); - $es = elgg_get_entities($options); - $this->assertIsA($es, 'array'); + $es = elgg_get_entities($options); + $this->assertIsA($es, 'array'); - // should only ever return one object because of group by - $this->assertIdentical(count($es), $valid_num); - foreach ($es as $e) { - $this->assertTrue(in_array($e->getType(), $valid)); - } + // should only ever return one object because of group by + $this->assertIdentical(count($es), $valid_num); + foreach ($es as $e) { + $this->assertTrue(in_array($e->getType(), $valid)); + } } diff --git a/mod/diagnostics/index.php b/mod/diagnostics/index.php index 9a7b66191..0cae3743c 100644 --- a/mod/diagnostics/index.php +++ b/mod/diagnostics/index.php @@ -1,7 +1,7 @@ +$body .= elgg_view('page_elements/contentwrapper', array('body' => elgg_echo('diagnostics:description') . elgg_view('diagnostics/forms/download')) ); // unit tests $body .= elgg_view_title(elgg_echo('diagnostics:unittester')); + +$test_body = '

' . elgg_echo('diagnostics:unittester:description') . '

'; +$test_body .= '

' . elgg_echo('diagnostics:unittester:warning') . '

'; + if (isset($CONFIG->debug)) { // create a button to run tests $js = "onclick=\"window.location='{$CONFIG->wwwroot}engine/tests/suite.php'\""; $params = array('type' => 'button', 'value' => elgg_echo('diagnostics:test:executeall'), 'js' => $js); - $button = elgg_view('input/button', $params); + $test_body .= elgg_view('input/button', $params); } else { // no tests when not in debug mode - $button = elgg_echo('diagnostics:unittester:debug'); + $test_body .= elgg_echo('diagnostics:unittester:debug'); } -$body .= elgg_view('page_elements/contentwrapper', array('body' => - elgg_echo('diagnostics:unittester:description') . "
$button") + +$body .= elgg_view('page_elements/contentwrapper', array( + 'body' => $test_body) ); // create page diff --git a/mod/diagnostics/languages/en.php b/mod/diagnostics/languages/en.php index 2562c10b8..ae72564d7 100644 --- a/mod/diagnostics/languages/en.php +++ b/mod/diagnostics/languages/en.php @@ -1,44 +1,45 @@ '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:unittester:description' => 'Unit tests are useful to detect errors introduced by new plugins or modifications to Elgg.', + + 'diagnostics:unittester:description' => 'Unit tests check Elgg Core for broken or buggy APIs.', 'diagnostics:unittester:debug' => 'The site must be in debug mode to run unit tests.', - + 'diagnostics:unittester:warning' => 'WARNING: These tests can leave behind debugging objects in your database. DO NOT USE ON A PRODUCTION SITE!', + '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' => 'SUCCESS', - + 'diagnostics:unittest:example' => 'Example unit test, only available in debug mode.', - + 'diagnostics:unittester:report' => 'Test report for %s', - + 'diagnostics:download' => 'Download .txt', - - + + 'diagnostics:header' => '======================================================================== Elgg Diagnostic Report Generated %s by %s ======================================================================== - + ', 'diagnostics:report:basic' => ' Elgg Release %s, version %s @@ -63,8 +64,8 @@ Global variables: %s ------------------------------------------------------------------------', - + ); - + add_translation("en",$english); ?> \ No newline at end of file diff --git a/mod/diagnostics/start.php b/mod/diagnostics/start.php index 76676c6a4..f4d1ab2af 100644 --- a/mod/diagnostics/start.php +++ b/mod/diagnostics/start.php @@ -43,31 +43,8 @@ function diagnostics_page_handler($page) { global $CONFIG; - 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"); - } + // 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 deleted file mode 100644 index 2068ec280..000000000 --- a/mod/diagnostics/testreport.php +++ /dev/null @@ -1,43 +0,0 @@ - - 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 deleted file mode 100644 index 8b1993041..000000000 --- a/mod/diagnostics/unittester.php +++ /dev/null @@ -1,41 +0,0 @@ - $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/test.php b/mod/diagnostics/views/default/diagnostics/test.php deleted file mode 100644 index 7546e6024..000000000 --- a/mod/diagnostics/views/default/diagnostics/test.php +++ /dev/null @@ -1,27 +0,0 @@ - -
-
- -
-
- -
-
- 'execute', 'value' => elgg_echo('diagnostics:test:executetest'))); - - echo elgg_view('input/form', array('action' => $vars['url'] . "pg/diagnostics/tests/{$vars['function']}", 'body' => $form_body)); - ?> -
-
\ No newline at end of file diff --git a/mod/diagnostics/views/default/diagnostics/testresult.php b/mod/diagnostics/views/default/diagnostics/testresult.php deleted file mode 100644 index 8db769f1d..000000000 --- a/mod/diagnostics/views/default/diagnostics/testresult.php +++ /dev/null @@ -1,40 +0,0 @@ -isSuccess()) - $successmessage = elgg_echo('diagnostics:unittester:testresult:success'); - else - $successmessage = elgg_echo('diagnostics:unittester:testresult:fail'); - } -?> -
-
-
-

:

-
-
- getDetails(); ?> -
-
- getDebug(); ?> -
-
-
\ No newline at end of file