function FieldAttachStorageTest::testEntityCreateBundle in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/field/src/Tests/FieldAttachStorageTest.php \Drupal\field\Tests\FieldAttachStorageTest::testEntityCreateBundle()
 
Test entity_bundle_create().
File
- core/
modules/ field/ src/ Tests/ FieldAttachStorageTest.php, line 280  - Contains \Drupal\field\Tests\FieldAttachStorageTest.
 
Class
- FieldAttachStorageTest
 - Tests storage-related Field Attach API functions.
 
Namespace
Drupal\field\TestsCode
function testEntityCreateBundle() {
  $entity_type = 'entity_test_rev';
  $this
    ->createFieldWithStorage('', $entity_type);
  $cardinality = $this->fieldTestData->field_storage
    ->getCardinality();
  // Create a new bundle.
  $new_bundle = 'test_bundle_' . Unicode::strtolower($this
    ->randomMachineName());
  entity_test_create_bundle($new_bundle, NULL, $entity_type);
  // Add a field to that bundle.
  $this->fieldTestData->field_definition['bundle'] = $new_bundle;
  entity_create('field_config', $this->fieldTestData->field_definition)
    ->save();
  // Save an entity with data in the field.
  $entity = entity_create($entity_type, array(
    'type' => $this->fieldTestData->field
      ->getTargetBundle(),
  ));
  $values = $this
    ->_generateTestFieldValues($cardinality);
  $entity->{$this->fieldTestData->field_name} = $values;
  // Verify the field data is present on load.
  $entity = $this
    ->entitySaveReload($entity);
  $this
    ->assertEqual(count($entity->{$this->fieldTestData->field_name}), $cardinality, "Data is retrieved for the new bundle");
}