- Patch #308296 by Dave Reid, Damien Tournoud: clean-up of drupalCreateNode().
parent
526401c4c8
commit
26395c843f
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
}
|
||||
if (empty($settings['uid'])) {
|
||||
global $user;
|
||||
$defaults['uid'] = $user->uid;
|
||||
}
|
||||
$node = ($settings + $defaults);
|
||||
$node = (object)$node;
|
||||
|
||||
// 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');
|
||||
}
|
||||
|
||||
// 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 = (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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue