Index: modules/node/node.test =================================================================== RCS file: /cvs/drupal/drupal/modules/node/node.test,v retrieving revision 1.3 diff -u -p -r1.3 node.test --- modules/node/node.test 10 May 2008 07:05:40 -0000 1.3 +++ modules/node/node.test 17 May 2008 02:32:25 -0000 @@ -20,28 +20,26 @@ class NodeRevisionsTestCase extends Drup */ function prepareRevisions($log = FALSE) { - $return_array = array(); - $numtimes = 3; // First, middle, last. - for ($i = 0; $i < $numtimes; $i++) { - $settings = array('revision' => 1); - if ($log && $i == 1) { - $log_message = $this->randomName(32); - $settings['log'] = $log_message; - $return_array['log'] = $log_message; - } - if ($i != 0) { - $settings['nid'] = $node->nid; - } - $node = $this->drupalCreateNode($settings); + $test_user = $this->drupalCreateUser(array('administer nodes')); + $this->drupalLogin($test_user); + + $node = $this->drupalCreateNode(); + for ($i=0; $i<3; $i++) { + + $update = array('revision' => true, + 'log' => $this->randomName(32), + ); + + $node = $this->drupalUpdateNode($node->nid, $update); if ($i == 1) { - $return_array['text'] = $node->body; - $return_array['vid'] = $node->vid; + $revisions['vid'] = $node->vid; + $revisions['text'] = $node->body; } - // Avoid confusion on the revisions overview page which is sorted by r.timestamp. - sleep(1); } - $return_array['node'] = $node; - return $return_array; + $revisions['node'] = $node; + $revisions['log'] = $node->log; + $this->drupalLogout(); + return $revisions; } /** Index: modules/simpletest/drupal_web_test_case.php =================================================================== RCS file: /cvs/drupal/drupal/modules/simpletest/drupal_web_test_case.php,v retrieving revision 1.6 diff -u -p -r1.6 drupal_web_test_case.php --- modules/simpletest/drupal_web_test_case.php 16 May 2008 02:09:22 -0000 1.6 +++ modules/simpletest/drupal_web_test_case.php 17 May 2008 02:32:34 -0000 @@ -34,14 +34,15 @@ class DrupalWebTestCase extends UnitTest } /** - * Creates a node based on default settings. + * Creates a node based on default settings. This does not use the simpletest + * browser, meaning the node will not be owned by the current simpletest user. * - * @param settings - * An assocative array of settings to change from the defaults, keys are + * @param values + * An associative array of values to change from the defaults, keys are * node properties, for example 'body' => 'Hello, world!'. * @return object Created node object. */ - function drupalCreateNode($settings = array()) { + function drupalCreateNodeInternally($values = array()) { // Populate defaults array $defaults = array( 'body' => $this->randomName(32), @@ -68,7 +69,7 @@ class DrupalWebTestCase extends UnitTest global $user; $defaults['uid'] = $user->uid; } - $node = ($settings + $defaults); + $node = ($values + $defaults); $node = (object)$node; node_save($node); @@ -79,6 +80,69 @@ class DrupalWebTestCase extends UnitTest } /** + * Creates a node based on default settings. This uses the internal simpletest + * browser, meaning the node will be owned by the current simpletest _browser user. + * + * @param values + * An associative array of values to change from the defaults, keys are + * node properties, for example 'body' => 'Hello, world!'. + * @return object Created node object. + */ + function drupalCreateNode($values = array()) { + $defaults = array( + 'type' => 'page', + 'title' => $this->randomName(8), + ); + + $edit = ($values + $defaults); + + if (empty($edit['body'])) { + $content_type = db_fetch_array(db_query("select name, has_body from {node_type} where type='%s'", $edit['type'])); + + if ($content_type['has_body']) { + $edit['body'] = $this->randomName(32); + } + } + $type = $edit['type']; + unset($edit['type']); // Only used in URL. + $this->drupalPost('node/add/'. $type, $edit, t('Save')); + + $node = node_load(array('title' => $edit['title'])); + $this->assertRaw(t('@type %title has been created.', array('@type' => node_get_types('name', $node), '%title' => $edit['title'])), t('Node created successfully.')); + + return $node; + } + + /** + * Updates a node using the internal simpletest browser. + * + * @param nid + * The nid of the node you would like to update. + * @param values + * An associative array of values to change from the defaults, keys are + * node properties, for example 'body' => 'Hello, world!'. + * @return object Created node object. + */ + function drupalUpdateNode($nid, $values) { + $defaults = array( + 'title' => $this->randomName(8), + 'body' => $this->randomName(32), + ); + + $values = (array)$values; + $edit = ($values + $defaults); + + if (!is_numeric($nid)) { + $this->fail(t('No nid to update')); + return; + } + + $this->drupalPost('node/'. $nid .'/edit', $edit, t('Save')); + $this->assertRaw(t($edit['title']), t('Node updated successfully.')); + return node_load(array('title' => $edit['title'])); + } + + /** * Creates a custom content type based on default settings. * * @param settings