X-Git-Url: http://aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=web%2Fcore%2Fmodules%2Ffield%2Fsrc%2FTests%2FFieldImportDeleteUninstallUiTest.php;fp=web%2Fcore%2Fmodules%2Ffield%2Fsrc%2FTests%2FFieldImportDeleteUninstallUiTest.php;h=e35308603f99a14f303f594db2e58475fbdfce03;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hp=0000000000000000000000000000000000000000;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad;p=yaffs-website diff --git a/web/core/modules/field/src/Tests/FieldImportDeleteUninstallUiTest.php b/web/core/modules/field/src/Tests/FieldImportDeleteUninstallUiTest.php new file mode 100644 index 000000000..e35308603 --- /dev/null +++ b/web/core/modules/field/src/Tests/FieldImportDeleteUninstallUiTest.php @@ -0,0 +1,117 @@ +drupalLogin($this->drupalCreateUser(['synchronize configuration'])); + } + + /** + * Tests deleting field storages and fields as part of config import. + */ + public function testImportDeleteUninstall() { + // Create a telephone field. + $field_storage = FieldStorageConfig::create([ + 'field_name' => 'field_tel', + 'entity_type' => 'entity_test', + 'type' => 'telephone', + ]); + $field_storage->save(); + FieldConfig::create([ + 'field_storage' => $field_storage, + 'bundle' => 'entity_test', + ])->save(); + + // Create a text field. + $date_field_storage = FieldStorageConfig::create([ + 'field_name' => 'field_date', + 'entity_type' => 'entity_test', + 'type' => 'datetime', + ]); + $date_field_storage->save(); + FieldConfig::create([ + 'field_storage' => $date_field_storage, + 'bundle' => 'entity_test', + ])->save(); + + // Create an entity which has values for the telephone and text field. + $entity = EntityTest::create(); + $value = '+0123456789'; + $entity->field_tel = $value; + $entity->field_date = time(); + $entity->name->value = $this->randomMachineName(); + $entity->save(); + + // Delete the text field before exporting configuration so that we can test + // that deleted fields that are provided by modules that will be uninstalled + // are also purged and that the UI message includes such fields. + $date_field_storage->delete(); + + // Verify entity has been created properly. + $id = $entity->id(); + $entity = EntityTest::load($id); + $this->assertEqual($entity->field_tel->value, $value); + $this->assertEqual($entity->field_tel[0]->value, $value); + + $active = $this->container->get('config.storage'); + $sync = $this->container->get('config.storage.sync'); + $this->copyConfig($active, $sync); + + // Stage uninstall of the Telephone module. + $core_extension = $this->config('core.extension')->get(); + unset($core_extension['module']['telephone']); + $sync->write('core.extension', $core_extension); + + // Stage the field deletion + $sync->delete('field.storage.entity_test.field_tel'); + $sync->delete('field.field.entity_test.entity_test.field_tel'); + $this->drupalGet('admin/config/development/configuration'); + // Test that the message for one field being purged during a configuration + // synchronization is correct. + $this->assertText('This synchronization will delete data from the field entity_test.field_tel.'); + + // Stage an uninstall of the datetime module to test the message for + // multiple fields. + unset($core_extension['module']['datetime']); + $sync->write('core.extension', $core_extension); + + $this->drupalGet('admin/config/development/configuration'); + $this->assertText('This synchronization will delete data from the fields: entity_test.field_tel, entity_test.field_date.'); + + // This will purge all the data, delete the field and uninstall the + // Telephone and Text modules. + $this->drupalPostForm(NULL, [], t('Import all')); + $this->assertNoText('Field data will be deleted by this synchronization.'); + $this->rebuildContainer(); + $this->assertFalse(\Drupal::moduleHandler()->moduleExists('telephone')); + $this->assertFalse(\Drupal::entityManager()->loadEntityByUuid('field_storage_config', $field_storage->uuid()), 'The telephone field has been deleted by the configuration synchronization'); + $deleted_storages = \Drupal::state()->get('field.storage.deleted') ?: []; + $this->assertFalse(isset($deleted_storages[$field_storage->uuid()]), 'Telephone field has been completed removed from the system.'); + $this->assertFalse(isset($deleted_storages[$field_storage->uuid()]), 'Text field has been completed removed from the system.'); + } + +}