diff --git a/core/modules/image/lib/Drupal/image/Tests/ImageFieldDefaultImagesTest.php b/core/modules/image/lib/Drupal/image/Tests/ImageFieldDefaultImagesTest.php index fdc49de..54be792 100644 --- a/core/modules/image/lib/Drupal/image/Tests/ImageFieldDefaultImagesTest.php +++ b/core/modules/image/lib/Drupal/image/Tests/ImageFieldDefaultImagesTest.php @@ -160,7 +160,7 @@ public function testDefaultImages() { // Confirm that the image default is shown for a new article node. $article = $this->drupalCreateNode(array('type' => 'article')); - $article_built = $this->drupalBuildView($article); + $article_built = $this->drupalBuildEntityView($article); $this->assertEqual( $article_built[$field_name]['#items'][0]->target_id, $default_images['instance']->id(), @@ -172,7 +172,7 @@ public function testDefaultImages() { // Confirm that the image default is shown for a new page node. $page = $this->drupalCreateNode(array('type' => 'page')); - $page_built = $this->drupalBuildView($page); + $page_built = $this->drupalBuildEntityView($page); $this->assertEqual( $page_built[$field_name]['#items'][0]->target_id, $default_images['instance2']->id(), @@ -198,8 +198,8 @@ public function testDefaultImages() { ); // Reload the nodes and confirm the field instance defaults are used. - $article_built = $this->drupalBuildView($article = node_load($article->id(), TRUE)); - $page_built = $this->drupalBuildView($page = node_load($page->id(), TRUE)); + $article_built = $this->drupalBuildEntityView($article = node_load($article->id(), TRUE)); + $page_built = $this->drupalBuildEntityView($page = node_load($page->id(), TRUE)); $this->assertEqual( $article_built[$field_name]['#items'][0]->target_id, $default_images['instance']->id(), @@ -234,8 +234,8 @@ public function testDefaultImages() { ); // Reload the nodes. - $article_built = $this->drupalBuildView($article = node_load($article->id(), TRUE)); - $page_built = $this->drupalBuildView($page = node_load($page->id(), TRUE)); + $article_built = $this->drupalBuildEntityView($article = node_load($article->id(), TRUE)); + $page_built = $this->drupalBuildEntityView($page = node_load($page->id(), TRUE)); // Confirm the article uses the new default. $this->assertEqual( @@ -269,8 +269,8 @@ public function testDefaultImages() { ); // Reload the nodes. - $article_built = $this->drupalBuildView($article = node_load($article->id(), TRUE)); - $page_built = $this->drupalBuildView($page = node_load($page->id(), TRUE)); + $article_built = $this->drupalBuildEntityView($article = node_load($article->id(), TRUE)); + $page_built = $this->drupalBuildEntityView($page = node_load($page->id(), TRUE)); // Confirm the article uses the new field (not instance) default. $this->assertEqual( $article_built[$field_name]['#items'][0]->target_id, diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeEntityViewModeAlterTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeEntityViewModeAlterTest.php index 17ab549..156e37d 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeEntityViewModeAlterTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeEntityViewModeAlterTest.php @@ -51,7 +51,7 @@ function testNodeViewModeChange() { $this->assertNoText('Data that should appear only in the body for the node.', 'Body text not present'); // Test that the correct build mode has been set. - $build = $this->drupalBuildView($node); + $build = $this->drupalBuildEntityView($node); $this->assertEqual($build['#view_mode'], 'teaser', 'The view mode has correctly been set to teaser.'); } } diff --git a/core/modules/node/lib/Drupal/node/Tests/SummaryLengthTest.php b/core/modules/node/lib/Drupal/node/Tests/SummaryLengthTest.php index eb168f8..8568d44 100644 --- a/core/modules/node/lib/Drupal/node/Tests/SummaryLengthTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/SummaryLengthTest.php @@ -36,7 +36,7 @@ function testSummaryLength() { $this->loggedInUser = $web_user; // Render the node as a teaser. - $content = $this->drupalBuildView($node, 'teaser'); + $content = $this->drupalBuildEntityView($node, 'teaser'); $this->assertTrue(strlen($content['body'][0]['#markup']) < 600, 'Teaser is less than 600 characters long.'); $this->drupalSetContent(drupal_render($content)); // The string 'What is a Drupalism?' is between the 200th and 600th @@ -54,7 +54,7 @@ function testSummaryLength() { // Render the node as a teaser again and check that the summary is now only // 200 characters in length and so does not include 'What is a Drupalism?'. - $content = $this->drupalBuildView($node, 'teaser'); + $content = $this->drupalBuildEntityView($node, 'teaser'); $this->assertTrue(strlen($content['body'][0]['#markup']) < 200, 'Teaser is less than 200 characters long.'); $this->drupalSetContent(drupal_render($content)); $this->assertText($node->label()); diff --git a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php index afe6d2b..92cd299 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php @@ -15,6 +15,7 @@ use Drupal\Core\DrupalKernel; use Drupal\Core\Database\Database; use Drupal\Core\Database\ConnectionNotDefinedException; +use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Language\Language; use Drupal\Core\Session\AccountInterface; use Drupal\Core\Session\AnonymousUserSession; @@ -342,9 +343,30 @@ protected function drupalCreateContentType(array $values = array()) { } /** - * @needsdoc + * Builds the renderable view of an entity. + * + * Entities postpone the composition of their renderable arrays to #pre_render + * functions in order to maximize cache efficacy. This means that the full + * rendable array for an entity is constructed in drupal_render(). Some tests + * require the complete renderable array for an entity outside of the + * drupal_render process in order to verify the presence of specific values. + * This method isolates the steps in the render process that produce an + * entity's renderable array. + * + * @param \Drupal\Core\Entity\EntityInterface $entity + * The entity to prepare a renderable array for. + * @param string $view_mode + * (optional) The view mode that should be used to build the entity. + * @param null $langcode + * (optional) For which language the entity should be prepared, defaults to + * the current content language. + * @param bool $reset + * (optional) Whether to clear the cache for this entity. + * @return array + * + * @see drupal_render() */ - protected function drupalBuildView($entity, $view_mode = 'full', $langcode = NULL, $reset = FALSE) { + protected function drupalBuildEntityView(EntityInterface $entity, $view_mode = 'full', $langcode = NULL, $reset = FALSE) { $render_controller = $this->container->get('entity.manager')->getViewBuilder($entity->getEntityTypeId()); if ($reset) { $render_controller->resetCache(array($entity->id()));