You are here

public function DuplicateFieldCollectionTest::testDuplicateFieldCollection in Field collection 8.3

Same name and namespace in other branches
  1. 8 tests/src/Kernel/DuplicateFieldCollectionTest.php \Drupal\Tests\field_collection\Kernel\DuplicateFieldCollectionTest::testDuplicateFieldCollection()

Ensures field_collection_field_storage_config_insert() works correctly.

File

tests/src/Kernel/DuplicateFieldCollectionTest.php, line 32

Class

DuplicateFieldCollectionTest
Tests importing field_collection from config.

Namespace

Drupal\Tests\field_collection\Kernel

Code

public function testDuplicateFieldCollection() {
  $values = [
    'type' => 'field_collection',
    'field_name' => 'my_collection',
    'label' => 'My Collection',
  ];
  FieldStorageConfig::create($values + [
    'entity_type' => 'user',
  ])
    ->save();

  // Change the label of the field collection.
  $field_collection_first = FieldCollection::load('my_collection');
  $field_collection_first
    ->set('label', 'A new label');
  $field_collection_first
    ->save();
  FieldStorageConfig::create($values + [
    'entity_type' => 'node',
  ])
    ->save();

  // If field_collection_field_storage_config_insert() had created a new field
  // collection, it would not have the custom name.
  $field_collection_second = FieldCollection::load('my_collection');
  $this
    ->assertSame('A new label', $field_collection_second
    ->label());
}