Problem/Motivation
In
#2099131: Use #pre_render pattern for entity render caching →
, the render process was separated into a "cache tag collection" phase and a "renderable building" phase. The building is postponed through a #pre_render
callback set by the entity view builder class. This change was made to delay the costly building of an entity's renderable array until after a cache entry check is conducted.
Because of this change, tests may no longer assume that the full renderable array is available by simply calling entity_view
or entity_view_multiple
. The full renderable build for an entity is really only available once drupal_render
has run. This has, in fact, always been true since #pre_render
functions were always capable of altering the render array.
The code changes in #2099131 introduced the method WebTestBase::drupalBuildEntityView()
that returns the full renderable array for an entity; it invokes the entity's view builder and invokes its #pre_render
functions.
Rather than use a method that artificially pulls together pieces of different code paths, we should really only rely on the existing code paths, namely, the output of drupal_render()
.
Proposed resolution
Refactor tests to use drupal_render()
if they currently use entity_view
, entity_view_multiple
or WebTestBase::drupalBuildEntityView
. Then assert against the rendered output strings.
Or, since drupal_render
manipulates the passed-in array by reference, the build can be passed to drupal_render()
and then assessed. For example:
$controller = $this->entityManager->getViewBuilder($entity_type);
$build = $controller->view($entity);
drupal_render($build);
$this->assertEqual($build['label']['#markup'], $values[$current_langcode]['name']);
Remove WebTestBase::drupalBuildEntityView
.
User interface changes
None.
API changes
None.
Postponed until
#2099131: Use #pre_render pattern for entity render caching →