diff --git a/core/modules/field/tests/src/Kernel/BulkDeleteTest.php b/core/modules/field/tests/src/Kernel/BulkDeleteTest.php index 6890bda..b01926a 100644 --- a/core/modules/field/tests/src/Kernel/BulkDeleteTest.php +++ b/core/modules/field/tests/src/Kernel/BulkDeleteTest.php @@ -212,22 +212,22 @@ function testDeleteField() { } /** - * Tests... + * Tests that recreating a field with the name as a deleted field works. */ public function testPurgeWithDeletedAndActiveField() { $bundle = reset($this->bundles); // Create another field storage. $field_name = 'bf_3'; - $field_storage = FieldStorageConfig::create(array( + $deleted_field_storage = FieldStorageConfig::create(array( 'field_name' => $field_name, 'entity_type' => $this->entityTypeId, 'type' => 'test_field', 'cardinality' => 1 )); - $field_storage->save(); + $deleted_field_storage->save(); // Create the field. FieldConfig::create([ - 'field_storage' => $field_storage, + 'field_storage' => $deleted_field_storage, 'bundle' => $bundle, ])->save(); @@ -240,9 +240,13 @@ public function testPurgeWithDeletedAndActiveField() { } // Delete the field. - $field = FieldConfig::loadByName($this->entityTypeId, $bundle, $field_name); - $field->delete(); - $uuid = $field->uuid(); + $deleted_field = FieldConfig::loadByName($this->entityTypeId, $bundle, $field_name); + $deleted_field->delete(); + $deleted_field_uuid = $deleted_field->uuid(); + + // Reload the field storage. + $field_storages = entity_load_multiple_by_properties('field_storage_config', array('uuid' => $deleted_field_storage->uuid(), 'include_deleted' => TRUE)); + $deleted_field_storage = reset($field_storages); // Create the field again. $field_storage = FieldStorageConfig::create(array( @@ -258,9 +262,9 @@ public function testPurgeWithDeletedAndActiveField() { ])->save(); // The field still exists, deleted, with the same field name. - $fields = entity_load_multiple_by_properties('field_config', array('uuid' => $uuid, 'include_deleted' => TRUE)); - $this->assertTrue(isset($fields[$uuid]) && $fields[$uuid]->isDeleted(), 'The field exists and is deleted'); - $this->assertTrue(isset($fields[$uuid]) && $fields[$uuid]->getName() == $field_name); + $fields = entity_load_multiple_by_properties('field_config', array('uuid' => $deleted_field_uuid, 'include_deleted' => TRUE)); + $this->assertTrue(isset($fields[$deleted_field_uuid]) && $fields[$deleted_field_uuid]->isDeleted(), 'The field exists and is deleted'); + $this->assertTrue(isset($fields[$deleted_field_uuid]) && $fields[$deleted_field_uuid]->getName() == $field_name); for ($i = 0; $i < 10; $i++) { $entity = $this->container->get('entity_type.manager') @@ -270,8 +274,24 @@ public function testPurgeWithDeletedAndActiveField() { $entity->save(); } + // Check that the two field storages have different tables. + $storage = \Drupal::entityManager()->getStorage($this->entityTypeId); + /** @var \Drupal\Core\Entity\Sql\DefaultTableMapping $table_mapping */ + $table_mapping = $storage->getTableMapping(); + $deleted_table_name = $table_mapping->getDedicatedDataTableName($deleted_field_storage, TRUE); + $active_table_name = $table_mapping->getDedicatedDataTableName($field_storage); + field_purge_batch(50); + // Ensure the new field still has its table and the deleted one has been + // removed. + $this->assertTrue(\Drupal::database()->schema()->tableExists($active_table_name)); + $this->assertFalse(\Drupal::database()->schema()->tableExists($deleted_table_name)); + + // The field has been removed from the system. + $fields = entity_load_multiple_by_properties('field_config', array('field_storage_uuid' => $deleted_field_storage->uuid(), 'deleted' => TRUE, 'include_deleted' => TRUE)); + $this->assertEqual(count($fields), 0, 'The field is gone'); + // Verify there are still 10 entries in the main table. $count = \Drupal::database() ->select('entity_test__' . $field_name, 'f')