You are here

public function FieldCollectionBasicTestCase::testFieldDeletion in Field collection 8.3

Same name and namespace in other branches
  1. 8 tests/src/Functional/FieldCollectionBasicTestCase.php \Drupal\Tests\field_collection\Functional\FieldCollectionBasicTestCase::testFieldDeletion()

Test deleting the field corresponding to a field collection.

File

tests/src/Functional/FieldCollectionBasicTestCase.php, line 179

Class

FieldCollectionBasicTestCase
Test basics.

Namespace

Drupal\Tests\field_collection\Functional

Code

public function testFieldDeletion() {

  // Create a separate content type with the field collection field.
  $this
    ->drupalCreateContentType([
    'type' => 'test_content_type',
    'name' => 'Test content type',
  ]);
  $field_collection_field_1 = $this->field_collection_field;
  $field_collection_field_2 = $this
    ->addFieldCollectionFieldToContentType('test_content_type');
  list(, $field_collection_item_1) = $this
    ->createNodeWithFieldCollection('article');
  list(, $field_collection_item_2) = $this
    ->createNodeWithFieldCollection('test_content_type');

  /** @var \Drupal\field_collection\FieldCollectionItemInterface $field_collection_item_1 */
  $field_collection_item_id_1 = $field_collection_item_1
    ->id();

  /** @var \Drupal\field_collection\FieldCollectionItemInterface $field_collection_item_2 */
  $field_collection_item_id_2 = $field_collection_item_2
    ->id();
  $field_collection_field_1
    ->delete();
  field_purge_batch(100);
  $this
    ->assertNull(FieldCollectionItem::load($field_collection_item_id_1), 'field_collection_item deleted with the field_collection field.');
  $this
    ->assertNotNull(FieldCollectionItem::load($field_collection_item_id_2), 'Other field_collection_item still exists.');
  $this
    ->assertNotNull(FieldCollection::load($this->field_collection_name), 'field_collection config entity still exists.');
  $field_collection_field_2
    ->delete();
  field_purge_batch(100);
  $this
    ->assertNull(FieldCollectionItem::load($field_collection_item_id_2), 'Other field_collection_item deleted with it\'s field.');
  $this
    ->assertNull(FieldCollection::load($this->field_collection_name), 'field_collection config entity deleted.');
}