Creates a node based on default settings.
array $settings: (optional) An associative array of settings for the node, as used in entity_create(). Override the defaults by specifying the key and value in the array, for example:
$this
->drupalCreateNode(array(
'title' => t('Hello, world!'),
'type' => 'article',
));
The following defaults are provided:
$settings['body'][0] = array(
'value' => $this
->randomName(32),
'format' => filter_default_format(),
);
\Drupal\node\Plugin\Core\Entity\Node The created node entity.
protected function drupalCreateNode(array $settings = array()) {
// Populate defaults array.
$settings += array(
'body' => array(
array(),
),
'title' => $this
->randomName(8),
'changed' => REQUEST_TIME,
'promote' => NODE_NOT_PROMOTED,
'revision' => 1,
'log' => '',
'status' => NODE_PUBLISHED,
'sticky' => NODE_NOT_STICKY,
'type' => 'page',
'langcode' => Language::LANGCODE_NOT_SPECIFIED,
);
// Add in comment settings for nodes.
if (module_exists('comment')) {
$settings += array(
'comment' => COMMENT_NODE_OPEN,
);
}
// 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.
$settings['body'][0] += array(
'value' => $this
->randomName(32),
'format' => filter_default_format(),
);
$node = entity_create('node', $settings);
if (!empty($settings['revision'])) {
$node
->setNewRevision();
}
$node
->save();
return $node;
}