? .DS_Store ? simpletest ? simpletest_upload_tests.patch ? tests/.DS_Store ? tests/functional/.DS_Store ? tests/functional/tracker.test Index: drupal_test_case.php =================================================================== RCS file: /cvs/drupal/contributions/modules/simpletest/drupal_test_case.php,v retrieving revision 1.68 diff -u -p -r1.68 drupal_test_case.php --- drupal_test_case.php 25 Mar 2008 15:07:57 -0000 1.68 +++ drupal_test_case.php 27 Mar 2008 13:34:16 -0000 @@ -559,8 +559,10 @@ class DrupalTestCase extends UnitTestCas * @param $tamper * If this is set to TRUE then you can post anything, otherwise hidden and * nonexistent fields are not posted. + * @param $curl_options + * Options passed into curlExec */ - function drupalPost($path, $edit, $submit, $tamper = FALSE) { + function drupalPost($path, $edit, $submit, $tamper = FALSE, $curl_options = array()) { $submit_matches = FALSE; if (isset($path)) { $html = $this->drupalGet($path); @@ -578,7 +580,7 @@ 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); + $submit_matches = $this->handleForm($post, $edit, $submit, $form, $curl_options); $action = isset($form['action']) ? $this->getAbsoluteUrl($form['action']) : $this->getUrl(); } // We post only if we managed to handle every field in edit and the @@ -595,7 +597,7 @@ class DrupalTestCase extends UnitTestCas $encoded_post .= $key .'='. rawurlencode($value) .'&'; } } - return $this->curlExec(array(CURLOPT_URL => $action, CURLOPT_POSTFIELDS => $encoded_post)); + return $this->curlExec(array(CURLOPT_URL => $action, CURLOPT_POSTFIELDS => $encoded_post) + $curl_options); } } // We have not found a form which contained all fields of $edit. @@ -607,7 +609,7 @@ class DrupalTestCase extends UnitTestCas } } - protected function handleForm(&$post, &$edit, $submit, $form) { + protected function handleForm(&$post, &$edit, $submit, $form, &$curl_options) { // Retrieve the form elements. $elements = $form->xpath('.//input|.//textarea|.//select'); $submit_matches = FALSE; @@ -626,6 +628,10 @@ class DrupalTestCase extends UnitTestCas $post[$name] = $edit[$name]; unset($edit[$name]); break; + case 'file': + $post[$name] = '@'. $edit[$name]; + unset($edit[$name]); + $curl_options[CURLOPT_UPLOAD] = TRUE; case 'radio': if ($edit[$name] == $value) { $post[$name] = $edit[$name]; @@ -649,7 +655,7 @@ class DrupalTestCase extends UnitTestCas $new_value = $edit[$name]; foreach ($element->option as $option) { if (is_array($new_value)) { - $option_value= (string)$option['value']; + $option_value = (string)$option['value']; if (in_array($option_value, $new_value)) { $post[$name][] = $option_value; unset($edit[$name]); @@ -660,6 +666,7 @@ class DrupalTestCase extends UnitTestCas unset($edit[$name]); } } + break; } } if (($type == 'submit' || $type == 'image') && $submit == $value) { Index: tests/functional/upload.test =================================================================== RCS file: /cvs/drupal/contributions/modules/simpletest/tests/functional/upload.test,v retrieving revision 1.12 diff -u -p -r1.12 upload.test --- tests/functional/upload.test 24 Mar 2008 02:36:46 -0000 1.12 +++ tests/functional/upload.test 27 Mar 2008 13:34:16 -0000 @@ -23,22 +23,14 @@ class UploadTestCase extends DrupalTestC * Create node; upload files to node; and edit, and delete uploads. */ function testNodeUpload() { - $admin_user = $this->drupalCreateUser(array('administer site configuration')); - $web_user = $this->drupalCreateUser(array('access content', 'edit any page content', 'upload files', 'view uploaded files')); - - $this->drupalLogin($admin_user); - // Setup upload settings. - $edit = array(); - $edit['upload_list_default'] = '1'; // Yes. - $edit['upload_extensions_default'] = 'jpg jpeg gif png txt doc xls pdf ppt pps odt ods odp'; - $edit['upload_uploadsize_default'] = '1'; - $edit['upload_usersize_default'] = '1'; - $this->drupalPost('admin/settings/uploads', $edit, t('Save configuration')); - $this->assertText('The configuration options have been saved.', 'Upload setting saved.'); - - $this->drupalGet('logout'); - $this->drupalLogin($web_user); + $this->drupalVariableSet('upload_list_default','1'); + $this->drupalVariableSet('upload_extensions_default','jpg jpeg gif png txt doc xls pdf ppt pps odt ods odp'); + $this->drupalVariableSet('upload_uploadsize_default','1'); + $this->drupalVariableSet('upload_usersize_default','1'); + + $user = $this->drupalCreateUser(array('access content', 'edit any page content', 'upload files', 'view uploaded files')); + $this->drupalLogin($user); // Create a node and attempt to attach files. $node = $this->drupalCreateNode(); @@ -90,7 +82,8 @@ class UploadTestCase extends DrupalTestC function uploadFile($node, $filename) { $edit = array(); $edit['files[upload]'] = $this->getFilePath($filename); - $this->drupalPost('node/'. $node->nid .'/edit', $edit, t('Save')); + $this->drupalPost('node/'. $node->nid .'/edit', $edit, t('Attach')); + $this->drupalPost(NULL, array(), t('Save')); $this->assertWantedRaw(t('Page %title has been updated.', array('%title' => $node->title)), 'File attached successfully.'); }