comparison core/modules/simpletest/simpletest.module @ 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
3 /** 3 /**
4 * @file 4 * @file
5 * Provides testing functionality. 5 * Provides testing functionality.
6 */ 6 */
7 7
8 use Drupal\Core\Url;
8 use Drupal\Core\Asset\AttachedAssetsInterface; 9 use Drupal\Core\Asset\AttachedAssetsInterface;
9 use Drupal\Core\Database\Database; 10 use Drupal\Core\Database\Database;
11 use Drupal\Core\File\Exception\FileException;
10 use Drupal\Core\Render\Element; 12 use Drupal\Core\Render\Element;
11 use Drupal\Core\Routing\RouteMatchInterface; 13 use Drupal\Core\Routing\RouteMatchInterface;
12 use Drupal\simpletest\TestBase; 14 use Drupal\simpletest\TestBase;
13 use Drupal\Core\Test\TestDatabase; 15 use Drupal\Core\Test\TestDatabase;
14 use Drupal\simpletest\TestDiscovery; 16 use Drupal\simpletest\TestDiscovery;
27 $output .= '<h3>' . t('About') . '</h3>'; 29 $output .= '<h3>' . t('About') . '</h3>';
28 $output .= '<p>' . t('The Testing module provides a framework for running automated tests. It can be used to verify a working state of Drupal before and after any code changes, or as a means for developers to write and execute tests for their modules. For more information, see the <a href=":simpletest">online documentation for the Testing module</a>.', [':simpletest' => 'https://www.drupal.org/documentation/modules/simpletest']) . '</p>'; 30 $output .= '<p>' . t('The Testing module provides a framework for running automated tests. It can be used to verify a working state of Drupal before and after any code changes, or as a means for developers to write and execute tests for their modules. For more information, see the <a href=":simpletest">online documentation for the Testing module</a>.', [':simpletest' => 'https://www.drupal.org/documentation/modules/simpletest']) . '</p>';
29 $output .= '<h3>' . t('Uses') . '</h3>'; 31 $output .= '<h3>' . t('Uses') . '</h3>';
30 $output .= '<dl>'; 32 $output .= '<dl>';
31 $output .= '<dt>' . t('Running tests') . '</dt>'; 33 $output .= '<dt>' . t('Running tests') . '</dt>';
32 $output .= '<dd><p>' . t('Visit the <a href=":admin-simpletest">Testing page</a> to display a list of available tests. For comprehensive testing, select <em>all</em> tests, or individually select tests for more targeted testing. Note that it might take several minutes for all tests to complete.', [':admin-simpletest' => \Drupal::url('simpletest.test_form')]) . '</p>'; 34 $output .= '<dd><p>' . t('Visit the <a href=":admin-simpletest">Testing page</a> to display a list of available tests. For comprehensive testing, select <em>all</em> tests, or individually select tests for more targeted testing. Note that it might take several minutes for all tests to complete.', [':admin-simpletest' => Url::fromRoute('simpletest.test_form')->toString()]) . '</p>';
33 $output .= '<p>' . t('After the tests run, a message will be displayed next to each test group indicating whether tests within it passed, failed, or had exceptions. A pass means that the test returned the expected results, while fail means that it did not. An exception normally indicates an error outside of the test, such as a PHP warning or notice. If there were failures or exceptions, the results will be expanded to show details, and the tests that had failures or exceptions will be indicated in red or pink rows. You can then use these results to refine your code and tests, until all tests pass.') . '</p></dd>'; 35 $output .= '<p>' . t('After the tests run, a message will be displayed next to each test group indicating whether tests within it passed, failed, or had exceptions. A pass means that the test returned the expected results, while fail means that it did not. An exception normally indicates an error outside of the test, such as a PHP warning or notice. If there were failures or exceptions, the results will be expanded to show details, and the tests that had failures or exceptions will be indicated in red or pink rows. You can then use these results to refine your code and tests, until all tests pass.') . '</p></dd>';
34 $output .= '</dl>'; 36 $output .= '</dl>';
35 return $output; 37 return $output;
36 38
37 case 'simpletest.test_form': 39 case 'simpletest.test_form':
136 if (isset($test_list['phpunit'])) { 138 if (isset($test_list['phpunit'])) {
137 $test_list = array_merge($test_list, $test_list['phpunit']); 139 $test_list = array_merge($test_list, $test_list['phpunit']);
138 unset($test_list['phpunit']); 140 unset($test_list['phpunit']);
139 } 141 }
140 142
141 $test_id = db_insert('simpletest_test_id') 143 $test_id = \Drupal::database()->insert('simpletest_test_id')
142 ->useDefaults(['test_id']) 144 ->useDefaults(['test_id'])
143 ->execute(); 145 ->execute();
144 146
145 // Clear out the previous verbose files. 147 // Clear out the previous verbose files.
146 file_unmanaged_delete_recursive('public://simpletest/verbose'); 148 try {
149 \Drupal::service('file_system')->deleteRecursive('public://simpletest/verbose');
150 }
151 catch (FileException $e) {
152 // Ignore failed deletes.
153 }
147 154
148 // Get the info for the first test being run. 155 // Get the info for the first test being run.
149 $first_test = reset($test_list); 156 $first_test = reset($test_list);
150 $info = TestDiscovery::getTestInfo($first_test); 157 $info = TestDiscovery::getTestInfo($first_test);
151 158
668 /** 675 /**
669 * Removes prefixed tables from the database from crashed tests. 676 * Removes prefixed tables from the database from crashed tests.
670 */ 677 */
671 function simpletest_clean_database() { 678 function simpletest_clean_database() {
672 $schema = Database::getConnection()->schema(); 679 $schema = Database::getConnection()->schema();
673 $tables = db_find_tables('test%'); 680 $tables = $schema->findTables('test%');
674 $count = 0; 681 $count = 0;
675 foreach ($tables as $table) { 682 foreach ($tables as $table) {
676 // Only drop tables which begin wih 'test' followed by digits, for example, 683 // Only drop tables which begin wih 'test' followed by digits, for example,
677 // {test12345678node__body}. 684 // {test12345678node__body}.
678 if (preg_match('/^test\d+.*/', $table, $matches)) { 685 if (preg_match('/^test\d+.*/', $table, $matches)) {
697 if (is_dir(DRUPAL_ROOT . '/sites/simpletest')) { 704 if (is_dir(DRUPAL_ROOT . '/sites/simpletest')) {
698 $files = scandir(DRUPAL_ROOT . '/sites/simpletest'); 705 $files = scandir(DRUPAL_ROOT . '/sites/simpletest');
699 foreach ($files as $file) { 706 foreach ($files as $file) {
700 if ($file[0] != '.') { 707 if ($file[0] != '.') {
701 $path = DRUPAL_ROOT . '/sites/simpletest/' . $file; 708 $path = DRUPAL_ROOT . '/sites/simpletest/' . $file;
702 file_unmanaged_delete_recursive($path, function ($any_path) { 709 try {
703 @chmod($any_path, 0700); 710 \Drupal::service('file_system')->deleteRecursive($path, function ($any_path) {
704 }); 711 @chmod($any_path, 0700);
712 });
713 }
714 catch (FileException $e) {
715 // Ignore failed deletes.
716 }
705 $count++; 717 $count++;
706 } 718 }
707 } 719 }
708 } 720 }
709 721