View source
<?php
namespace Drupal\field\Tests;
class FieldImportDeleteUninstallUiTest extends FieldTestBase {
public static $modules = array(
'entity_test',
'telephone',
'config',
'filter',
'datetime',
);
protected function setUp() {
parent::setUp();
$this
->drupalLogin($this
->drupalCreateUser(array(
'synchronize configuration',
)));
}
public function testImportDeleteUninstall() {
$field_storage = entity_create('field_storage_config', array(
'field_name' => 'field_tel',
'entity_type' => 'entity_test',
'type' => 'telephone',
));
$field_storage
->save();
entity_create('field_config', array(
'field_storage' => $field_storage,
'bundle' => 'entity_test',
))
->save();
$date_field_storage = entity_create('field_storage_config', array(
'field_name' => 'field_date',
'entity_type' => 'entity_test',
'type' => 'datetime',
));
$date_field_storage
->save();
entity_create('field_config', array(
'field_storage' => $date_field_storage,
'bundle' => 'entity_test',
))
->save();
$entity = entity_create('entity_test');
$value = '+0123456789';
$entity->field_tel = $value;
$entity->field_date = time();
$entity->name->value = $this
->randomMachineName();
$entity
->save();
$date_field_storage
->delete();
$id = $entity
->id();
$entity = entity_load('entity_test', $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);
$core_extension = $this
->config('core.extension')
->get();
unset($core_extension['module']['telephone']);
$sync
->write('core.extension', $core_extension);
$sync
->delete('field.storage.entity_test.field_tel');
$sync
->delete('field.field.entity_test.entity_test.field_tel');
$this
->drupalGet('admin/config/development/configuration');
$this
->assertText('This synchronization will delete data from the field entity_test.field_tel.');
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
->drupalPostForm(NULL, array(), 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') ?: array();
$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.');
}
}