summaryrefslogtreecommitdiff
path: root/modules
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
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')
-rw-r--r--modules/blog/blog.test2
-rw-r--r--modules/menu/menu.test4
-rw-r--r--modules/path/path.test7
-rw-r--r--modules/php/php.test18
-rw-r--r--modules/simpletest/drupal_web_test_case.php48
-rw-r--r--modules/tracker/tracker.test2
-rw-r--r--modules/upload/upload.test6
7 files changed, 49 insertions, 38 deletions
diff --git a/modules/blog/blog.test b/modules/blog/blog.test
index 5994d6e29..8e73eeaf9 100644
--- a/modules/blog/blog.test
+++ b/modules/blog/blog.test
@@ -66,7 +66,7 @@ class BlogTestCase extends DrupalWebTestCase {
// Login the user.
$this->drupalLogin($user);
// Create blog node.
- $node = $this->drupalCreateNode(array('type' => 'blog', 'uid' => $user->uid));
+ $node = $this->drupalCreateNode(array('type' => 'blog'));
// Verify the user has access to all the blog nodes.
$this->verifyBlogs($user, $node, $admin);
// Verify the blog links are displayed.
diff --git a/modules/menu/menu.test b/modules/menu/menu.test
index d0647bb0f..8c7a46635 100644
--- a/modules/menu/menu.test
+++ b/modules/menu/menu.test
@@ -136,8 +136,8 @@ class MenuTestCase extends DrupalWebTestCase {
*/
function doMenuTests($menu_name = 'navigation') {
// Add nodes to use as links for menu links.
- $node1 = $this->drupalCreateNode(array('type' => 'article', 'uid' => $this->big_user->uid));
- $node2 = $this->drupalCreateNode(array('type' => 'article', 'uid' => $this->big_user->uid));
+ $node1 = $this->drupalCreateNode(array('type' => 'article'));
+ $node2 = $this->drupalCreateNode(array('type' => 'article'));
// Add menu links.
$item1 = $this->addMenuLink(0, 'node/' . $node1->nid, $menu_name);
diff --git a/modules/path/path.test b/modules/path/path.test
index 18e2b6939..13b46313e 100644
--- a/modules/path/path.test
+++ b/modules/path/path.test
@@ -15,8 +15,9 @@ class PathTestCase extends DrupalWebTestCase {
*/
function setUp() {
parent::setUp('path');
- // create and login user
- $web_user = $this->drupalCreateUser(array('edit any page content', 'create page content', 'administer url aliases', 'create url aliases'));
+
+ // Create test user and login.
+ $web_user = $this->drupalCreateUser(array('create page content', 'edit own page content', 'administer url aliases', 'create url aliases'));
$this->drupalLogin($web_user);
}
@@ -24,7 +25,7 @@ class PathTestCase extends DrupalWebTestCase {
* Test alias functionality through the admin interfaces.
*/
function testAdminAlias() {
- // create test node
+ // Create test node.
$node1 = $this->drupalCreateNode();
// Create alias.
diff --git a/modules/php/php.test b/modules/php/php.test
index 487c5a5d6..bf1ea6a24 100644
--- a/modules/php/php.test
+++ b/modules/php/php.test
@@ -20,16 +20,10 @@ class PHPTestCase extends DrupalWebTestCase {
/**
* Create a test node with PHP code in the body.
*
- * @param stdObject User object to create node for.
* @return stdObject Node object.
*/
- function createNodeWithCode($user) {
- $node = $this->drupalCreateNode(array('uid' => $user->uid));
- $edit = array();
- $edit['body'] = '<?php print "SimpleTest PHP was executed!"; ?>';
- $this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));
- $this->assertRaw(t('Page %title has been updated.', array('%title' => $node->title)), t('PHP code inserted into node.'));
- return $node;
+ function createNodeWithCode() {
+ return $this->drupalCreateNode(array('body' => '<?php print "SimpleTest PHP was executed!"; ?>'));
}
}
@@ -58,10 +52,10 @@ class PHPFilterTestCase extends PHPTestCase {
// Create node with PHP filter enabled.
$web_user = $this->drupalCreateUser(array('access content', 'create page content', 'edit own page content'));
$this->drupalLogin($web_user);
-
- $node = $this->createNodeWithCode($web_user);
+ $node = $this->createNodeWithCode();
// Make sure that the PHP code shows up as text.
+ $this->drupalGet('node/'. $node->nid);
$this->assertText('print', t('PHP code is displayed.'));
// Change filter to PHP filter and see that PHP code is evaluated.
@@ -95,10 +89,10 @@ class PHPAccessTestCase extends PHPTestCase {
// Create node with PHP filter enabled.
$web_user = $this->drupalCreateUser(array('access content', 'create page content', 'edit own page content'));
$this->drupalLogin($web_user);
-
- $node = $this->createNodeWithCode($web_user);
+ $node = $this->createNodeWithCode();
// Make sure that the PHP code shows up as text.
+ $this->drupalGet('node/'. $node->nid);
$this->assertText('print', t('PHP code is displayed.'));
// Make sure that user doesn't have access to filter.
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
diff --git a/modules/tracker/tracker.test b/modules/tracker/tracker.test
index 4063b16b4..2f2249738 100644
--- a/modules/tracker/tracker.test
+++ b/modules/tracker/tracker.test
@@ -17,7 +17,7 @@ class TrackerTest extends DrupalWebTestCase {
function setUp() {
parent::setUp('comment', 'tracker');
- $permissions = array('access comments', 'post comments', 'post comments without approval');
+ $permissions = array('access comments', 'create page content', 'post comments', 'post comments without approval');
$this->user = $this->drupalCreateUser($permissions);
$this->other_user = $this->drupalCreateUser($permissions);
}
diff --git a/modules/upload/upload.test b/modules/upload/upload.test
index 8103b873d..141b10adf 100644
--- a/modules/upload/upload.test
+++ b/modules/upload/upload.test
@@ -20,7 +20,7 @@ class UploadTestCase extends DrupalWebTestCase {
function testNodeUpload() {
global $base_url;
$admin_user = $this->drupalCreateUser(array('administer site configuration'));
- $web_user = $this->drupalCreateUser(array('access content', 'edit any page content', 'upload files', 'view uploaded files'));
+ $web_user = $this->drupalCreateUser(array('access content', 'edit own page content', 'upload files', 'view uploaded files'));
$this->drupalLogin($admin_user);
@@ -88,7 +88,7 @@ class UploadTestCase extends DrupalWebTestCase {
*/
function testFilesFilter() {
$admin_user = $this->drupalCreateUser(array('administer site configuration'));
- $web_user = $this->drupalCreateUser(array('access content', 'edit any page content', 'upload files', 'view uploaded files'));
+ $web_user = $this->drupalCreateUser(array('access content', 'edit own page content', 'upload files', 'view uploaded files'));
$this->drupalLogin($admin_user);
@@ -131,7 +131,7 @@ class UploadTestCase extends DrupalWebTestCase {
$file = current($files)->filepath;
$admin_user = $this->drupalCreateUser(array('administer site configuration'));
- $web_user = $this->drupalCreateUser(array('access content', 'edit any page content', 'upload files', 'view uploaded files'));
+ $web_user = $this->drupalCreateUser(array('access content', 'edit own page content', 'upload files', 'view uploaded files'));
$this->drupalLogin($admin_user);