diff --git a/core/tests/Drupal/FunctionalJavascriptTests/JavascriptTestBase.php b/core/tests/Drupal/FunctionalJavascriptTests/JavascriptTestBase.php index 2c2ac3a..8c3798a 100644 --- a/core/tests/Drupal/FunctionalJavascriptTests/JavascriptTestBase.php +++ b/core/tests/Drupal/FunctionalJavascriptTests/JavascriptTestBase.php @@ -3,6 +3,7 @@ namespace Drupal\FunctionalJavascriptTests; use Drupal\Tests\BrowserTestBase; +use Zend\Escaper\Escaper; use Zumba\Mink\Driver\PhantomJSDriver; /** @@ -109,7 +110,10 @@ protected function assertJsCondition($condition, $timeout = 1000, $message = '') * The file name of the resulting screenshot. If using the default phantomjs * driver then this should be a JPG filename. * @param string $background_color - * (optional) Background color name. + * (optional) Background color name. To use the default background color set + * to NULL, however this can result in completely black screenshots if the + * theme does not have a background color. This string is escaped by + * \Zend\Escaper\Escaper::escapeJs(). * * @throws \Behat\Mink\Exception\UnsupportedDriverActionException * When operation not supported by the driver. @@ -119,7 +123,8 @@ protected function assertJsCondition($condition, $timeout = 1000, $message = '') protected function createScreenshot($filename, $background_color = 'white') { $session = $this->getSession(); if (!empty($background_color)) { - $session->executeScript("document.body.style.backgroundColor = '" . $background_color . "';"); + $escaper = new Escaper(); + $session->executeScript("document.body.style.backgroundColor = '" . $escaper->escapeJs($background_color) . "';"); } $image = $session->getScreenshot(); file_put_contents($filename, $image);