]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Fixes #1526: Big honking warning added to unit tests. Getter test also deletes its...
authorbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>
Wed, 17 Feb 2010 15:32:23 +0000 (15:32 +0000)
committerbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>
Wed, 17 Feb 2010 15:32:23 +0000 (15:32 +0000)
git-svn-id: http://code.elgg.org/elgg/trunk@3945 36083f99-b078-4883-b0ff-0f9b5a30f544

engine/tests/api/entity_getter_functions.php
mod/diagnostics/index.php
mod/diagnostics/languages/en.php
mod/diagnostics/start.php
mod/diagnostics/testreport.php [deleted file]
mod/diagnostics/unittester.php [deleted file]
mod/diagnostics/views/default/diagnostics/test.php [deleted file]
mod/diagnostics/views/default/diagnostics/testresult.php [deleted file]

index d09f1066d1026d5a7298da89ae9473e63b81e292..f3f892d792f0f340a6caf6ed87b3a64b57f4eeb8 100644 (file)
@@ -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));
+               }
        }
 
 
index 9a7b6619119531cf0820104f6d4d0300b2fec7bd..0cae3743cb64579cc157e6030606083e7694859f 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /**
  * Elgg diagnostics
- * 
+ *
  * @package ElggDiagnostics
  * @author Curverider Ltd
  * @link http://elgg.com/
@@ -14,23 +14,28 @@ set_context('admin');
 
 // system diagnostics
 $body = elgg_view_title(elgg_echo('diagnostics'));
-$body .= elgg_view('page_elements/contentwrapper', array('body' => 
+$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 = '<p>' . elgg_echo('diagnostics:unittester:description') . '</p>';
+$test_body .= '<h3>' . elgg_echo('diagnostics:unittester:warning') . '</h3>';
+
 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') . "<br />$button")
+
+$body .= elgg_view('page_elements/contentwrapper', array(
+       'body' => $test_body)
 );
 
 // create page
index 2562c10b8fe08b33239e80c7f643bec9a6c78472..ae72564d779890914c56493726cb4b06b7c30544 100644 (file)
@@ -1,44 +1,45 @@
 <?php
        /**
         * Elgg diagnostics language pack.
-        * 
+        *
         * @package ElggDiagnostics
         * @author Curverider Ltd
         * @link http://elgg.com/
         */
 
        $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: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
index 76676c6a461bd4568ec329bd4d49c31bad3edd14..f4d1ab2af66b614f5c1b3cffa20ea4013d1e97df 100644 (file)
@@ -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 (file)
index 2068ec2..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-<?php
-       /**
-        * Elgg diagnostics - test report
-        * 
-        * @package ElggDiagnostics
-        * @author Curverider Ltd
-        * @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
deleted file mode 100644 (file)
index 8b19930..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-<?php
-       /**
-        * Elgg diagnostics - unit tester
-        * 
-        * @package ElggDiagnostics
-        * @author Curverider Ltd
-        * @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/test.php b/mod/diagnostics/views/default/diagnostics/test.php
deleted file mode 100644 (file)
index 7546e60..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-<?php
-       /**
-        * Elgg diagnostics
-        * 
-        * @package ElggDiagnostics
-        * @author Curverider Ltd
-        * @link http://elgg.com/
-        */
-
-       
-?>
-<div class="test">
-       <div class="test_header">
-               <b><?php echo $vars['function']; ?></b>
-       </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
deleted file mode 100644 (file)
index 8db769f..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-<?php
-       /**
-        * Elgg diagnostics - test report
-        * 
-        * @package ElggDiagnostics
-        * @author Curverider Ltd
-        * @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><b><?php echo $vars['function']; ?> : </b><?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