/**
  * {@inheritdoc}
  */
 public function setUp()
 {
     parent::setUp();
     $this->installEntitySchema('entity_test_rev');
     $this->installEntitySchema('user');
     $field_name = 'test';
     $this->fieldStorage = FieldStorageConfig::create(['field_name' => $field_name, 'entity_type' => 'entity_test_rev', 'type' => 'string', 'cardinality' => 1]);
     $this->fieldStorage->save();
     $this->field = FieldConfig::create(['field_name' => $field_name, 'entity_type' => 'entity_test_rev', 'bundle' => 'entity_test_rev', 'required' => TRUE]);
     $this->field->save();
     // Create an entity with field data.
     $this->entity = EntityTestRev::create(['user_id' => mt_rand(1, 10), 'name' => $this->randomMachineName(), $field_name => $this->randomString()]);
     $this->entity->save();
 }
示例#2
0
 protected function setUp()
 {
     parent::setUp();
     // Create two content types. One will have an autocomplete tagging field,
     // and one won't.
     $this->nodeTypeWithTags = $this->drupalCreateContentType();
     $this->nodeTypeWithoutTags = $this->drupalCreateContentType();
     // Create the vocabulary for the tag field.
     $this->tagVocabulary = entity_create('taxonomy_vocabulary', array('name' => 'Views testing tags', 'vid' => 'views_testing_tags'));
     $this->tagVocabulary->save();
     // Create the tag field itself.
     $this->tagFieldName = 'field_views_testing_tags';
     $this->tagFieldStorage = entity_create('field_storage_config', array('field_name' => $this->tagFieldName, 'entity_type' => 'node', 'type' => 'taxonomy_term_reference', 'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED, 'settings' => array('allowed_values' => array(array('vocabulary' => $this->tagVocabulary->id(), 'parent' => 0)))));
     $this->tagFieldStorage->save();
     // Create an instance of the tag field on one of the content types, and
     // configure it to display an autocomplete widget.
     $this->tagField = array('field_storage' => $this->tagFieldStorage, 'bundle' => $this->nodeTypeWithTags->id());
     entity_create('field_config', $this->tagField)->save();
     entity_get_form_display('node', $this->nodeTypeWithTags->id(), 'default')->setComponent('field_views_testing_tags', array('type' => 'taxonomy_autocomplete'))->save();
     entity_get_display('node', $this->nodeTypeWithTags->id(), 'default')->setComponent('field_views_testing_tags', array('type' => 'taxonomy_term_reference_link', 'weight' => 10))->save();
     entity_get_display('node', $this->nodeTypeWithTags->id(), 'teaser')->setComponent('field_views_testing_tags', array('type' => 'taxonomy_term_reference_link', 'weight' => 10))->save();
 }
 /**
  * Tests that vocabulary machine name changes are mirrored in field definitions.
  */
 function testTaxonomyTermFieldChangeMachineName()
 {
     // Add several entries in the 'allowed_values' setting, to make sure that
     // they all get updated.
     $this->field_storage->settings['allowed_values'] = array(array('vocabulary' => $this->vocabulary->id(), 'parent' => '0'), array('vocabulary' => $this->vocabulary->id(), 'parent' => '0'), array('vocabulary' => 'foo', 'parent' => '0'));
     $this->field_storage->save();
     // Change the machine name.
     $new_name = drupal_strtolower($this->randomMachineName());
     $this->vocabulary->vid = $new_name;
     $this->vocabulary->save();
     // Check that the field is still attached to the vocabulary.
     $field_storage = FieldStorageConfig::loadByName('entity_test', $this->field_name);
     $allowed_values = $field_storage->getSetting('allowed_values');
     $this->assertEqual($allowed_values[0]['vocabulary'], $new_name, 'Index 0: Machine name was updated correctly.');
     $this->assertEqual($allowed_values[1]['vocabulary'], $new_name, 'Index 1: Machine name was updated correctly.');
     $this->assertEqual($allowed_values[2]['vocabulary'], 'foo', 'Index 2: Machine name was left untouched.');
 }
 /**
  * {@inheritdoc}
  */
 public function save(array $form, FormStateInterface $form_state)
 {
     $field_label = $form_state->get('field_config')->label();
     try {
         $this->entity->save();
         drupal_set_message($this->t('Updated field %label field settings.', array('%label' => $field_label)));
         $request = $this->getRequest();
         if (($destinations = $request->query->get('destinations')) && ($next_destination = FieldUI::getNextDestination($destinations))) {
             $request->query->remove('destinations');
             $form_state->setRedirectUrl($next_destination);
         } else {
             $form_state->setRedirectUrl(FieldUI::getOverviewRouteInfo($form_state->get('entity_type_id'), $form_state->get('bundle')));
         }
     } catch (\Exception $e) {
         drupal_set_message($this->t('Attempt to update field %label failed: %message.', array('%label' => $field_label, '%message' => $e->getMessage())), 'error');
     }
 }
 /**
  * Tests a simple site export import case.
  */
 public function testExportImport()
 {
     // After installation there is no snapshot and nothing to import.
     $this->drupalGet('admin/config/development/configuration');
     $this->assertNoText(t('Warning message'));
     $this->assertText(t('There are no configuration changes to import.'));
     $this->originalSlogan = $this->config('system.site')->get('slogan');
     $this->newSlogan = $this->randomString(16);
     $this->assertNotEqual($this->newSlogan, $this->originalSlogan);
     $this->config('system.site')->set('slogan', $this->newSlogan)->save();
     $this->assertEqual($this->config('system.site')->get('slogan'), $this->newSlogan);
     // Create a content type.
     $this->contentType = $this->drupalCreateContentType();
     // Create a field.
     $this->fieldName = Unicode::strtolower($this->randomMachineName());
     $this->fieldStorage = entity_create('field_storage_config', array('field_name' => $this->fieldName, 'entity_type' => 'node', 'type' => 'text'));
     $this->fieldStorage->save();
     entity_create('field_config', array('field_storage' => $this->fieldStorage, 'bundle' => $this->contentType->id()))->save();
     // Update the displays so that configuration does not change unexpectedly on
     // import.
     entity_get_form_display('node', $this->contentType->id(), 'default')->setComponent($this->fieldName, array('type' => 'text_textfield'))->save();
     entity_get_display('node', $this->contentType->id(), 'full')->setComponent($this->fieldName)->save();
     entity_get_display('node', $this->contentType->id(), 'default')->setComponent($this->fieldName)->save();
     entity_get_display('node', $this->contentType->id(), 'teaser')->removeComponent($this->fieldName)->save();
     $this->drupalGet('node/add/' . $this->contentType->id());
     $this->assertFieldByName("{$this->fieldName}[0][value]", '', 'Widget is displayed');
     // Export the configuration.
     $this->drupalPostForm('admin/config/development/configuration/full/export', array(), 'Export');
     $this->tarball = $this->getRawContent();
     $this->config('system.site')->set('slogan', $this->originalSlogan)->save();
     $this->assertEqual($this->config('system.site')->get('slogan'), $this->originalSlogan);
     // Delete the custom field.
     $fields = FieldConfig::loadMultiple();
     foreach ($fields as $field) {
         if ($field->getName() == $this->fieldName) {
             $field->delete();
         }
     }
     $field_storages = FieldStorageConfig::loadMultiple();
     foreach ($field_storages as $field_storage) {
         if ($field_storage->getName() == $this->fieldName) {
             $field_storage->delete();
         }
     }
     $this->drupalGet('node/add/' . $this->contentType->id());
     $this->assertNoFieldByName("{$this->fieldName}[0][value]", '', 'Widget is not displayed');
     // Import the configuration.
     $filename = 'temporary://' . $this->randomMachineName();
     file_put_contents($filename, $this->tarball);
     $this->drupalPostForm('admin/config/development/configuration/full/import', array('files[import_tarball]' => $filename), 'Upload');
     // There is no snapshot yet because an import has never run.
     $this->assertNoText(t('Warning message'));
     $this->assertNoText(t('There are no configuration changes to import.'));
     $this->assertText($this->contentType->label());
     $this->drupalPostForm(NULL, array(), 'Import all');
     // After importing the snapshot has been updated an there are no warnings.
     $this->assertNoText(t('Warning message'));
     $this->assertText(t('There are no configuration changes to import.'));
     $this->assertEqual($this->config('system.site')->get('slogan'), $this->newSlogan);
     $this->drupalGet('node/add');
     $this->assertFieldByName("{$this->fieldName}[0][value]", '', 'Widget is displayed');
     $this->config('system.site')->set('slogan', $this->originalSlogan)->save();
     $this->drupalGet('admin/config/development/configuration');
     $this->assertText(t('Warning message'));
     $this->assertText('The following items in your active configuration have changes since the last import that may be lost on the next import.');
     // Ensure the item is displayed as part of a list (to avoid false matches
     // on the rest of the page) and that the list markup is not escaped.
     $this->assertRaw('<li>system.site</li>');
     // Remove everything from staging. The warning about differences between the
     // active and snapshot should no longer exist.
     \Drupal::service('config.storage.staging')->deleteAll();
     $this->drupalGet('admin/config/development/configuration');
     $this->assertNoText(t('Warning message'));
     $this->assertNoText('The following items in your active configuration have changes since the last import that may be lost on the next import.');
     $this->assertText(t('There are no configuration changes to import.'));
     // Write a file to staging. The warning about differences between the
     // active and snapshot should now exist.
     /** @var \Drupal\Core\Config\StorageInterface $staging */
     $staging = $this->container->get('config.storage.staging');
     $data = $this->config('system.site')->get();
     $data['slogan'] = 'in the face';
     $this->copyConfig($this->container->get('config.storage'), $staging);
     $staging->write('system.site', $data);
     $this->drupalGet('admin/config/development/configuration');
     $this->assertText(t('Warning message'));
     $this->assertText('The following items in your active configuration have changes since the last import that may be lost on the next import.');
     // Ensure the item is displayed as part of a list (to avoid false matches
     // on the rest of the page) and that the list markup is not escaped.
     $this->assertRaw('<li>system.site</li>');
 }
 /**
  * Tests a simple site export import case.
  */
 public function testExportImport()
 {
     // After installation there is no snapshot and nothing to import.
     $this->drupalGet('admin/config/development/configuration');
     $this->assertNoText(t('Warning message'));
     $this->assertText(t('There are no configuration changes to import.'));
     $this->originalSlogan = $this->config('system.site')->get('slogan');
     $this->newSlogan = $this->randomString(16);
     $this->assertNotEqual($this->newSlogan, $this->originalSlogan);
     $this->config('system.site')->set('slogan', $this->newSlogan)->save();
     $this->assertEqual($this->config('system.site')->get('slogan'), $this->newSlogan);
     // Create a content type.
     $this->contentType = $this->drupalCreateContentType();
     // Create a field.
     $this->fieldName = Unicode::strtolower($this->randomMachineName());
     $this->fieldStorage = entity_create('field_storage_config', array('field_name' => $this->fieldName, 'entity_type' => 'node', 'type' => 'text'));
     $this->fieldStorage->save();
     entity_create('field_config', array('field_storage' => $this->fieldStorage, 'bundle' => $this->contentType->id()))->save();
     // Update the displays so that configuration does not change unexpectedly on
     // import.
     entity_get_form_display('node', $this->contentType->id(), 'default')->setComponent($this->fieldName, array('type' => 'text_textfield'))->save();
     entity_get_display('node', $this->contentType->id(), 'full')->setComponent($this->fieldName)->save();
     entity_get_display('node', $this->contentType->id(), 'default')->setComponent($this->fieldName)->save();
     entity_get_display('node', $this->contentType->id(), 'teaser')->removeComponent($this->fieldName)->save();
     $this->drupalGet('node/add/' . $this->contentType->id());
     $this->assertFieldByName("{$this->fieldName}[0][value]", '', 'Widget is displayed');
     // Export the configuration.
     $this->drupalPostForm('admin/config/development/configuration/full/export', array(), 'Export');
     $this->tarball = $this->getRawContent();
     $this->config('system.site')->set('slogan', $this->originalSlogan)->save();
     $this->assertEqual($this->config('system.site')->get('slogan'), $this->originalSlogan);
     // Delete the custom field.
     $fields = FieldConfig::loadMultiple();
     foreach ($fields as $field) {
         if ($field->field_name == $this->fieldName) {
             $field->delete();
         }
     }
     $field_storages = FieldStorageConfig::loadMultiple();
     foreach ($field_storages as $field_storage) {
         if ($field_storage->getName() == $this->fieldName) {
             $field_storage->delete();
         }
     }
     $this->drupalGet('node/add/' . $this->contentType->id());
     $this->assertNoFieldByName("{$this->fieldName}[0][value]", '', 'Widget is not displayed');
     // Import the configuration.
     $filename = 'temporary://' . $this->randomMachineName();
     file_put_contents($filename, $this->tarball);
     $this->drupalPostForm('admin/config/development/configuration/full/import', array('files[import_tarball]' => $filename), 'Upload');
     // There is no snapshot yet because an import has never run.
     $this->assertNoText(t('Warning message'));
     $this->assertNoText(t('There are no configuration changes to import.'));
     $this->assertText($this->contentType->label());
     $this->drupalPostForm(NULL, array(), 'Import all');
     // After importing the snapshot has been updated an there are no warnings.
     $this->assertNoText(t('Warning message'));
     $this->assertText(t('There are no configuration changes to import.'));
     $this->assertEqual($this->config('system.site')->get('slogan'), $this->newSlogan);
     $this->drupalGet('node/add');
     $this->assertFieldByName("{$this->fieldName}[0][value]", '', 'Widget is displayed');
     $this->config('system.site')->set('slogan', $this->originalSlogan)->save();
     $this->drupalGet('admin/config/development/configuration');
     $this->assertText(t('Warning message'));
     $this->assertText('Your current configuration has changed. Changes to these configuration items will be lost on the next synchronization: system.site');
     // Remove everything from staging. The warning about differences between the
     // active and snapshot should still exist.
     \Drupal::service('config.storage.staging')->deleteAll();
     $this->drupalGet('admin/config/development/configuration');
     $this->assertText(t('Warning message'));
     $this->assertText('Your current configuration has changed. Changes to these configuration items will be lost on the next synchronization: system.site');
     $this->assertText(t('There are no configuration changes to import.'));
 }