diff --git a/core/modules/simpletest/simpletest.module b/core/modules/simpletest/simpletest.module index 3b46028..bc43a4b 100644 --- a/core/modules/simpletest/simpletest.module +++ b/core/modules/simpletest/simpletest.module @@ -329,6 +329,7 @@ function _simpletest_batch_operation($test_list_init, $test_id, &$context) { \Drupal::moduleHandler()->invokeAll('test_finished', array($test->results)); // Gather results and compose the report. + $renderer = \Drupal::service('renderer'); $test_results[$test_class] = $test->results; foreach ($test_results[$test_class] as $key => $value) { $test_results[$key] += $value; @@ -340,20 +341,20 @@ function _simpletest_batch_operation($test_list_init, $test_id, &$context) { '#theme' => 'simpletest_result_summary', '#label' => t($test_results[$class]['#name'] . ':'), ); - array_unshift($items, drupal_render($class_test_result)); + array_unshift($items, $renderer->render($class_test_result)); } $context['message'] = t('Processed test @num of @max - %test.', array('%test' => $info['name'], '@num' => $max - $size, '@max' => $max)); $overall_results = $test_results + array( '#theme' => 'simpletest_result_summary', '#label' => t('Overall results:'), ); - $context['message'] .= drupal_render($overall_results); + $context['message'] .= $renderer->render($overall_results); $item_list = array( '#theme' => 'item_list', '#items' => $items, ); - $context['message'] .= drupal_render($item_list); + $context['message'] .= $renderer->render($item_list); // Save working values for the next iteration. $context['sandbox']['tests'] = $test_list; diff --git a/core/modules/simpletest/src/Form/SimpletestResultsForm.php b/core/modules/simpletest/src/Form/SimpletestResultsForm.php index 9ddc451..9f077b3 100644 --- a/core/modules/simpletest/src/Form/SimpletestResultsForm.php +++ b/core/modules/simpletest/src/Form/SimpletestResultsForm.php @@ -43,11 +43,21 @@ class SimpletestResultsForm extends FormBase { protected $database; /** + * The container. + * + * We need this so we can perform a non-standard redirect in submitForm(). + * + * @var \Symfony\Component\DependencyInjection\ContainerInterface + */ + protected $container; + + /** * {@inheritdoc} */ public static function create(ContainerInterface $container) { return new static( - $container->get('database') + $container->get('database'), + $container ); } @@ -57,8 +67,9 @@ public static function create(ContainerInterface $container) { * @param \Drupal\Core\Database\Connection $database * The database connection service. */ - public function __construct(Connection $database) { + public function __construct(Connection $database, ContainerInterface $container) { $this->database = $database; + $this->container = $container; } /** @@ -94,10 +105,10 @@ protected static function buildStatusImageMap() { '#alt' => 'Debug', ); return array( - 'pass' => drupal_render($image_pass), - 'fail' => drupal_render($image_fail), - 'exception' => drupal_render($image_exception), - 'debug' => drupal_render($image_debug), + 'pass' => \Drupal::service('renderer')->render($image_pass), + 'fail' => \Drupal::service('renderer')->render($image_fail), + 'exception' => \Drupal::service('renderer')->render($image_exception), + 'debug' => \Drupal::service('renderer')->render($image_debug), ); } @@ -205,7 +216,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) { // Under normal circumstances, a form object's submitForm() should never be // called directly, FormBuilder::submitForm() should be called instead. // However, it calls $form_state->setProgrammed(), which disables the Batch API. - $simpletest_test_form = new SimpletestTestForm(); + $simpletest_test_form = SimpletestTestForm::create($this->container); $simpletest_test_form->buildForm($form_execute, $form_state_execute); $simpletest_test_form->submitForm($form_execute, $form_state_execute); if ($redirect = $form_state_execute->getRedirect()) { diff --git a/core/modules/simpletest/src/Form/SimpletestTestForm.php b/core/modules/simpletest/src/Form/SimpletestTestForm.php index 92c8a54..82dbe30 100644 --- a/core/modules/simpletest/src/Form/SimpletestTestForm.php +++ b/core/modules/simpletest/src/Form/SimpletestTestForm.php @@ -11,6 +11,8 @@ use Drupal\Component\Utility\SafeMarkup; use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Render\Renderer; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * List tests arranged in groups that can be selected and run. @@ -18,6 +20,30 @@ class SimpletestTestForm extends FormBase { /** + * Rendering service. + * + * @var Drupal\Core\Render\Renderer + */ + protected $renderer; + + /** + * Constructor where we inject the renderer service. + * + * @param \Drupal\Core\Render\Renderer $renderer + * The renderer service. + */ + public function __construct(Renderer $renderer) { + $this->renderer = $renderer; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + return new static($container->get('renderer')); + } + + /** * {@inheritdoc} */ public function getFormId() { @@ -99,8 +125,8 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#suffix' => '(' . $this->t('Collapse') . ')', ); $form['tests']['#attached']['drupalSettings']['simpleTest']['images'] = [ - drupal_render($image_collapsed), - drupal_render($image_extended), + $this->renderer->render($image_collapsed), + $this->renderer->render($image_extended), ]; // Generate the list of tests arranged by group. diff --git a/core/modules/simpletest/src/KernelTestBase.php b/core/modules/simpletest/src/KernelTestBase.php index bd611f4..5ae06ed 100644 --- a/core/modules/simpletest/src/KernelTestBase.php +++ b/core/modules/simpletest/src/KernelTestBase.php @@ -561,7 +561,7 @@ protected function registerStreamWrapper($scheme, $class, $type = StreamWrapperI } /** - * Renders a render array. + * Renders a render array using the mocked Drupal's configuration. * * @param array $elements * The elements to render. diff --git a/core/modules/simpletest/src/Tests/KernelTestBaseTest.php b/core/modules/simpletest/src/Tests/KernelTestBaseTest.php index 6d92255..6d89965 100644 --- a/core/modules/simpletest/src/Tests/KernelTestBaseTest.php +++ b/core/modules/simpletest/src/Tests/KernelTestBaseTest.php @@ -295,11 +295,11 @@ function testEnableModulesTheme() { ); $this->enableModules(array('system')); // _theme() throws an exception if modules are not loaded yet. - $this->assertTrue(drupal_render($element)); + $this->assertTrue($this->render($element)); $element = $original_element; $this->disableModules(array('entity_test')); - $this->assertTrue(drupal_render($element)); + $this->assertTrue($this->render($element)); } /** diff --git a/core/modules/simpletest/src/WebTestBase.php b/core/modules/simpletest/src/WebTestBase.php index 8e29d46..9ab8039 100644 --- a/core/modules/simpletest/src/WebTestBase.php +++ b/core/modules/simpletest/src/WebTestBase.php @@ -303,11 +303,11 @@ protected function drupalCreateContentType(array $values = array()) { * * Entities postpone the composition of their renderable arrays to #pre_render * functions in order to maximize cache efficacy. This means that the full - * renderable 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. + * renderable array for an entity is constructed in + * \Drupal::service('renderer')->render(). Some tests require the complete + * renderable array for an entity outside of the rendering 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. @@ -320,7 +320,7 @@ protected function drupalCreateContentType(array $values = array()) { * (optional) Whether to clear the cache for this entity. * @return array * - * @see drupal_render() + * @see \Drupal::service('renderer')->render() */ protected function drupalBuildEntityView(EntityInterface $entity, $view_mode = 'full', $langcode = NULL, $reset = FALSE) { $ensure_fully_built = function(&$elements) use (&$ensure_fully_built) {