1 field_permission_example.test public GenericFieldTest::codeTestGenericAddAllFields($node_type = NULL)

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.

File

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

Class

GenericFieldTest
A generic field testing class.

Code

public function codeTestGenericAddAllFields($node_type = NULL) {
  $this->instanceNames = array();
  if (!$node_type) {
    $node_type = $this->backdropCreateContentType();
  }
  foreach ($this->getFieldTypes() as $field_type) {
    $instance_name = backdrop_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' => backdrop_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;
}