function DrupalWebTestCase::drupalCreateNode
Creates a node based on default settings.
Parameters
$settings: An associative array of settings to change from the defaults, keys are node properties, for example 'title' => 'Hello, world!'.
Return value
Created node object.
124 calls to DrupalWebTestCase::drupalCreateNode()
- AccessDeniedTestCase::testAccessDenied in modules/
system/ system.test - BlogTestCase::doBasicTests in modules/
blog/ blog.test - Run basic tests on the indicated user.
- BlogTestCase::testBlog in modules/
blog/ blog.test - Login users, create blog nodes, and test blog functionality through the admin and user interfaces.
- BlogTestCase::testUnprivilegedUser in modules/
blog/ blog.test - Confirm that the "You are not allowed to post a new blog entry." message shows up if a user submitted blog entries, has been denied that permission, and goes to the blog page.
- CascadingStylesheetsTestCase::testRenderInlineFullPage in modules/
simpletest/ tests/ common.test - Tests rendering inline stylesheets through a full page request.
File
-
modules/
simpletest/ drupal_web_test_case.php, line 1041
Class
- DrupalWebTestCase
- Test case for typical Drupal tests.
Code
protected function drupalCreateNode($settings = array()) {
// Populate defaults array.
$settings += array(
'title' => $this->randomName(8),
'comment' => 2,
'changed' => REQUEST_TIME,
'moderate' => 0,
'promote' => 0,
'revision' => 1,
'log' => '',
'status' => 1,
'sticky' => 0,
'type' => 'page',
'revisions' => NULL,
'language' => LANGUAGE_NONE,
);
// Add the body after the language is defined so that it may be set
// properly.
$settings += array(
'body' => array(
$settings['language'] => array(
array(),
),
),
);
// 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 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;
}
}
// Merge body field value and format separately.
$body = array(
'value' => $this->randomName(32),
'format' => filter_default_format(),
);
$settings['body'][$settings['language']][0] += $body;
$node = (object) $settings;
node_save($node);
// Small hack to link revisions to our test user.
db_update('node_revision')->fields(array(
'uid' => $node->uid,
))
->condition('vid', $node->vid)
->execute();
return $node;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.