summaryrefslogtreecommitdiff
path: root/modules/simpletest
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2009-04-22 09:57:10 +0000
committerDries Buytaert <dries@buytaert.net>2009-04-22 09:57:10 +0000
commit26395c843fd6e96743cfc929ca01f004a45abfe6 (patch)
tree6639d0c04c05fa182dafab5b8abbb2fa72c2b32d /modules/simpletest
parent526401c4c8f7e1a8126c4810a7d7023c4f8bafc5 (diff)
downloadbrdo-26395c843fd6e96743cfc929ca01f004a45abfe6.tar.gz
brdo-26395c843fd6e96743cfc929ca01f004a45abfe6.tar.bz2
- Patch #308296 by Dave Reid, Damien Tournoud: clean-up of drupalCreateNode().
Diffstat (limited to 'modules/simpletest')
-rw-r--r--modules/simpletest/drupal_web_test_case.php48
1 files changed, 32 insertions, 16 deletions
diff --git a/modules/simpletest/drupal_web_test_case.php b/modules/simpletest/drupal_web_test_case.php
index 9ca1241cf..3b42342c1 100644
--- a/modules/simpletest/drupal_web_test_case.php
+++ b/modules/simpletest/drupal_web_test_case.php
@@ -56,11 +56,11 @@ class DrupalWebTestCase {
protected $elements = NULL;
/**
- * Whether a user is logged in the internal browser.
+ * The current user logged in using the internal browser.
*
* @var bool
*/
- protected $isLoggedIn = FALSE;
+ protected $loggedInUser = FALSE;
/**
* The current cookie file used by cURL.
@@ -486,7 +486,7 @@ class DrupalWebTestCase {
*/
protected function drupalCreateNode($settings = array()) {
// Populate defaults array
- $defaults = array(
+ $settings += array(
'body' => $this->randomName(32),
'title' => $this->randomName(8),
'comment' => 2,
@@ -502,18 +502,30 @@ class DrupalWebTestCase {
'revisions' => NULL,
'taxonomy' => NULL,
);
- $defaults['teaser'] = $defaults['body'];
- // If we already have a node, we use the original node's created time, and this
- if (isset($defaults['created'])) {
- $defaults['date'] = format_date($defaults['created'], 'custom', 'Y-m-d H:i:s O');
+
+ // Use the original node's created time for existing nodes.
+ if (isset($settings['created']) && !isset($settings['date'])) {
+ $settings['date'] = format_date($settings['created'], 'custom', 'Y-m-d H:i:s O');
}
- if (empty($settings['uid'])) {
- global $user;
- $defaults['uid'] = $user->uid;
+
+ // Add the default teaser.
+ if (!isset($settings['teaser'])) {
+ $settings['teaser'] = $settings['body'];
+ }
+
+ // If the node's user uid is not specified manually, use the currently
+ // logged in user if available, or else the user running the test.
+ if (!isset($settings['uid'])) {
+ if ($this->loggedInUser) {
+ $settings['uid'] = $this->loggedInUser->uid;
+ }
+ else {
+ global $user;
+ $settings['uid'] = $user->uid;
+ }
}
- $node = ($settings + $defaults);
- $node = (object)$node;
+ $node = (object) $settings;
node_save($node);
// small hack to link revisions to our test user
@@ -768,7 +780,7 @@ class DrupalWebTestCase {
* @see drupalCreateUser()
*/
protected function drupalLogin(stdClass $user) {
- if ($this->isLoggedIn) {
+ if ($this->loggedInUser) {
$this->drupalLogout();
}
@@ -782,7 +794,9 @@ class DrupalWebTestCase {
$pass = $pass && $this->assertNoText(t('The username %name has been blocked.', array('%name' => $user->name)), t('No blocked message at login page'), t('User login'));
$pass = $pass && $this->assertNoText(t('The name %name is a reserved username.', array('%name' => $user->name)), t('No reserved message at login page'), t('User login'));
- $this->isLoggedIn = $pass;
+ if ($pass) {
+ $this->loggedInUser = $user;
+ }
}
/*
@@ -797,7 +811,9 @@ class DrupalWebTestCase {
$pass = $this->assertField('name', t('Username field found.'), t('Logout'));
$pass = $pass && $this->assertField('pass', t('Password field found.'), t('Logout'));
- $this->isLoggedIn = !$pass;
+ if ($pass) {
+ $this->loggedInUser = FALSE;
+ }
}
/**
@@ -921,7 +937,7 @@ class DrupalWebTestCase {
drupal_save_session(TRUE);
// Ensure that internal logged in variable and cURL options are reset.
- $this->isLoggedIn = FALSE;
+ $this->loggedInUser = FALSE;
$this->additionalCurlOptions = array();
// Reload module list and implementations to ensure that test module hooks