Index: drupal_test_case.php =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/simpletest/drupal_test_case.php,v retrieving revision 1.46 diff -u -r1.46 drupal_test_case.php --- drupal_test_case.php 21 Jan 2008 06:48:49 -0000 1.46 +++ drupal_test_case.php 25 Jan 2008 02:36:01 -0000 @@ -32,44 +32,24 @@ * * @param settings An array of settings to change from the defaults, in the form of 'body' => 'Hello, world!' */ - function drupalCreateNode($settings = array()) { - - // Populate defaults array - $defaults = array( - 'body' => $this->randomName(32), - 'title' => $this->randomName(8), - 'comment' => 2, - 'changed' => time(), - 'format' => 1, - 'moderate' => 0, - 'promote' => 0, - 'revision' => 1, - 'log' => '', - 'status' => 1, - 'sticky' => 0, - 'type' => 'page', - 'revisions' => NULL, - 'taxonomy' => NULL, - ); - $defaults['teaser'] = $defaults['body']; - // If we already have a node, we use the original node's created time, and this - $defaults['date'] = format_date($defaults['created'], 'custom', 'Y-m-d H:i:s O'); + function drupalCreateNode($settings = array(), $type = 'page') { + $content_type = db_fetch_array(db_query("select name, has_body from {node_type} where type='%s'", $type)); + $defaults['title'] = $this->randomName(8); - if (empty($settings['uid'])) { - global $user; - $defaults['uid'] = $user->uid; - } - $node = ($settings + $defaults); - $node = (object)$node; - - node_save($node); + if ($content_type['has_body']) { + $defaults['body'] = $this->randomName(32); + } - // small hack to link revisions to our test user - db_query('UPDATE {node_revisions} SET uid = %d WHERE vid = %d', $node->uid, $node->vid); + $edit = ($settings + $defaults); + $this->drupalPostRequest("node/add/". $type, $edit, t('Save')); + $this->assertWantedRaw(t('!type %title has been created.', array ('!type' => $content_type['name'], '%title' => $edit['title'])), $content_type['name'] .' created'); + + $node = node_load(array('title' => $edit['title'])); + $this->assertNotNull($node, $content_type['name'] ." loaded successfully"); $this->_cleanupNodes[] = $node->nid; return $node; } - + /** * Creates a custom content type based on default settings. * @@ -430,6 +410,18 @@ return $user; } + /** + * Log the current user out of the internal browser + */ + function drupalLogoutUser($user = NULL, $submit = 'Log in') { + //make a request to the logout page + $this->drupalGet('logout'); + //load the user page, the idea being if you were properly logged out you should be seeing a login screen + $this->drupalGet('user'); + $this->assertWantedRaw( "Username", "Found Username Field"); + $this->assertWantedRaw( "Password", "Found Username Field"); + } + /** * tearDown implementation, setting back switched modules etc */