? .bzr ? node_format.patch ? simpletest ? simplify.patch ? upload.patch ? tests/enable_modules.test ? tests/homepage.test ? tests/menu_enable.patch ? tests/menu_tests.patch Index: drupal_test_case.php =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/simpletest/drupal_test_case.php,v retrieving revision 1.81 diff -u -p -r1.81 drupal_test_case.php --- drupal_test_case.php 1 Apr 2008 23:42:07 -0000 1.81 +++ drupal_test_case.php 3 Apr 2008 08:35:45 -0000 @@ -8,20 +8,14 @@ class DrupalTestCase extends UnitTestCas protected $_logged_in = FALSE; protected $_content; protected $plain_text; - protected $_originalModules = array(); - protected $_modules = array(); - protected $_cleanupVariables = array(); - protected $_cleanupUsers = array(); - protected $_cleanupRoles = array(); - protected $_cleanupNodes = array(); - protected $_cleanupContentTypes = array(); protected $ch; + protected $_modules = array(); // We do not reuse the cookies in further runs, so we do not need a file // but we still need cookie handling, so we set the jar to NULL protected $cookie_file = NULL; // Overwrite this any time to supply cURL options as necessary, // DrupalTestCase itself never sets this but always obeys whats set. - protected $curl_options = array(); + protected $curl_options = array(CURLOPT_PROXY => 'http://localhost:8080'); /** * Retrieve the test information from getInfo(). @@ -80,7 +74,6 @@ class DrupalTestCase extends UnitTestCas // small hack to link revisions to our test user db_query('UPDATE {node_revisions} SET uid = %d WHERE vid = %d', $node->uid, $node->vid); - $this->_cleanupNodes[] = $node->nid; return $node; } @@ -125,7 +118,6 @@ class DrupalTestCase extends UnitTestCas node_type_save($type); node_types_rebuild(); - $this->_cleanupContentTypes[] = $type->type; return $type; } @@ -255,10 +247,6 @@ class DrupalTestCase extends UnitTestCas $old_value = variable_get($name, NULL); if ($value !== $old_value) { variable_set($name, $value); - /* Use array_key_exists instead of isset so NULL values do not get overwritten */ - if (!array_key_exists($name, $this->_cleanupVariables)) { - $this->_cleanupVariables[$name] = $old_value; - } } } @@ -292,9 +280,6 @@ class DrupalTestCase extends UnitTestCas return FALSE; } - // Add to list of users to remove when testing is completed. - $this->_cleanupUsers[] = $account->uid; - // Add the raw password so that we can log in as this user. $account->pass_raw = $edit['pass']; return $account; @@ -323,9 +308,9 @@ class DrupalTestCase extends UnitTestCas // Assign permissions to role and mark it for clean-up. db_query("INSERT INTO {permission} (rid, perm) VALUES (%d, '%s')", $role->rid, $permission_string); $this->assertTrue(db_affected_rows(), ' [role] created permissions: ' . $permission_string); - $this->_cleanupRoles[] = $role->rid; return $role->rid; - } else { + } + else { return FALSE; } } @@ -420,69 +405,7 @@ class DrupalTestCase extends UnitTestCas $this->_logged_in = FALSE; $this->_modules = $this->_originalModules; $this->curlClose(); - return; - } - if ($this->_modules != $this->_originalModules) { - $form_state['values'] = array('status' => $this->_originalModules, 'op' => t('Save configuration')); - drupal_execute('system_modules', $form_state); - - //rebuilding all caches - drupal_rebuild_theme_registry(); - node_types_rebuild(); - menu_rebuild(); - cache_clear_all('schema', 'cache'); - module_rebuild_cache(); - - $this->_modules = $this->_originalModules; } - - foreach ($this->_cleanupVariables as $name => $value) { - if (is_null($value)) { - variable_del($name); - } else { - variable_set($name, $value); - } - } - $this->_cleanupVariables = array(); - - //delete nodes - foreach ($this->_cleanupNodes as $nid) { - node_delete($nid); - } - $this->_cleanupNodes = array(); - - //delete roles - while (sizeof($this->_cleanupRoles) > 0) { - $rid = array_pop($this->_cleanupRoles); - db_query("DELETE FROM {role} WHERE rid = %d", $rid); - db_query("DELETE FROM {permission} WHERE rid = %d", $rid); - } - - //delete users and their content - while (sizeof($this->_cleanupUsers) > 0) { - $uid = array_pop($this->_cleanupUsers); - // cleanup nodes this user created - $result = db_query("SELECT nid FROM {node} WHERE uid = %d", $uid); - while ($node = db_fetch_array($result)) { - node_delete($node['nid']); - } - user_delete(array(), $uid); - } - - //delete content types - foreach ($this->_cleanupContentTypes as $type) { - node_type_delete($type); - } - $this->_cleanupContentTypes = array(); - - //Output drupal warnings and messages into assert messages - $drupal_msgs = drupal_get_messages(); - foreach($drupal_msgs as $type => $msgs) { - foreach ($msgs as $msg) { - $this->assertTrue(TRUE, "$type: $msg"); - } - } - parent::tearDown(); } @@ -625,24 +548,37 @@ class DrupalTestCase extends UnitTestCas // We try to set the fields of this form as specified in $edit. $edit = $edit_save; $post = array(); - $submit_matches = $this->handleForm($post, $edit, $submit, $form); + $upload = array(); + $submit_matches = $this->handleForm($post, $edit, $upload, $submit, $form); $action = isset($form['action']) ? $this->getAbsoluteUrl($form['action']) : $this->getUrl(); } // We post only if we managed to handle every field in edit and the // submit button matches; if (!$edit && $submit_matches) { - $encoded_post = ''; - foreach ($post as $key => $value) { - if (is_array($value)) { - foreach ($value as $v) { - $encoded_post .= $key .'='. rawurlencode($v) .'&'; + // This part is not pretty. There is very little I can do. + if ($upload) { + foreach ($post as &$value) { + if ($value[0] == '@') { + $this->fail(t("Can't upload and post a value starting with @")); + return FALSE; } } - else { - $encoded_post .= $key .'='. rawurlencode($value) .'&'; + foreach ($upload as $key => $file) { + $post[$key] = '@'. realpath($file); + } + $this->pass(var_export($post, TRUE)); + } + else { + $post_array = $post; + $post = array(); + foreach ($post_array as $key => $value) { + // Whethet this needs to be urlencode or rawurlencode, is not + // quite clear, but this seems to be the better choice. + $post[] = urlencode($key) .'='. urlencode($value); } + $post = implode('&', $post); } - return $this->curlExec(array(CURLOPT_URL => $action, CURLOPT_POSTFIELDS => $encoded_post)); + return $this->curlExec(array(CURLOPT_URL => $action, CURLOPT_POSTFIELDS => $post)); } } // We have not found a form which contained all fields of $edit. @@ -665,7 +601,7 @@ class DrupalTestCase extends UnitTestCas * @param array $form Array of form elements. * @return boolean Submit value matches a valid submit input in the form. */ - protected function handleForm(&$post, &$edit, $submit, $form) { + protected function handleForm(&$post, &$edit, &$upload, $submit, $form) { // Retrieve the form elements. $elements = $form->xpath('.//input|.//textarea|.//select'); $submit_matches = FALSE; @@ -676,6 +612,7 @@ class DrupalTestCase extends UnitTestCas // for