Chris@0: drupalPlaceBlock('system_breadcrumb_block'); Chris@0: $this->drupalPlaceBlock('local_tasks_block'); Chris@0: Chris@0: // Create a test user. Chris@0: $admin_user = $this->drupalCreateUser(['access content', 'administer content types', 'administer node fields', 'administer node form display', 'administer node display', 'administer taxonomy', 'administer taxonomy_term fields', 'administer taxonomy_term display', 'administer users', 'administer account settings', 'administer user display', 'bypass node access']); Chris@0: $this->drupalLogin($admin_user); Chris@0: Chris@0: // Create content type, with underscores. Chris@0: $type_name = strtolower($this->randomMachineName(8)) . '_test'; Chris@0: $type = $this->drupalCreateContentType(['name' => $type_name, 'type' => $type_name]); Chris@0: $this->type = $type->id(); Chris@0: Chris@0: // Create a default vocabulary. Chris@0: $vocabulary = Vocabulary::create([ Chris@0: 'name' => $this->randomMachineName(), Chris@0: 'description' => $this->randomMachineName(), Chris@0: 'vid' => Unicode::strtolower($this->randomMachineName()), Chris@0: 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED, Chris@0: 'help' => '', Chris@0: 'nodes' => ['article' => 'article'], Chris@0: 'weight' => mt_rand(0, 10), Chris@0: ]); Chris@0: $vocabulary->save(); Chris@0: $this->vocabulary = $vocabulary->id(); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Tests formatter settings. Chris@0: */ Chris@0: public function testFormatterUI() { Chris@0: $manage_fields = 'admin/structure/types/manage/' . $this->type; Chris@0: $manage_display = $manage_fields . '/display'; Chris@0: Chris@0: // Create a field, and a node with some data for the field. Chris@0: $this->fieldUIAddNewField($manage_fields, 'test', 'Test field'); Chris@0: Chris@0: // Get the display options (formatter and settings) that were automatically Chris@0: // assigned for the 'default' display. Chris@0: $display = entity_get_display('node', $this->type, 'default'); Chris@0: $display_options = $display->getComponent('field_test'); Chris@0: $format = $display_options['type']; Chris@0: $default_settings = \Drupal::service('plugin.manager.field.formatter')->getDefaultSettings($format); Chris@0: $setting_name = key($default_settings); Chris@0: $setting_value = $display_options['settings'][$setting_name]; Chris@0: Chris@0: // Display the "Manage display" screen and check that the expected formatter Chris@0: // is selected. Chris@0: $this->drupalGet($manage_display); Chris@0: $this->assertFieldByName('fields[field_test][type]', $format, 'The expected formatter is selected.'); Chris@0: $this->assertText("$setting_name: $setting_value", 'The expected summary is displayed.'); Chris@0: Chris@0: // Check whether formatter weights are respected. Chris@0: $result = $this->xpath('//select[@id=:id]/option', [':id' => 'edit-fields-field-test-type']); Chris@0: $options = array_map(function ($item) { Chris@0: return (string) $item->attributes()->value[0]; Chris@0: }, $result); Chris@0: $expected_options = [ Chris@0: 'field_no_settings', Chris@0: 'field_empty_test', Chris@0: 'field_empty_setting', Chris@0: 'field_test_default', Chris@0: 'field_test_multiple', Chris@0: 'field_test_with_prepare_view', Chris@0: 'field_test_applicable', Chris@0: ]; Chris@0: $this->assertEqual($options, $expected_options, 'The expected formatter ordering is respected.'); Chris@0: Chris@0: // Ensure that fields can be hidden directly by changing the region. Chris@0: $this->drupalGet($manage_display); Chris@0: $this->assertFieldByName('fields[field_test][region]', 'content'); Chris@0: $edit = ['fields[field_test][region]' => 'hidden']; Chris@0: $this->drupalPostForm($manage_display, $edit, t('Save')); Chris@0: $this->assertFieldByName('fields[field_test][region]', 'hidden'); Chris@0: $display = EntityViewDisplay::load("node.{$this->type}.default"); Chris@0: $this->assertNull($display->getComponent('field_test')); Chris@0: Chris@0: // Restore the field to the content region. Chris@0: $edit = [ Chris@0: 'fields[field_test][type]' => 'field_test_default', Chris@0: 'fields[field_test][region]' => 'content', Chris@0: ]; Chris@0: $this->drupalPostForm($manage_display, $edit, t('Save')); Chris@0: Chris@0: // Change the formatter and check that the summary is updated. Chris@0: $edit = [ Chris@0: 'fields[field_test][type]' => 'field_test_multiple', Chris@0: 'fields[field_test][region]' => 'content', Chris@0: 'refresh_rows' => 'field_test' Chris@0: ]; Chris@0: $this->drupalPostAjaxForm(NULL, $edit, ['op' => t('Refresh')]); Chris@0: $format = 'field_test_multiple'; Chris@0: $default_settings = \Drupal::service('plugin.manager.field.formatter')->getDefaultSettings($format); Chris@0: $setting_name = key($default_settings); Chris@0: $setting_value = $default_settings[$setting_name]; Chris@0: $this->assertFieldByName('fields[field_test][type]', $format, 'The expected formatter is selected.'); Chris@0: $this->assertText("$setting_name: $setting_value", 'The expected summary is displayed.'); Chris@0: Chris@0: // Submit the form and check that the display is updated. Chris@0: $this->drupalPostForm(NULL, [], t('Save')); Chris@0: $display = entity_get_display('node', $this->type, 'default'); Chris@0: $display_options = $display->getComponent('field_test'); Chris@0: $current_format = $display_options['type']; Chris@0: $current_setting_value = $display_options['settings'][$setting_name]; Chris@0: $this->assertEqual($current_format, $format, 'The formatter was updated.'); Chris@0: $this->assertEqual($current_setting_value, $setting_value, 'The setting was updated.'); Chris@0: Chris@0: // Assert that hook_field_formatter_settings_summary_alter() is called. Chris@0: $this->assertText('field_test_field_formatter_settings_summary_alter'); Chris@0: Chris@0: // Click on the formatter settings button to open the formatter settings Chris@0: // form. Chris@0: $this->drupalPostAjaxForm(NULL, [], "field_test_settings_edit"); Chris@0: Chris@0: // Assert that the field added in Chris@0: // field_test_field_formatter_third_party_settings_form() is present. Chris@0: $fieldname = 'fields[field_test][settings_edit_form][third_party_settings][field_third_party_test][field_test_field_formatter_third_party_settings_form]'; Chris@0: $this->assertField($fieldname, 'The field added in hook_field_formatter_third_party_settings_form() is present on the settings form.'); Chris@0: $edit = [$fieldname => 'foo']; Chris@0: $this->drupalPostAjaxForm(NULL, $edit, "field_test_plugin_settings_update"); Chris@0: Chris@0: // Save the form to save the third party settings. Chris@0: $this->drupalPostForm(NULL, [], t('Save')); Chris@0: Chris@0: \Drupal::entityManager()->clearCachedFieldDefinitions(); Chris@0: $id = 'node.' . $this->type . '.default'; Chris@0: $storage = $this->container->get('entity_type.manager')->getStorage('entity_view_display'); Chris@0: $storage->resetCache([$id]); Chris@0: $display = $storage->load($id); Chris@0: $this->assertEqual($display->getRenderer('field_test')->getThirdPartySetting('field_third_party_test', 'field_test_field_formatter_third_party_settings_form'), 'foo'); Chris@0: $this->assertTrue(in_array('field_third_party_test', $display->calculateDependencies()->getDependencies()['module']), 'The display has a dependency on field_third_party_test module.'); Chris@0: Chris@0: // Confirm that the third party settings are not updated on the settings form. Chris@0: $this->drupalPostAjaxForm(NULL, [], "field_test_settings_edit"); Chris@0: $this->assertFieldByName($fieldname, ''); Chris@0: Chris@0: // Test the empty setting formatter. Chris@0: $edit = [ Chris@0: 'fields[field_test][type]' => 'field_empty_setting', Chris@0: 'fields[field_test][region]' => 'content', Chris@0: ]; Chris@0: $this->drupalPostForm(NULL, $edit, t('Save')); Chris@0: $this->assertNoText('Default empty setting now has a value.'); Chris@0: $this->assertFieldById('edit-fields-field-test-settings-edit'); Chris@0: $this->drupalPostAjaxForm(NULL, [], "field_test_settings_edit"); Chris@0: $fieldname = 'fields[field_test][settings_edit_form][settings][field_empty_setting]'; Chris@0: $edit = [$fieldname => 'non empty setting']; Chris@0: $this->drupalPostAjaxForm(NULL, $edit, "field_test_plugin_settings_update"); Chris@0: $this->assertText('Default empty setting now has a value.'); Chris@0: Chris@0: // Test the settings form behavior. An edit button should be present since Chris@0: // there are third party settings to configure. Chris@0: $edit = [ Chris@0: 'fields[field_test][type]' => 'field_no_settings', Chris@0: 'fields[field_test][region]' => 'content', Chris@0: 'refresh_rows' => 'field_test', Chris@0: ]; Chris@0: $this->drupalPostAjaxForm(NULL, $edit, ['op' => t('Refresh')]); Chris@0: $this->assertFieldByName('field_test_settings_edit'); Chris@0: Chris@0: // Make sure we can save the third party settings when there are no settings available Chris@0: $this->drupalPostAjaxForm(NULL, [], "field_test_settings_edit"); Chris@0: $this->drupalPostAjaxForm(NULL, $edit, "field_test_plugin_settings_update"); Chris@0: Chris@0: // When a module providing third-party settings to a formatter (or widget) Chris@0: // is uninstalled, the formatter remains enabled but the provided settings, Chris@0: // together with the corresponding form elements, are removed from the Chris@0: // display component. Chris@0: \Drupal::service('module_installer')->uninstall(['field_third_party_test']); Chris@0: Chris@0: // Ensure the button is still there after the module has been disabled. Chris@0: $this->drupalGet($manage_display); Chris@0: $this->assertResponse(200); Chris@0: $this->assertFieldByName('field_test_settings_edit'); Chris@0: Chris@0: // Ensure that third-party form elements are not present anymore. Chris@0: $this->drupalPostAjaxForm(NULL, [], 'field_test_settings_edit'); Chris@0: $fieldname = 'fields[field_test][settings_edit_form][third_party_settings][field_third_party_test][field_test_field_formatter_third_party_settings_form]'; Chris@0: $this->assertNoField($fieldname); Chris@0: Chris@0: // Ensure that third-party settings were removed from the formatter. Chris@0: $display = EntityViewDisplay::load("node.{$this->type}.default"); Chris@0: $component = $display->getComponent('field_test'); Chris@0: $this->assertFalse(array_key_exists('field_third_party_test', $component['third_party_settings'])); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Tests widget settings. Chris@0: */ Chris@0: public function testWidgetUI() { Chris@0: // Admin Manage Fields page. Chris@0: $manage_fields = 'admin/structure/types/manage/' . $this->type; Chris@0: // Admin Manage Display page. Chris@0: $manage_display = $manage_fields . '/form-display'; Chris@0: Chris@0: // Creates a new field that can be used with multiple formatters. Chris@0: // Reference: Drupal\field_test\Plugin\Field\FieldWidget\TestFieldWidgetMultiple::isApplicable(). Chris@0: $this->fieldUIAddNewField($manage_fields, 'test', 'Test field'); Chris@0: Chris@0: // Get the display options (formatter and settings) that were automatically Chris@0: // assigned for the 'default' display. Chris@0: $display = entity_get_form_display('node', $this->type, 'default'); Chris@0: $display_options = $display->getComponent('field_test'); Chris@0: $widget_type = $display_options['type']; Chris@0: $default_settings = \Drupal::service('plugin.manager.field.widget')->getDefaultSettings($widget_type); Chris@0: $setting_name = key($default_settings); Chris@0: $setting_value = $display_options['settings'][$setting_name]; Chris@0: Chris@0: // Display the "Manage form display" screen and check if the expected Chris@0: // widget is selected. Chris@0: $this->drupalGet($manage_display); Chris@0: $this->assertFieldByName('fields[field_test][type]', $widget_type, 'The expected widget is selected.'); Chris@0: $this->assertText("$setting_name: $setting_value", 'The expected summary is displayed.'); Chris@0: Chris@0: // Check whether widget weights are respected. Chris@0: $result = $this->xpath('//select[@id=:id]/option', [':id' => 'edit-fields-field-test-type']); Chris@0: $options = array_map(function ($item) { Chris@0: return (string) $item->attributes()->value[0]; Chris@0: }, $result); Chris@0: $expected_options = [ Chris@0: 'test_field_widget', Chris@0: 'test_field_widget_multiple', Chris@0: ]; Chris@0: $this->assertEqual($options, $expected_options, 'The expected widget ordering is respected.'); Chris@0: Chris@0: // Change the widget and check that the summary is updated. Chris@0: $edit = [ Chris@0: 'fields[field_test][type]' => 'test_field_widget_multiple', Chris@0: 'fields[field_test][region]' => 'content', Chris@0: 'refresh_rows' => 'field_test', Chris@0: ]; Chris@0: $this->drupalPostAjaxForm(NULL, $edit, ['op' => t('Refresh')]); Chris@0: $widget_type = 'test_field_widget_multiple'; Chris@0: $default_settings = \Drupal::service('plugin.manager.field.widget')->getDefaultSettings($widget_type); Chris@0: $setting_name = key($default_settings); Chris@0: $setting_value = $default_settings[$setting_name]; Chris@0: $this->assertFieldByName('fields[field_test][type]', $widget_type, 'The expected widget is selected.'); Chris@0: $this->assertText("$setting_name: $setting_value", 'The expected summary is displayed.'); Chris@0: Chris@0: // Submit the form and check that the display is updated. Chris@0: $this->drupalPostForm(NULL, [], t('Save')); Chris@0: $display = entity_get_form_display('node', $this->type, 'default'); Chris@0: $display_options = $display->getComponent('field_test'); Chris@0: $current_widget = $display_options['type']; Chris@0: $current_setting_value = $display_options['settings'][$setting_name]; Chris@0: $this->assertEqual($current_widget, $widget_type, 'The widget was updated.'); Chris@0: $this->assertEqual($current_setting_value, $setting_value, 'The setting was updated.'); Chris@0: Chris@0: // Assert that hook_field_widget_settings_summary_alter() is called. Chris@0: $this->assertText('field_test_field_widget_settings_summary_alter'); Chris@0: Chris@0: // Click on the widget settings button to open the widget settings form. Chris@0: $this->drupalPostAjaxForm(NULL, [], "field_test_settings_edit"); Chris@0: Chris@0: // Assert that the field added in Chris@0: // field_test_field_widget_third_party_settings_form() is present. Chris@0: $fieldname = 'fields[field_test][settings_edit_form][third_party_settings][field_third_party_test][field_test_widget_third_party_settings_form]'; Chris@0: $this->assertField($fieldname, 'The field added in hook_field_widget_third_party_settings_form() is present on the settings form.'); Chris@0: $edit = [$fieldname => 'foo']; Chris@0: $this->drupalPostAjaxForm(NULL, $edit, "field_test_plugin_settings_update"); Chris@0: Chris@0: // Save the form to save the third party settings. Chris@0: $this->drupalPostForm(NULL, [], t('Save')); Chris@0: \Drupal::entityManager()->clearCachedFieldDefinitions(); Chris@0: $storage = $this->container->get('entity_type.manager')->getStorage('entity_form_display'); Chris@0: $storage->resetCache(['node.' . $this->type . '.default']); Chris@0: $display = $storage->load('node.' . $this->type . '.default'); Chris@0: $this->assertEqual($display->getRenderer('field_test')->getThirdPartySetting('field_third_party_test', 'field_test_widget_third_party_settings_form'), 'foo'); Chris@0: $this->assertTrue(in_array('field_third_party_test', $display->calculateDependencies()->getDependencies()['module']), 'Form display does not have a dependency on field_third_party_test module.'); Chris@0: Chris@0: // Confirm that the third party settings are not updated on the settings form. Chris@0: $this->drupalPostAjaxForm(NULL, [], "field_test_settings_edit"); Chris@0: $this->assertFieldByName($fieldname, ''); Chris@0: Chris@0: // Creates a new field that can not be used with the multiple formatter. Chris@0: // Reference: Drupal\field_test\Plugin\Field\FieldWidget\TestFieldWidgetMultiple::isApplicable(). Chris@0: $this->fieldUIAddNewField($manage_fields, 'onewidgetfield', 'One Widget Field'); Chris@0: Chris@0: // Go to the Manage Form Display. Chris@0: $this->drupalGet($manage_display); Chris@0: Chris@0: // Checks if the select elements contain the specified options. Chris@0: $this->assertFieldSelectOptions('fields[field_test][type]', ['test_field_widget', 'test_field_widget_multiple']); Chris@0: $this->assertFieldSelectOptions('fields[field_onewidgetfield][type]', ['test_field_widget']); Chris@0: Chris@0: // Ensure that fields can be hidden directly by changing the region. Chris@0: $this->assertFieldByName('fields[field_test][region]', 'content'); Chris@0: $edit = ['fields[field_test][region]' => 'hidden']; Chris@0: $this->drupalPostForm(NULL, $edit, t('Save')); Chris@0: $this->assertFieldByName('fields[field_test][region]', 'hidden'); Chris@0: $display = EntityFormDisplay::load("node.{$this->type}.default"); Chris@0: $this->assertNull($display->getComponent('field_test')); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Tests switching view modes to use custom or 'default' settings'. Chris@0: */ Chris@0: public function testViewModeCustom() { Chris@0: // Create a field, and a node with some data for the field. Chris@0: $this->fieldUIAddNewField('admin/structure/types/manage/' . $this->type, 'test', 'Test field'); Chris@0: \Drupal::entityManager()->clearCachedFieldDefinitions(); Chris@0: // For this test, use a formatter setting value that is an integer unlikely Chris@0: // to appear in a rendered node other than as part of the field being tested Chris@0: // (for example, unlikely to be part of the "Submitted by ... on ..." line). Chris@0: $value = 12345; Chris@0: $settings = [ Chris@0: 'type' => $this->type, Chris@0: 'field_test' => [['value' => $value]], Chris@0: ]; Chris@0: $node = $this->drupalCreateNode($settings); Chris@0: Chris@0: // Gather expected output values with the various formatters. Chris@0: $formatter_plugin_manager = \Drupal::service('plugin.manager.field.formatter'); Chris@0: $field_test_default_settings = $formatter_plugin_manager->getDefaultSettings('field_test_default'); Chris@0: $field_test_with_prepare_view_settings = $formatter_plugin_manager->getDefaultSettings('field_test_with_prepare_view'); Chris@0: $output = [ Chris@0: 'field_test_default' => $field_test_default_settings['test_formatter_setting'] . '|' . $value, Chris@0: 'field_test_with_prepare_view' => $field_test_with_prepare_view_settings['test_formatter_setting_additional'] . '|' . $value . '|' . ($value + 1), Chris@0: ]; Chris@0: Chris@0: // Check that the field is displayed with the default formatter in 'rss' Chris@0: // mode (uses 'default'), and hidden in 'teaser' mode (uses custom settings). Chris@0: $this->assertNodeViewText($node, 'rss', $output['field_test_default'], "The field is displayed as expected in view modes that use 'default' settings."); Chris@0: $this->assertNodeViewNoText($node, 'teaser', $value, "The field is hidden in view modes that use custom settings."); Chris@0: Chris@0: // Change formatter for 'default' mode, check that the field is displayed Chris@0: // accordingly in 'rss' mode. Chris@0: $edit = [ Chris@0: 'fields[field_test][type]' => 'field_test_with_prepare_view', Chris@0: 'fields[field_test][region]' => 'content', Chris@0: ]; Chris@0: $this->drupalPostForm('admin/structure/types/manage/' . $this->type . '/display', $edit, t('Save')); Chris@0: $this->assertNodeViewText($node, 'rss', $output['field_test_with_prepare_view'], "The field is displayed as expected in view modes that use 'default' settings."); Chris@0: Chris@0: // Specialize the 'rss' mode, check that the field is displayed the same. Chris@0: $edit = [ Chris@0: "display_modes_custom[rss]" => TRUE, Chris@0: ]; Chris@0: $this->drupalPostForm('admin/structure/types/manage/' . $this->type . '/display', $edit, t('Save')); Chris@0: $this->assertNodeViewText($node, 'rss', $output['field_test_with_prepare_view'], "The field is displayed as expected in newly specialized 'rss' mode."); Chris@0: Chris@0: // Set the field to 'hidden' in the view mode, check that the field is Chris@0: // hidden. Chris@0: $edit = [ Chris@0: 'fields[field_test][region]' => 'hidden', Chris@0: ]; Chris@0: $this->drupalPostForm('admin/structure/types/manage/' . $this->type . '/display/rss', $edit, t('Save')); Chris@0: $this->assertNodeViewNoText($node, 'rss', $value, "The field is hidden in 'rss' mode."); Chris@0: Chris@0: // Set the view mode back to 'default', check that the field is displayed Chris@0: // accordingly. Chris@0: $edit = [ Chris@0: "display_modes_custom[rss]" => FALSE, Chris@0: ]; Chris@0: $this->drupalPostForm('admin/structure/types/manage/' . $this->type . '/display', $edit, t('Save')); Chris@0: $this->assertNodeViewText($node, 'rss', $output['field_test_with_prepare_view'], "The field is displayed as expected when 'rss' mode is set back to 'default' settings."); Chris@0: Chris@0: // Specialize the view mode again. Chris@0: $edit = [ Chris@0: "display_modes_custom[rss]" => TRUE, Chris@0: ]; Chris@0: $this->drupalPostForm('admin/structure/types/manage/' . $this->type . '/display', $edit, t('Save')); Chris@0: // Check that the previous settings for the view mode have been kept. Chris@0: $this->assertNodeViewNoText($node, 'rss', $value, "The previous settings are kept when 'rss' mode is specialized again."); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Tests the local tasks are displayed correctly for view modes. Chris@0: */ Chris@0: public function testViewModeLocalTasks() { Chris@0: $manage_display = 'admin/structure/types/manage/' . $this->type . '/display'; Chris@0: $this->drupalGet($manage_display); Chris@0: $this->assertNoLink('Full content'); Chris@0: $this->assertLink('Teaser'); Chris@0: Chris@0: $this->drupalGet($manage_display . '/teaser'); Chris@0: $this->assertNoLink('Full content'); Chris@0: $this->assertLink('Default'); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Tests that fields with no explicit display settings do not break. Chris@0: */ Chris@0: public function testNonInitializedFields() { Chris@0: // Create a test field. Chris@0: $this->fieldUIAddNewField('admin/structure/types/manage/' . $this->type, 'test', 'Test'); Chris@0: Chris@0: // Check that the field appears as 'hidden' on the 'Manage display' page Chris@0: // for the 'teaser' mode. Chris@0: $this->drupalGet('admin/structure/types/manage/' . $this->type . '/display/teaser'); Chris@0: $this->assertFieldByName('fields[field_test][region]', 'hidden', 'The field is displayed as \'hidden \'.'); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Tests hiding the view modes fieldset when there's only one available. Chris@0: */ Chris@0: public function testSingleViewMode() { Chris@0: $this->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary . '/display'); Chris@0: $this->assertNoText('Use custom display settings for the following view modes', 'Custom display settings fieldset found.'); Chris@0: Chris@0: // This may not trigger a notice when 'view_modes_custom' isn't available. Chris@0: $this->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary . '/overview/display', [], t('Save')); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Tests that a message is shown when there are no fields. Chris@0: */ Chris@0: public function testNoFieldsDisplayOverview() { Chris@0: // Create a fresh content type without any fields. Chris@0: NodeType::create([ Chris@0: 'type' => 'no_fields', Chris@0: 'name' => 'No fields', Chris@0: ])->save(); Chris@0: Chris@0: $this->drupalGet('admin/structure/types/manage/no_fields/display'); Chris@0: $this->assertRaw(t('There are no fields yet added. You can add new fields on the Manage fields page.', [':link' => \Drupal::url('entity.node.field_ui_fields', ['node_type' => 'no_fields'])])); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Asserts that a string is found in the rendered node in a view mode. Chris@0: * Chris@12: * @param \Drupal\Core\Entity\EntityInterface $node Chris@0: * The node. Chris@0: * @param $view_mode Chris@0: * The view mode in which the node should be displayed. Chris@0: * @param $text Chris@0: * Plain text to look for. Chris@0: * @param $message Chris@0: * Message to display. Chris@0: * Chris@0: * @return Chris@0: * TRUE on pass, FALSE on fail. Chris@0: */ Chris@0: public function assertNodeViewText(EntityInterface $node, $view_mode, $text, $message) { Chris@0: return $this->assertNodeViewTextHelper($node, $view_mode, $text, $message, FALSE); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Asserts that a string is not found in the rendered node in a view mode. Chris@0: * Chris@12: * @param \Drupal\Core\Entity\EntityInterface $node Chris@0: * The node. Chris@0: * @param $view_mode Chris@0: * The view mode in which the node should be displayed. Chris@0: * @param $text Chris@0: * Plain text to look for. Chris@0: * @param $message Chris@0: * Message to display. Chris@0: * @return Chris@0: * TRUE on pass, FALSE on fail. Chris@0: */ Chris@0: public function assertNodeViewNoText(EntityInterface $node, $view_mode, $text, $message) { Chris@0: return $this->assertNodeViewTextHelper($node, $view_mode, $text, $message, TRUE); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Asserts that a string is (not) found in the rendered nodein a view mode. Chris@0: * Chris@0: * This helper function is used by assertNodeViewText() and Chris@0: * assertNodeViewNoText(). Chris@0: * Chris@12: * @param \Drupal\Core\Entity\EntityInterface $node Chris@0: * The node. Chris@0: * @param $view_mode Chris@0: * The view mode in which the node should be displayed. Chris@0: * @param $text Chris@0: * Plain text to look for. Chris@0: * @param $message Chris@0: * Message to display. Chris@0: * @param $not_exists Chris@0: * TRUE if this text should not exist, FALSE if it should. Chris@0: * Chris@0: * @return Chris@0: * TRUE on pass, FALSE on fail. Chris@0: */ Chris@0: public function assertNodeViewTextHelper(EntityInterface $node, $view_mode, $text, $message, $not_exists) { Chris@0: // Make sure caches on the tester side are refreshed after changes Chris@0: // submitted on the tested side. Chris@0: \Drupal::entityManager()->clearCachedFieldDefinitions(); Chris@0: Chris@0: // Save current content so that we can restore it when we're done. Chris@0: $old_content = $this->getRawContent(); Chris@0: Chris@0: // Render a cloned node, so that we do not alter the original. Chris@0: $clone = clone $node; Chris@0: $element = node_view($clone, $view_mode); Chris@0: $output = \Drupal::service('renderer')->renderRoot($element); Chris@0: $this->verbose(t('Rendered node - view mode: @view_mode', ['@view_mode' => $view_mode]) . '