diff -u b/core/modules/node/lib/Drupal/node/Plugin/Search/NodeSearch.php b/core/modules/node/lib/Drupal/node/Plugin/Search/NodeSearch.php --- b/core/modules/node/lib/Drupal/node/Plugin/Search/NodeSearch.php +++ b/core/modules/node/lib/Drupal/node/Plugin/Search/NodeSearch.php @@ -241,7 +241,7 @@ // Render the node for the extra fields, but only if it has been // customized for this content type. $display = entity_load('entity_display', 'node.' . $node->bundle() . '.search_result_extra'); - if ($display) { + if ($display && $display->status) { $build = $node_render->view($node, 'search_result_extra', $item->langcode); // Remove some components "helpfully" added automatically during node // view building. diff -u b/core/modules/search/lib/Drupal/search/Tests/SearchFieldsTest.php b/core/modules/search/lib/Drupal/search/Tests/SearchFieldsTest.php --- b/core/modules/search/lib/Drupal/search/Tests/SearchFieldsTest.php +++ b/core/modules/search/lib/Drupal/search/Tests/SearchFieldsTest.php @@ -81,8 +81,10 @@ 'fields[field_for_excerpt][type]' => 'hidden', ), t('Save')); - // Clear all caches, because this test does not appear to work otherwise. - $this->drupalPostForm('admin/config/development/performance', array(), t('Clear all caches')); + // Clear some static caches. This is a testing artifact due to mixing + // UI calls and API calls in this test. + \Drupal::entityManager()->clearCachedFieldDefinitions(); + field_info_cache_clear(); // Create a node with different values in the 3 fields. $this->drupalPostForm('node/add/' . $type, @@ -99,45 +101,12 @@ // Update the search index. $this->container->get('plugin.manager.search')->createInstance('node_search')->updateIndex(); search_update_totals(); - - $this->drupalGet('admin/reports/dblog'); } /** * Tests that the search field display modes work correctly. */ function testSearchFieldDisplays() { - // Reality check: verify that the information is on the node. - $this->drupalGet('node/' . $this->node->id()); - $this->assertText('index contents database', 'Index text is on the node'); - $this->assertText('excerpt snippet highlighted', 'Excerpt text is on the node'); - $this->assertText('display output formatted', 'Display text is on the node'); - - // Reality check: verify that the display modes are working. - $build = node_view($this->node, 'default'); - $out = drupal_render($build); - $this->assertTrue(strpos($out, 'index contents database') > 0, 'Index text is present in full view mode (' . strip_tags($out) . ')'); - $this->assertTrue(strpos($out, 'excerpt snippet highlighted') > 0, 'Excerpt text is not present in full view mode'); - $this->assertTrue(strpos($out, 'display output formatted') > 0, 'Display text is not present in full view mode'); - - $build = node_view($this->node, 'search_index'); - $out = drupal_render($build); - $this->assertTrue(strpos($out, 'index contents database') > 0, 'Index text is present in index view mode (' . strip_tags($out) . ')'); - $this->assertFalse(strpos($out, 'excerpt snippet highlighted') > 0, 'Excerpt text is not present in index view mode'); - $this->assertFalse(strpos($out, 'display output formatted') > 0, 'Display text is not present in index view mode'); - - $build = node_view($this->node, 'search_result'); - $out = drupal_render($build); - $this->assertFalse(strpos($out, 'index contents database') > 0, 'Index text is not present in excerpt view mode (' . strip_tags($out) . ')'); - $this->assertTrue(strpos($out, 'excerpt snippet highlighted') > 0, 'Excerpt text is present in excerpt view mode'); - $this->assertFalse(strpos($out, 'display output formatted') > 0, 'Display text is not present in excerpt view mode'); - - $build = node_view($this->node, 'search_result_extra'); - $out = drupal_render($build); - $this->assertFalse(strpos($out, 'index contents database') > 0, 'Index text is present not in result view mode (' . strip_tags($out) . ')'); - $this->assertFalse(strpos($out, 'excerpt snippet highlighted') > 0, 'Excerpt text is not present in result view mode'); - $this->assertTrue(strpos($out, 'display output formatted') > 0, 'Display text is present in result view mode'); - // Verify that if we search for excerpt or display words, we find nothing // because they are not in the index. $this->drupalPostForm('search/node', array('keys' => 'excerpt'), t('Search')); @@ -174,6 +143,13 @@ array( 'display_modes_custom[search_result_extra]' => FALSE, ), t('Save')); + + // Clear some static caches. This is a testing artifact due to mixing + // UI calls and API calls in this test. + \Drupal::entityManager()->clearCachedFieldDefinitions(); + field_info_cache_clear(); + entity_load('entity_display', 'node.sft_bundle.search_result_extra', TRUE); + // Verify that the display stuff is now not displayed in search results. $this->drupalPostForm('search/node', array('keys' => 'index'), t('Search')); $this->assertNoText('display output formatted', 'Display field is not displayed');