function FieldUnitTestBase::createFieldWithInstance

Create a field and an instance of it.

Parameters

string $suffix: (optional) A string that should only contain characters that are valid in PHP variable names as well.

6 calls to FieldUnitTestBase::createFieldWithInstance()
FieldAttachOtherTest::setUp in drupal/core/modules/field/lib/Drupal/field/Tests/FieldAttachOtherTest.php
Set the default field storage backend for fields created during tests.
FieldAttachOtherTest::testFieldAttachExtractFormValues in drupal/core/modules/field/lib/Drupal/field/Tests/FieldAttachOtherTest.php
Test field_attach_extract_form_values().
FieldAttachOtherTest::testFieldAttachForm in drupal/core/modules/field/lib/Drupal/field/Tests/FieldAttachOtherTest.php
Test field_attach_form().
FieldAttachOtherTest::testFieldAttachValidate in drupal/core/modules/field/lib/Drupal/field/Tests/FieldAttachOtherTest.php
Test field_attach_validate().
FieldAttachOtherTest::testFieldAttachView in drupal/core/modules/field/lib/Drupal/field/Tests/FieldAttachOtherTest.php
Test field_attach_view() and field_attach_prepare_view().

... See full list

File

drupal/core/modules/field/lib/Drupal/field/Tests/FieldUnitTestBase.php, line 52
Contains \Drupal\field\Tests\FieldUnitTestBase.

Class

FieldUnitTestBase
Parent class for Field API unit tests.

Namespace

Drupal\field\Tests

Code

function createFieldWithInstance($suffix = '') {
  $field_name = 'field_name' . $suffix;
  $field = 'field' . $suffix;
  $field_id = 'field_id' . $suffix;
  $instance = 'instance' . $suffix;
  $this->{$field_name} = drupal_strtolower($this
    ->randomName() . '_field_name' . $suffix);
  $this->{$field} = array(
    'field_name' => $this->{$field_name},
    'type' => 'test_field',
    'cardinality' => 4,
  );
  $this->{$field} = field_create_field($this->{$field});
  $this->{$field_id} = $this->{$field}['uuid'];
  $this->{$instance} = array(
    'field_name' => $this->{$field_name},
    'entity_type' => 'test_entity',
    'bundle' => 'test_bundle',
    'label' => $this
      ->randomName() . '_label',
    'description' => $this
      ->randomName() . '_description',
    'weight' => mt_rand(0, 127),
    'settings' => array(
      'test_instance_setting' => $this
        ->randomName(),
    ),
  );
  field_create_instance($this->{$instance});
  entity_get_form_display('test_entity', 'test_bundle', 'default')
    ->setComponent($this->{$field_name}, array(
    'type' => 'test_field_widget',
    'settings' => array(
      'test_widget_setting' => $this
        ->randomName(),
    ),
  ))
    ->save();
}