You are here

public function FieldTypePluginManagerTest::testCreateInstance in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/field/src/Tests/FieldTypePluginManagerTest.php \Drupal\field\Tests\FieldTypePluginManagerTest::testCreateInstance()

Tests creation of field item instances.

File

core/modules/field/src/Tests/FieldTypePluginManagerTest.php, line 36
Contains \Drupal\field\Tests\FieldTypePluginManagerTest.

Class

FieldTypePluginManagerTest
Tests the field type manager.

Namespace

Drupal\field\Tests

Code

public function testCreateInstance() {

  /** @var \Drupal\Core\Field\FieldTypePluginManagerInterface $field_type_manager */
  $field_type_manager = \Drupal::service('plugin.manager.field.field_type');
  foreach (array(
    'test_field',
    'shape',
    'hidden_test_field',
  ) as $type) {
    $definition = $field_type_manager
      ->getDefinition($type);
    $class = $definition['class'];
    $field_name = 'field_' . $type;
    $field_definition = BaseFieldDefinition::create($type);
    $configuration = array(
      'field_definition' => $field_definition,
      'name' => $field_name,
      'parent' => NULL,
    );
    $instance = $field_type_manager
      ->createInstance($type, $configuration);
    $this
      ->assertTrue($instance instanceof $class, SafeMarkup::format('Created a @class instance', array(
      '@class' => $class,
    )));
    $this
      ->assertEqual($field_name, $instance
      ->getName(), SafeMarkup::format('Instance name is @name', array(
      '@name' => $field_name,
    )));
  }
}