You are here

function PublishContentWebCaseTest::drupalCreateNode in Publish Content 5.2

HACK: taken from simpletest for Drupal 6 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 'body' => 'Hello, world!'.

Return value

object Created node object.

6 calls to PublishContentWebCaseTest::drupalCreateNode()
PublishContentWebCaseTest::testDoPublishByNodeOwner in tests/publishcontent.test
PublishContentWebCaseTest::testDoPublishNotByNodeOwner in tests/publishcontent.test
PublishContentWebCaseTest::testDoUnpublishByNodeOwner in tests/publishcontent.test
PublishContentWebCaseTest::testDoUnpublishNotByNodeOwner in tests/publishcontent.test
PublishContentWebCaseTest::testNoPermissionAndNotOwner in tests/publishcontent.test

... See full list

File

tests/publishcontent.test, line 228
Unit tests for Publish Content module. prerequesite: make sure that 'authenticated user' does not have any access like 'publish [content type] content' or 'unpublish [content type] content'

Class

PublishContentWebCaseTest
@file Unit tests for Publish Content module. prerequesite: make sure that 'authenticated user' does not have any access like 'publish [content type] content' or 'unpublish [content type] content'

Code

function drupalCreateNode($settings = array()) {

  // Populate defaults array
  $defaults = array(
    'body' => $this
      ->randomName(32),
    'title' => $this
      ->randomName(8),
    'comment' => 2,
    'changed' => time(),
    'format' => FILTER_FORMAT_DEFAULT,
    'moderate' => 0,
    'promote' => 0,
    'revision' => 1,
    'log' => '',
    'status' => 1,
    'sticky' => 0,
    'type' => 'page',
    '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;
  node_save($node);

  // small hack to link revisions to our test user
  db_query('UPDATE {node_revisions} SET uid = %d WHERE vid = %d', $node->uid, $node->vid);
  return $node;
}