Beispiel #1
0
 /**
  * Enables the exportables module.
  */
 function dsExportablesSetup()
 {
     /** @var $display EntityViewDisplay */
     $display = EntityViewDisplay::load('node.article.default');
     $display->delete();
     \Drupal::service('module_installer')->install(array('ds_exportables_test'));
 }
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->drupalPlaceBlock('local_tasks_block');
     $this->drupalPlaceBlock('local_actions_block');
     $this->drupalPlaceBlock('page_title_block');
     $this->type = $this->createProfileType('test', 'Test profile', TRUE);
     $id = $this->type->id();
     $field_storage = FieldStorageConfig::create(['field_name' => 'profile_fullname', 'entity_type' => 'profile', 'type' => 'text']);
     $field_storage->save();
     $this->field = FieldConfig::create(['field_storage' => $field_storage, 'bundle' => $this->type->id(), 'label' => 'Full name']);
     $this->field->save();
     // Configure the default display.
     $this->display = EntityViewDisplay::load("profile.{$this->type->id()}.default");
     if (!$this->display) {
         $this->display = EntityViewDisplay::create(['targetEntityType' => 'profile', 'bundle' => $this->type->id(), 'mode' => 'default', 'status' => TRUE]);
         $this->display->save();
     }
     $this->display->setComponent($this->field->getName(), ['type' => 'string'])->save();
     // Configure rhe default form.
     $this->form = EntityFormDisplay::load("profile.{$this->type->id()}.default");
     if (!$this->form) {
         $this->form = EntityFormDisplay::create(['targetEntityType' => 'profile', 'bundle' => $this->type->id(), 'mode' => 'default', 'status' => TRUE]);
         $this->form->save();
     }
     $this->form->setComponent($this->field->getName(), ['type' => 'string_textfield'])->save();
     $this->checkPermissions(['administer profile types', "view own {$id} profile", "view any {$id} profile", "add own {$id} profile", "add any {$id} profile", "edit own {$id} profile", "edit any {$id} profile", "delete own {$id} profile", "delete any {$id} profile"]);
     user_role_grant_permissions(AccountInterface::AUTHENTICATED_ROLE, ['access user profiles']);
     $this->adminUser = $this->drupalCreateUser(['administer profile types', "view any {$id} profile", "add any {$id} profile", "edit any {$id} profile", "delete any {$id} profile"]);
 }
 /**
  * Tests the Drupal 7 user picture to Drupal 8 entity display migration.
  */
 public function testUserPictureEntityDisplay()
 {
     $component = EntityViewDisplay::load('user.user.default')->getComponent('user_picture');
     $this->assertIdentical('image', $component['type']);
     $this->assertIdentical('', $component['settings']['image_style']);
     $this->assertIdentical('content', $component['settings']['image_link']);
 }
 /**
  * Tests markup is escaped in the entity reference select and label formatter.
  */
 public function testEntityReferenceXSS()
 {
     $this->drupalCreateContentType(['type' => 'article']);
     // Create a node with markup in the title.
     $node_type_one = $this->drupalCreateContentType();
     $node = ['type' => $node_type_one->id(), 'title' => '<em>I am kitten</em>'];
     $referenced_node = $this->drupalCreateNode($node);
     $node_type_two = $this->drupalCreateContentType(['name' => '<em>bundle with markup</em>']);
     $this->drupalCreateNode(['type' => $node_type_two->id(), 'title' => 'My bundle has markup']);
     $this->createEntityReferenceField('node', 'article', 'entity_reference_test', 'Entity Reference test', 'node', 'default', ['target_bundles' => [$node_type_one->id(), $node_type_two->id()]]);
     EntityFormDisplay::load('node.article.default')->setComponent('entity_reference_test', ['type' => 'options_select'])->save();
     EntityViewDisplay::load('node.article.default')->setComponent('entity_reference_test', ['type' => 'entity_reference_label'])->save();
     // Create a node and reference the node with markup in the title.
     $this->drupalLogin($this->rootUser);
     $this->drupalGet('node/add/article');
     $this->assertEscaped($referenced_node->getTitle());
     $this->assertEscaped($node_type_two->label());
     $edit = ['title[0][value]' => $this->randomString(), 'entity_reference_test' => $referenced_node->id()];
     $this->drupalPostForm(NULL, $edit, 'Save and publish');
     $this->assertEscaped($referenced_node->getTitle());
     // Test the options_buttons type.
     EntityFormDisplay::load('node.article.default')->setComponent('entity_reference_test', ['type' => 'options_buttons'])->save();
     $this->drupalGet('node/add/article');
     $this->assertEscaped($referenced_node->getTitle());
     // options_buttons does not support optgroups.
     $this->assertNoText('bundle with markup');
 }
 /**
  * Asserts a display entity.
  *
  * @param string $id
  *   The entity ID.
  * @param string $component_id
  *   The ID of the display component.
  */
 protected function assertDisplay($id, $component_id)
 {
     $component = EntityViewDisplay::load($id)->getComponent($component_id);
     $this->assertTrue(is_array($component));
     $this->assertIdentical('hidden', $component['label']);
     $this->assertIdentical('comment_default', $component['type']);
     $this->assertIdentical(20, $component['weight']);
 }
 /**
  * Tests comment variables migrated into an entity display.
  */
 public function testCommentEntityDisplay()
 {
     foreach (['page', 'story', 'article'] as $type) {
         $component = EntityViewDisplay::load('node.' . $type . '.default')->getComponent('comment');
         $this->assertIdentical('hidden', $component['label']);
         $this->assertIdentical('comment_default', $component['type']);
         $this->assertIdentical(20, $component['weight']);
     }
 }
 /**
  * Tests the dependency between ImageStyle and entity display components.
  */
 public function testEntityDisplayDependency()
 {
     // Create two image styles.
     /** @var \Drupal\image\ImageStyleInterface $style */
     $style = ImageStyle::create(['name' => 'main_style']);
     $style->save();
     /** @var \Drupal\image\ImageStyleInterface $replacement */
     $replacement = ImageStyle::create(['name' => 'replacement_style']);
     $replacement->save();
     // Create a node-type, named 'note'.
     $node_type = NodeType::create(['type' => 'note']);
     $node_type->save();
     // Create an image field and attach it to the 'note' node-type.
     FieldStorageConfig::create(['entity_type' => 'node', 'field_name' => 'sticker', 'type' => 'image'])->save();
     FieldConfig::create(['entity_type' => 'node', 'field_name' => 'sticker', 'bundle' => 'note'])->save();
     // Create the default entity view display and set the 'sticker' field to use
     // the 'main_style' images style in formatter.
     /** @var \Drupal\Core\Entity\Display\EntityViewDisplayInterface $view_display */
     $view_display = EntityViewDisplay::create(['targetEntityType' => 'node', 'bundle' => 'note', 'mode' => 'default', 'status' => TRUE])->setComponent('sticker', ['settings' => ['image_style' => 'main_style']]);
     $view_display->save();
     // Create the default entity form display and set the 'sticker' field to use
     // the 'main_style' images style in the widget.
     /** @var \Drupal\Core\Entity\Display\EntityFormDisplayInterface $form_display */
     $form_display = EntityFormDisplay::create(['targetEntityType' => 'node', 'bundle' => 'note', 'mode' => 'default', 'status' => TRUE])->setComponent('sticker', ['settings' => ['preview_image_style' => 'main_style']]);
     $form_display->save();
     // Check that the entity displays exists before dependency removal.
     $this->assertNotNull(EntityViewDisplay::load($view_display->id()));
     $this->assertNotNull(EntityFormDisplay::load($form_display->id()));
     // Delete the 'main_style' image style. Before that, emulate the UI process
     // of selecting a replacement style by setting the replacement image style
     // ID in the image style storage.
     /** @var \Drupal\image\ImageStyleStorageInterface $storage */
     $storage = $this->container->get('entity.manager')->getStorage($style->getEntityTypeId());
     $storage->setReplacementId('main_style', 'replacement_style');
     $style->delete();
     // Check that the entity displays exists after dependency removal.
     $this->assertNotNull($view_display = EntityViewDisplay::load($view_display->id()));
     $this->assertNotNull($form_display = EntityFormDisplay::load($form_display->id()));
     // Check that the 'sticker' formatter component exists in both displays.
     $this->assertNotNull($formatter = $view_display->getComponent('sticker'));
     $this->assertNotNull($widget = $form_display->getComponent('sticker'));
     // Check that both displays are using now 'replacement_style' for images.
     $this->assertSame('replacement_style', $formatter['settings']['image_style']);
     $this->assertSame('replacement_style', $widget['settings']['preview_image_style']);
     // Delete the 'replacement_style' without setting a replacement image style.
     $replacement->delete();
     // The entity view and form displays exists after dependency removal.
     $this->assertNotNull($view_display = EntityViewDisplay::load($view_display->id()));
     $this->assertNotNull($form_display = EntityFormDisplay::load($form_display->id()));
     // The 'sticker' formatter component should be hidden in view display.
     $this->assertNull($view_display->getComponent('sticker'));
     $this->assertTrue($view_display->get('hidden')['sticker']);
     // The 'sticker' widget component should be active in form displays, but the
     // image preview should be disabled.
     $this->assertNotNull($widget = $form_display->getComponent('sticker'));
     $this->assertSame('', $widget['settings']['preview_image_style']);
 }
 /**
  * Tests the Drupal 6 vocabulary-node type association to Drupal 8 migration.
  */
 public function testVocabularyEntityDisplay()
 {
     // Test that the field exists.
     $component = EntityViewDisplay::load('node.page.default')->getComponent('tags');
     $this->assertIdentical('entity_reference_label', $component['type']);
     $this->assertIdentical(20, $component['weight']);
     // Test the Id map.
     $this->assertIdentical(array('node', 'article', 'default', 'tags'), $this->getMigration('d6_vocabulary_entity_display')->getIdMap()->lookupDestinationID(array(4, 'article')));
 }
 /**
  * Tests the Drupal 6 upload settings to Drupal 8 entity display migration.
  */
 public function testUploadEntityDisplay()
 {
     $display = EntityViewDisplay::load('node.page.default');
     $component = $display->getComponent('upload');
     $this->assertIdentical('file_default', $component['type']);
     $display = EntityViewDisplay::load('node.story.default');
     $component = $display->getComponent('upload');
     $this->assertIdentical('file_default', $component['type']);
     // Assure this doesn't exist.
     $display = EntityViewDisplay::load('node.article.default');
     $component = $display->getComponent('upload');
     $this->assertTrue(is_null($component));
     $this->assertIdentical(array('node', 'page', 'default', 'upload'), $this->getMigration('d6_upload_entity_display')->getIdMap()->lookupDestinationID(array('page')));
 }
Beispiel #10
0
 /**
  * Tests image style deletion.
  */
 public function testDelete()
 {
     $this->drupalGet('admin/config/media/image-styles/manage/medium/delete');
     // Checks that the 'replacement' select element is displayed.
     $this->assertFieldByName('replacement');
     // Checks that UI messages are correct.
     $this->assertRaw(t('If this style is in use on the site, you may select another style to replace it. All images that have been generated for this style will be permanently deleted. If no replacement style is selected, the dependent configurations might need manual reconfiguration.'));
     $this->assertNoRaw(t('All images that have been generated for this style will be permanently deleted. The dependent configurations might need manual reconfiguration.'));
     // Delete 'medium' image style but replace it with 'thumbnail'. This style
     // is involved in 'node.page.default' display view and form.
     $this->drupalPostForm(NULL, ['replacement' => 'thumbnail'], t('Delete'));
     /** @var \Drupal\Core\Entity\Display\EntityViewDisplayInterface $view_display */
     $view_display = EntityViewDisplay::load('node.page.default');
     // Checks that the formatter setting is replaced.
     if ($this->assertNotNull($component = $view_display->getComponent('foo'))) {
         $this->assertIdentical($component['settings']['image_style'], 'thumbnail');
     }
     /** @var \Drupal\Core\Entity\Display\EntityFormDisplayInterface $form_display */
     $form_display = EntityFormDisplay::load('node.page.default');
     // Check that the widget setting is replaced.
     if ($this->assertNotNull($component = $form_display->getComponent('foo'))) {
         $this->assertIdentical($component['settings']['preview_image_style'], 'thumbnail');
     }
     $this->drupalGet('admin/config/media/image-styles/manage/thumbnail/delete');
     // Checks that the 'replacement' select element is displayed.
     $this->assertFieldByName('replacement');
     // Checks that UI messages are correct.
     $this->assertRaw(t('If this style is in use on the site, you may select another style to replace it. All images that have been generated for this style will be permanently deleted. If no replacement style is selected, the dependent configurations might need manual reconfiguration.'));
     $this->assertNoRaw(t('All images that have been generated for this style will be permanently deleted. The dependent configurations might need manual reconfiguration.'));
     // Delete 'thumbnail' image style. Provide no replacement.
     $this->drupalPostForm(NULL, [], t('Delete'));
     $view_display = EntityViewDisplay::load('node.page.default');
     // Checks that the formatter setting is disabled.
     $this->assertNull($view_display->getComponent('foo'));
     $this->assertNotNull($view_display->get('hidden')['foo']);
     // Checks that widget setting is preserved with the image preview disabled.
     $form_display = EntityFormDisplay::load('node.page.default');
     $this->assertNotNull($widget = $form_display->getComponent('foo'));
     $this->assertIdentical($widget['settings']['preview_image_style'], '');
     // Now, there's only one image style configured on the system: 'large'.
     $this->drupalGet('admin/config/media/image-styles/manage/large/delete');
     // Checks that the 'replacement' select element is not displayed.
     $this->assertNoFieldByName('replacement');
     // Checks that UI messages are correct.
     $this->assertNoRaw(t('If this style is in use on the site, you may select another style to replace it. All images that have been generated for this style will be permanently deleted. If no replacement style is selected, the dependent configurations might need manual reconfiguration.'));
     $this->assertRaw(t('All images that have been generated for this style will be permanently deleted. The dependent configurations might need manual reconfiguration.'));
 }
 /**
  * Tests migration of user profile fields.
  */
 public function testUserProfileFields()
 {
     $display = EntityViewDisplay::load('user.user.default');
     // Test a text field.
     $component = $display->getComponent('profile_color');
     $this->assertIdentical('text_default', $component['type']);
     // Test a list field.
     $component = $display->getComponent('profile_bands');
     $this->assertIdentical('text_default', $component['type']);
     // Test a date field.
     $component = $display->getComponent('profile_birthdate');
     $this->assertIdentical('datetime_default', $component['type']);
     // Test PROFILE_PRIVATE field is hidden.
     $this->assertNull($display->getComponent('profile_sell_address'));
     // Test PROFILE_HIDDEN field is hidden.
     $this->assertNull($display->getComponent('profile_sold_to'));
 }
 /**
  * Tests post-update responsive_image_post_update_dependency().
  *
  * @see responsive_image_post_update_dependency()
  */
 public function testPostUpdateDependency()
 {
     // Installing the 'wide' responsive image style.
     $wide_image_style = Yaml::decode(file_get_contents(__DIR__ . '/../../../../../profiles/standard/config/optional/responsive_image.styles.wide.yml'));
     $this->config('responsive_image.styles.wide')->setData($wide_image_style)->save(TRUE);
     // Change 'field_image' formatter to a responsive image formatter.
     $options = ['type' => 'responsive_image', 'label' => 'hidden', 'settings' => ['responsive_image_style' => 'wide', 'image_link' => ''], 'third_party_settings' => []];
     $display = $this->config('core.entity_view_display.node.article.default');
     $display->set('content.field_image', $options)->save(TRUE);
     // Check that there's no dependency to 'responsive_image.styles.wide'.
     $dependencies = $display->get('dependencies.config') ?: [];
     $this->assertFalse(in_array('responsive_image.styles.wide', $dependencies));
     // Run updates.
     $this->runUpdates();
     /** @var \Drupal\Core\Entity\Display\EntityViewDisplayInterface $view_display */
     $view_display = EntityViewDisplay::load('node.article.default');
     $dependencies = $view_display->getDependencies() + ['config' => []];
     // Check that post-update added a 'responsive_image.styles.wide' dependency.
     $this->assertTrue(in_array('responsive_image.styles.wide', $dependencies['config']));
 }
 /**
  * Tests view mode setting integration.
  *
  * @see comment_entity_view_display_presave()
  * @see CommentDefaultFormatter::calculateDependencies()
  */
 public function testViewMode()
 {
     $mode = Unicode::strtolower($this->randomMachineName());
     // Create a new comment view mode and a view display entity.
     EntityViewMode::create(['id' => "comment.{$mode}", 'targetEntityType' => 'comment', 'settings' => ['comment_type' => 'comment']])->save();
     EntityViewDisplay::create(['targetEntityType' => 'comment', 'bundle' => 'comment', 'mode' => $mode])->setStatus(TRUE)->save();
     // Create a comment field attached to a host 'entity_test' entity.
     FieldStorageConfig::create(['entity_type' => 'entity_test', 'type' => 'comment', 'field_name' => $field_name = Unicode::strtolower($this->randomMachineName()), 'settings' => ['comment_type' => 'comment']])->save();
     FieldConfig::create(['entity_type' => 'entity_test', 'bundle' => 'entity_test', 'field_name' => $field_name])->save();
     $component = ['type' => 'comment_default', 'settings' => ['view_mode' => $mode, 'pager_id' => 0]];
     // Create a new 'entity_test' view display on host entity that uses the
     // custom comment display in field formatter to show the field.
     EntityViewDisplay::create(['targetEntityType' => 'entity_test', 'bundle' => 'entity_test', 'mode' => 'default'])->setComponent($field_name, $component)->setStatus(TRUE)->save();
     $host_display_id = 'entity_test.entity_test.default';
     $comment_display_id = "comment.comment.{$mode}";
     // Disable the "comment.comment.$mode" display.
     EntityViewDisplay::load($comment_display_id)->setStatus(FALSE)->save();
     /** @var \Drupal\Core\Entity\Display\EntityViewDisplayInterface $host_display */
     $host_display = EntityViewDisplay::load($host_display_id);
     // Check that the field formatter has been disabled on host view display.
     $this->assertNull($host_display->getComponent($field_name));
     $this->assertTrue($host_display->get('hidden')[$field_name]);
     // Check that the proper warning has been logged.
     $arguments = ['@id' => $host_display_id, '@name' => $field_name, '@display' => EntityViewMode::load("comment.{$mode}")->label(), '@mode' => $mode];
     $logged = (bool) Database::getConnection()->select('watchdog')->fields('watchdog', ['wid'])->condition('type', 'system')->condition('message', "View display '@id': Comment field formatter '@name' was disabled because it is using the comment view display '@display' (@mode) that was just disabled.")->condition('variables', serialize($arguments))->execute()->fetchField();
     $this->assertTrue($logged);
     // Re-enable the comment view display.
     EntityViewDisplay::load($comment_display_id)->setStatus(TRUE)->save();
     // Re-enable the comment field formatter on host entity view display.
     EntityViewDisplay::load($host_display_id)->setComponent($field_name, $component)->save();
     // Delete the "comment.$mode" view mode.
     EntityViewMode::load("comment.{$mode}")->delete();
     // Check that the comment view display entity has been deleted too.
     $this->assertNull(EntityViewDisplay::load($comment_display_id));
     /** @var \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display */
     $host_display = EntityViewDisplay::load($host_display_id);
     // Check that the field formatter has been disabled on host view display.
     $this->assertNull($host_display->getComponent($field_name));
     $this->assertTrue($host_display->get('hidden')[$field_name]);
 }
 /**
  * Tests integration with entity view display.
  */
 public function testEntityViewDisplayDependency()
 {
     // Create a responsive image style.
     ResponsiveImageStyle::create(['id' => 'foo', 'label' => 'Foo', 'breakpoint_group' => 'responsive_image_test_module'])->save();
     // Create an image field to be used with a responsive image formatter.
     FieldStorageConfig::create(['type' => 'image', 'entity_type' => 'entity_test', 'field_name' => 'bar'])->save();
     FieldConfig::create(['entity_type' => 'entity_test', 'bundle' => 'entity_test', 'field_name' => 'bar'])->save();
     /** @var \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display */
     $display = EntityViewDisplay::create(['targetEntityType' => 'entity_test', 'bundle' => 'entity_test', 'mode' => 'default']);
     $display->setComponent('bar', ['type' => 'responsive_image', 'label' => 'hidden', 'settings' => ['responsive_image_style' => 'foo', 'image_link' => ''], 'third_party_settings' => []])->save();
     // Check that the 'foo' field is on the display.
     $this->assertNotNull($display = EntityViewDisplay::load('entity_test.entity_test.default'));
     $this->assertTrue($display->getComponent('bar'));
     $this->assertArrayNotHasKey('bar', $display->get('hidden'));
     // Delete the responsive image style.
     ResponsiveImageStyle::load('foo')->delete();
     // Check that the view display was not deleted.
     $this->assertNotNull($display = EntityViewDisplay::load('entity_test.entity_test.default'));
     // Check that the 'foo' field was disabled.
     $this->assertNull($display->getComponent('bar'));
     $this->assertArrayHasKey('bar', $display->get('hidden'));
 }
 /**
  * Tests formatter settings.
  */
 function testFormatterUI()
 {
     $manage_fields = 'admin/structure/types/manage/' . $this->type;
     $manage_display = $manage_fields . '/display';
     // Create a field, and a node with some data for the field.
     $this->fieldUIAddNewField($manage_fields, 'test', 'Test field');
     // Get the display options (formatter and settings) that were automatically
     // assigned for the 'default' display.
     $display = entity_get_display('node', $this->type, 'default');
     $display_options = $display->getComponent('field_test');
     $format = $display_options['type'];
     $default_settings = \Drupal::service('plugin.manager.field.formatter')->getDefaultSettings($format);
     $setting_name = key($default_settings);
     $setting_value = $display_options['settings'][$setting_name];
     // Display the "Manage display" screen and check that the expected formatter
     // is selected.
     $this->drupalGet($manage_display);
     $this->assertFieldByName('fields[field_test][type]', $format, 'The expected formatter is selected.');
     $this->assertText("{$setting_name}: {$setting_value}", 'The expected summary is displayed.');
     // Check whether formatter weights are respected.
     $result = $this->xpath('//select[@id=:id]/option', array(':id' => 'edit-fields-field-test-type'));
     $options = array_map(function ($item) {
         return (string) $item->attributes()->value[0];
     }, $result);
     $expected_options = array('field_no_settings', 'field_empty_test', 'field_empty_setting', 'field_test_default', 'field_test_multiple', 'field_test_with_prepare_view', 'field_test_applicable', 'hidden');
     $this->assertEqual($options, $expected_options, 'The expected formatter ordering is respected.');
     // Change the formatter and check that the summary is updated.
     $edit = array('fields[field_test][type]' => 'field_test_multiple', 'refresh_rows' => 'field_test');
     $this->drupalPostAjaxForm(NULL, $edit, array('op' => t('Refresh')));
     $format = 'field_test_multiple';
     $default_settings = \Drupal::service('plugin.manager.field.formatter')->getDefaultSettings($format);
     $setting_name = key($default_settings);
     $setting_value = $default_settings[$setting_name];
     $this->assertFieldByName('fields[field_test][type]', $format, 'The expected formatter is selected.');
     $this->assertText("{$setting_name}: {$setting_value}", 'The expected summary is displayed.');
     // Submit the form and check that the display is updated.
     $this->drupalPostForm(NULL, array(), t('Save'));
     $display = entity_get_display('node', $this->type, 'default');
     $display_options = $display->getComponent('field_test');
     $current_format = $display_options['type'];
     $current_setting_value = $display_options['settings'][$setting_name];
     $this->assertEqual($current_format, $format, 'The formatter was updated.');
     $this->assertEqual($current_setting_value, $setting_value, 'The setting was updated.');
     // Assert that hook_field_formatter_settings_summary_alter() is called.
     $this->assertText('field_test_field_formatter_settings_summary_alter');
     // Click on the formatter settings button to open the formatter settings
     // form.
     $this->drupalPostAjaxForm(NULL, array(), "field_test_settings_edit");
     // Assert that the field added in
     // field_test_field_formatter_third_party_settings_form() is present.
     $fieldname = 'fields[field_test][settings_edit_form][third_party_settings][field_third_party_test][field_test_field_formatter_third_party_settings_form]';
     $this->assertField($fieldname, 'The field added in hook_field_formatter_third_party_settings_form() is present on the settings form.');
     $edit = array($fieldname => 'foo');
     $this->drupalPostAjaxForm(NULL, $edit, "field_test_plugin_settings_update");
     // Save the form to save the third party settings.
     $this->drupalPostForm(NULL, array(), t('Save'));
     \Drupal::entityManager()->clearCachedFieldDefinitions();
     $id = 'node.' . $this->type . '.default';
     $storage = $this->container->get('entity_type.manager')->getStorage('entity_view_display');
     $storage->resetCache([$id]);
     $display = $storage->load($id);
     $this->assertEqual($display->getRenderer('field_test')->getThirdPartySetting('field_third_party_test', 'field_test_field_formatter_third_party_settings_form'), 'foo');
     $this->assertTrue(in_array('field_third_party_test', $display->calculateDependencies()->getDependencies()['module']), 'The display has a dependency on field_third_party_test module.');
     // Confirm that the third party settings are not updated on the settings form.
     $this->drupalPostAjaxForm(NULL, array(), "field_test_settings_edit");
     $this->assertFieldByName($fieldname, '');
     // Test the empty setting formatter.
     $edit = array('fields[field_test][type]' => 'field_empty_setting');
     $this->drupalPostForm(NULL, $edit, t('Save'));
     $this->assertNoText('Default empty setting now has a value.');
     $this->assertFieldById('edit-fields-field-test-settings-edit');
     $this->drupalPostAjaxForm(NULL, array(), "field_test_settings_edit");
     $fieldname = 'fields[field_test][settings_edit_form][settings][field_empty_setting]';
     $edit = array($fieldname => 'non empty setting');
     $this->drupalPostAjaxForm(NULL, $edit, "field_test_plugin_settings_update");
     $this->assertText('Default empty setting now has a value.');
     // Test the settings form behavior. An edit button should be present since
     // there are third party settings to configure.
     $edit = array('fields[field_test][type]' => 'field_no_settings', 'refresh_rows' => 'field_test');
     $this->drupalPostAjaxForm(NULL, $edit, array('op' => t('Refresh')));
     $this->assertFieldByName('field_test_settings_edit');
     // Make sure we can save the third party settings when there are no settings available
     $this->drupalPostAjaxForm(NULL, array(), "field_test_settings_edit");
     $this->drupalPostAjaxForm(NULL, $edit, "field_test_plugin_settings_update");
     // When a module providing third-party settings to a formatter (or widget)
     // is uninstalled, the formatter remains enabled but the provided settings,
     // together with the corresponding form elements, are removed from the
     // display component.
     \Drupal::service('module_installer')->uninstall(array('field_third_party_test'));
     // Ensure the button is still there after the module has been disabled.
     $this->drupalGet($manage_display);
     $this->assertResponse(200);
     $this->assertFieldByName('field_test_settings_edit');
     // Ensure that third-party form elements are not present anymore.
     $this->drupalPostAjaxForm(NULL, array(), 'field_test_settings_edit');
     $fieldname = 'fields[field_test][settings_edit_form][third_party_settings][field_third_party_test][field_test_field_formatter_third_party_settings_form]';
     $this->assertNoField($fieldname);
     // Ensure that third-party settings were removed from the formatter.
     $display = EntityViewDisplay::load("node.{$this->type}.default");
     $component = $display->getComponent('field_test');
     $this->assertFalse(array_key_exists('field_third_party_test', $component['third_party_settings']));
 }
 /**
  * Tests the rendered entity output with the test field configured to show.
  */
 public function testRenderedEntityWithField()
 {
     \Drupal::currentUser()->setAccount($this->user);
     // Show the test_field on the entity_test.entity_test.foobar view display.
     EntityViewDisplay::load('entity_test.entity_test.foobar')->setComponent('test_field', ['type' => 'string', 'label' => 'above'])->save();
     $view = Views::getView('test_field_entity_test_rendered');
     $build = ['#type' => 'view', '#name' => 'test_field_entity_test_rendered', '#view' => $view, '#display_id' => 'default'];
     $renderer = \Drupal::service('renderer');
     $renderer->renderPlain($build);
     for ($i = 1; $i <= 3; $i++) {
         $view_field = $view->style_plugin->getField($i - 1, 'rendered_entity');
         $search_result = strpos($view_field, "Test {$i}") !== FALSE;
         $this->assertTrue($search_result, "The text 'Test {$i}' found in the view.");
     }
     $this->assertConfigDependencies($view->storage);
     $this->assertCacheabilityMetadata($build);
 }
 /**
  * Tests the embedded references.
  */
 function testEmbeddedReferences()
 {
     // Create two reference fields, one to a translatable and untranslatable
     // node type, one only for a untranslatable. Only the first one should be
     // available.
     $field1 = FieldStorageConfig::create(array('field_name' => 'field1', 'entity_type' => 'node', 'type' => 'entity_reference', 'cardinality' => -1, 'settings' => array('target_type' => 'node')));
     $field1->save();
     $field2 = FieldStorageConfig::create(array('field_name' => 'field2', 'entity_type' => 'node', 'type' => 'entity_reference', 'cardinality' => -1, 'settings' => array('target_type' => 'node')));
     $field2->save();
     $this->createNodeType('untranslatable', 'Untranslatable', FALSE);
     // Create field instances on the content type.
     FieldConfig::create(array('field_storage' => $field1, 'bundle' => 'article', 'label' => 'Field 1', 'translatable' => FALSE, 'settings' => array()))->save();
     FieldConfig::create(array('field_storage' => $field1, 'bundle' => 'untranslatable', 'label' => 'Field 1', 'translatable' => FALSE, 'settings' => array()))->save();
     FieldConfig::create(array('field_storage' => $field2, 'bundle' => 'untranslatable', 'label' => 'Field 2', 'translatable' => FALSE, 'settings' => array()))->save();
     EntityViewDisplay::load('node.article.default')->setComponent('field1', ['type' => 'entity_reference_entity_view', 'settings' => ['view_mode' => 'teaser']])->save();
     $this->drupalGet('admin/tmgmt/settings');
     $checked_reference_fields = array('embedded_fields[node][field1]' => TRUE);
     $this->assertNoField('embedded_fields[node][field_image]');
     $this->assertNoField('embedded_fields[node][field_tags]');
     $this->assertNoField('embedded_fields[node][title]');
     $this->assertNoField('embedded_fields[node][uid]');
     $this->assertNoField('embedded_fields[node][field2]');
     $this->assertNoField('embedded_fields[node][type]');
     $this->drupalPostForm(NULL, $checked_reference_fields, t('Save configuration'));
     // Check if the save was successful.
     $this->assertText(t('The configuration options have been saved.'));
     $this->assertFieldChecked('edit-embedded-fields-node-field1');
     // Create translatable child node.
     $edit = ['title' => 'Child title', 'type' => 'article', 'langcode' => 'en'];
     $child_node = $this->createNode($edit);
     // Create translatable parent node.
     $edit = ['title' => 'Parent title', 'type' => 'article', 'langcode' => 'en'];
     $edit['field1'][]['target_id'] = $child_node->id();
     $parent_node = $this->createNode($edit);
     // Create a translation job.
     $job = $this->createJob('en', 'de');
     $job->translator = $this->default_translator->id();
     $job->save();
     $job_item = tmgmt_job_item_create('content', $parent_node->getEntityTypeId(), $parent_node->id(), array('tjid' => $job->id()));
     $job_item->save();
     $job->requestTranslation();
     // Visit preview page.
     $this->drupalGet(URL::fromRoute('entity.tmgmt_job_item.canonical', ['tmgmt_job_item' => $job_item->id()]));
     $this->clickLink(t('Preview'));
     // Check if parent and child nodes are translated.
     $this->assertText('de(de-ch): ' . $parent_node->getTitle());
     $this->assertText('de(de-ch): ' . $parent_node->body->value);
     $this->assertText('de(de-ch): ' . $child_node->getTitle());
     $this->assertText('de(de-ch): ' . $child_node->body->value);
 }
Beispiel #18
0
  /**
   * {@inheritdoc}
   */
  protected function setUp() {
    parent::setUp();

    $this->installEntitySchema($this->entityTypeId);
    $this->installEntitySchema('filter_format');

    // Setup a field and an entity display.
    EntityViewDisplay::create([
      'targetEntityType' => 'entity_test',
      'bundle' => 'entity_test',
      'mode' => 'default',
    ])->save();
    FieldStorageConfig::create([
      'field_name' => $this->fieldName,
      'entity_type' => $this->entityTypeId,
      'type' => 'text',
    ])->save();
    FieldConfig::create([
      'entity_type' => $this->entityTypeId,
      'field_name' => $this->fieldName,
      'bundle' => $this->entityTypeId,
    ])->save();

    $this->entityViewDisplay = EntityViewDisplay::load('entity_test.entity_test.default');

    // Create a test entity with a test value.
    $this->entity = EntityTest::create();
    $this->entity->{$this->fieldName}->value = 'lorem ipsum';
    $this->entity->save();

    // Set the default filter format.
    FilterFormat::create([
      'format' => 'test_format',
      'name' => $this->randomMachineName(),
    ])->save();
    $this->container->get('config.factory')
      ->getEditable('filter.settings')
      ->set('fallback_format', 'test_format')
      ->save();
  }
 /**
  * Tests CRUD for fields and fields fields with default images.
  */
 public function testDefaultImages()
 {
     $node_storage = $this->container->get('entity.manager')->getStorage('node');
     // Create files to use as the default images.
     $files = $this->drupalGetTestFiles('image');
     // Create 10 files so the default image fids are not a single value.
     for ($i = 1; $i <= 10; $i++) {
         $filename = $this->randomMachineName() . "{$i}";
         $desired_filepath = 'public://' . $filename;
         file_unmanaged_copy($files[0]->uri, $desired_filepath, FILE_EXISTS_ERROR);
         $file = File::create(['uri' => $desired_filepath, 'filename' => $filename, 'name' => $filename]);
         $file->save();
     }
     $default_images = array();
     foreach (array('field', 'field', 'field2', 'field_new', 'field_new') as $image_target) {
         $file = File::create((array) array_pop($files));
         $file->save();
         $default_images[$image_target] = $file;
     }
     // Create an image field and add an field to the article content type.
     $field_name = strtolower($this->randomMachineName());
     $storage_settings['default_image'] = array('uuid' => $default_images['field']->uuid(), 'alt' => '', 'title' => '', 'width' => 0, 'height' => 0);
     $field_settings['default_image'] = array('uuid' => $default_images['field']->uuid(), 'alt' => '', 'title' => '', 'width' => 0, 'height' => 0);
     $widget_settings = array('preview_image_style' => 'medium');
     $field = $this->createImageField($field_name, 'article', $storage_settings, $field_settings, $widget_settings);
     // The field default image id should be 2.
     $this->assertEqual($field->getSetting('default_image')['uuid'], $default_images['field']->uuid());
     // Also test \Drupal\field\Entity\FieldConfig::getSettings().
     $this->assertEqual($field->getSettings()['default_image']['uuid'], $default_images['field']->uuid());
     $field_storage = $field->getFieldStorageDefinition();
     // The field default image id should be 1.
     $this->assertEqual($field_storage->getSetting('default_image')['uuid'], $default_images['field']->uuid());
     // Also test \Drupal\field\Entity\FieldStorageConfig::getSettings().
     $this->assertEqual($field_storage->getSettings()['default_image']['uuid'], $default_images['field']->uuid());
     // Add another field with another default image to the page content type.
     $field2 = FieldConfig::create(['field_storage' => $field_storage, 'bundle' => 'page', 'label' => $field->label(), 'required' => $field->isRequired(), 'settings' => array('default_image' => array('uuid' => $default_images['field2']->uuid(), 'alt' => '', 'title' => '', 'width' => 0, 'height' => 0))]);
     $field2->save();
     $widget_settings = entity_get_form_display('node', $field->getTargetBundle(), 'default')->getComponent($field_name);
     entity_get_form_display('node', 'page', 'default')->setComponent($field_name, $widget_settings)->save();
     entity_get_display('node', 'page', 'default')->setComponent($field_name)->save();
     // Confirm the defaults are present on the article field settings form.
     $field_id = $field->id();
     $this->drupalGet("admin/structure/types/manage/article/fields/{$field_id}/storage");
     $this->assertFieldByXpath('//input[@name="settings[default_image][uuid][fids]"]', $default_images['field']->id(), format_string('Article image field default equals expected file ID of @fid.', array('@fid' => $default_images['field']->id())));
     // Confirm the defaults are present on the article field edit form.
     $this->drupalGet("admin/structure/types/manage/article/fields/{$field_id}");
     $this->assertFieldByXpath('//input[@name="settings[default_image][uuid][fids]"]', $default_images['field']->id(), format_string('Article image field field default equals expected file ID of @fid.', array('@fid' => $default_images['field']->id())));
     // Confirm the defaults are present on the page field settings form.
     $this->drupalGet("admin/structure/types/manage/page/fields/{$field_id}/storage");
     $this->assertFieldByXpath('//input[@name="settings[default_image][uuid][fids]"]', $default_images['field']->id(), format_string('Page image field default equals expected file ID of @fid.', array('@fid' => $default_images['field']->id())));
     // Confirm the defaults are present on the page field edit form.
     $field2_id = $field2->id();
     $this->drupalGet("admin/structure/types/manage/page/fields/{$field2_id}");
     $this->assertFieldByXpath('//input[@name="settings[default_image][uuid][fids]"]', $default_images['field2']->id(), format_string('Page image field field default equals expected file ID of @fid.', array('@fid' => $default_images['field2']->id())));
     // Confirm that the image default is shown for a new article node.
     $article = $this->drupalCreateNode(array('type' => 'article'));
     $article_built = $this->drupalBuildEntityView($article);
     $this->assertEqual($article_built[$field_name][0]['#item']->target_id, $default_images['field']->id(), format_string('A new article node without an image has the expected default image file ID of @fid.', array('@fid' => $default_images['field']->id())));
     // Also check that the field renders without warnings when the label is
     // hidden.
     EntityViewDisplay::load('node.article.default')->setComponent($field_name, array('label' => 'hidden', 'type' => 'image'))->save();
     $this->drupalGet('node/' . $article->id());
     // Confirm that the image default is shown for a new page node.
     $page = $this->drupalCreateNode(array('type' => 'page'));
     $page_built = $this->drupalBuildEntityView($page);
     $this->assertEqual($page_built[$field_name][0]['#item']->target_id, $default_images['field2']->id(), format_string('A new page node without an image has the expected default image file ID of @fid.', array('@fid' => $default_images['field2']->id())));
     // Upload a new default for the field storage.
     $default_image_settings = $field_storage->getSetting('default_image');
     $default_image_settings['uuid'] = $default_images['field_new']->uuid();
     $field_storage->setSetting('default_image', $default_image_settings);
     $field_storage->save();
     // Confirm that the new default is used on the article field settings form.
     $this->drupalGet("admin/structure/types/manage/article/fields/{$field_id}/storage");
     $this->assertFieldByXpath('//input[@name="settings[default_image][uuid][fids]"]', $default_images['field_new']->id(), format_string('Updated image field default equals expected file ID of @fid.', array('@fid' => $default_images['field_new']->id())));
     // Reload the nodes and confirm the field field defaults are used.
     $node_storage->resetCache(array($article->id(), $page->id()));
     $article_built = $this->drupalBuildEntityView($article = $node_storage->load($article->id()));
     $page_built = $this->drupalBuildEntityView($page = $node_storage->load($page->id()));
     $this->assertEqual($article_built[$field_name][0]['#item']->target_id, $default_images['field']->id(), format_string('An existing article node without an image has the expected default image file ID of @fid.', array('@fid' => $default_images['field']->id())));
     $this->assertEqual($page_built[$field_name][0]['#item']->target_id, $default_images['field2']->id(), format_string('An existing page node without an image has the expected default image file ID of @fid.', array('@fid' => $default_images['field2']->id())));
     // Upload a new default for the article's field field.
     $default_image_settings = $field->getSetting('default_image');
     $default_image_settings['uuid'] = $default_images['field_new']->uuid();
     $field->setSetting('default_image', $default_image_settings);
     $field->save();
     // Confirm the new field field default is used on the article field
     // admin form.
     $this->drupalGet("admin/structure/types/manage/article/fields/{$field_id}");
     $this->assertFieldByXpath('//input[@name="settings[default_image][uuid][fids]"]', $default_images['field_new']->id(), format_string('Updated article image field field default equals expected file ID of @fid.', array('@fid' => $default_images['field_new']->id())));
     // Reload the nodes.
     $node_storage->resetCache(array($article->id(), $page->id()));
     $article_built = $this->drupalBuildEntityView($article = $node_storage->load($article->id()));
     $page_built = $this->drupalBuildEntityView($page = $node_storage->load($page->id()));
     // Confirm the article uses the new default.
     $this->assertEqual($article_built[$field_name][0]['#item']->target_id, $default_images['field_new']->id(), format_string('An existing article node without an image has the expected default image file ID of @fid.', array('@fid' => $default_images['field_new']->id())));
     // Confirm the page remains unchanged.
     $this->assertEqual($page_built[$field_name][0]['#item']->target_id, $default_images['field2']->id(), format_string('An existing page node without an image has the expected default image file ID of @fid.', array('@fid' => $default_images['field2']->id())));
     // Confirm the default image is shown on the node form.
     $file = File::load($default_images['field_new']->id());
     $this->drupalGet('node/add/article');
     $this->assertRaw($file->getFilename());
     // Remove the instance default from articles.
     $default_image_settings = $field->getSetting('default_image');
     $default_image_settings['uuid'] = 0;
     $field->setSetting('default_image', $default_image_settings);
     $field->save();
     // Confirm the article field field default has been removed.
     $this->drupalGet("admin/structure/types/manage/article/fields/{$field_id}");
     $this->assertFieldByXpath('//input[@name="settings[default_image][uuid][fids]"]', '', 'Updated article image field field default has been successfully removed.');
     // Reload the nodes.
     $node_storage->resetCache(array($article->id(), $page->id()));
     $article_built = $this->drupalBuildEntityView($article = $node_storage->load($article->id()));
     $page_built = $this->drupalBuildEntityView($page = $node_storage->load($page->id()));
     // Confirm the article uses the new field (not field) default.
     $this->assertEqual($article_built[$field_name][0]['#item']->target_id, $default_images['field_new']->id(), format_string('An existing article node without an image has the expected default image file ID of @fid.', array('@fid' => $default_images['field_new']->id())));
     // Confirm the page remains unchanged.
     $this->assertEqual($page_built[$field_name][0]['#item']->target_id, $default_images['field2']->id(), format_string('An existing page node without an image has the expected default image file ID of @fid.', array('@fid' => $default_images['field2']->id())));
     $non_image = $this->drupalGetTestFiles('text');
     $this->drupalPostForm(NULL, array('files[settings_default_image_uuid]' => drupal_realpath($non_image[0]->uri)), t("Upload"));
     $this->assertText('The specified file text-0.txt could not be uploaded.');
     $this->assertText('Only files with the following extensions are allowed: png gif jpg jpeg.');
     // Confirm the default image is shown on the node form.
     $file = File::load($default_images['field_new']->id());
     $this->drupalGet('node/add/article');
     $this->assertRaw($file->getFilename());
 }
  /**
   * {@inheritdoc}
   */
  protected function setUp() {
    parent::setUp();

    // Create a vocabulary.
    $this->vocabulary = $this->createVocabulary();

    // Create 11 terms, which have some sub-string in common, in a
    // non-alphabetical order, so that we will have more than 10 matches later
    // when we test the correct number of results is returned, and we can test
    // the order of the results. The location of the sub-string to match varies
    // also, since it should not be necessary to start with the sub-string to
    // match it. Save term IDs to reuse later.
    $termNames = [
      'aaa 20 bbb',
      'aaa 70 bbb',
      'aaa 10 bbb',
      'aaa 12 bbb',
      'aaa 40 bbb',
      'aaa 11 bbb',
      'aaa 30 bbb',
      'aaa 50 bbb',
      'aaa 80',
      'aaa 90',
      'bbb 60 aaa',
    ];
    foreach ($termNames as $termName) {
      $term = $this->createTerm($this->vocabulary, ['name' => $termName]);
      $this->termIds[$termName] = $term->id();
    }

    // Create a taxonomy_term_reference field on the article Content Type that
    // uses a taxonomy_autocomplete widget.
    $this->fieldName = Unicode::strtolower($this->randomMachineName());
    FieldStorageConfig::create([
      'field_name' => $this->fieldName,
      'entity_type' => 'node',
      'type' => 'entity_reference',
      'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
      'settings' => [
        'target_type' => 'taxonomy_term',
      ],
    ])->save();
    FieldConfig::create([
      'field_name' => $this->fieldName,
      'bundle' => 'article',
      'entity_type' => 'node',
      'settings' => [
        'handler' => 'default',
        'handler_settings' => [
          // Restrict selection of terms to a single vocabulary.
          'target_bundles' => [
            $this->vocabulary->id() => $this->vocabulary->id(),
          ],
        ],
      ],
    ])->save();
    EntityFormDisplay::load('node.article.default')
      ->setComponent($this->fieldName, [
        'type' => 'entity_reference_autocomplete',
      ])
      ->save();
    EntityViewDisplay::load('node.article.default')
      ->setComponent($this->fieldName, [
        'type' => 'entity_reference_label',
      ])
      ->save();

    // Create a user and then login.
    $this->adminUser = $this->drupalCreateUser(['create article content']);
    $this->drupalLogin($this->adminUser);

    // Retrieve the autocomplete url.
    $this->drupalGet('node/add/article');
    $result = $this->xpath('//input[@name="' . $this->fieldName . '[0][target_id]"]');
    $this->autocompleteUrl = $this->getAbsoluteUrl($result[0]['data-autocomplete-path']);
  }
 /**
  * Tests deleting a bundle.
  */
 public function testDeleteBundle()
 {
     // Create a node bundle, display and form display object.
     $type = NodeType::create(array('type' => 'article'));
     $type->save();
     node_add_body_field($type);
     entity_get_display('node', 'article', 'default')->save();
     entity_get_form_display('node', 'article', 'default')->save();
     // Delete the bundle.
     $type->delete();
     $display = EntityViewDisplay::load('node.article.default');
     $this->assertFalse((bool) $display);
     $form_display = EntityFormDisplay::load('node.article.default');
     $this->assertFalse((bool) $form_display);
 }
  /**
   * {@inheritdoc}
   */
  public function save(array $form, FormStateInterface $form_state) {
    /** @var \Drupal\contact\ContactFormInterface $contact_form */
    $contact_form = $this->entity;
    // Get the original ID.
    $original_id = $contact_form->getOriginalId();
    $new_id = $contact_form->id();

    // Create the new form.
    $contact_form = $contact_form->createDuplicate();
    $contact_form->set('id', $new_id);
    $contact_form->save();

    // Clone configurable fields.
    foreach ($this->fieldManager->getFieldDefinitions('contact_message', $original_id) as $field) {
      if ($field instanceof BaseFieldDefinition) {
        continue;
      }
      if ($this->moduleHandler->moduleExists('field')) {
        if ($config = $field->getConfig($original_id)) {
          $new_config = FieldConfig::create([
            'bundle' => $contact_form->id(),
            'uuid' => NULL,
          ] + $config->toArray());
          $new_config->save();
        }
      }
    }

    // Clone the entity form display.
    $display = EntityFormDisplay::load('contact_message.' . $original_id . '.default');
    EntityFormDisplay::create([
      'bundle' => $contact_form->id(),
      'uuid' => NULL,
    ] + $display->toArray())->save();

    // Clone the entity view display.
    $display = EntityViewDisplay::load('contact_message.' . $original_id . '.default');
    EntityViewDisplay::create([
      'bundle' => $contact_form->id(),
      'uuid' => NULL,
    ] + $display->toArray())->save();

    // Redirect and show messge.
    $form_state->setRedirect('entity.contact_form.edit_form', ['contact_form' => $contact_form->id()]);
    $edit_link = $this->entity->link($this->t('Edit'));
    drupal_set_message($this->t('Contact form %label has been added.', array('%label' => $contact_form->label())));
    $this->logger('contact')->notice('Contact form %label has been added.', array('%label' => $contact_form->label(), 'link' => $edit_link));
  }
 /**
  * Test that migrated entity display settings can be loaded using D8 API's.
  */
 public function testEntityDisplaySettings()
 {
     // Run tests.
     $field_name = "field_test";
     $expected = array('label' => 'above', 'weight' => 1, 'type' => 'text_trimmed', 'settings' => array('trim_length' => 600), 'third_party_settings' => array());
     // Can we load any entity display.
     $display = EntityViewDisplay::load('node.story.teaser');
     $this->assertIdentical($expected, $display->getComponent($field_name));
     // Test migrate worked with multiple bundles.
     $display = EntityViewDisplay::load('node.test_page.teaser');
     $expected['weight'] = 35;
     $this->assertIdentical($expected, $display->getComponent($field_name));
     // Test RSS because that has been converted from 4 to rss.
     $display = EntityViewDisplay::load('node.story.rss');
     $expected['weight'] = 1;
     $this->assertIdentical($expected, $display->getComponent($field_name));
     // Test the default format with text_default which comes from a static map.
     $expected['type'] = 'text_default';
     $expected['settings'] = array();
     $display = EntityViewDisplay::load('node.story.default');
     $this->assertIdentical($expected, $display->getComponent($field_name));
     // Check that we can migrate multiple fields.
     $content = $display->get('content');
     $this->assertTrue(isset($content['field_test']), 'Settings for field_test exist.');
     $this->assertTrue(isset($content['field_test_two']), "Settings for field_test_two exist.");
     // Check that we can migrate a field where exclude is not set.
     $this->assertTrue(isset($content['field_test_exclude_unset']), "Settings for field_test_exclude_unset exist.");
     // Test the number field formatter settings are correct.
     $expected['weight'] = 1;
     $expected['type'] = 'number_integer';
     $expected['settings'] = array('thousand_separator' => ',', 'prefix_suffix' => TRUE);
     $component = $display->getComponent('field_test_two');
     $this->assertIdentical($expected, $component);
     $expected['weight'] = 2;
     $expected['type'] = 'number_decimal';
     $expected['settings'] = array('scale' => 2, 'decimal_separator' => '.', 'thousand_separator' => ',', 'prefix_suffix' => TRUE);
     $component = $display->getComponent('field_test_three');
     $this->assertIdentical($expected, $component);
     // Test the email field formatter settings are correct.
     $expected['weight'] = 6;
     $expected['type'] = 'email_mailto';
     $expected['settings'] = array();
     $component = $display->getComponent('field_test_email');
     $this->assertIdentical($expected, $component);
     // Test the link field formatter settings.
     $expected['weight'] = 7;
     $expected['type'] = 'link';
     $expected['settings'] = array('trim_length' => 80, 'url_only' => TRUE, 'url_plain' => TRUE, 'rel' => '0', 'target' => '0');
     $component = $display->getComponent('field_test_link');
     $this->assertIdentical($expected, $component);
     $expected['settings']['url_only'] = FALSE;
     $expected['settings']['url_plain'] = FALSE;
     $display = EntityViewDisplay::load('node.story.teaser');
     $component = $display->getComponent('field_test_link');
     $this->assertIdentical($expected, $component);
     // Test the file field formatter settings.
     $expected['weight'] = 8;
     $expected['type'] = 'file_default';
     $expected['settings'] = array();
     $component = $display->getComponent('field_test_filefield');
     $this->assertIdentical($expected, $component);
     $display = EntityViewDisplay::load('node.story.default');
     $expected['type'] = 'file_url_plain';
     $component = $display->getComponent('field_test_filefield');
     $this->assertIdentical($expected, $component);
     // Test the image field formatter settings.
     $expected['weight'] = 9;
     $expected['type'] = 'image';
     $expected['settings'] = array('image_style' => '', 'image_link' => '');
     $component = $display->getComponent('field_test_imagefield');
     $this->assertIdentical($expected, $component);
     $display = EntityViewDisplay::load('node.story.teaser');
     $expected['settings']['image_link'] = 'file';
     $component = $display->getComponent('field_test_imagefield');
     $this->assertIdentical($expected, $component);
     // Test phone field.
     $expected['weight'] = 13;
     $expected['type'] = 'basic_string';
     $expected['settings'] = array();
     $component = $display->getComponent('field_test_phone');
     $this->assertIdentical($expected, $component);
     // Test date field.
     $defaults = array('format_type' => 'fallback', 'timezone_override' => '');
     $expected['weight'] = 10;
     $expected['type'] = 'datetime_default';
     $expected['settings'] = array('format_type' => 'fallback') + $defaults;
     $component = $display->getComponent('field_test_date');
     $this->assertIdentical($expected, $component);
     $display = EntityViewDisplay::load('node.story.default');
     $expected['settings']['format_type'] = 'long';
     $component = $display->getComponent('field_test_date');
     $this->assertIdentical($expected, $component);
     // Test date stamp field.
     $expected['weight'] = 11;
     $expected['settings']['format_type'] = 'fallback';
     $component = $display->getComponent('field_test_datestamp');
     $this->assertIdentical($expected, $component);
     $display = EntityViewDisplay::load('node.story.teaser');
     $expected['settings'] = array('format_type' => 'medium') + $defaults;
     $component = $display->getComponent('field_test_datestamp');
     $this->assertIdentical($expected, $component);
     // Test datetime field.
     $expected['weight'] = 12;
     $expected['settings'] = array('format_type' => 'short') + $defaults;
     $component = $display->getComponent('field_test_datetime');
     $this->assertIdentical($expected, $component);
     $display = EntityViewDisplay::load('node.story.default');
     $expected['settings']['format_type'] = 'fallback';
     $component = $display->getComponent('field_test_datetime');
     $this->assertIdentical($expected, $component);
     // Test a date field with a random format which should be mapped
     // to datetime_default.
     $display = EntityViewDisplay::load('node.story.rss');
     $expected['settings']['format_type'] = 'fallback';
     $component = $display->getComponent('field_test_datetime');
     $this->assertIdentical($expected, $component);
     // Test that our Id map has the correct data.
     $this->assertIdentical(array('node', 'story', 'teaser', 'field_test'), Migration::load('d6_field_formatter_settings')->getIdMap()->lookupDestinationID(array('story', 'teaser', 'node', 'field_test')));
 }
Beispiel #24
0
 /**
  * Adds a contextual tab to entities.
  *
  * @param RouteMatchInterface $route_match
  *
  * @return RedirectResponse
  */
 public function contextualTab(RouteMatchInterface $route_match)
 {
     $parameter_name = $route_match->getRouteObject()->getOption('_ds_entity_type_id');
     $entity = $route_match->getParameter($parameter_name);
     $entity_type_id = $entity->getEntityTypeId();
     $destination = $entity->toUrl();
     if (!empty($entity->ds_switch->value)) {
         $view_mode = $entity->ds_switch->value;
     } else {
         $view_mode = 'full';
     }
     // Get the manage display URI.
     $route = FieldUI::getOverviewRouteInfo($entity_type_id, $entity->bundle());
     /** @var $entity_display EntityDisplayBase */
     $entity_display = EntityViewDisplay::load($entity_type_id . '.' . $entity->bundle() . '.' . $view_mode);
     $route_parameters = $route->getRouteParameters();
     if ($entity_display && $entity_display->getThirdPartySetting('ds', 'layout')) {
         $route_parameters['view_mode_name'] = $view_mode;
         $admin_route_name = "entity.entity_view_display.{$entity_type_id}.view_mode";
     } else {
         $admin_route_name = "entity.entity_view_display.{$entity_type_id}.default";
     }
     $route->setOption('query', array('destination' => $destination->toString()));
     $url = new Url($admin_route_name, $route_parameters, $route->getOptions());
     return new RedirectResponse($url->toString());
 }
Beispiel #25
0
  /**
   * Test selecting layouts, classes, region to block and fields.
   */
  function testDStestLayouts() {
    // Check that the ds_3col_equal_width layout is not available (through the alter).
    $this->drupalGet('admin/structure/types/manage/article/display');
    $this->assertNoRaw('ds_3col_stacked_equal_width', 'ds_3col_stacked_equal_width not available');

    // Create code and block field.
    $this->dsCreateTokenField();
    $this->dsCreateBlockField();

    $layout = array(
      'layout' => 'ds_2col_stacked',
    );

    $assert = array(
      'regions' => array(
        'header' => '<td colspan="8">' . t('Header') . '</td>',
        'left' => '<td colspan="8">' . t('Left') . '</td>',
        'right' => '<td colspan="8">' . t('Right') . '</td>',
        'footer' => '<td colspan="8">' . t('Footer') . '</td>',
      ),
    );

    $fields = array(
      'fields[node_post_date][region]' => 'header',
      'fields[node_author][region]' => 'left',
      'fields[node_links][region]' => 'left',
      'fields[body][region]' => 'right',
      'fields[dynamic_token_field:node-test_field][region]' => 'left',
      'fields[dynamic_block_field:node-test_block_field][region]' => 'left',
      'fields[node_submitted_by][region]' => 'left',
      'fields[ds_extras_extra_test_field][region]' => 'header',
    );

    // Setup first layout.
    $this->dsSelectLayout($layout, $assert);
    $this->dsConfigureClasses();
    $this->dsSelectClasses();
    $this->dsConfigureUI($fields);

    // Assert the two extra fields are found.
    $this->drupalGet('admin/structure/types/manage/article/display');
    $this->assertRaw('ds_extras_extra_test_field');
    $this->assertRaw('ds_extras_second_field');

    // Assert we have configuration.
    $entity_display = entity_load('entity_view_display', 'node.article.default');
    $data = $entity_display->getThirdPartySettings('ds');

    $this->assertTrue(!empty($data), t('Configuration found for layout settings for node article'));
    $this->assertTrue(in_array('ds_extras_extra_test_field', $data['regions']['header']), t('Extra field is in header'));
    $this->assertTrue(in_array('node_post_date', $data['regions']['header']), t('Post date is in header'));
    $this->assertTrue(in_array('dynamic_token_field:node-test_field', $data['regions']['left']), t('Test field is in left'));
    $this->assertTrue(in_array('node_author', $data['regions']['left']), t('Author is in left'));
    $this->assertTrue(in_array('node_links', $data['regions']['left']), t('Links is in left'));
    $this->assertTrue(in_array('dynamic_block_field:node-test_block_field', $data['regions']['left']), t('Test block field is in left'));
    $this->assertTrue(in_array('body', $data['regions']['right']), t('Body is in right'));
    $this->assertTrue(in_array('class_name_1', $data['layout']['settings']['classes']['header']), t('Class name 1 is in header'));
    $this->assertTrue(empty($data['layout']['settings']['classes']['left']), t('Left has no classes'));
    $this->assertTrue(empty($data['layout']['settings']['classes']['right']), t('Right has classes'));
    $this->assertTrue(in_array('class_name_2', $data['layout']['settings']['classes']['footer']), t('Class name 2 is in header'));

    // Create a article node and verify settings.
    $settings = array(
      'type' => 'article',
    );
    $node = $this->drupalCreateNode($settings);
    $this->drupalGet('node/' . $node->id());

    // Assert regions.
    $this->assertRaw('group-header', 'Template found (region header)');
    $this->assertRaw('group-header class_name_1', 'Class found (class_name_1)');
    $this->assertRaw('group-left', 'Template found (region left)');
    $this->assertRaw('group-right', 'Template found (region right)');
    $this->assertRaw('group-footer', 'Template found (region footer)');
    $this->assertRaw('group-footer class_name_2', 'Class found (class_name_2)');

    // Assert custom fields.
    $this->assertRaw('field--name-dynamic-token-fieldnode-test-field', t('Custom field found'));
    $this->assertRaw('field--name-dynamic-block-fieldnode-test-block-field', t('Custom block field found'));

    // @todo title isn't set, cause we are dealing with the block itself not the instance
    //$this->assertRaw('Recent content</h2>', t('Custom block field found'));
    $this->assertRaw('Submitted by', t('Submitted field found'));
    $this->assertText('This is an extra field made available through "Extra fields" functionality.');

    // Test HTML5 wrappers
    $this->assertNoRaw('<header class="group-header', 'Header not found.');
    $this->assertNoRaw('<footer class="group-right', 'Footer not found.');
    $this->assertNoRaw('<article', 'Article not found.');
    $wrappers = array(
      'layout_configuration[region_wrapper][header]' => 'header',
      'layout_configuration[region_wrapper][right]' => 'footer',
      'layout_configuration[region_wrapper][outer_wrapper]' => 'article',
    );
    $this->dsConfigureUI($wrappers);
    $this->drupalGet('node/' . $node->id());
    $this->assertRaw('<header class="group-header', 'Header found.');
    $this->assertRaw('<footer class="group-right', 'Footer found.');
    $this->assertRaw('<article', 'Article found.');

    // Let's create a block field, enable the full mode first.
    $edit = array('display_modes_custom[full]' => '1');
    $this->drupalPostForm('admin/structure/types/manage/article/display', $edit, t('Save'));

    // Select layout.
    $layout = array(
      'layout' => 'ds_2col',
    );

    $assert = array(
      'regions' => array(
        'left' => '<td colspan="8">' . t('Left') . '</td>',
        'right' => '<td colspan="8">' . t('Right') . '</td>',
      ),
    );
    $this->dsSelectLayout($layout, $assert, 'admin/structure/types/manage/article/display/full');

    // Create new block field.
    $edit = array(
      'new_block_region' => 'Block region',
      'new_block_region_key' => 'block_region',
    );
    $this->drupalPostForm('admin/structure/types/manage/article/display/full', $edit, t('Save'));
    $this->assertRaw('<td colspan="9">' . t('Block region') . '</td>', 'Block region found');

    // Configure fields
    $fields = array(
      'fields[node_author][region]' => 'left',
      'fields[node_links][region]' => 'left',
      'fields[body][region]' => 'right',
      'fields[dynamic_token_field:node-test_field][region]' => 'block_region',
    );
    $this->dsConfigureUI($fields, 'admin/structure/types/manage/article/display/full');

    // Set block in sidebar

    // @todo fix this

    /*
    $edit = array(
      'blocks[ds_extras_block_region][region]' => 'sidebar_first',
    );
    $this->drupalPostForm('admin/structure/block', $edit, t('Save blocks'));

    // Assert the block is on the node page.
    $this->drupalGet('node/' . $node->id());
    $this->assertRaw('Block region</h2>', 'Block region found');
    $this->assertText('Test code field on node ' . $node->id(), 'Post date in block');
    */

    // Change layout via admin/structure/ds/layout-change.
    // First verify that header and footer are not here.
    $this->drupalGet('admin/structure/types/manage/article/display/full');
    $this->assertNoRaw('<td colspan="8">' . t('Header') . '</td>', 'Header region not found');
    $this->assertNoRaw('<td colspan="8">' . t('Footer') . '</td>', 'Footer region not found');

    // Remap the regions.
    $edit = array(
      'ds_left' => 'header',
      'ds_right' => 'footer',
      'ds_block_region' => 'footer',
    );
    $this->drupalPostForm('admin/structure/ds/change-layout/node/article/full/ds_2col_stacked', $edit, t('Save'));
    $this->drupalGet('admin/structure/types/manage/article/display/full');

    // Verify new regions.
    $this->assertRaw('<td colspan="9">' . t('Header') . '</td>', 'Header region found');
    $this->assertRaw('<td colspan="9">' . t('Footer') . '</td>', 'Footer region found');
    $this->assertRaw('<td colspan="9">' . t('Block region') . '</td>', 'Block region found');

    // Verify settings.
    $entity_display = EntityViewDisplay::load('node.article.full', TRUE);
    $data = $entity_display->getThirdPartySettings('ds');
    $this->assertTrue(in_array('node_author', $data['regions']['header']), t('Author is in header'));
    $this->assertTrue(in_array('node_links', $data['regions']['header']), t('Links field is in header'));
    $this->assertTrue(in_array('body', $data['regions']['footer']), t('Body field is in footer'));
    $this->assertTrue(in_array('dynamic_token_field:node-test_field', $data['regions']['footer']), t('Test field is in footer'));

    // Test that a default view mode with no layout is not affected by a disabled view mode.
    $edit = array(
      'layout' => '',
      'display_modes_custom[full]' => FALSE,
    );
    $this->drupalPostForm('admin/structure/types/manage/article/display', $edit, t('Save'));
    $this->drupalGet('node/' . $node->id());
    $this->assertNoText('Test code field on node 1', 'No ds field from full view mode layout');
  }
 /**
  * Tests the comment formatter configured with a custom comment view mode.
  */
 public function testViewMode()
 {
     $this->drupalLogin($this->webUser);
     $this->drupalGet($this->node->toUrl());
     $comment_text = $this->randomMachineName();
     // Post a comment.
     $this->postComment($this->node, $comment_text);
     // Comment displayed in 'default' display mode found and has body text.
     $comment_element = $this->cssSelect('.comment-wrapper');
     $this->assertTrue(!empty($comment_element));
     $this->assertRaw('<p>' . $comment_text . '</p>');
     // Create a new comment entity view mode.
     $mode = Unicode::strtolower($this->randomMachineName());
     EntityViewMode::create(['targetEntityType' => 'comment', 'id' => "comment.{$mode}"])->save();
     // Create the corresponding entity view display for article node-type. Note
     // that this new view display mode doesn't contain the comment body.
     EntityViewDisplay::create(['targetEntityType' => 'comment', 'bundle' => 'comment', 'mode' => $mode])->setStatus(TRUE)->save();
     /** @var \Drupal\Core\Entity\Display\EntityViewDisplayInterface $node_display */
     $node_display = EntityViewDisplay::load('node.article.default');
     $formatter = $node_display->getComponent('comment');
     // Change the node comment field formatter to use $mode mode instead of
     // 'default' mode.
     $formatter['settings']['view_mode'] = $mode;
     $node_display->setComponent('comment', $formatter)->save();
     // Reloading the node page to show the same node with its same comment but
     // with a different display mode.
     $this->drupalGet($this->node->toUrl());
     // The comment should exist but without the body text because we used $mode
     // mode this time.
     $comment_element = $this->cssSelect('.comment-wrapper');
     $this->assertTrue(!empty($comment_element));
     $this->assertNoRaw('<p>' . $comment_text . '</p>');
 }
Beispiel #27
0
 /**
  * Tests forum functionality through the admin and user interfaces.
  */
 function testForum()
 {
     //Check that the basic forum install creates a default forum topic
     $this->drupalGet('/forum');
     // Look for the "General discussion" default forum
     $this->assertRaw(t('<a href="' . Url::fromRoute('forum.page', ['taxonomy_term' => 1])->toString() . '">General discussion</a>'), "Found the default forum at the /forum listing");
     // Check the presence of expected cache tags.
     $this->assertCacheTag('config:forum.settings');
     $this->drupalGet(Url::fromRoute('forum.page', ['taxonomy_term' => 1]));
     $this->assertCacheTag('config:forum.settings');
     // Do the admin tests.
     $this->doAdminTests($this->adminUser);
     // Check display order.
     $display = EntityViewDisplay::load('node.forum.default');
     $body = $display->getComponent('body');
     $comment = $display->getComponent('comment_forum');
     $taxonomy = $display->getComponent('taxonomy_forums');
     // Assert field order is body » taxonomy » comments.
     $this->assertTrue($taxonomy['weight'] < $body['weight']);
     $this->assertTrue($body['weight'] < $comment['weight']);
     // Check form order.
     $display = EntityFormDisplay::load('node.forum.default');
     $body = $display->getComponent('body');
     $comment = $display->getComponent('comment_forum');
     $taxonomy = $display->getComponent('taxonomy_forums');
     // Assert category comes before body in order.
     $this->assertTrue($taxonomy['weight'] < $body['weight']);
     $this->generateForumTopics();
     // Login an unprivileged user to view the forum topics and generate an
     // active forum topics list.
     $this->drupalLogin($this->webUser);
     // Verify that this user is shown a message that they may not post content.
     $this->drupalGet('forum/' . $this->forum['tid']);
     $this->assertText(t('You are not allowed to post new content in the forum'), "Authenticated user without permission to post forum content is shown message in local tasks to that effect.");
     // Log in, and do basic tests for a user with permission to edit any forum
     // content.
     $this->doBasicTests($this->editAnyTopicsUser, TRUE);
     // Create a forum node authored by this user.
     $any_topics_user_node = $this->createForumTopic($this->forum, FALSE);
     // Log in, and do basic tests for a user with permission to edit only its
     // own forum content.
     $this->doBasicTests($this->editOwnTopicsUser, FALSE);
     // Create a forum node authored by this user.
     $own_topics_user_node = $this->createForumTopic($this->forum, FALSE);
     // Verify that this user cannot edit forum content authored by another user.
     $this->verifyForums($any_topics_user_node, FALSE, 403);
     // Verify that this user is shown a local task to add new forum content.
     $this->drupalGet('forum');
     $this->assertLink(t('Add new Forum topic'));
     $this->drupalGet('forum/' . $this->forum['tid']);
     $this->assertLink(t('Add new Forum topic'));
     // Login a user with permission to edit any forum content.
     $this->drupalLogin($this->editAnyTopicsUser);
     // Verify that this user can edit forum content authored by another user.
     $this->verifyForums($own_topics_user_node, TRUE);
     // Verify the topic and post counts on the forum page.
     $this->drupalGet('forum');
     // Verify row for testing forum.
     $forum_arg = array(':forum' => 'forum-list-' . $this->forum['tid']);
     // Topics cell contains number of topics and number of unread topics.
     $xpath = $this->buildXPathQuery('//tr[@id=:forum]//td[@class="forum__topics"]', $forum_arg);
     $topics = $this->xpath($xpath);
     $topics = trim($topics[0]);
     $this->assertEqual($topics, '6', 'Number of topics found.');
     // Verify the number of unread topics.
     $unread_topics = $this->container->get('forum_manager')->unreadTopics($this->forum['tid'], $this->editAnyTopicsUser->id());
     $unread_topics = \Drupal::translation()->formatPlural($unread_topics, '1 new post', '@count new posts');
     $xpath = $this->buildXPathQuery('//tr[@id=:forum]//td[@class="forum__topics"]//a', $forum_arg);
     $this->assertFieldByXPath($xpath, $unread_topics, 'Number of unread topics found.');
     // Verify that the forum name is in the unread topics text.
     $xpath = $this->buildXPathQuery('//tr[@id=:forum]//em[@class="placeholder"]', $forum_arg);
     $this->assertFieldByXpath($xpath, $this->forum['name'], 'Forum name found in unread topics text.');
     // Verify total number of posts in forum.
     $xpath = $this->buildXPathQuery('//tr[@id=:forum]//td[@class="forum__posts"]', $forum_arg);
     $this->assertFieldByXPath($xpath, '6', 'Number of posts found.');
     // Test loading multiple forum nodes on the front page.
     $this->drupalLogin($this->drupalCreateUser(array('administer content types', 'create forum content', 'post comments')));
     $this->drupalPostForm('admin/structure/types/manage/forum', array('options[promote]' => 'promote'), t('Save content type'));
     $this->createForumTopic($this->forum, FALSE);
     $this->createForumTopic($this->forum, FALSE);
     $this->drupalGet('node');
     // Test adding a comment to a forum topic.
     $node = $this->createForumTopic($this->forum, FALSE);
     $edit = array();
     $edit['comment_body[0][value]'] = $this->randomMachineName();
     $this->drupalPostForm('node/' . $node->id(), $edit, t('Save'));
     $this->assertResponse(200);
     // Test editing a forum topic that has a comment.
     $this->drupalLogin($this->editAnyTopicsUser);
     $this->drupalGet('forum/' . $this->forum['tid']);
     $this->drupalPostForm('node/' . $node->id() . '/edit', array(), t('Save'));
     $this->assertResponse(200);
     // Test the root forum page title change.
     $this->drupalGet('forum');
     $this->assertCacheTag('config:taxonomy.vocabulary.' . $this->forum['vid']);
     $this->assertTitle(t('Forums | Drupal'));
     $vocabulary = Vocabulary::load($this->forum['vid']);
     $vocabulary->set('name', 'Discussions');
     $vocabulary->save();
     $this->drupalGet('forum');
     $this->assertTitle(t('Discussions | Drupal'));
     // Test anonymous action link.
     $this->drupalLogout();
     $this->drupalGet('forum/' . $this->forum['tid']);
     $this->assertLink(t('Log in to post new content in the forum.'));
 }
 /**
  * Asserts that a particular component is NOT included in a display.
  *
  * @param string $display_id
  *   The display ID.
  * @param string $component_id
  *   The component ID.
  */
 protected function assertComponentNotExists($display_id, $component_id)
 {
     $component = EntityViewDisplay::load($display_id)->getComponent($component_id);
     $this->assertTrue(is_null($component));
 }
 /**
  * {@inheritdoc}
  */
 public function calculateDependencies()
 {
     $dependencies = parent::calculateDependencies();
     if ($mode = $this->getSetting('view_mode')) {
         if ($bundle = $this->getFieldSetting('comment_type')) {
             /** @var \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display */
             if ($display = EntityViewDisplay::load("comment.{$bundle}.{$mode}")) {
                 $dependencies[$display->getConfigDependencyKey()][] = $display->getConfigDependencyName();
             }
         }
     }
     return $dependencies;
 }
Beispiel #30
0
 /**
  * Tests image style configuration import that does a delete.
  */
 function testConfigImport()
 {
     // Create a new style.
     $style_name = strtolower($this->randomMachineName(10));
     $style_label = $this->randomString();
     $style = entity_create('image_style', array('name' => $style_name, 'label' => $style_label));
     $style->save();
     // Create an image field that uses the new style.
     $field_name = strtolower($this->randomMachineName(10));
     $this->createImageField($field_name, 'article');
     entity_get_display('node', 'article', 'default')->setComponent($field_name, array('type' => 'image', 'settings' => array('image_style' => $style_name)))->save();
     // Create a new node with an image attached.
     $test_image = current($this->drupalGetTestFiles('image'));
     $nid = $this->uploadNodeImage($test_image, $field_name, 'article', $this->randomMachineName());
     $node = Node::load($nid);
     // Get node field original image URI.
     $fid = $node->get($field_name)->target_id;
     $original_uri = File::load($fid)->getFileUri();
     // Test that image is displayed using newly created style.
     $this->drupalGet('node/' . $nid);
     $this->assertRaw(file_url_transform_relative($style->buildUrl($original_uri)), format_string('Image displayed using style @style.', array('@style' => $style_name)));
     // Copy config to sync, and delete the image style.
     $sync = $this->container->get('config.storage.sync');
     $active = $this->container->get('config.storage');
     // Remove the image field from the display, to avoid a dependency error
     // during import.
     EntityViewDisplay::load('node.article.default')->removeComponent($field_name)->save();
     $this->copyConfig($active, $sync);
     $sync->delete('image.style.' . $style_name);
     $this->configImporter()->import();
     $this->assertFalse(ImageStyle::load($style_name), 'Style deleted after config import.');
     $this->assertEqual($this->getImageCount($style), 0, 'Image style was flushed after being deleted by config import.');
 }