diff --git a/core/modules/simpletest/simpletest.module b/core/modules/simpletest/simpletest.module index a210da9..70f75d6 100644 --- a/core/modules/simpletest/simpletest.module +++ b/core/modules/simpletest/simpletest.module @@ -706,20 +706,20 @@ function simpletest_clean_temporary_directories($directory = NULL) { if (is_dir($simpletest_root)) { // If the $directory is not valid string or NULL then get the type of it for // debugging purposes in the watchdog error message below. - $directory = is_string($directory) && !empty($directory) ? $directory : gettype($directory); + $path = is_string($directory) && !empty($directory) ? $directory : gettype($directory); // Do not recognize any, except expected directory pattern as wrong // directory being passed accidentally may cause catastrophic consequences. - preg_match('/^(sites\/simpletest\/)(.*)/', $directory, $matches); + preg_match('/^(sites\/simpletest\/)(.*)/', $path, $matches); if (!empty($matches[2]) && is_dir($simpletest_root . $matches[2])) { $directories[] = $matches[2]; } - elseif ($directory == 'NULL') { + elseif ($directory === NULL) { $directories = scandir($simpletest_root); } else { $logger = \Drupal::logger('Testing'); - $logger->error('The %path is not eligible for removing in %func().', ['%path' => $directory, '%func' => __FUNCTION__]); + $logger->error('The %path is not eligible for removing in %func().', ['%path' => $path, '%func' => __FUNCTION__]); } foreach ($directories as $file) { @@ -738,19 +738,19 @@ function simpletest_clean_temporary_directories($directory = NULL) { } } - if (!is_null($directory) && $directory != 'NULL') { - // We do not need anything else if this function was called from within a - // running test instead of using "Clean environment" button. The system - // messages below may cause failure on some tests. - // @see https://www.drupal.org/node/2745123#comment-11837053 - return $result; - } - elseif ($count > 0) { - drupal_set_message(\Drupal::translation()->formatPlural($count, 'Removed 1 temporary directory.', 'Removed @count temporary directories.')); - } - else { - drupal_set_message(t('No temporary directories to remove.')); + // To prevent some tests failure do not display any messages if this function + // was called from within a test instead of using "Clean environment" button. + // @see https://www.drupal.org/node/2745123#comment-11837053 + if ($directory === NULL) { + if ($count > 0) { + drupal_set_message(\Drupal::translation()->formatPlural($count, 'Removed 1 temporary directory.', 'Removed @count temporary directories.')); + } + else { + drupal_set_message(t('No temporary directories to remove.')); + } } + + return $result; } /**