function GenericFieldTest::codeTestGenericAddAllFields
Add all testable fields as instances to a content type.
As a side-effect: Store the names of the instances created in $this->$instance_names.
Parameters
object $node_type: A content type object. If none is provided, one will be generated.
Return value
object The content type object that has the fields attached.
2 calls to GenericFieldTest::codeTestGenericAddAllFields()
- FieldTestPermissionsExample::testAddRemoveFieldnoteCode in field_permission_example/
tests/ field_permission_example.test - Add and remove the field through code.
- GenericFieldTest::createFieldContentForUser in field_permission_example/
tests/ field_permission_example.test - Create a node with some field content.
File
-
field_permission_example/
tests/ field_permission_example.test, line 140
Class
- GenericFieldTest
- A generic field testing class.
Code
public function codeTestGenericAddAllFields($node_type = NULL) {
$this->instanceNames = array();
if (!$node_type) {
$node_type = $this->drupalCreateContentType();
}
foreach ($this->getFieldTypes() as $field_type) {
$instance_name = drupal_strtolower($this->randomName(32));
$field = array(
'field_name' => $instance_name,
'type' => $field_type,
);
$field = field_create_field($field);
$instance = array(
'field_name' => $instance_name,
'entity_type' => 'node',
'bundle' => $node_type->name,
'label' => drupal_strtolower($this->randomName(20)),
);
// Finally create the instance.
$instance = field_create_instance($instance);
// Reset the caches...
_field_info_collate_fields(TRUE);
// Grab this instance.
$verify_instance = field_info_instance('node', $instance_name, $node_type->name);
$this->assertTrue($verify_instance, 'Instance object exists.');
$this->assertTrue($verify_instance != NULL, 'field_info_instance() says ' . $instance_name . ' (' . $node_type->name . ') was created.');
$this->instanceNames[] = $instance_name;
}
return $node_type;
}