comparison core/scripts/run-tests.sh @ 18:af1871eacc83

Update to Drupal core 8.7.1
author Chris Cannam
date Thu, 09 May 2019 15:33:08 +0100
parents 129ea1e6d783
children
comparison
equal deleted inserted replaced
17:129ea1e6d783 18:af1871eacc83
10 use Drupal\Component\Utility\Timer; 10 use Drupal\Component\Utility\Timer;
11 use Drupal\Component\Uuid\Php; 11 use Drupal\Component\Uuid\Php;
12 use Drupal\Core\Composer\Composer; 12 use Drupal\Core\Composer\Composer;
13 use Drupal\Core\Asset\AttachedAssets; 13 use Drupal\Core\Asset\AttachedAssets;
14 use Drupal\Core\Database\Database; 14 use Drupal\Core\Database\Database;
15 use Drupal\Core\File\Exception\FileException;
16 use Drupal\Core\File\FileSystemInterface;
15 use Drupal\Core\StreamWrapper\PublicStream; 17 use Drupal\Core\StreamWrapper\PublicStream;
16 use Drupal\Core\Test\TestDatabase; 18 use Drupal\Core\Test\TestDatabase;
17 use Drupal\Core\Test\TestRunnerKernel; 19 use Drupal\Core\Test\TestRunnerKernel;
18 use Drupal\simpletest\Form\SimpletestResultsForm; 20 use Drupal\simpletest\Form\SimpletestResultsForm;
19 use Drupal\simpletest\TestBase; 21 use Drupal\simpletest\TestBase;
58 // Sub-process exited already; this is just for clarity. 60 // Sub-process exited already; this is just for clarity.
59 exit(SIMPLETEST_SCRIPT_EXIT_SUCCESS); 61 exit(SIMPLETEST_SCRIPT_EXIT_SUCCESS);
60 } 62 }
61 63
62 if ($args['list']) { 64 if ($args['list']) {
63 // Display all available tests. 65 // Display all available tests organized by one @group annotation.
64 echo "\nAvailable test groups & classes\n"; 66 echo "\nAvailable test groups & classes\n";
65 echo "-------------------------------\n\n"; 67 echo "-------------------------------\n\n";
66 try { 68 try {
67 $groups = \Drupal::service('test_discovery')->getTestClasses($args['module']); 69 $groups = \Drupal::service('test_discovery')->getTestClasses($args['module']);
68 } 70 }
69 catch (Exception $e) { 71 catch (Exception $e) {
70 error_log((string) $e); 72 error_log((string) $e);
71 echo (string) $e; 73 echo (string) $e;
72 exit(SIMPLETEST_SCRIPT_EXIT_EXCEPTION); 74 exit(SIMPLETEST_SCRIPT_EXIT_EXCEPTION);
73 } 75 }
76
77 // A given class can appear in multiple groups. For historical reasons, we
78 // need to present each test only once. The test is shown in the group that is
79 // printed first.
80 $printed_tests = [];
74 foreach ($groups as $group => $tests) { 81 foreach ($groups as $group => $tests) {
75 echo $group . "\n"; 82 echo $group . "\n";
76 foreach ($tests as $class => $info) { 83 $tests = array_diff(array_keys($tests), $printed_tests);
77 echo " - $class\n"; 84 foreach ($tests as $test) {
78 } 85 echo " - $test\n";
86 }
87 $printed_tests = array_merge($printed_tests, $tests);
79 } 88 }
80 exit(SIMPLETEST_SCRIPT_EXIT_SUCCESS); 89 exit(SIMPLETEST_SCRIPT_EXIT_SUCCESS);
81 } 90 }
82 91
83 // List-files and list-files-json provide a way for external tools such as the 92 // List-files and list-files-json provide a way for external tools such as the
960 } 969 }
961 // Delete the test site directory. 970 // Delete the test site directory.
962 // simpletest_clean_temporary_directories() cannot be used here, since it 971 // simpletest_clean_temporary_directories() cannot be used here, since it
963 // would also delete file directories of other tests that are potentially 972 // would also delete file directories of other tests that are potentially
964 // running concurrently. 973 // running concurrently.
965 file_unmanaged_delete_recursive($test_directory, ['Drupal\simpletest\TestBase', 'filePreDeleteCallback']); 974 try {
966 $messages[] = "- Removed test site directory."; 975 \Drupal::service('file_system')->deleteRecursive($test_directory, ['Drupal\simpletest\TestBase', 'filePreDeleteCallback']);
976 $messages[] = "- Removed test site directory.";
977 }
978 catch (FileException $e) {
979 // Ignore failed deletes.
980 }
967 } 981 }
968 982
969 // Clear out all database tables from the test. 983 // Clear out all database tables from the test.
970 try { 984 try {
971 $schema = Database::getConnection('default', 'default')->schema(); 985 $schema = Database::getConnection('default', 'default')->schema();
1017 } 1031 }
1018 $all_tests = []; 1032 $all_tests = [];
1019 foreach ($groups as $group => $tests) { 1033 foreach ($groups as $group => $tests) {
1020 $all_tests = array_merge($all_tests, array_keys($tests)); 1034 $all_tests = array_merge($all_tests, array_keys($tests));
1021 } 1035 }
1022 $test_list = $all_tests; 1036 $test_list = array_unique($all_tests);
1023 } 1037 }
1024 else { 1038 else {
1025 if ($args['class']) { 1039 if ($args['class']) {
1026 $test_list = []; 1040 $test_list = [];
1027 foreach ($args['test_names'] as $test_class) { 1041 foreach ($args['test_names'] as $test_class) {
1137 } 1151 }
1138 catch (Exception $e) { 1152 catch (Exception $e) {
1139 echo (string) $e; 1153 echo (string) $e;
1140 exit(SIMPLETEST_SCRIPT_EXIT_EXCEPTION); 1154 exit(SIMPLETEST_SCRIPT_EXIT_EXCEPTION);
1141 } 1155 }
1156 // Store all the groups so we can suggest alternatives if we need to.
1157 $all_groups = array_keys($groups);
1158 // Verify that the groups exist.
1159 if (!empty($unknown_groups = array_diff($args['test_names'], $all_groups))) {
1160 $first_group = reset($unknown_groups);
1161 simpletest_script_print_error('Test group not found: ' . $first_group);
1162 simpletest_script_print_alternatives($first_group, $all_groups);
1163 exit(SIMPLETEST_SCRIPT_EXIT_FAILURE);
1164 }
1165 // Ensure our list of tests contains only one entry for each test.
1142 foreach ($args['test_names'] as $group_name) { 1166 foreach ($args['test_names'] as $group_name) {
1143 if (isset($groups[$group_name])) { 1167 $test_list = array_merge($test_list, array_flip(array_keys($groups[$group_name])));
1144 $test_list = array_merge($test_list, array_keys($groups[$group_name])); 1168 }
1145 } 1169 $test_list = array_flip($test_list);
1146 else {
1147 simpletest_script_print_error('Test group not found: ' . $group_name);
1148 simpletest_script_print_alternatives($group_name, array_keys($groups));
1149 exit(SIMPLETEST_SCRIPT_EXIT_FAILURE);
1150 }
1151 }
1152 } 1170 }
1153 } 1171 }
1154 1172
1155 // If the test list creation does not automatically limit by test type then 1173 // If the test list creation does not automatically limit by test type then
1156 // we need to do so here. 1174 // we need to do so here.
1563 $html = '<head>' . $render_service->renderPlain($js_assets_header) . $render_service->renderPlain($css_assets) . '</head><body>' . $render_service->renderPlain($form) . $render_service->renderPlain($js_assets_footer) . '</body>'; 1581 $html = '<head>' . $render_service->renderPlain($js_assets_header) . $render_service->renderPlain($css_assets) . '</head><body>' . $render_service->renderPlain($form) . $render_service->renderPlain($js_assets_footer) . '</body>';
1564 1582
1565 // Ensure we have assets verbose directory - tests with no verbose output will 1583 // Ensure we have assets verbose directory - tests with no verbose output will
1566 // not have created one. 1584 // not have created one.
1567 $directory = PublicStream::basePath() . '/simpletest/verbose'; 1585 $directory = PublicStream::basePath() . '/simpletest/verbose';
1568 file_prepare_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS); 1586 \Drupal::service('file_system')->prepareDirectory($directory, FileSystemInterface::CREATE_DIRECTORY | FileSystemInterface::MODIFY_PERMISSIONS);
1569 $php = new Php(); 1587 $php = new Php();
1570 $uuid = $php->generate(); 1588 $uuid = $php->generate();
1571 $filename = $directory . '/results-' . $uuid . '.html'; 1589 $filename = $directory . '/results-' . $uuid . '.html';
1572 $base_url = getenv('SIMPLETEST_BASE_URL'); 1590 $base_url = getenv('SIMPLETEST_BASE_URL');
1573 if (empty($base_url)) { 1591 if (empty($base_url)) {