.../comment/src/Plugin/Action/UnpublishByKeywordComment.php | 2 +- core/modules/node/src/Plugin/Search/NodeSearch.php | 4 ++-- core/modules/simpletest/src/AssertContentTrait.php | 8 +++++++- core/modules/system/src/Tests/Render/RenderCacheTest.php | 10 +++++----- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/core/modules/comment/src/Plugin/Action/UnpublishByKeywordComment.php b/core/modules/comment/src/Plugin/Action/UnpublishByKeywordComment.php index 56706ad..6b70450 100644 --- a/core/modules/comment/src/Plugin/Action/UnpublishByKeywordComment.php +++ b/core/modules/comment/src/Plugin/Action/UnpublishByKeywordComment.php @@ -28,7 +28,7 @@ class UnpublishByKeywordComment extends ConfigurableActionBase { */ public function execute($comment = NULL) { $build = comment_view($comment); - $text = drupal_render($build); + $text = \Drupal::service('renderer')->renderPlain($build); foreach ($this->configuration['keywords'] as $keyword) { if (strpos($text, $keyword) !== FALSE) { $comment->setPublished(FALSE); diff --git a/core/modules/node/src/Plugin/Search/NodeSearch.php b/core/modules/node/src/Plugin/Search/NodeSearch.php index 6bd2e18..9dc4442 100644 --- a/core/modules/node/src/Plugin/Search/NodeSearch.php +++ b/core/modules/node/src/Plugin/Search/NodeSearch.php @@ -329,7 +329,7 @@ protected function prepareResults(StatementInterface $found) { // Fetch comment count for snippet. $rendered = SafeMarkup::set( - $this->renderer->render($build) . ' ' . + $this->renderer->renderPlain($build) . ' ' . SafeMarkup::escape($this->moduleHandler->invoke('comment', 'node_update_index', array($node, $item->langcode))) ); @@ -354,7 +354,7 @@ protected function prepareResults(StatementInterface $found) { if ($type->displaySubmitted()) { $result += array( - 'user' => $this->renderer->render($username), + 'user' => $this->renderer->renderPlain($username), 'date' => $node->getChangedTime(), ); } diff --git a/core/modules/simpletest/src/AssertContentTrait.php b/core/modules/simpletest/src/AssertContentTrait.php index b043ea9..3cce705 100644 --- a/core/modules/simpletest/src/AssertContentTrait.php +++ b/core/modules/simpletest/src/AssertContentTrait.php @@ -10,6 +10,7 @@ use Drupal\Component\Serialization\Json; use Drupal\Component\Utility\SafeMarkup; use Drupal\Component\Utility\Xss; +use Drupal\Core\Render\RenderContext; use Symfony\Component\CssSelector\CssSelector; /** @@ -808,7 +809,12 @@ protected function assertNoTitle($title, $message = '', $group = 'Other') { * TRUE on pass, FALSE on fail. */ protected function assertThemeOutput($callback, array $variables = array(), $expected = '', $message = '', $group = 'Other') { - $output = \Drupal::theme()->render($callback, $variables); + /** @var \Drupal\Core\Render\RendererInterface $renderer */ + $renderer = \Drupal::service('renderer'); + + $output = $renderer->executeInRenderContext(new RenderContext(), function() use ($callback, $variables) { + return \Drupal::theme()->render($callback, $variables); + }); $this->verbose( '
' . 'Result:' . '
' . SafeMarkup::checkPlain(var_export($output, TRUE)) . '
' . '
' . 'Expected:' . '
' . SafeMarkup::checkPlain(var_export($expected, TRUE)) . '
' diff --git a/core/modules/system/src/Tests/Render/RenderCacheTest.php b/core/modules/system/src/Tests/Render/RenderCacheTest.php index b4317d1..975358c 100644 --- a/core/modules/system/src/Tests/Render/RenderCacheTest.php +++ b/core/modules/system/src/Tests/Render/RenderCacheTest.php @@ -77,14 +77,14 @@ protected function doTestUser1WithContexts($contexts) { ]; $element = $test_element; $element['#markup'] = 'content for user 1'; - $output = \Drupal::service('renderer')->render($element); + $output = \Drupal::service('renderer')->renderRoot($element); $this->assertEqual($output, 'content for user 1'); // Verify the cache is working by rendering the same element but with // different markup passed in; the result should be the same. $element = $test_element; $element['#markup'] = 'should not be used'; - $output = \Drupal::service('renderer')->render($element); + $output = \Drupal::service('renderer')->renderRoot($element); $this->assertEqual($output, 'content for user 1'); \Drupal::service('account_switcher')->switchBack(); @@ -93,7 +93,7 @@ protected function doTestUser1WithContexts($contexts) { \Drupal::service('account_switcher')->switchTo($first_authenticated_user); $element = $test_element; $element['#markup'] = 'content for authenticated users'; - $output = \Drupal::service('renderer')->render($element); + $output = \Drupal::service('renderer')->renderRoot($element); $this->assertEqual($output, 'content for authenticated users'); \Drupal::service('account_switcher')->switchBack(); @@ -102,7 +102,7 @@ protected function doTestUser1WithContexts($contexts) { \Drupal::service('account_switcher')->switchTo($second_authenticated_user); $element = $test_element; $element['#markup'] = 'should not be used'; - $output = \Drupal::service('renderer')->render($element); + $output = \Drupal::service('renderer')->renderRoot($element); $this->assertEqual($output, 'content for authenticated users'); \Drupal::service('account_switcher')->switchBack(); @@ -111,7 +111,7 @@ protected function doTestUser1WithContexts($contexts) { \Drupal::service('account_switcher')->switchTo($admin_user); $element = $test_element; $element['#markup'] = 'content for admin user'; - $output = \Drupal::service('renderer')->render($element); + $output = \Drupal::service('renderer')->renderRoot($element); $this->assertEqual($output, 'content for admin user'); \Drupal::service('account_switcher')->switchBack(); }