Update Composer, update everything

This commit is contained in:
Oliver Davies 2018-11-23 12:29:20 +00:00
parent ea3e94409f
commit dda5c284b6
19527 changed files with 1135420 additions and 351004 deletions

26
web/core/scripts/drupal Normal file
View file

@ -0,0 +1,26 @@
#!/usr/bin/env php
<?php
/**
* @file
* Provides CLI commands for Drupal.
*/
use Drupal\Core\Command\QuickStartCommand;
use Drupal\Core\Command\InstallCommand;
use Drupal\Core\Command\ServerCommand;
use Symfony\Component\Console\Application;
if (PHP_SAPI !== 'cli') {
return;
}
$classloader = require_once __DIR__ . '/../../autoload.php';
$application = new Application('drupal', \Drupal::VERSION);
$application->add(new QuickStartCommand());
$application->add(new InstallCommand($classloader));
$application->add(new ServerCommand($classloader));
$application->run();

View file

@ -2,6 +2,7 @@
<?php
/**
* @file
* Drupal shell execution script
*
* Check for your PHP interpreter - on Windows you'll probably have to
@ -11,6 +12,7 @@
* @param path Drupal's absolute root directory in local file system (optional).
* @param URI A URI to execute, including HTTP protocol prefix.
*/
$script = basename(array_shift($_SERVER['argv']));
if (in_array('--help', $_SERVER['argv']) || empty($_SERVER['argv'])) {
@ -56,8 +58,8 @@ EOF;
exit;
}
// define default settings
$cmd = 'index.php';
// define default settings
$_SERVER['HTTP_HOST'] = 'default';
$_SERVER['PHP_SELF'] = '/index.php';
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
@ -69,10 +71,10 @@ $_SERVER['HTTP_USER_AGENT'] = 'console';
// toggle verbose mode
if (in_array('--verbose', $_SERVER['argv'])) {
$_verbose_mode = true;
$_verbose_mode = TRUE;
}
else {
$_verbose_mode = false;
$_verbose_mode = FALSE;
}
// parse invocation arguments

View file

@ -1,7 +1,14 @@
/**
* @file
*
* Compile *.es6.js files to ES5.
* Provides the build:js command to compile *.es6.js files to ES5.
*
* Run build:js with --file to only parse a specific file. Using the --check
* flag build:js can be run to check if files are compiled correctly.
* @example <caption>Only process misc/drupal.es6.js and misc/drupal.init.es6.js</caption
* yarn run build:js -- --file misc/drupal.es6.js --file misc/drupal.init.es6.js
* @example <caption>Check if all files have been compiled correctly</caption
* yarn run build:js -- --check
*
* @internal This file is part of the core javascript build process and is only
* meant to be used in that context.
@ -9,46 +16,34 @@
'use strict';
const fs = require('fs');
const path = require('path');
const babel = require('babel-core');
const glob = require('glob');
const argv = require('minimist')(process.argv.slice(2));
const changeOrAdded = require('./changeOrAdded');
const check = require('./check');
const log = require('./log');
// Logging human-readable timestamp.
const log = function (message) {
// eslint-disable-next-line no-console
console.log(`[${new Date().toTimeString().slice(0, 8)}] ${message}`);
};
function addSourceMappingUrl(code, loc) {
return code + '\n\n//# sourceMappingURL=' + path.basename(loc);
}
const changedOrAdded = (filePath) => {
babel.transformFile(filePath, {
sourceMaps: true,
comments: false
}, function (err, result) {
const fileName = filePath.slice(0, -7);
// we've requested for a sourcemap to be written to disk
let mapLoc = `${fileName}.js.map`;
fs.writeFile(mapLoc, JSON.stringify(result.map));
fs.writeFile(`${fileName}.js`, addSourceMappingUrl(result.code, mapLoc));
log(`'${filePath}' is being processed.`);
});
};
// Match only on .es6.js files.
const fileMatch = './**/*.es6.js';
// Ignore everything in node_modules
const globOptions = {
ignore: 'node_modules/**'
ignore: './node_modules/**'
};
const processFiles = (error, filePaths) => {
if (error) {
process.exitCode = 1;
}
filePaths.forEach(changedOrAdded);
// Process all the found files.
let callback = changeOrAdded;
if (argv.check) {
callback = check;
}
filePaths.forEach(callback);
};
glob(fileMatch, globOptions, processFiles);
if (argv.file) {
processFiles(null, [].concat(argv.file));
}
else {
glob(fileMatch, globOptions, processFiles);
}
process.exitCode = 0;

View file

@ -11,57 +11,33 @@
const fs = require('fs');
const path = require('path');
const babel = require('babel-core');
const chokidar = require('chokidar');
// Logging human-readable timestamp.
const log = function log(message) {
// eslint-disable-next-line no-console
console.log(`[${new Date().toTimeString().slice(0, 8)}] ${message}`);
};
function addSourceMappingUrl(code, loc) {
return `${code}\n\n//# sourceMappingURL=${path.basename(loc)}`;
}
const changeOrAdded = require('./changeOrAdded');
const log = require('./log');
// Match only on .es6.js files.
const fileMatch = './**/*.es6.js';
// Ignore everything in node_modules
const watcher = chokidar.watch(fileMatch, {
ignoreInitial: true,
ignored: 'node_modules/**'
ignored: './node_modules/**'
});
const changedOrAdded = (filePath) => {
babel.transformFile(filePath, {
sourceMaps: true,
comments: false
}, (err, result) => {
const fileName = filePath.slice(0, -7);
// we've requested for a sourcemap to be written to disk
const mapLoc = `${fileName}.js.map`;
fs.writeFileSync(mapLoc, JSON.stringify(result.map));
fs.writeFileSync(`${fileName}.js`, addSourceMappingUrl(result.code, mapLoc));
log(`'${filePath}' has been changed.`);
});
};
const unlinkHandler = (err) => {
if (err) {
log(err);
}
};
// Watch for filesystem changes.
watcher
.on('add', filePath => changedOrAdded(filePath))
.on('change', filePath => changedOrAdded(filePath))
.on('add', changeOrAdded)
.on('change', changeOrAdded)
.on('unlink', (filePath) => {
const fileName = filePath.slice(0, -7);
fs.stat(`${fileName}.js`, () => {
fs.unlink(`${fileName}.js`, unlinkHandler);
});
fs.stat(`${fileName}.js.map`, () => {
fs.unlink(`${fileName}.js.map`, unlinkHandler);
});
})
.on('ready', () => log(`Watching '${fileMatch}' for changes.`));

View file

@ -0,0 +1,15 @@
const fs = require('fs');
const log = require('./log');
const compile = require('./compile');
module.exports = (filePath) => {
log(`'${filePath}' is being processed.`);
// Transform the file.
compile(filePath, function write(code) {
const fileName = filePath.slice(0, -7);
// Write the result to the filesystem.
fs.writeFile(`${fileName}.js`, code, () => {
log(`'${filePath}' is finished.`);
});
});
}

View file

@ -0,0 +1,23 @@
const chalk = require('chalk');
const fs = require('fs');
const log = require('./log');
const compile = require('./compile');
module.exports = (filePath) => {
log(`'${filePath}' is being checked.`);
// Transform the file.
compile(filePath, function check(code) {
const fileName = filePath.slice(0, -7);
fs.readFile(`${fileName}.js`, function read(err, data) {
if (err) {
log(chalk.red(err));
process.exitCode = 1;
return;
}
if (code !== data.toString()) {
log(chalk.red(`'${filePath}' is not updated.`));
process.exitCode = 1;
}
});
});
}

View file

@ -0,0 +1,31 @@
const chalk = require('chalk');
const log = require('./log');
const babel = require('babel-core');
module.exports = (filePath, callback) => {
// Transform the file.
// Check process.env.NODE_ENV to see if we should create sourcemaps.
babel.transformFile(
filePath,
{
sourceMaps: process.env.NODE_ENV === 'development' ? 'inline' : false,
comments: false,
plugins: [
['add-header-comment', {
'header': [
`DO NOT EDIT THIS FILE.\nSee the following change record for more information,\nhttps://www.drupal.org/node/2815083\n@preserve`
]
}]
]
},
(err, result) => {
if (err) {
log(chalk.red(err));
process.exitCode = 1;
}
else {
callback(result.code);
}
}
);
};

View file

@ -0,0 +1,35 @@
module.exports = function (results) {
results = results || [];
const errorType = {
warnings: {},
errors: {},
};
results.reduce((result, current) => {
current.messages.forEach((msg) => {
if (msg.severity === 1) {
errorType.warnings[msg.ruleId] = errorType.warnings[msg.ruleId] + 1 || 1
}
if (msg.severity === 2) {
errorType.errors[msg.ruleId] = errorType.errors[msg.ruleId] + 1 || 1
}
});
return result;
});
const reduceErrorCounts = (errorType) => Object.entries(errorType).sort((a, b) => b[1] - a[1])
.reduce((result, current) => result.concat([`${current[0]}: ${current[1]}`]), []).join('\n');
const warnings = reduceErrorCounts(errorType.warnings);
const errors = reduceErrorCounts(errorType.errors);
return `
Errors:
${'='.repeat(30)}
${errors}
${'\n'.repeat(4)}
Warnings:
${'='.repeat(30)}
${warnings}`;
};

View file

@ -0,0 +1,4 @@
module.exports = (message) => {
// Logging human-readable timestamp.
console.log(`[${new Date().toTimeString().slice(0, 8)}] ${message}`);
}

View file

@ -1,12 +0,0 @@
#!/bin/bash
# Rename *.js files in *.es6.js. Only need to be run once.
# Should be removed after *.es6.js files are committed to core.
#
# @internal This file is part of the core javascript build process and is only
# meant to be used in that context.
for js in `find ./{misc,modules,themes} -name '*.js'`;
do
mv ${js} ${js%???}.es6.js;
done

View file

@ -2,6 +2,7 @@
<?php
/**
* @file
* Drupal hash script - to generate a hash from a plaintext password
*
* @param password1 [password2 [password3 ...]]
@ -16,7 +17,7 @@ if (PHP_SAPI !== 'cli') {
}
if (version_compare(PHP_VERSION, '5.4.5') < 0) {
$version = PHP_VERSION;
$version = PHP_VERSION;
echo <<<EOF
ERROR: This script requires at least PHP version 5.4.5. You invoked it with
@ -64,7 +65,6 @@ $kernel->boot();
$password_hasher = $kernel->getContainer()->get('password');
foreach ($passwords as $password) {
print("\npassword: $password \t\thash: ". $password_hasher->hash($password) ."\n");
print("\npassword: $password \t\thash: " . $password_hasher->hash($password) . "\n");
}
print("\n");

View file

@ -15,11 +15,11 @@ if (PHP_SAPI !== 'cli') {
return;
}
require __DIR__ . '/../../autoload.php';
$autoloader = require __DIR__ . '/../../autoload.php';
require_once __DIR__ . '/../includes/bootstrap.inc';
$request = Request::createFromGlobals();
Settings::initialize(DrupalKernel::findSitePath($request));
Settings::initialize(DRUPAL_ROOT, DrupalKernel::findSitePath($request), $autoloader);
$timestamp = time();
$token = Crypt::hmacBase64($timestamp, Settings::get('hash_salt'));

185
web/core/scripts/run-tests.sh Executable file → Normal file
View file

@ -9,18 +9,19 @@ use Drupal\Component\FileSystem\FileSystem;
use Drupal\Component\Utility\Html;
use Drupal\Component\Utility\Timer;
use Drupal\Component\Uuid\Php;
use Drupal\Core\Composer\Composer;
use Drupal\Core\Asset\AttachedAssets;
use Drupal\Core\Database\Database;
use Drupal\Core\Site\Settings;
use Drupal\Core\StreamWrapper\PublicStream;
use Drupal\Core\Test\TestDatabase;
use Drupal\Core\Test\TestRunnerKernel;
use Drupal\simpletest\Form\SimpletestResultsForm;
use Drupal\simpletest\TestBase;
use Drupal\simpletest\TestDiscovery;
use PHPUnit\Framework\TestCase;
use PHPUnit\Runner\Version;
use Symfony\Component\HttpFoundation\Request;
$autoloader = require_once __DIR__ . '/../../autoload.php';
// Define some colors for display.
// A nice calming green.
const SIMPLETEST_SCRIPT_COLOR_PASS = 32;
@ -36,11 +37,6 @@ const SIMPLETEST_SCRIPT_EXIT_SUCCESS = 0;
const SIMPLETEST_SCRIPT_EXIT_FAILURE = 1;
const SIMPLETEST_SCRIPT_EXIT_EXCEPTION = 2;
if (!class_exists('\PHPUnit_Framework_TestCase')) {
echo "\nrun-tests.sh requires the PHPUnit testing framework. Please use 'composer install --dev' to ensure that it is present.\n\n";
exit(SIMPLETEST_SCRIPT_EXIT_FAILURE);
}
// Set defaults and get overrides.
list($args, $count) = simpletest_script_parse_args();
@ -51,14 +47,9 @@ if ($args['help'] || $count == 0) {
simpletest_script_init();
try {
$request = Request::createFromGlobals();
$kernel = TestRunnerKernel::createFromRequest($request, $autoloader);
$kernel->prepareLegacyRequest($request);
}
catch (Exception $e) {
echo (string) $e;
exit(SIMPLETEST_SCRIPT_EXIT_EXCEPTION);
if (!class_exists(TestCase::class)) {
echo "\nrun-tests.sh requires the PHPUnit testing framework. Please use 'composer install' to ensure that it is present.\n\n";
exit(SIMPLETEST_SCRIPT_EXIT_FAILURE);
}
if ($args['execute-test']) {
@ -73,7 +64,7 @@ if ($args['list']) {
echo "\nAvailable test groups & classes\n";
echo "-------------------------------\n\n";
try {
$groups = simpletest_test_get_all($args['module']);
$groups = \Drupal::service('test_discovery')->getTestClasses($args['module']);
}
catch (Exception $e) {
error_log((string) $e);
@ -97,9 +88,10 @@ if ($args['list-files'] || $args['list-files-json']) {
$test_discovery = NULL;
try {
$test_discovery = \Drupal::service('test_discovery');
} catch (Exception $e) {
}
catch (Exception $e) {
error_log((string) $e);
echo (string)$e;
echo (string) $e;
exit(SIMPLETEST_SCRIPT_EXIT_EXCEPTION);
}
// TestDiscovery::findAllClassFiles() gives us a classmap similar to a
@ -112,7 +104,7 @@ if ($args['list-files'] || $args['list-files-json']) {
}
// Output the list of files.
else {
foreach(array_values($test_classes) as $test_class) {
foreach (array_values($test_classes) as $test_class) {
echo $test_class . "\n";
}
}
@ -133,20 +125,32 @@ if ($args['clean']) {
echo "\nEnvironment cleaned.\n";
// Get the status messages and print them.
$messages = drupal_get_messages('status');
foreach ($messages['status'] as $text) {
$messages = \Drupal::messenger()->messagesByType('status');
foreach ($messages as $text) {
echo " - " . $text . "\n";
}
exit(SIMPLETEST_SCRIPT_EXIT_SUCCESS);
}
// Ensure we have the correct PHPUnit version for the version of PHP.
if (class_exists('\PHPUnit_Runner_Version')) {
$phpunit_version = \PHPUnit_Runner_Version::id();
}
else {
$phpunit_version = Version::id();
}
if (!Composer::upgradePHPUnitCheck($phpunit_version)) {
simpletest_script_print_error("PHPUnit testing framework version 6 or greater is required when running on PHP 7.0 or greater. Run the command 'composer run-script drupal-phpunit-upgrade' in order to fix this.");
exit(SIMPLETEST_SCRIPT_EXIT_FAILURE);
}
$test_list = simpletest_script_get_test_list();
// Try to allocate unlimited time to run the tests.
drupal_set_time_limit(0);
simpletest_script_reporter_init();
$tests_to_run = array();
$tests_to_run = [];
for ($i = 0; $i < $args['repeat']; $i++) {
$tests_to_run = array_merge($tests_to_run, $test_list);
}
@ -304,6 +308,15 @@ All arguments are long options.
--non-html Removes escaping from output. Useful for reading results on the
CLI.
--suppress-deprecations
Stops tests from failing if deprecation errors are triggered. If
this is not set the value specified in the
SYMFONY_DEPRECATIONS_HELPER environment variable, or the value
specified in core/phpunit.xml (if it exists), or the default value
will be used. The default is that any unexpected silenced
deprecation error will fail tests.
<test1>[,<test2>[,<test3> ...]]
One or more tests to be run. By default, these are interpreted
@ -343,7 +356,7 @@ EOF;
*/
function simpletest_script_parse_args() {
// Set default values.
$args = array(
$args = [
'script' => '',
'help' => FALSE,
'list' => FALSE,
@ -365,16 +378,17 @@ function simpletest_script_parse_args() {
'verbose' => FALSE,
'keep-results' => FALSE,
'keep-results-table' => FALSE,
'test_names' => array(),
'test_names' => [],
'repeat' => 1,
'die-on-fail' => FALSE,
'suppress-deprecations' => FALSE,
'browser' => FALSE,
// Used internally.
'test-id' => 0,
'execute-test' => '',
'xml' => '',
'non-html' => FALSE,
);
];
// Override with set values.
$args['script'] = basename(array_shift($_SERVER['argv']));
@ -397,7 +411,7 @@ function simpletest_script_parse_args() {
$args[$matches[1]] = array_shift($_SERVER['argv']);
}
// Clear extraneous values.
$args['test_names'] = array();
$args['test_names'] = [];
$count++;
}
else {
@ -422,7 +436,7 @@ function simpletest_script_parse_args() {
if ($args['browser']) {
$args['keep-results'] = TRUE;
}
return array($args, $count);
return [$args, $count];
}
/**
@ -456,6 +470,25 @@ function simpletest_script_init() {
exit(SIMPLETEST_SCRIPT_EXIT_FAILURE);
}
// Detect if we're in the top-level process using the private 'execute-test'
// argument. Determine if being run on drupal.org's testing infrastructure
// using the presence of 'drupaltestbot' in the database url.
// @todo https://www.drupal.org/project/drupalci_testbot/issues/2860941 Use
// better environment variable to detect DrupalCI.
// @todo https://www.drupal.org/project/drupal/issues/2942473 Remove when
// dropping PHPUnit 4 and PHP 5 support.
if (!$args['execute-test'] && preg_match('/drupalci/', $args['sqlite'])) {
// Update PHPUnit if needed and possible. There is a later check once the
// autoloader is in place to ensure we're on the correct version. We need to
// do this before the autoloader is in place to ensure that it is correct.
$composer = ($composer = rtrim('\\' === DIRECTORY_SEPARATOR ? preg_replace('/[\r\n].*/', '', `where.exe composer.phar`) : `which composer.phar`))
? $php . ' ' . escapeshellarg($composer)
: 'composer';
passthru("$composer run-script drupal-phpunit-upgrade-check");
}
$autoloader = require_once __DIR__ . '/../../autoload.php';
// Get URL from arguments.
if (!empty($args['url'])) {
$parsed_url = parse_url($args['url']);
@ -514,6 +547,17 @@ function simpletest_script_init() {
}
chdir(realpath(__DIR__ . '/../..'));
// Prepare the kernel.
try {
$request = Request::createFromGlobals();
$kernel = TestRunnerKernel::createFromRequest($request, $autoloader);
$kernel->prepareLegacyRequest($request);
}
catch (Exception $e) {
echo (string) $e;
exit(SIMPLETEST_SCRIPT_EXIT_EXCEPTION);
}
}
/**
@ -590,13 +634,13 @@ function simpletest_script_setup_database($new = FALSE) {
else {
$sqlite = DRUPAL_ROOT . '/' . $args['sqlite'];
}
$databases['test-runner']['default'] = array(
$databases['test-runner']['default'] = [
'driver' => 'sqlite',
'database' => $sqlite,
'prefix' => array(
'prefix' => [
'default' => '',
),
);
],
];
// Create the test runner SQLite database, unless it exists already.
if ($new && !file_exists($sqlite)) {
if (!is_dir(dirname($sqlite))) {
@ -658,7 +702,7 @@ function simpletest_script_execute_batch($test_classes) {
$total_status = SIMPLETEST_SCRIPT_EXIT_SUCCESS;
// Multi-process execution.
$children = array();
$children = [];
while (!empty($test_classes) || !empty($children)) {
while (count($children) < $args['concurrency']) {
if (empty($test_classes)) {
@ -668,7 +712,7 @@ function simpletest_script_execute_batch($test_classes) {
try {
$test_id = Database::getConnection('default', 'test-runner')
->insert('simpletest_test_id')
->useDefaults(array('test_id'))
->useDefaults(['test_id'])
->execute();
}
catch (Exception $e) {
@ -680,7 +724,7 @@ function simpletest_script_execute_batch($test_classes) {
$test_class = array_shift($test_classes);
// Fork a child process.
$command = simpletest_script_command($test_id, $test_class);
$process = proc_open($command, array(), $pipes, NULL, NULL, array('bypass_shell' => TRUE));
$process = proc_open($command, [], $pipes, NULL, NULL, ['bypass_shell' => TRUE]);
if (!is_resource($process)) {
echo "Unable to fork test process. Aborting.\n";
@ -688,12 +732,12 @@ function simpletest_script_execute_batch($test_classes) {
}
// Register our new child.
$children[] = array(
$children[] = [
'process' => $process,
'test_id' => $test_id,
'class' => $test_class,
'pipes' => $pipes,
);
];
}
// Wait for children every 200ms.
@ -754,7 +798,7 @@ function simpletest_script_run_phpunit($test_id, $class) {
set_time_limit($reflection->getStaticPropertyValue('runLimit'));
}
$results = simpletest_run_phpunit_tests($test_id, array($class), $status);
$results = simpletest_run_phpunit_tests($test_id, [$class], $status);
simpletest_process_phpunit_results($results);
// Map phpunit results to a data structure we can pass to
@ -780,10 +824,13 @@ function simpletest_script_run_one_test($test_id, $test_class) {
else {
$class_name = $test_class;
// Use empty array to run all the test methods.
$methods = array();
$methods = [];
}
$test = new $class_name($test_id);
if (is_subclass_of($test_class, '\PHPUnit_Framework_TestCase')) {
if ($args['suppress-deprecations']) {
putenv('SYMFONY_DEPRECATIONS_HELPER=disabled');
}
if (is_subclass_of($test_class, TestCase::class)) {
$status = simpletest_script_run_phpunit($test_id, $test_class);
}
else {
@ -833,7 +880,7 @@ function simpletest_script_command($test_id, $test_class) {
}
$command .= ' --php ' . escapeshellarg($php);
$command .= " --test-id $test_id";
foreach (array('verbose', 'keep-results', 'color', 'die-on-fail') as $arg) {
foreach (['verbose', 'keep-results', 'color', 'die-on-fail', 'suppress-deprecations'] as $arg) {
if ($args[$arg]) {
$command .= ' --' . $arg;
}
@ -865,7 +912,7 @@ function simpletest_script_command($test_id, $test_class) {
* @see simpletest_script_run_one_test()
*/
function simpletest_script_cleanup($test_id, $test_class, $exitcode) {
if (is_subclass_of($test_class, '\PHPUnit_Framework_TestCase')) {
if (is_subclass_of($test_class, TestCase::class)) {
// PHPUnit test, move on.
return;
}
@ -886,7 +933,7 @@ function simpletest_script_cleanup($test_id, $test_class, $exitcode) {
// Do not output verbose cleanup messages in case of a positive exitcode.
$output = !empty($exitcode);
$messages = array();
$messages = [];
$messages[] = "- Found database prefix '$db_prefix' for test ID $test_id.";
@ -915,7 +962,7 @@ function simpletest_script_cleanup($test_id, $test_class, $exitcode) {
// simpletest_clean_temporary_directories() cannot be used here, since it
// would also delete file directories of other tests that are potentially
// running concurrently.
file_unmanaged_delete_recursive($test_directory, array('Drupal\simpletest\TestBase', 'filePreDeleteCallback'));
file_unmanaged_delete_recursive($test_directory, ['Drupal\simpletest\TestBase', 'filePreDeleteCallback']);
$messages[] = "- Removed test site directory.";
}
@ -955,18 +1002,20 @@ function simpletest_script_cleanup($test_id, $test_class, $exitcode) {
function simpletest_script_get_test_list() {
global $args;
/** $test_discovery \Drupal\simpletest\TestDiscovery */
$test_discovery = \Drupal::service('test_discovery');
$types_processed = empty($args['types']);
$test_list = array();
$test_list = [];
if ($args['all'] || $args['module']) {
try {
$groups = simpletest_test_get_all($args['module'], $args['types']);
$groups = $test_discovery->getTestClasses($args['module'], $args['types']);
$types_processed = TRUE;
}
catch (Exception $e) {
echo (string) $e;
exit(SIMPLETEST_SCRIPT_EXIT_EXCEPTION);
}
$all_tests = array();
$all_tests = [];
foreach ($groups as $group => $tests) {
$all_tests = array_merge($all_tests, array_keys($tests));
}
@ -974,7 +1023,7 @@ function simpletest_script_get_test_list() {
}
else {
if ($args['class']) {
$test_list = array();
$test_list = [];
foreach ($args['test_names'] as $test_class) {
list($class_name) = explode('::', $test_class, 2);
if (class_exists($class_name)) {
@ -982,13 +1031,13 @@ function simpletest_script_get_test_list() {
}
else {
try {
$groups = simpletest_test_get_all(NULL, $args['types']);
$groups = $test_discovery->getTestClasses(NULL, $args['types']);
}
catch (Exception $e) {
echo (string) $e;
exit(SIMPLETEST_SCRIPT_EXIT_EXCEPTION);
}
$all_classes = array();
$all_classes = [];
foreach ($groups as $group) {
$all_classes = array_merge($all_classes, array_keys($group));
}
@ -1020,7 +1069,7 @@ function simpletest_script_get_test_list() {
else {
foreach ($matches[1] as $class_name) {
$namespace_class = $namespace . '\\' . $class_name;
if (is_subclass_of($namespace_class, '\Drupal\simpletest\TestBase') || is_subclass_of($namespace_class, '\PHPUnit_Framework_TestCase')) {
if (is_subclass_of($namespace_class, '\Drupal\simpletest\TestBase') || is_subclass_of($namespace_class, TestCase::class)) {
$test_list[] = $namespace_class;
}
}
@ -1035,7 +1084,7 @@ function simpletest_script_get_test_list() {
// minimal conditions only; i.e., a '*.php' file that has '/Tests/' in
// its path.
// Ignore anything from third party vendors.
$ignore = array('.', '..', 'vendor');
$ignore = ['.', '..', 'vendor'];
$files = [];
if ($args['directory'][0] === '/') {
$directory = $args['directory'];
@ -1074,7 +1123,7 @@ function simpletest_script_get_test_list() {
else {
foreach ($matches[1] as $class_name) {
$namespace_class = $namespace . '\\' . $class_name;
if (is_subclass_of($namespace_class, '\Drupal\simpletest\TestBase') || is_subclass_of($namespace_class, '\PHPUnit_Framework_TestCase')) {
if (is_subclass_of($namespace_class, '\Drupal\simpletest\TestBase') || is_subclass_of($namespace_class, TestCase::class)) {
$test_list[] = $namespace_class;
}
}
@ -1083,7 +1132,7 @@ function simpletest_script_get_test_list() {
}
else {
try {
$groups = simpletest_test_get_all(NULL, $args['types']);
$groups = $test_discovery->getTestClasses(NULL, $args['types']);
$types_processed = TRUE;
}
catch (Exception $e) {
@ -1125,11 +1174,11 @@ function simpletest_script_get_test_list() {
function simpletest_script_reporter_init() {
global $args, $test_list, $results_map;
$results_map = array(
$results_map = [
'pass' => 'Pass',
'fail' => 'Fail',
'exception' => 'Exception',
);
];
echo "\n";
echo "Drupal test run\n";
@ -1170,13 +1219,13 @@ function simpletest_script_reporter_display_summary($class, $results) {
// Output all test results vertically aligned.
// Cut off the class name after 60 chars, and pad each group with 3 digits
// by default (more than 999 assertions are rare).
$output = vsprintf('%-60.60s %10s %9s %14s %12s', array(
$output = vsprintf('%-60.60s %10s %9s %14s %12s', [
$class,
$results['#pass'] . ' passes',
!$results['#fail'] ? '' : $results['#fail'] . ' fails',
!$results['#exception'] ? '' : $results['#exception'] . ' exceptions',
!$results['#debug'] ? '' : $results['#debug'] . ' messages',
));
]);
$status = ($results['#fail'] || $results['#exception'] ? 'fail' : 'pass');
simpletest_script_print($output . "\n", simpletest_script_color_code($status));
@ -1197,7 +1246,7 @@ function simpletest_script_reporter_write_xml_results() {
}
$test_class = '';
$xml_files = array();
$xml_files = [];
foreach ($results as $result) {
if (isset($results_map[$result->status])) {
@ -1213,7 +1262,7 @@ function simpletest_script_reporter_write_xml_results() {
$doc = new DomDocument('1.0');
$root = $doc->createElement('testsuite');
$root = $doc->appendChild($root);
$xml_files[$test_class] = array('doc' => $doc, 'suite' => $root);
$xml_files[$test_class] = ['doc' => $doc, 'suite' => $root];
}
}
@ -1408,10 +1457,10 @@ function simpletest_script_color_code($status) {
* string in $array would be identical to $string by changing 1/4 or fewer of
* its characters.
*
* @see http://php.net/manual/en/function.levenshtein.php
* @see http://php.net/manual/function.levenshtein.php
*/
function simpletest_script_print_alternatives($string, $array, $degree = 4) {
$alternatives = array();
$alternatives = [];
foreach ($array as $item) {
$lev = levenshtein($string, $item);
if ($lev <= strlen($item) / $degree || FALSE !== strpos($string, $item)) {
@ -1439,7 +1488,7 @@ function simpletest_script_print_alternatives($string, $array, $degree = 4) {
*/
function simpletest_script_load_messages_by_test_id($test_ids) {
global $args;
$results = array();
$results = [];
// Sqlite has a maximum number of variables per query. If required, the
// database query is split into chunks.
@ -1447,15 +1496,15 @@ function simpletest_script_load_messages_by_test_id($test_ids) {
$test_id_chunks = array_chunk($test_ids, SIMPLETEST_SCRIPT_SQLITE_VARIABLE_LIMIT);
}
else {
$test_id_chunks = array($test_ids);
$test_id_chunks = [$test_ids];
}
foreach ($test_id_chunks as $test_id_chunk) {
try {
$result_chunk = Database::getConnection('default', 'test-runner')
->query("SELECT * FROM {simpletest} WHERE test_id IN ( :test_ids[] ) ORDER BY test_class, message_id", array(
->query("SELECT * FROM {simpletest} WHERE test_id IN ( :test_ids[] ) ORDER BY test_class, message_id", [
':test_ids[]' => $test_id_chunk,
))->fetchAll();
])->fetchAll();
}
catch (Exception $e) {
echo (string) $e;
@ -1491,12 +1540,12 @@ function simpletest_script_open_browser() {
}
// Get the results form.
$form = array();
$form = [];
SimpletestResultsForm::addResultForm($form, $results);
// Get the assets to make the details element collapsible and theme the result
// form.
$assets = new \Drupal\Core\Asset\AttachedAssets();
$assets = new AttachedAssets();
$assets->setLibraries([
'core/drupal.collapse',
'system/admin',

View file

@ -0,0 +1,24 @@
#!/usr/bin/env php
<?php
/**
* @file
* A command line application to install Drupal for tests.
*/
use Drupal\TestSite\TestSiteApplication;
if (PHP_SAPI !== 'cli') {
return;
}
// Use the PHPUnit bootstrap to prime an autoloader that works for test classes.
// Note we have to disable the SYMFONY_DEPRECATIONS_HELPER to ensure deprecation
// notices are not triggered.
putenv('SYMFONY_DEPRECATIONS_HELPER=disabled');
require_once __DIR__ . '/../tests/bootstrap.php';
// The application version is 0.1.0 to indicate that it is for internal use only
// and not currently API.
$app = new TestSiteApplication('test-site', '0.1.0');
$app->run();

View file

@ -9,6 +9,8 @@
* and in the right human-readable format.
*/
use Drupal\Core\Locale\CountryManager;
// Determine DRUPAL_ROOT.
$dir = dirname(__FILE__);
while (!defined('DRUPAL_ROOT')) {
@ -35,9 +37,11 @@ USAGE;
// Fake the t() function used in CountryManager.php instead of attempting a full
// Drupal bootstrap of core/includes/bootstrap.inc (where t() is declared).
if (!function_exists('t')) {
function t($string) {
return $string;
}
}
// Read in existing codes.
@ -45,7 +49,7 @@ if (!function_exists('t')) {
// @see https://www.drupal.org/node/1436754
require_once DRUPAL_ROOT . '/core/lib/Drupal/Core/Locale/CountryManagerInterface.php';
require_once DRUPAL_ROOT . '/core/lib/Drupal/Core/Locale/CountryManager.php';
$existing_countries = \Drupal\Core\Locale\CountryManager::getStandardList();
$existing_countries = CountryManager::getStandardList();
$countries = $existing_countries;
// Parse the source data into an array.
@ -53,19 +57,21 @@ $data = json_decode(file_get_contents($uri));
foreach ($data->main->en->localeDisplayNames->territories as $code => $name) {
// Use any alternate codes the Drupal community wishes to.
$alt_codes = array(
$alt_codes = [
// 'CI-alt-variant', // Use CI-alt-variant instead of the CI entry.
);
];
if (in_array($code, $alt_codes)) {
// Just use the first 2 character part of the alt code.
$code = strtok($code, '-');
}
// Skip any codes we wish to exclude from our country list.
$exclude_codes = array(
'EU', // The European Union is not a country.
'ZZ', // Don't allow "Unknown Region".
);
$exclude_codes = [
// The European Union is not a country.
'EU',
// Don't allow "Unknown Region".
'ZZ',
];
if (in_array($code, $exclude_codes)) {
continue;
}
@ -95,5 +101,5 @@ foreach ($countries as $code => $name) {
// Replace the actual PHP code in standard.inc.
$file = DRUPAL_ROOT . '/core/lib/Drupal/Core/Locale/CountryManager.php';
$content = file_get_contents($file);
$content = preg_replace('/(\$countries = array\(\n)(.+?)(^\s+\);)/ms', '$1' . $out . '$3', $content);
$content = preg_replace('/(\$countries = \[\n)(.+?)(^\s+\];)/ms', '$1' . $out . '$3', $content, -1, $count);
file_put_contents($file, $content);