Update to Drupal 8.2.0. For more information, see https://www.drupal.org/project/drupal/releases/8.2.0
This commit is contained in:
parent
2f563ab520
commit
f1c8716f57
1732 changed files with 52334 additions and 11780 deletions
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Drupal\Core\Test;
|
||||
|
||||
use Drupal\Component\FileSystem\FileSystem;
|
||||
use Drupal\Core\Database\ConnectionNotDefinedException;
|
||||
use Drupal\Core\Database\Database;
|
||||
|
||||
|
@ -10,6 +11,21 @@ use Drupal\Core\Database\Database;
|
|||
*/
|
||||
class TestDatabase {
|
||||
|
||||
/**
|
||||
* A random number used to ensure that test fixtures are unique to each test
|
||||
* method.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $lockId;
|
||||
|
||||
/**
|
||||
* The test database prefix.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $databasePrefix;
|
||||
|
||||
/**
|
||||
* Returns the database connection to the site running Simpletest.
|
||||
*
|
||||
|
@ -41,4 +57,104 @@ class TestDatabase {
|
|||
return $connection;
|
||||
}
|
||||
|
||||
/**
|
||||
* TestDatabase constructor.
|
||||
*
|
||||
* @param string|null $db_prefix
|
||||
* If not provided a new test lock is generated.
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
* Thrown when $db_prefix does not match the regular expression.
|
||||
*/
|
||||
public function __construct($db_prefix = NULL) {
|
||||
if ($db_prefix === NULL) {
|
||||
$this->lockId = $this->getTestLock();
|
||||
$this->databasePrefix = 'test' . $this->lockId;
|
||||
}
|
||||
else {
|
||||
$this->databasePrefix = $db_prefix;
|
||||
// It is possible that we're running a test inside a test. In which case
|
||||
// $db_prefix will be something like test12345678test90123456 and the
|
||||
// generated lock ID for the running test method would be 90123456.
|
||||
preg_match('/test(\d+)$/', $db_prefix, $matches);
|
||||
if (!isset($matches[1])) {
|
||||
throw new \InvalidArgumentException("Invalid database prefix: $db_prefix");
|
||||
}
|
||||
$this->lockId = $matches[1];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the relative path to the test site directory.
|
||||
*
|
||||
* @return string
|
||||
* The relative path to the test site directory.
|
||||
*/
|
||||
public function getTestSitePath() {
|
||||
return 'sites/simpletest/' . $this->lockId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the test database prefix.
|
||||
*
|
||||
* @return string
|
||||
* The test database prefix.
|
||||
*/
|
||||
public function getDatabasePrefix() {
|
||||
return $this->databasePrefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a unique lock ID for the test method.
|
||||
*
|
||||
* @return int
|
||||
* The unique lock ID for the test method.
|
||||
*/
|
||||
protected function getTestLock() {
|
||||
// Ensure that the generated lock ID is not in use, which may happen when
|
||||
// tests are run concurrently.
|
||||
do {
|
||||
$lock_id = mt_rand(10000000, 99999999);
|
||||
// If we're only running with a concurrency of 1 there's no need to create
|
||||
// a test lock file as there is no chance of the random number generated
|
||||
// clashing.
|
||||
if (getenv('RUN_TESTS_CONCURRENCY') > 1 && @symlink(__FILE__, $this->getLockFile($lock_id)) === FALSE) {
|
||||
$lock_id = NULL;
|
||||
}
|
||||
} while ($lock_id === NULL);
|
||||
return $lock_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Releases all test locks.
|
||||
*
|
||||
* This should only be called once all the test fixtures have been cleaned up.
|
||||
*/
|
||||
public static function releaseAllTestLocks() {
|
||||
$tmp = file_directory_os_temp();
|
||||
$dir = dir($tmp);
|
||||
while (($entry = $dir->read()) !== FALSE) {
|
||||
if ($entry === '.' || $entry === '..') {
|
||||
continue;
|
||||
}
|
||||
$entry_path = $tmp . '/' . $entry;
|
||||
if (preg_match('/^test_\d+/', $entry) && is_link($entry_path)) {
|
||||
unlink($entry_path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the lock file path.
|
||||
*
|
||||
* @param int $lock_id
|
||||
* The test method lock ID.
|
||||
*
|
||||
* @return string
|
||||
* A file path to the symbolic link that prevents the lock ID being re-used.
|
||||
*/
|
||||
protected function getLockFile($lock_id) {
|
||||
return FileSystem::getOsTemporaryDirectory() . '/test_' . $lock_id;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -15,15 +15,18 @@ class TestRunnerKernel extends DrupalKernel {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function createFromRequest(Request $request, $class_loader, $environment = 'test_runner', $allow_dumping = TRUE) {
|
||||
return parent::createFromRequest($request, $class_loader, $environment);
|
||||
public static function createFromRequest(Request $request, $class_loader, $environment = 'test_runner', $allow_dumping = TRUE, $app_root = NULL) {
|
||||
return parent::createFromRequest($request, $class_loader, $environment, $allow_dumping, $app_root);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __construct($environment, $class_loader) {
|
||||
parent::__construct($environment, $class_loader, FALSE);
|
||||
public function __construct($environment, $class_loader, $allow_dumping = FALSE, $app_root = NULL) {
|
||||
// Force $allow_dumping to FALSE, because the test runner kernel should
|
||||
// always have to rebuild its container, and potentially avoid isolation
|
||||
// issues against the tests.
|
||||
parent::__construct($environment, $class_loader, FALSE, $app_root);
|
||||
|
||||
// Prime the module list and corresponding Extension objects.
|
||||
// @todo Remove System module. Needed because
|
||||
|
@ -73,7 +76,7 @@ class TestRunnerKernel extends DrupalKernel {
|
|||
$this->getContainer()->get('stream_wrapper_manager')->register();
|
||||
|
||||
// Create the build/artifacts directory if necessary.
|
||||
include_once DRUPAL_ROOT . '/core/includes/file.inc';
|
||||
include_once $this->getAppRoot() . '/core/includes/file.inc';
|
||||
if (!is_dir('public://simpletest')) {
|
||||
mkdir('public://simpletest', 0777, TRUE);
|
||||
}
|
||||
|
|
Reference in a new issue