You are here

function FieldStorageCrudTest::testRead in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/field/src/Tests/FieldStorageCrudTest.php \Drupal\field\Tests\FieldStorageCrudTest::testRead()

Tests reading field storage definitions.

File

core/modules/field/src/Tests/FieldStorageCrudTest.php, line 209
Contains \Drupal\field\Tests\FieldStorageCrudTest.

Class

FieldStorageCrudTest
Tests field storage create, read, update, and delete.

Namespace

Drupal\field\Tests

Code

function testRead() {
  $field_storage_definition = array(
    'field_name' => 'field_1',
    'entity_type' => 'entity_test',
    'type' => 'test_field',
  );
  $field_storage = entity_create('field_storage_config', $field_storage_definition);
  $field_storage
    ->save();
  $id = $field_storage
    ->id();

  // Check that 'single column' criteria works.
  $fields = entity_load_multiple_by_properties('field_storage_config', array(
    'field_name' => $field_storage_definition['field_name'],
  ));
  $this
    ->assertTrue(count($fields) == 1 && isset($fields[$id]), 'The field was properly read.');

  // Check that 'multi column' criteria works.
  $fields = entity_load_multiple_by_properties('field_storage_config', array(
    'field_name' => $field_storage_definition['field_name'],
    'type' => $field_storage_definition['type'],
  ));
  $this
    ->assertTrue(count($fields) == 1 && isset($fields[$id]), 'The field was properly read.');
  $fields = entity_load_multiple_by_properties('field_storage_config', array(
    'field_name' => $field_storage_definition['field_name'],
    'type' => 'foo',
  ));
  $this
    ->assertTrue(empty($fields), 'No field was found.');

  // Create a field from the field storage.
  $field_definition = array(
    'field_name' => $field_storage_definition['field_name'],
    'entity_type' => 'entity_test',
    'bundle' => 'entity_test',
  );
  entity_create('field_config', $field_definition)
    ->save();
}