diff --git a/core/modules/search/lib/Drupal/search/Tests/SearchFieldsTest.php b/core/modules/search/lib/Drupal/search/Tests/SearchFieldsTest.php index 0a8508a..0d4fdcb 100644 --- a/core/modules/search/lib/Drupal/search/Tests/SearchFieldsTest.php +++ b/core/modules/search/lib/Drupal/search/Tests/SearchFieldsTest.php @@ -6,6 +6,7 @@ */ namespace Drupal\search\Tests; +use Drupal\Tests\Core\Cache\CacheCollectorTest; /** * Tests that fields and display modes work properly in Node search. @@ -13,11 +14,18 @@ class SearchFieldsTest extends SearchTestBase { /** + * Node view builder. + * + * @var \Drupal\Core\Entity\EntityViewBuilderInterface + */ + protected $viewBuilder; + + /** * Modules to enable. * * @var array */ - public static $modules = array('search', 'field_ui'); + public static $modules = array('search', 'field_ui', 'text'); /** * Node used for testing. @@ -35,6 +43,11 @@ public static function getInfo() { function setUp() { parent::setUp(); + foreach (\Drupal::entityManager()->getStorageController('view_mode')->loadMultiple() as $view_mode) { + $view_mode->status = TRUE; + $view_mode->save(); + } + $this->viewBuilder = \Drupal::entityManager()->getViewBuilder('node'); // Create a new content type. $type = 'sft_bundle'; $this->drupalCreateContentType(array('type' => $type, 'name' => $type)); @@ -92,9 +105,16 @@ function setUp() { 'field_for_excerpt[0][value]' => 'excerpt snippet highlighted', 'field_for_display[0][value]' => 'display output formatted', ), t('Save and publish')); - $node = node_load(1, TRUE); - $node = $node->getUntranslated(); - $this->node = $node; + \Drupal::cache()->deleteTags(array('entity_field_info')); + $nodes = \Drupal::entityManager()->getStorageController('node')->loadByProperties(array('title' => 'Title header')); + $node = reset($nodes); + debug($node->getPropertyDefinitions()); + debug(entity_load('field_entity', 'node.field_for_index')); + debug(entity_load('field_entity', 'node.body')); + debug(entity_load('field_instance', 'node.sft_bundle.field_for_index')); + debug(entity_load('field_instance', 'node.sft_bundle.body')); + debug($node->getPropertyValues()); + $this->node = $node->getUntranslated(); // Update the search index. $this->container->get('plugin.manager.search')->createInstance('node_search')->updateIndex(); @@ -104,9 +124,24 @@ function setUp() { } /** + * View a node in the given view mode. + * + * @param \Drupal\Core\Entity\EntityInterface $node + * The node to output. + * @param string $view_mode + * (optional) View mode to view the node in. Defaults to NULL. + * + * @return array + * Render array for the node. + */ + protected function viewNode($node, $view_mode = NULL) { + return array('nodes' => $this->viewBuilder->view($node, $view_mode)); + } + + /** * Tests that the search field display modes work correctly. */ - function testSearchFieldDisplays() { + public 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'); @@ -114,25 +149,25 @@ function testSearchFieldDisplays() { $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); + $build = $this->viewNode($this->node); + $out = 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'); + $build = $this->viewNode($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'); + $build = $this->viewNode($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'); + $build = $this->viewNode($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');