Mercurial > hg > cmmr2012-drupal-site
comparison core/modules/simpletest/src/TestBase.php @ 5:12f9dff5fda9 tip
Update to Drupal core 8.7.1
author | Chris Cannam |
---|---|
date | Thu, 09 May 2019 15:34:47 +0100 |
parents | a9cd425dd02b |
children |
comparison
equal
deleted
inserted
replaced
4:a9cd425dd02b | 5:12f9dff5fda9 |
---|---|
1 <?php | 1 <?php |
2 | 2 |
3 namespace Drupal\simpletest; | 3 namespace Drupal\simpletest; |
4 | 4 |
5 use Drupal\Component\Assertion\Handle; | 5 use Drupal\Component\Assertion\Handle; |
6 use Drupal\Component\Render\FormattableMarkup; | |
6 use Drupal\Component\Render\MarkupInterface; | 7 use Drupal\Component\Render\MarkupInterface; |
7 use Drupal\Component\Utility\Crypt; | 8 use Drupal\Component\Utility\Crypt; |
8 use Drupal\Component\Render\FormattableMarkup; | 9 use Drupal\Component\Utility\Environment; |
9 use Drupal\Core\Database\Database; | 10 use Drupal\Core\Database\Database; |
11 use Drupal\Core\File\FileSystemInterface; | |
10 use Drupal\Core\Site\Settings; | 12 use Drupal\Core\Site\Settings; |
11 use Drupal\Core\StreamWrapper\PublicStream; | 13 use Drupal\Core\StreamWrapper\PublicStream; |
12 use Drupal\Core\Test\TestDatabase; | 14 use Drupal\Core\Test\TestDatabase; |
13 use Drupal\Core\Test\TestSetupTrait; | 15 use Drupal\Core\Test\TestSetupTrait; |
14 use Drupal\Core\Utility\Error; | 16 use Drupal\Core\Utility\Error; |
901 if ($this->verbose) { | 903 if ($this->verbose) { |
902 // Initialize verbose debugging. | 904 // Initialize verbose debugging. |
903 $this->verbose = TRUE; | 905 $this->verbose = TRUE; |
904 $this->verboseDirectory = PublicStream::basePath() . '/simpletest/verbose'; | 906 $this->verboseDirectory = PublicStream::basePath() . '/simpletest/verbose'; |
905 $this->verboseDirectoryUrl = file_create_url($this->verboseDirectory); | 907 $this->verboseDirectoryUrl = file_create_url($this->verboseDirectory); |
906 if (file_prepare_directory($this->verboseDirectory, FILE_CREATE_DIRECTORY) && !file_exists($this->verboseDirectory . '/.htaccess')) { | 908 if (\Drupal::service('file_system')->prepareDirectory($this->verboseDirectory, FileSystemInterface::CREATE_DIRECTORY) && !file_exists($this->verboseDirectory . '/.htaccess')) { |
907 file_put_contents($this->verboseDirectory . '/.htaccess', "<IfModule mod_expires.c>\nExpiresActive Off\n</IfModule>\n"); | 909 file_put_contents($this->verboseDirectory . '/.htaccess', "<IfModule mod_expires.c>\nExpiresActive Off\n</IfModule>\n"); |
908 } | 910 } |
909 $this->verboseClassName = str_replace("\\", "_", $class); | 911 $this->verboseClassName = str_replace("\\", "_", $class); |
910 } | 912 } |
911 // HTTP auth settings (<username>:<password>) for the simpletest browser | 913 // HTTP auth settings (<username>:<password>) for the simpletest browser |
1123 $this->originalShutdownCallbacks = $callbacks; | 1125 $this->originalShutdownCallbacks = $callbacks; |
1124 $callbacks = []; | 1126 $callbacks = []; |
1125 | 1127 |
1126 // Create test directory ahead of installation so fatal errors and debug | 1128 // Create test directory ahead of installation so fatal errors and debug |
1127 // information can be logged during installation process. | 1129 // information can be logged during installation process. |
1128 file_prepare_directory($this->siteDirectory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS); | 1130 \Drupal::service('file_system')->prepareDirectory($this->siteDirectory, FileSystemInterface::CREATE_DIRECTORY | FileSystemInterface::MODIFY_PERMISSIONS); |
1129 | 1131 |
1130 // Prepare filesystem directory paths. | 1132 // Prepare filesystem directory paths. |
1131 $this->publicFilesDirectory = $this->siteDirectory . '/files'; | 1133 $this->publicFilesDirectory = $this->siteDirectory . '/files'; |
1132 $this->privateFilesDirectory = $this->siteDirectory . '/private'; | 1134 $this->privateFilesDirectory = $this->siteDirectory . '/private'; |
1133 $this->tempFilesDirectory = $this->siteDirectory . '/temp'; | 1135 $this->tempFilesDirectory = $this->siteDirectory . '/temp'; |
1175 // For performance, simply use the database prefix as hash salt. | 1177 // For performance, simply use the database prefix as hash salt. |
1176 'hash_salt' => $this->databasePrefix, | 1178 'hash_salt' => $this->databasePrefix, |
1177 'container_yamls' => [], | 1179 'container_yamls' => [], |
1178 ]); | 1180 ]); |
1179 | 1181 |
1180 drupal_set_time_limit($this->timeLimit); | 1182 Environment::setTimeLimit($this->timeLimit); |
1181 } | 1183 } |
1182 | 1184 |
1183 /** | 1185 /** |
1184 * Performs cleanup tasks after each individual test method has been run. | 1186 * Performs cleanup tasks after each individual test method has been run. |
1185 */ | 1187 */ |
1248 // Restore original dependency injection container. | 1250 // Restore original dependency injection container. |
1249 $this->container = $this->originalContainer; | 1251 $this->container = $this->originalContainer; |
1250 \Drupal::setContainer($this->originalContainer); | 1252 \Drupal::setContainer($this->originalContainer); |
1251 | 1253 |
1252 // Delete test site directory. | 1254 // Delete test site directory. |
1253 file_unmanaged_delete_recursive($this->siteDirectory, [$this, 'filePreDeleteCallback']); | 1255 \Drupal::service('file_system')->deleteRecursive($this->siteDirectory, [$this, 'filePreDeleteCallback']); |
1254 | 1256 |
1255 // Restore original database connection. | 1257 // Restore original database connection. |
1256 Database::removeConnection('default'); | 1258 Database::removeConnection('default'); |
1257 Database::renameConnection('simpletest_original_default', 'default'); | 1259 Database::renameConnection('simpletest_original_default', 'default'); |
1258 | 1260 |
1360 $settings[$name] = $value; | 1362 $settings[$name] = $value; |
1361 new Settings($settings); | 1363 new Settings($settings); |
1362 } | 1364 } |
1363 | 1365 |
1364 /** | 1366 /** |
1365 * Ensures test files are deletable within file_unmanaged_delete_recursive(). | 1367 * Ensures test files are deletable. |
1366 * | 1368 * |
1367 * Some tests chmod generated files to be read only. During | 1369 * Some tests chmod generated files to be read only. During |
1368 * TestBase::restoreEnvironment() and other cleanup operations, these files | 1370 * TestBase::restoreEnvironment() and other cleanup operations, these files |
1369 * need to get deleted too. | 1371 * need to get deleted too. |
1372 * | |
1373 * @see \Drupal\Core\File\FileSystemInterface::deleteRecursive() | |
1370 */ | 1374 */ |
1371 public static function filePreDeleteCallback($path) { | 1375 public static function filePreDeleteCallback($path) { |
1372 // When the webserver runs with the same system user as the test runner, we | 1376 // When the webserver runs with the same system user as the test runner, we |
1373 // can make read-only files writable again. If not, chmod will fail while | 1377 // can make read-only files writable again. If not, chmod will fail while |
1374 // the file deletion still works if file permissions have been configured | 1378 // the file deletion still works if file permissions have been configured |