Index: drupal_test_case.php =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/simpletest/drupal_test_case.php,v retrieving revision 1.85 diff -u -p -r1.85 drupal_test_case.php --- drupal_test_case.php 10 Apr 2008 00:39:01 -0000 1.85 +++ drupal_test_case.php 14 Apr 2008 00:27:43 -0000 @@ -33,14 +33,15 @@ class DrupalTestCase extends UnitTestCas } /** - * 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), @@ -67,7 +68,7 @@ class DrupalTestCase extends UnitTestCas global $user; $defaults['uid'] = $user->uid; } - $node = ($settings + $defaults); + $node = ($values + $defaults); $node = (object)$node; node_save($node); @@ -78,6 +79,69 @@ class DrupalTestCase extends UnitTestCas } /** + * 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 Index: ./tests/functional/node.test =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/simpletest/tests/functional/node.test,v retrieving revision 1.12 diff -u -p -r1.12 node.test --- ./tests/functional/node.test 10 Apr 2008 00:39:01 -0000 1.12 +++ ./tests/functional/node.test 14 Apr 2008 00:27:43 -0000 @@ -19,29 +19,26 @@ class NodeRevisionsTestCase extends Drup * If $log is TRUE, then a log message will be recorded. */ function prepareRevisions($log = FALSE) { - - $returnarray = array(); - $numtimes = 3; // First, middle, last. - for ($i = 0; $i < $numtimes; $i++) { - $settings = array('revision' => 1); - if ($log && $i == 1) { - $logmessage = $this->randomName(32); - $settings['log'] = $logmessage; - $returnarray['log'] = $logmessage; - } - 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) { - $returnarray['text'] = $node->body; - $returnarray['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); } - $returnarray['node'] = $node; - return $returnarray; + $revisions['node'] = $node; + $revisions['log'] = $node->log; + $this->drupalLogout(); + return $revisions; } /**