public function GenericFieldTest::createFieldContentForUser in Examples for Developers 7
Create a node with some field content.
Return value
object Node object for the created node.
1 call to GenericFieldTest::createFieldContentForUser()
- FieldTestPermissionsExample::createFieldContentForUser in field_permission_example/
tests/ field_permission_example.test - Override createFieldContentForUser().
1 method overrides GenericFieldTest::createFieldContentForUser()
- FieldTestPermissionsExample::createFieldContentForUser in field_permission_example/
tests/ field_permission_example.test - Override createFieldContentForUser().
File
- field_permission_example/
tests/ field_permission_example.test, line 332 - 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
->drupalCreateUser(array(
'bypass node access',
'administer content types',
));
}
$this
->drupalLogin($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
->drupalCreateNode($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;
}