X-Git-Url: http://aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fsimpletest%2Fsimpletest.module;h=35fdd92cc19d1e4fb67ad894ca593cfcf7c37347;hb=1c1cb0980bfa6caf0c24cce671b6bb541dc87583;hp=0e0ea2afd4006d6c66b5906ccdbeb864284c27b9;hpb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;p=yaffs-website diff --git a/web/core/modules/simpletest/simpletest.module b/web/core/modules/simpletest/simpletest.module index 0e0ea2afd..35fdd92cc 100644 --- a/web/core/modules/simpletest/simpletest.module +++ b/web/core/modules/simpletest/simpletest.module @@ -389,12 +389,12 @@ function simpletest_phpunit_command() { // The file in Composer's bin dir is a *nix link, which does not work when // extracted from a tarball and generally not on Windows. - $command = $vendor_dir . '/phpunit/phpunit/phpunit'; + $command = escapeshellarg($vendor_dir . '/phpunit/phpunit/phpunit'); if (substr(PHP_OS, 0, 3) == 'WIN') { // On Windows it is necessary to run the script using the PHP executable. $php_executable_finder = new PhpExecutableFinder(); $php = $php_executable_finder->find(); - $command = $php . ' -f ' . escapeshellarg($command) . ' --'; + $command = $php . ' -f ' . $command . ' --'; } return $command; } @@ -403,7 +403,7 @@ function simpletest_phpunit_command() { * Implements callback_batch_operation(). */ function _simpletest_batch_operation($test_list_init, $test_id, &$context) { - simpletest_classloader_register(); + \Drupal::service('test_discovery')->registerTestNamespaces(); // Get working values. if (!isset($context['sandbox']['max'])) { // First iteration: initialize working values. @@ -475,7 +475,7 @@ function _simpletest_batch_operation($test_list_init, $test_id, &$context) { */ function _simpletest_batch_finished($success, $results, $operations, $elapsed) { if ($success) { - drupal_set_message(t('The test run finished in @elapsed.', ['@elapsed' => $elapsed])); + \Drupal::messenger()->addStatus(t('The test run finished in @elapsed.', ['@elapsed' => $elapsed])); } else { // Use the test_id passed as a parameter to _simpletest_batch_operation(). @@ -487,8 +487,8 @@ function _simpletest_batch_finished($success, $results, $operations, $elapsed) { list($last_prefix, $last_test_class) = simpletest_last_test_get($test_id); simpletest_log_read($test_id, $last_prefix, $last_test_class); - drupal_set_message(t('The test run did not successfully finish.'), 'error'); - drupal_set_message(t('Use the Clean environment button to clean-up temporary files and tables.'), 'warning'); + \Drupal::messenger()->addError(t('The test run did not successfully finish.')); + \Drupal::messenger()->addWarning(t('Use the Clean environment button to clean-up temporary files and tables.')); } \Drupal::moduleHandler()->invokeAll('test_group_finished'); } @@ -587,6 +587,7 @@ function simpletest_log_read($test_id, $database_prefix, $test_class) { * instead. */ function simpletest_test_get_all($extension = NULL, array $types = []) { + @trigger_error('The ' . __FUNCTION__ . ' function is deprecated in version 8.3.x and will be removed in 9.0.0. Use \Drupal::service(\'test_discovery\')->getTestClasses($extension, $types) instead.', E_USER_DEPRECATED); return \Drupal::service('test_discovery')->getTestClasses($extension, $types); } @@ -597,6 +598,7 @@ function simpletest_test_get_all($extension = NULL, array $types = []) { * \Drupal::service('test_discovery')->registerTestNamespaces() instead. */ function simpletest_classloader_register() { + @trigger_error('The ' . __FUNCTION__ . ' function is deprecated in version 8.3.x and will be removed in 9.0.0. Use \Drupal::service(\'test_discovery\')->registerTestNamespaces() instead.', E_USER_DEPRECATED); \Drupal::service('test_discovery')->registerTestNamespaces(); } @@ -656,37 +658,34 @@ function simpletest_clean_environment() { simpletest_clean_temporary_directories(); if (\Drupal::config('simpletest.settings')->get('clear_results')) { $count = simpletest_clean_results_table(); - drupal_set_message(\Drupal::translation()->formatPlural($count, 'Removed 1 test result.', 'Removed @count test results.')); + \Drupal::messenger()->addStatus(\Drupal::translation()->formatPlural($count, 'Removed 1 test result.', 'Removed @count test results.')); } else { - drupal_set_message(t('Clear results is disabled and the test results table will not be cleared.'), 'warning'); + \Drupal::messenger()->addWarning(t('Clear results is disabled and the test results table will not be cleared.'), 'warning'); } - - // Detect test classes that have been added, renamed or deleted. - \Drupal::cache()->delete('simpletest'); - \Drupal::cache()->delete('simpletest_phpunit'); } /** * Removes prefixed tables from the database from crashed tests. */ function simpletest_clean_database() { + $schema = Database::getConnection()->schema(); $tables = db_find_tables('test%'); $count = 0; foreach ($tables as $table) { // Only drop tables which begin wih 'test' followed by digits, for example, // {test12345678node__body}. if (preg_match('/^test\d+.*/', $table, $matches)) { - db_drop_table($matches[0]); + $schema->dropTable($matches[0]); $count++; } } if ($count > 0) { - drupal_set_message(\Drupal::translation()->formatPlural($count, 'Removed 1 leftover table.', 'Removed @count leftover tables.')); + \Drupal::messenger()->addStatus(\Drupal::translation()->formatPlural($count, 'Removed 1 leftover table.', 'Removed @count leftover tables.')); } else { - drupal_set_message(t('No leftover tables to remove.')); + \Drupal::messenger()->addStatus(t('No leftover tables to remove.')); } } @@ -709,10 +708,10 @@ function simpletest_clean_temporary_directories() { } if ($count > 0) { - drupal_set_message(\Drupal::translation()->formatPlural($count, 'Removed 1 temporary directory.', 'Removed @count temporary directories.')); + \Drupal::messenger()->addStatus(\Drupal::translation()->formatPlural($count, 'Removed 1 temporary directory.', 'Removed @count temporary directories.')); } else { - drupal_set_message(t('No temporary directories to remove.')); + \Drupal::messenger()->addStatus(t('No temporary directories to remove.')); } } @@ -856,6 +855,7 @@ function simpletest_phpunit_testcase_to_row($test_id, \SimpleXMLElement $testcas $attributes = $testcase->attributes(); + $function = $attributes->class . '->' . $attributes->name . '()'; $record = [ 'test_id' => $test_id, 'test_class' => (string) $attributes->class, @@ -863,9 +863,11 @@ function simpletest_phpunit_testcase_to_row($test_id, \SimpleXMLElement $testcas 'message' => $message, // @todo: Check on the proper values for this. 'message_group' => 'Other', - 'function' => $attributes->class . '->' . $attributes->name . '()', + 'function' => $function, 'line' => $attributes->line ?: 0, - 'file' => $attributes->file, + // There are situations when the file will not be present because a PHPUnit + // @requires has caused a test to be skipped. + 'file' => $attributes->file ?: $function, ]; return $record; }