1 field_permission_example.test public GenericFieldTest::createFieldContentForUser( $account = NULL, $content = 'testable_content', $node_type = NULL, $instance_name = '', $column = NULL )

Create a node with some field content.

Return value

object: Node object for the created node.

File

modules/examples/field_permission_example/tests/field_permission_example.test, line 315
Tests for Field Permission Example.

Class

GenericFieldTest
A generic field testing class.

Code

public function createFieldContentForUser(
$account = NULL, 
$content = 'testable_content', 
$node_type = NULL, 
$instance_name = '', 
$column = NULL
) {
  if (!$column) {
    $this->fail('No column name given.');
    return NULL;
  }
  if (!$account) {
    $account = $this->backdropCreateUser(array(
      'bypass node access',
      'administer content types',
      'administer fields',
    ));
  }
  $this->backdropLogin($account);

  if (!$node_type) {
    $node_type = $this->codeTestGenericAddAllFields();
  }

  if (!$instance_name) {
    $instance_name = reset($this->instanceNames);
  }
  $field = array();
  $field[LANGUAGE_NONE][0][$column] = $content;

  $settings = array(
    'type' => $node_type->name,
    $instance_name => $field,
  );
  $node = $this->backdropCreateNode($settings);

  $this->assertTrue($node, 'Node of type ' . $node->type . ' allegedly created.');

  $node = node_load($node->nid);
  debug('Loaded node id: ' . $node->nid);
  $this->assertTrue($node->$instance_name, 'Field actually created.');
  $field = $node->$instance_name;
  $this->assertTrue($field[LANGUAGE_NONE][0][$column] == $content, 
  'Content was stored properly on the field.');
  return $node;
}