Update Composer, update everything
This commit is contained in:
parent
ea3e94409f
commit
dda5c284b6
19527 changed files with 1135420 additions and 351004 deletions
|
@ -84,7 +84,7 @@ a.simpletest-collapse {
|
|||
a.simpletest-collapse:focus,
|
||||
a.simpletest-collapse:hover {
|
||||
font-size: 80%;
|
||||
top: 0px;
|
||||
top: 0;
|
||||
height: auto;
|
||||
width: auto;
|
||||
overflow: visible;
|
||||
|
|
BIN
web/core/modules/simpletest/files/image-3.jpg
Normal file
BIN
web/core/modules/simpletest/files/image-3.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.8 KiB |
1
web/core/modules/simpletest/files/invalid-img-test.png
Normal file
1
web/core/modules/simpletest/files/invalid-img-test.png
Normal file
|
@ -0,0 +1 @@
|
|||
invalid image file
|
|
@ -2,6 +2,7 @@ id: d6_simpletest_settings
|
|||
label: Simpletest configuration
|
||||
migration_tags:
|
||||
- Drupal 6
|
||||
- Configuration
|
||||
source:
|
||||
plugin: variable
|
||||
variables:
|
||||
|
@ -10,6 +11,7 @@ source:
|
|||
- simpletest_httpauth_password
|
||||
- simpletest_httpauth_username
|
||||
- simpletest_verbose
|
||||
source_module: simpletest
|
||||
process:
|
||||
clear_results: simpletest_clear_results
|
||||
'httpauth/method': simpletest_httpauth_method
|
|
@ -2,6 +2,7 @@ id: d7_simpletest_settings
|
|||
label: SimpleTest configuration
|
||||
migration_tags:
|
||||
- Drupal 7
|
||||
- Configuration
|
||||
source:
|
||||
plugin: variable
|
||||
variables:
|
||||
|
@ -10,6 +11,7 @@ source:
|
|||
- simpletest_httpauth_password
|
||||
- simpletest_httpauth_username
|
||||
- simpletest_verbose
|
||||
source_module: simpletest
|
||||
process:
|
||||
clear_results: simpletest_clear_results
|
||||
'httpauth/method': simpletest_httpauth_method
|
|
@ -13,10 +13,17 @@
|
|||
/**
|
||||
* Alter the list of tests.
|
||||
*
|
||||
* This hook will not be invoked by the phpunit tool.
|
||||
*
|
||||
* @param $groups
|
||||
* A two dimensional array, the first key is the test group, the second is the
|
||||
* name of the test class, and the value is in associative array containing
|
||||
* 'name', 'description', 'group', and 'requires' keys.
|
||||
*
|
||||
* @deprecated in Drupal 8.6.x and will be removed before Drupal 9.0.0. Convert
|
||||
* your test to a PHPUnit-based one and implement test listeners.
|
||||
*
|
||||
* @see https://www.drupal.org/node/2939892
|
||||
*/
|
||||
function hook_simpletest_alter(&$groups) {
|
||||
// An alternative session handler module would not want to run the original
|
||||
|
@ -55,7 +62,6 @@ function hook_test_group_finished() {
|
|||
function hook_test_finished($results) {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @} End of "addtogroup hooks".
|
||||
*/
|
||||
|
|
144
web/core/modules/simpletest/simpletest.es6.js
Normal file
144
web/core/modules/simpletest/simpletest.es6.js
Normal file
|
@ -0,0 +1,144 @@
|
|||
/**
|
||||
* @file
|
||||
* Simpletest behaviors.
|
||||
*/
|
||||
|
||||
(function($, Drupal, drupalSettings) {
|
||||
/**
|
||||
* Collapses table rows followed by group rows on the test listing page.
|
||||
*
|
||||
* @type {Drupal~behavior}
|
||||
*
|
||||
* @prop {Drupal~behaviorAttach} attach
|
||||
* Attach collapse behavior on the test listing page.
|
||||
*/
|
||||
Drupal.behaviors.simpleTestGroupCollapse = {
|
||||
attach(context) {
|
||||
$(context)
|
||||
.find('.simpletest-group')
|
||||
.once('simpletest-group-collapse')
|
||||
.each(function() {
|
||||
const $group = $(this);
|
||||
const $image = $group.find('.simpletest-image');
|
||||
$image.html(drupalSettings.simpleTest.images[0]).on('click', () => {
|
||||
const $tests = $group.nextUntil('.simpletest-group');
|
||||
const expand = !$group.hasClass('expanded');
|
||||
$group.toggleClass('expanded', expand);
|
||||
$tests.toggleClass('js-hide', !expand);
|
||||
$image.html(drupalSettings.simpleTest.images[+expand]);
|
||||
});
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* Toggles test checkboxes to match the group checkbox.
|
||||
*
|
||||
* @type {Drupal~behavior}
|
||||
*
|
||||
* @prop {Drupal~behaviorAttach} attach
|
||||
* Attaches behavior for selecting all tests in a group.
|
||||
*/
|
||||
Drupal.behaviors.simpleTestSelectAll = {
|
||||
attach(context) {
|
||||
$(context)
|
||||
.find('.simpletest-group')
|
||||
.once('simpletest-group-select-all')
|
||||
.each(function() {
|
||||
const $group = $(this);
|
||||
const $cell = $group.find('.simpletest-group-select-all');
|
||||
const $groupCheckbox = $(
|
||||
`<input type="checkbox" id="${$cell.attr(
|
||||
'id',
|
||||
)}-group-select-all" class="form-checkbox" />`,
|
||||
);
|
||||
const $testCheckboxes = $group
|
||||
.nextUntil('.simpletest-group')
|
||||
.find('input[type=checkbox]');
|
||||
$cell.append($groupCheckbox);
|
||||
|
||||
// Toggle the test checkboxes when the group checkbox is toggled.
|
||||
$groupCheckbox.on('change', function() {
|
||||
const checked = $(this).prop('checked');
|
||||
$testCheckboxes.prop('checked', checked);
|
||||
});
|
||||
|
||||
// Update the group checkbox when a test checkbox is toggled.
|
||||
function updateGroupCheckbox() {
|
||||
let allChecked = true;
|
||||
$testCheckboxes.each(function() {
|
||||
if (!$(this).prop('checked')) {
|
||||
allChecked = false;
|
||||
return false;
|
||||
}
|
||||
});
|
||||
$groupCheckbox.prop('checked', allChecked);
|
||||
}
|
||||
|
||||
$testCheckboxes.on('change', updateGroupCheckbox);
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* Filters the test list table by a text input search string.
|
||||
*
|
||||
* Text search input: input.table-filter-text
|
||||
* Target table: input.table-filter-text[data-table]
|
||||
* Source text: .table-filter-text-source
|
||||
*
|
||||
* @type {Drupal~behavior}
|
||||
*
|
||||
* @prop {Drupal~behaviorAttach} attach
|
||||
* Attaches the filter behavior to the text input element.
|
||||
*/
|
||||
Drupal.behaviors.simpletestTableFilterByText = {
|
||||
attach(context) {
|
||||
const $input = $('input.table-filter-text').once('table-filter-text');
|
||||
const $table = $($input.attr('data-table'));
|
||||
let $rows;
|
||||
let searched = false;
|
||||
|
||||
function filterTestList(e) {
|
||||
const query = $(e.target)
|
||||
.val()
|
||||
.toLowerCase();
|
||||
|
||||
function showTestRow(index, row) {
|
||||
const $row = $(row);
|
||||
const $sources = $row.find('.table-filter-text-source');
|
||||
const textMatch =
|
||||
$sources
|
||||
.text()
|
||||
.toLowerCase()
|
||||
.indexOf(query) !== -1;
|
||||
$row.closest('tr').toggle(textMatch);
|
||||
}
|
||||
|
||||
// Filter if the length of the query is at least 3 characters.
|
||||
if (query.length >= 3) {
|
||||
// Indicate that a search has been performed, and hide the
|
||||
// "select all" checkbox.
|
||||
searched = true;
|
||||
$('#simpletest-form-table thead th.select-all input').hide();
|
||||
|
||||
$rows.each(showTestRow);
|
||||
}
|
||||
// Restore to the original state if any searching has occurred.
|
||||
else if (searched) {
|
||||
searched = false;
|
||||
$('#simpletest-form-table thead th.select-all input').show();
|
||||
// Restore all rows to their original display state.
|
||||
$rows.css('display', '');
|
||||
}
|
||||
}
|
||||
|
||||
if ($table.length) {
|
||||
$rows = $table.find('tbody tr');
|
||||
$input
|
||||
.trigger('focus')
|
||||
.on('keyup', Drupal.debounce(filterTestList, 200));
|
||||
}
|
||||
},
|
||||
};
|
||||
})(jQuery, Drupal, drupalSettings);
|
|
@ -6,6 +6,7 @@
|
|||
*/
|
||||
|
||||
use Drupal\Component\Utility\Environment;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Minimum value of PHP memory_limit for SimpleTest.
|
||||
|
@ -18,7 +19,7 @@ const SIMPLETEST_MINIMUM_PHP_MEMORY_LIMIT = '128M';
|
|||
function simpletest_requirements($phase) {
|
||||
$requirements = [];
|
||||
|
||||
$has_phpunit = class_exists('\PHPUnit_Framework_TestCase');
|
||||
$has_phpunit = class_exists(TestCase::class);
|
||||
$has_curl = function_exists('curl_init');
|
||||
$open_basedir = ini_get('open_basedir');
|
||||
|
||||
|
@ -28,7 +29,7 @@ function simpletest_requirements($phase) {
|
|||
];
|
||||
if (!$has_phpunit) {
|
||||
$requirements['phpunit']['severity'] = REQUIREMENT_ERROR;
|
||||
$requirements['phpunit']['description'] = t("The testing framework requires the PHPUnit package. Please run 'composer install --dev' to ensure it is present.");
|
||||
$requirements['phpunit']['description'] = t("The testing framework requires the PHPUnit package. Please run 'composer install' to ensure it is present.");
|
||||
}
|
||||
|
||||
$requirements['curl'] = [
|
||||
|
|
|
@ -1,48 +1,29 @@
|
|||
/**
|
||||
* @file
|
||||
* Simpletest behaviors.
|
||||
*/
|
||||
* DO NOT EDIT THIS FILE.
|
||||
* See the following change record for more information,
|
||||
* https://www.drupal.org/node/2815083
|
||||
* @preserve
|
||||
**/
|
||||
|
||||
(function ($, Drupal, drupalSettings) {
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Collapses table rows followed by group rows on the test listing page.
|
||||
*
|
||||
* @type {Drupal~behavior}
|
||||
*
|
||||
* @prop {Drupal~behaviorAttach} attach
|
||||
* Attach collapse behavior on the test listing page.
|
||||
*/
|
||||
Drupal.behaviors.simpleTestGroupCollapse = {
|
||||
attach: function (context) {
|
||||
attach: function attach(context) {
|
||||
$(context).find('.simpletest-group').once('simpletest-group-collapse').each(function () {
|
||||
var $group = $(this);
|
||||
var $image = $group.find('.simpletest-image');
|
||||
$image
|
||||
.html(drupalSettings.simpleTest.images[0])
|
||||
.on('click', function () {
|
||||
var $tests = $group.nextUntil('.simpletest-group');
|
||||
var expand = !$group.hasClass('expanded');
|
||||
$group.toggleClass('expanded', expand);
|
||||
$tests.toggleClass('js-hide', !expand);
|
||||
$image.html(drupalSettings.simpleTest.images[+expand]);
|
||||
});
|
||||
$image.html(drupalSettings.simpleTest.images[0]).on('click', function () {
|
||||
var $tests = $group.nextUntil('.simpletest-group');
|
||||
var expand = !$group.hasClass('expanded');
|
||||
$group.toggleClass('expanded', expand);
|
||||
$tests.toggleClass('js-hide', !expand);
|
||||
$image.html(drupalSettings.simpleTest.images[+expand]);
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Toggles test checkboxes to match the group checkbox.
|
||||
*
|
||||
* @type {Drupal~behavior}
|
||||
*
|
||||
* @prop {Drupal~behaviorAttach} attach
|
||||
* Attaches behavior for selecting all tests in a group.
|
||||
*/
|
||||
Drupal.behaviors.simpleTestSelectAll = {
|
||||
attach: function (context) {
|
||||
attach: function attach(context) {
|
||||
$(context).find('.simpletest-group').once('simpletest-group-select-all').each(function () {
|
||||
var $group = $(this);
|
||||
var $cell = $group.find('.simpletest-group-select-all');
|
||||
|
@ -50,13 +31,11 @@
|
|||
var $testCheckboxes = $group.nextUntil('.simpletest-group').find('input[type=checkbox]');
|
||||
$cell.append($groupCheckbox);
|
||||
|
||||
// Toggle the test checkboxes when the group checkbox is toggled.
|
||||
$groupCheckbox.on('change', function () {
|
||||
var checked = $(this).prop('checked');
|
||||
$testCheckboxes.prop('checked', checked);
|
||||
});
|
||||
|
||||
// Update the group checkbox when a test checkbox is toggled.
|
||||
function updateGroupCheckbox() {
|
||||
var allChecked = true;
|
||||
$testCheckboxes.each(function () {
|
||||
|
@ -73,23 +52,11 @@
|
|||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Filters the test list table by a text input search string.
|
||||
*
|
||||
* Text search input: input.table-filter-text
|
||||
* Target table: input.table-filter-text[data-table]
|
||||
* Source text: .table-filter-text-source
|
||||
*
|
||||
* @type {Drupal~behavior}
|
||||
*
|
||||
* @prop {Drupal~behaviorAttach} attach
|
||||
* Attaches the filter behavior to the text input element.
|
||||
*/
|
||||
Drupal.behaviors.simpletestTableFilterByText = {
|
||||
attach: function (context) {
|
||||
attach: function attach(context) {
|
||||
var $input = $('input.table-filter-text').once('table-filter-text');
|
||||
var $table = $($input.attr('data-table'));
|
||||
var $rows;
|
||||
var $rows = void 0;
|
||||
var searched = false;
|
||||
|
||||
function filterTestList(e) {
|
||||
|
@ -102,22 +69,17 @@
|
|||
$row.closest('tr').toggle(textMatch);
|
||||
}
|
||||
|
||||
// Filter if the length of the query is at least 3 characters.
|
||||
if (query.length >= 3) {
|
||||
// Indicate that a search has been performed, and hide the
|
||||
// "select all" checkbox.
|
||||
searched = true;
|
||||
$('#simpletest-form-table thead th.select-all input').hide();
|
||||
|
||||
$rows.each(showTestRow);
|
||||
}
|
||||
// Restore to the original state if any searching has occurred.
|
||||
else if (searched) {
|
||||
searched = false;
|
||||
$('#simpletest-form-table thead th.select-all input').show();
|
||||
// Restore all rows to their original display state.
|
||||
$rows.css('display', '');
|
||||
}
|
||||
} else if (searched) {
|
||||
searched = false;
|
||||
$('#simpletest-form-table thead th.select-all input').show();
|
||||
|
||||
$rows.css('display', '');
|
||||
}
|
||||
}
|
||||
|
||||
if ($table.length) {
|
||||
|
@ -126,5 +88,4 @@
|
|||
}
|
||||
}
|
||||
};
|
||||
|
||||
})(jQuery, Drupal, drupalSettings);
|
||||
})(jQuery, Drupal, drupalSettings);
|
|
@ -13,6 +13,7 @@ use Drupal\simpletest\TestBase;
|
|||
use Drupal\Core\Test\TestDatabase;
|
||||
use Drupal\simpletest\TestDiscovery;
|
||||
use Drupal\Tests\Listeners\SimpletestUiPrinter;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Process\PhpExecutableFinder;
|
||||
use Drupal\Core\Test\TestStatus;
|
||||
|
||||
|
@ -284,8 +285,15 @@ function simpletest_phpunit_xml_filepath($test_id) {
|
|||
*
|
||||
* @return string
|
||||
* The path to core's phpunit.xml.dist configuration file.
|
||||
*
|
||||
* @deprecated in Drupal 8.4.x for removal before Drupal 9.0.0. PHPUnit test
|
||||
* runners should change directory into core/ and then run the phpunit tool.
|
||||
* See simpletest_phpunit_run_command() for an example.
|
||||
*
|
||||
* @see simpletest_phpunit_run_command()
|
||||
*/
|
||||
function simpletest_phpunit_configuration_filepath() {
|
||||
@trigger_error('The ' . __FUNCTION__ . ' function is deprecated since version 8.4.x and will be removed in 9.0.0.', E_USER_DEPRECATED);
|
||||
return \Drupal::root() . '/core/phpunit.xml.dist';
|
||||
}
|
||||
|
||||
|
@ -337,7 +345,7 @@ function simpletest_phpunit_run_command(array $unescaped_test_classnames, $phpun
|
|||
}
|
||||
else {
|
||||
// Double escape namespaces so they'll work in a regexp.
|
||||
$escaped_test_classnames = array_map(function($class) {
|
||||
$escaped_test_classnames = array_map(function ($class) {
|
||||
return addslashes($class);
|
||||
}, $unescaped_test_classnames);
|
||||
|
||||
|
@ -355,7 +363,7 @@ function simpletest_phpunit_run_command(array $unescaped_test_classnames, $phpun
|
|||
|
||||
// exec in a subshell so that the environment is isolated when running tests
|
||||
// via the simpletest UI.
|
||||
$ret = exec(join($command, " "), $output, $status);
|
||||
$ret = exec(implode(" ", $command), $output, $status);
|
||||
|
||||
chdir($old_cwd);
|
||||
putenv('SIMPLETEST_DB=');
|
||||
|
@ -381,12 +389,12 @@ function simpletest_phpunit_command() {
|
|||
|
||||
// The file in Composer's bin dir is a *nix link, which does not work when
|
||||
// extracted from a tarball and generally not on Windows.
|
||||
$command = $vendor_dir . '/phpunit/phpunit/phpunit';
|
||||
$command = escapeshellarg($vendor_dir . '/phpunit/phpunit/phpunit');
|
||||
if (substr(PHP_OS, 0, 3) == 'WIN') {
|
||||
// On Windows it is necessary to run the script using the PHP executable.
|
||||
$php_executable_finder = new PhpExecutableFinder();
|
||||
$php = $php_executable_finder->find();
|
||||
$command = $php . ' -f ' . escapeshellarg($command) . ' --';
|
||||
$command = $php . ' -f ' . $command . ' --';
|
||||
}
|
||||
return $command;
|
||||
}
|
||||
|
@ -395,7 +403,7 @@ function simpletest_phpunit_command() {
|
|||
* Implements callback_batch_operation().
|
||||
*/
|
||||
function _simpletest_batch_operation($test_list_init, $test_id, &$context) {
|
||||
simpletest_classloader_register();
|
||||
\Drupal::service('test_discovery')->registerTestNamespaces();
|
||||
// Get working values.
|
||||
if (!isset($context['sandbox']['max'])) {
|
||||
// First iteration: initialize working values.
|
||||
|
@ -412,7 +420,7 @@ function _simpletest_batch_operation($test_list_init, $test_id, &$context) {
|
|||
|
||||
// Perform the next test.
|
||||
$test_class = array_shift($test_list);
|
||||
if (is_subclass_of($test_class, \PHPUnit_Framework_TestCase::class)) {
|
||||
if (is_subclass_of($test_class, TestCase::class)) {
|
||||
$phpunit_results = simpletest_run_phpunit_tests($test_id, [$test_class]);
|
||||
simpletest_process_phpunit_results($phpunit_results);
|
||||
$test_results[$test_class] = simpletest_summarize_phpunit_result($phpunit_results)[$test_class];
|
||||
|
@ -437,20 +445,20 @@ function _simpletest_batch_operation($test_list_init, $test_id, &$context) {
|
|||
'#theme' => 'simpletest_result_summary',
|
||||
'#label' => t($test_results[$class]['#name'] . ':'),
|
||||
];
|
||||
array_unshift($items, drupal_render($class_test_result));
|
||||
array_unshift($items, \Drupal::service('renderer')->render($class_test_result));
|
||||
}
|
||||
$context['message'] = t('Processed test @num of @max - %test.', ['%test' => $info['name'], '@num' => $max - $size, '@max' => $max]);
|
||||
$overall_results = $test_results + [
|
||||
'#theme' => 'simpletest_result_summary',
|
||||
'#label' => t('Overall results:'),
|
||||
];
|
||||
$context['message'] .= drupal_render($overall_results);
|
||||
$context['message'] .= \Drupal::service('renderer')->render($overall_results);
|
||||
|
||||
$item_list = [
|
||||
'#theme' => 'item_list',
|
||||
'#items' => $items,
|
||||
];
|
||||
$context['message'] .= drupal_render($item_list);
|
||||
$context['message'] .= \Drupal::service('renderer')->render($item_list);
|
||||
|
||||
// Save working values for the next iteration.
|
||||
$context['sandbox']['tests'] = $test_list;
|
||||
|
@ -467,7 +475,7 @@ function _simpletest_batch_operation($test_list_init, $test_id, &$context) {
|
|||
*/
|
||||
function _simpletest_batch_finished($success, $results, $operations, $elapsed) {
|
||||
if ($success) {
|
||||
drupal_set_message(t('The test run finished in @elapsed.', ['@elapsed' => $elapsed]));
|
||||
\Drupal::messenger()->addStatus(t('The test run finished in @elapsed.', ['@elapsed' => $elapsed]));
|
||||
}
|
||||
else {
|
||||
// Use the test_id passed as a parameter to _simpletest_batch_operation().
|
||||
|
@ -479,8 +487,8 @@ function _simpletest_batch_finished($success, $results, $operations, $elapsed) {
|
|||
list($last_prefix, $last_test_class) = simpletest_last_test_get($test_id);
|
||||
simpletest_log_read($test_id, $last_prefix, $last_test_class);
|
||||
|
||||
drupal_set_message(t('The test run did not successfully finish.'), 'error');
|
||||
drupal_set_message(t('Use the <em>Clean environment</em> button to clean-up temporary files and tables.'), 'warning');
|
||||
\Drupal::messenger()->addError(t('The test run did not successfully finish.'));
|
||||
\Drupal::messenger()->addWarning(t('Use the <em>Clean environment</em> button to clean-up temporary files and tables.'));
|
||||
}
|
||||
\Drupal::moduleHandler()->invokeAll('test_group_finished');
|
||||
}
|
||||
|
@ -579,6 +587,7 @@ function simpletest_log_read($test_id, $database_prefix, $test_class) {
|
|||
* instead.
|
||||
*/
|
||||
function simpletest_test_get_all($extension = NULL, array $types = []) {
|
||||
@trigger_error('The ' . __FUNCTION__ . ' function is deprecated in version 8.3.x and will be removed in 9.0.0. Use \Drupal::service(\'test_discovery\')->getTestClasses($extension, $types) instead.', E_USER_DEPRECATED);
|
||||
return \Drupal::service('test_discovery')->getTestClasses($extension, $types);
|
||||
}
|
||||
|
||||
|
@ -589,6 +598,7 @@ function simpletest_test_get_all($extension = NULL, array $types = []) {
|
|||
* \Drupal::service('test_discovery')->registerTestNamespaces() instead.
|
||||
*/
|
||||
function simpletest_classloader_register() {
|
||||
@trigger_error('The ' . __FUNCTION__ . ' function is deprecated in version 8.3.x and will be removed in 9.0.0. Use \Drupal::service(\'test_discovery\')->registerTestNamespaces() instead.', E_USER_DEPRECATED);
|
||||
\Drupal::service('test_discovery')->registerTestNamespaces();
|
||||
}
|
||||
|
||||
|
@ -648,37 +658,34 @@ function simpletest_clean_environment() {
|
|||
simpletest_clean_temporary_directories();
|
||||
if (\Drupal::config('simpletest.settings')->get('clear_results')) {
|
||||
$count = simpletest_clean_results_table();
|
||||
drupal_set_message(\Drupal::translation()->formatPlural($count, 'Removed 1 test result.', 'Removed @count test results.'));
|
||||
\Drupal::messenger()->addStatus(\Drupal::translation()->formatPlural($count, 'Removed 1 test result.', 'Removed @count test results.'));
|
||||
}
|
||||
else {
|
||||
drupal_set_message(t('Clear results is disabled and the test results table will not be cleared.'), 'warning');
|
||||
\Drupal::messenger()->addWarning(t('Clear results is disabled and the test results table will not be cleared.'), 'warning');
|
||||
}
|
||||
|
||||
// Detect test classes that have been added, renamed or deleted.
|
||||
\Drupal::cache()->delete('simpletest');
|
||||
\Drupal::cache()->delete('simpletest_phpunit');
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes prefixed tables from the database from crashed tests.
|
||||
*/
|
||||
function simpletest_clean_database() {
|
||||
$schema = Database::getConnection()->schema();
|
||||
$tables = db_find_tables('test%');
|
||||
$count = 0;
|
||||
foreach ($tables as $table) {
|
||||
// Only drop tables which begin wih 'test' followed by digits, for example,
|
||||
// {test12345678node__body}.
|
||||
if (preg_match('/^test\d+.*/', $table, $matches)) {
|
||||
db_drop_table($matches[0]);
|
||||
$schema->dropTable($matches[0]);
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
|
||||
if ($count > 0) {
|
||||
drupal_set_message(\Drupal::translation()->formatPlural($count, 'Removed 1 leftover table.', 'Removed @count leftover tables.'));
|
||||
\Drupal::messenger()->addStatus(\Drupal::translation()->formatPlural($count, 'Removed 1 leftover table.', 'Removed @count leftover tables.'));
|
||||
}
|
||||
else {
|
||||
drupal_set_message(t('No leftover tables to remove.'));
|
||||
\Drupal::messenger()->addStatus(t('No leftover tables to remove.'));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -701,10 +708,10 @@ function simpletest_clean_temporary_directories() {
|
|||
}
|
||||
|
||||
if ($count > 0) {
|
||||
drupal_set_message(\Drupal::translation()->formatPlural($count, 'Removed 1 temporary directory.', 'Removed @count temporary directories.'));
|
||||
\Drupal::messenger()->addStatus(\Drupal::translation()->formatPlural($count, 'Removed 1 temporary directory.', 'Removed @count temporary directories.'));
|
||||
}
|
||||
else {
|
||||
drupal_set_message(t('No temporary directories to remove.'));
|
||||
\Drupal::messenger()->addStatus(t('No temporary directories to remove.'));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -764,9 +771,10 @@ function simpletest_mail_alter(&$message) {
|
|||
* @param $phpunit_xml_file
|
||||
* Path to the PHPUnit XML file.
|
||||
*
|
||||
* @return array[]
|
||||
* @return array[]|null
|
||||
* The results as array of rows in a format that can be inserted into
|
||||
* {simpletest}.
|
||||
* {simpletest}. If the phpunit_xml_file does not have any contents then the
|
||||
* function will return NULL.
|
||||
*/
|
||||
function simpletest_phpunit_xml_to_rows($test_id, $phpunit_xml_file) {
|
||||
$contents = @file_get_contents($phpunit_xml_file);
|
||||
|
@ -786,7 +794,7 @@ function simpletest_phpunit_xml_to_rows($test_id, $phpunit_xml_file) {
|
|||
*
|
||||
* @param \SimpleXMLElement $element
|
||||
* The PHPUnit xml to search for test cases.
|
||||
* @param \SimpleXMLElement $suite
|
||||
* @param \SimpleXMLElement $parent
|
||||
* (Optional) The parent of the current element. Defaults to NULL.
|
||||
*
|
||||
* @return array
|
||||
|
|
|
@ -1,4 +1,9 @@
|
|||
services:
|
||||
test_discovery:
|
||||
class: Drupal\simpletest\TestDiscovery
|
||||
arguments: ['@app.root', '@class_loader', '@module_handler', '@?cache.discovery']
|
||||
arguments: ['@app.root', '@class_loader', '@module_handler']
|
||||
cache_context.test_discovery:
|
||||
class: Drupal\simpletest\Cache\Context\TestDiscoveryCacheContext
|
||||
arguments: ['@test_discovery', '@private_key']
|
||||
tags:
|
||||
- { name: cache.context}
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -2,34 +2,18 @@
|
|||
|
||||
namespace Drupal\simpletest;
|
||||
|
||||
use Drupal\Component\Render\MarkupInterface;
|
||||
use Drupal\Tests\AssertHelperTrait as BaseAssertHelperTrait;
|
||||
|
||||
/**
|
||||
* Provides helper methods for assertions.
|
||||
*
|
||||
* @deprecated in Drupal 8.4.x. Will be removed before Drupal 9.0.0. Use
|
||||
* Drupal\Tests\AssertHelperTrait instead.
|
||||
*
|
||||
* @see https://www.drupal.org/node/2884454
|
||||
*/
|
||||
trait AssertHelperTrait {
|
||||
|
||||
/**
|
||||
* Casts MarkupInterface objects into strings.
|
||||
*
|
||||
* @param string|array $value
|
||||
* The value to act on.
|
||||
*
|
||||
* @return mixed
|
||||
* The input value, with MarkupInterface objects casted to string.
|
||||
*/
|
||||
protected static function castSafeStrings($value) {
|
||||
if ($value instanceof MarkupInterface) {
|
||||
$value = (string) $value;
|
||||
}
|
||||
if (is_array($value)) {
|
||||
array_walk_recursive($value, function (&$item) {
|
||||
if ($item instanceof MarkupInterface) {
|
||||
$item = (string) $item;
|
||||
}
|
||||
});
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
use BaseAssertHelperTrait;
|
||||
|
||||
}
|
||||
|
|
|
@ -2,66 +2,20 @@
|
|||
|
||||
namespace Drupal\simpletest;
|
||||
|
||||
use Drupal\block\Entity\Block;
|
||||
use Drupal\Tests\block\Traits\BlockCreationTrait as BaseBlockCreationTrait;
|
||||
|
||||
/**
|
||||
* Provides methods to create and place block with default settings.
|
||||
*
|
||||
* This trait is meant to be used only by test classes.
|
||||
*
|
||||
* @deprecated in Drupal 8.4.x. Will be removed before Drupal 9.0.0. Use
|
||||
* \Drupal\Tests\block\Traits\BlockCreationTrait instead.
|
||||
*
|
||||
* @see https://www.drupal.org/node/2884454
|
||||
*/
|
||||
trait BlockCreationTrait {
|
||||
|
||||
/**
|
||||
* Creates a block instance based on default settings.
|
||||
*
|
||||
* @param string $plugin_id
|
||||
* The plugin ID of the block type for this block instance.
|
||||
* @param array $settings
|
||||
* (optional) An associative array of settings for the block entity.
|
||||
* Override the defaults by specifying the key and value in the array, for
|
||||
* example:
|
||||
* @code
|
||||
* $this->drupalPlaceBlock('system_powered_by_block', array(
|
||||
* 'label' => t('Hello, world!'),
|
||||
* ));
|
||||
* @endcode
|
||||
* The following defaults are provided:
|
||||
* - label: Random string.
|
||||
* - ID: Random string.
|
||||
* - region: 'sidebar_first'.
|
||||
* - theme: The default theme.
|
||||
* - visibility: Empty array.
|
||||
*
|
||||
* @return \Drupal\block\Entity\Block
|
||||
* The block entity.
|
||||
*
|
||||
* @todo
|
||||
* Add support for creating custom block instances.
|
||||
*/
|
||||
protected function placeBlock($plugin_id, array $settings = []) {
|
||||
$config = \Drupal::configFactory();
|
||||
$settings += [
|
||||
'plugin' => $plugin_id,
|
||||
'region' => 'sidebar_first',
|
||||
'id' => strtolower($this->randomMachineName(8)),
|
||||
'theme' => $config->get('system.theme')->get('default'),
|
||||
'label' => $this->randomMachineName(8),
|
||||
'visibility' => [],
|
||||
'weight' => 0,
|
||||
];
|
||||
$values = [];
|
||||
foreach (['region', 'id', 'theme', 'plugin', 'weight', 'visibility'] as $key) {
|
||||
$values[$key] = $settings[$key];
|
||||
// Remove extra values that do not belong in the settings array.
|
||||
unset($settings[$key]);
|
||||
}
|
||||
foreach ($values['visibility'] as $id => $visibility) {
|
||||
$values['visibility'][$id]['id'] = $id;
|
||||
}
|
||||
$values['settings'] = $settings;
|
||||
$block = Block::create($values);
|
||||
$block->save();
|
||||
return $block;
|
||||
}
|
||||
use BaseBlockCreationTrait;
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,94 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\simpletest\Cache\Context;
|
||||
|
||||
use Drupal\Core\Cache\CacheableMetadata;
|
||||
use Drupal\Core\Cache\Context\CacheContextInterface;
|
||||
use Drupal\Core\PrivateKey;
|
||||
use Drupal\Core\Site\Settings;
|
||||
use Drupal\simpletest\TestDiscovery;
|
||||
|
||||
/**
|
||||
* Defines the TestDiscoveryCacheContext service.
|
||||
*
|
||||
* Cache context ID: 'test_discovery'.
|
||||
*/
|
||||
class TestDiscoveryCacheContext implements CacheContextInterface {
|
||||
|
||||
/**
|
||||
* The test discovery service.
|
||||
*
|
||||
* @var \Drupal\simpletest\TestDiscovery
|
||||
*/
|
||||
protected $testDiscovery;
|
||||
|
||||
/**
|
||||
* The private key service.
|
||||
*
|
||||
* @var \Drupal\Core\PrivateKey
|
||||
*/
|
||||
protected $privateKey;
|
||||
|
||||
/**
|
||||
* The hash of discovered test information.
|
||||
*
|
||||
* Services should not be stateful, but we only keep this information per
|
||||
* request. That way we don't perform a file scan every time we need this
|
||||
* hash. The test scan results are unlikely to change during the request.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $hash;
|
||||
|
||||
/**
|
||||
* Construct a test discovery cache context.
|
||||
*
|
||||
* @param \Drupal\simpletest\TestDiscovery $test_discovery
|
||||
* The test discovery service.
|
||||
* @param \Drupal\Core\PrivateKey $private_key
|
||||
* The private key service.
|
||||
*/
|
||||
public function __construct(TestDiscovery $test_discovery, PrivateKey $private_key) {
|
||||
$this->testDiscovery = $test_discovery;
|
||||
$this->privateKey = $private_key;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function getLabel() {
|
||||
return t('Test discovery');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getContext() {
|
||||
if (empty($this->hash)) {
|
||||
$tests = $this->testDiscovery->getTestClasses();
|
||||
$this->hash = $this->hash(serialize($tests));
|
||||
}
|
||||
return $this->hash;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCacheableMetadata() {
|
||||
return new CacheableMetadata();
|
||||
}
|
||||
|
||||
/**
|
||||
* Hashes the given string.
|
||||
*
|
||||
* @param string $identifier
|
||||
* The string to be hashed.
|
||||
*
|
||||
* @return string
|
||||
* The hash.
|
||||
*/
|
||||
protected function hash($identifier) {
|
||||
return hash('sha256', $this->privateKey->get() . Settings::getHashSalt() . $identifier);
|
||||
}
|
||||
|
||||
}
|
|
@ -2,52 +2,20 @@
|
|||
|
||||
namespace Drupal\simpletest;
|
||||
|
||||
use Drupal\Component\Render\FormattableMarkup;
|
||||
use Drupal\node\Entity\NodeType;
|
||||
use Drupal\Tests\node\Traits\ContentTypeCreationTrait as BaseContentTypeCreationTrait;
|
||||
|
||||
/**
|
||||
* Provides methods to create content type from given values.
|
||||
*
|
||||
* This trait is meant to be used only by test classes.
|
||||
*
|
||||
* @deprecated in Drupal 8.4.x. Will be removed before Drupal 9.0.0. Use
|
||||
* \Drupal\Tests\node\Traits\ContentTypeCreationTrait instead.
|
||||
*
|
||||
* @see https://www.drupal.org/node/2884454
|
||||
*/
|
||||
trait ContentTypeCreationTrait {
|
||||
|
||||
/**
|
||||
* Creates a custom content type based on default settings.
|
||||
*
|
||||
* @param array $values
|
||||
* An array of settings to change from the defaults.
|
||||
* Example: 'type' => 'foo'.
|
||||
*
|
||||
* @return \Drupal\node\Entity\NodeType
|
||||
* Created content type.
|
||||
*/
|
||||
protected function createContentType(array $values = []) {
|
||||
// Find a non-existent random type name.
|
||||
if (!isset($values['type'])) {
|
||||
do {
|
||||
$id = strtolower($this->randomMachineName(8));
|
||||
} while (NodeType::load($id));
|
||||
}
|
||||
else {
|
||||
$id = $values['type'];
|
||||
}
|
||||
$values += [
|
||||
'type' => $id,
|
||||
'name' => $id,
|
||||
];
|
||||
$type = NodeType::create($values);
|
||||
$status = $type->save();
|
||||
node_add_body_field($type);
|
||||
|
||||
if ($this instanceof \PHPUnit_Framework_TestCase) {
|
||||
$this->assertSame($status, SAVED_NEW, (new FormattableMarkup('Created content type %type.', ['%type' => $type->id()]))->__toString());
|
||||
}
|
||||
else {
|
||||
$this->assertEqual($status, SAVED_NEW, (new FormattableMarkup('Created content type %type.', ['%type' => $type->id()]))->__toString());
|
||||
}
|
||||
|
||||
return $type;
|
||||
}
|
||||
use BaseContentTypeCreationTrait;
|
||||
|
||||
}
|
||||
|
|
|
@ -17,6 +17,8 @@ use Symfony\Component\HttpFoundation\RedirectResponse;
|
|||
* Note that the UI strings are not translated because this form is also used
|
||||
* from run-tests.sh.
|
||||
*
|
||||
* @internal
|
||||
*
|
||||
* @see simpletest_script_open_browser()
|
||||
* @see run-tests.sh
|
||||
*/
|
||||
|
@ -110,7 +112,7 @@ class SimpletestResultsForm extends FormBase {
|
|||
// performed.
|
||||
$results = [];
|
||||
if (is_numeric($test_id) && !$results = $this->getResults($test_id)) {
|
||||
drupal_set_message($this->t('No test results to display.'), 'error');
|
||||
$this->messenger()->addError($this->t('No test results to display.'));
|
||||
return new RedirectResponse($this->url('simpletest.test_form', [], ['absolute' => TRUE]));
|
||||
}
|
||||
|
||||
|
@ -235,7 +237,7 @@ class SimpletestResultsForm extends FormBase {
|
|||
*
|
||||
* @param array $form
|
||||
* The form to attach the results to.
|
||||
* @param array $test_results
|
||||
* @param array $results
|
||||
* The simpletest results.
|
||||
*
|
||||
* @return array
|
||||
|
@ -288,7 +290,7 @@ class SimpletestResultsForm extends FormBase {
|
|||
'Filename',
|
||||
'Line',
|
||||
'Function',
|
||||
['colspan' => 2, 'data' => 'Status']
|
||||
['colspan' => 2, 'data' => 'Status'],
|
||||
];
|
||||
$form['result']['results'] = [];
|
||||
foreach ($test_results as $group => $assertions) {
|
||||
|
|
|
@ -7,6 +7,8 @@ use Drupal\Core\Form\FormStateInterface;
|
|||
|
||||
/**
|
||||
* Configure simpletest settings for this site.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class SimpletestSettingsForm extends ConfigFormBase {
|
||||
|
||||
|
|
|
@ -10,6 +10,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
|
|||
|
||||
/**
|
||||
* List tests arranged in groups that can be selected and run.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class SimpletestTestForm extends FormBase {
|
||||
|
||||
|
@ -71,7 +73,7 @@ class SimpletestTestForm extends FormBase {
|
|||
$form['clean'] = [
|
||||
'#type' => 'fieldset',
|
||||
'#title' => $this->t('Clean test environment'),
|
||||
'#description' => $this->t('Remove tables with the prefix "simpletest" and temporary directories that are left over from tests that crashed. This is intended for developers when creating tests.'),
|
||||
'#description' => $this->t('Remove tables with the prefix "test" followed by digits and temporary directories that are left over from tests that crashed. This is intended for developers when creating tests.'),
|
||||
'#weight' => 200,
|
||||
];
|
||||
$form['clean']['op'] = [
|
||||
|
@ -108,6 +110,10 @@ class SimpletestTestForm extends FormBase {
|
|||
];
|
||||
|
||||
$form['tests'] = [
|
||||
'#cache' => [
|
||||
'keys' => ['simpletest_ui_table'],
|
||||
'contexts' => ['test_discovery'],
|
||||
],
|
||||
'#type' => 'table',
|
||||
'#id' => 'simpletest-form-table',
|
||||
'#tableselect' => TRUE,
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
namespace Drupal\simpletest;
|
||||
|
||||
@trigger_error(__NAMESPACE__ . '\InstallerTestBase is deprecated in Drupal 8.6.0 and will be removed before Drupal 9.0.0. Instead, use \Drupal\FunctionalTests\Installer\InstallerTestBase, see https://www.drupal.org/node/2988752.', E_USER_DEPRECATED);
|
||||
|
||||
use Drupal\Core\DrupalKernel;
|
||||
use Drupal\Core\Language\Language;
|
||||
use Drupal\Core\Session\UserSession;
|
||||
|
@ -13,6 +15,10 @@ use Symfony\Component\HttpFoundation\RequestStack;
|
|||
|
||||
/**
|
||||
* Base class for testing the interactive installer.
|
||||
*
|
||||
* @deprecated in Drupal 8.6.0 and will be removed before Drupal 9.0.0.
|
||||
* Use \Drupal\FunctionalTests\Installer\InstallerTestBase. See
|
||||
* https://www.drupal.org/node/2988752
|
||||
*/
|
||||
abstract class InstallerTestBase extends WebTestBase {
|
||||
|
||||
|
@ -122,6 +128,9 @@ abstract class InstallerTestBase extends WebTestBase {
|
|||
// Select profile.
|
||||
$this->setUpProfile();
|
||||
|
||||
// Address the requirements problem screen, if any.
|
||||
$this->setUpRequirementsProblem();
|
||||
|
||||
// Configure settings.
|
||||
$this->setUpSettings();
|
||||
|
||||
|
@ -195,6 +204,23 @@ abstract class InstallerTestBase extends WebTestBase {
|
|||
$this->drupalPostForm(NULL, $edit, $this->translations['Save and continue']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Installer step: Requirements problem.
|
||||
*
|
||||
* Override this method to test specific requirements warnings or errors
|
||||
* during the installer.
|
||||
*
|
||||
* @see system_requirements()
|
||||
*/
|
||||
protected function setUpRequirementsProblem() {
|
||||
// By default, skip the "recommended PHP version" warning on older test
|
||||
// environments. This allows the installer to be tested consistently on
|
||||
// both recommended PHP versions and older (but still supported) versions.
|
||||
if (version_compare(phpversion(), '7.0') < 0) {
|
||||
$this->continueOnExpectedWarnings(['PHP']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Final installer step: Configure site.
|
||||
*/
|
||||
|
@ -218,4 +244,44 @@ abstract class InstallerTestBase extends WebTestBase {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Continues installation when an expected warning is found.
|
||||
*
|
||||
* @param string[] $expected_warnings
|
||||
* A list of warning summaries to expect on the requirements screen (e.g.
|
||||
* 'PHP', 'PHP OPcode caching', etc.). If only the expected warnings
|
||||
* are found, the test will click the "continue anyway" link to go to the
|
||||
* next screen of the installer. If an expected warning is not found, or if
|
||||
* a warning not in the list is present, a fail is raised.
|
||||
*/
|
||||
protected function continueOnExpectedWarnings($expected_warnings = []) {
|
||||
// Don't try to continue if there are errors.
|
||||
if (strpos($this->getTextContent(), 'Errors found') !== FALSE) {
|
||||
return;
|
||||
}
|
||||
// Allow only details elements that are directly after the warning header
|
||||
// or each other. There is no guaranteed wrapper we can rely on across
|
||||
// distributions. When there are multiple warnings, the selectors will be:
|
||||
// - h3#warning+details summary
|
||||
// - h3#warning+details+details summary
|
||||
// - etc.
|
||||
// We add one more selector than expected warnings to confirm that there
|
||||
// isn't any other warning before clicking the link.
|
||||
// @todo Make this more reliable in
|
||||
// https://www.drupal.org/project/drupal/issues/2927345.
|
||||
$selectors = [];
|
||||
for ($i = 0; $i <= count($expected_warnings); $i++) {
|
||||
$selectors[] = 'h3#warning' . implode('', array_fill(0, $i + 1, '+details')) . ' summary';
|
||||
}
|
||||
$warning_elements = $this->cssSelect(implode(', ', $selectors));
|
||||
|
||||
// Confirm that there are only the expected warnings.
|
||||
$warnings = [];
|
||||
foreach ($warning_elements as $warning) {
|
||||
$warnings[] = trim((string) $warning);
|
||||
}
|
||||
$this->assertEqual($expected_warnings, $warnings);
|
||||
$this->clickLink('continue anyway');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
namespace Drupal\simpletest;
|
||||
|
||||
use Drupal\Component\Utility\Html;
|
||||
use Drupal\Component\Utility\SafeMarkup;
|
||||
use Drupal\Component\Render\FormattableMarkup;
|
||||
use Drupal\Component\Utility\Variable;
|
||||
use Drupal\Core\Config\Development\ConfigSchemaChecker;
|
||||
use Drupal\Core\Database\Database;
|
||||
|
@ -14,28 +14,54 @@ use Drupal\Core\Extension\ExtensionDiscovery;
|
|||
use Drupal\Core\KeyValueStore\KeyValueMemoryFactory;
|
||||
use Drupal\Core\Language\Language;
|
||||
use Drupal\Core\Site\Settings;
|
||||
use Drupal\KernelTests\TestServiceProvider;
|
||||
use Symfony\Component\DependencyInjection\Parameter;
|
||||
use Drupal\Core\StreamWrapper\StreamWrapperInterface;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
/**
|
||||
* Base class for integration tests.
|
||||
* Base class for functional integration tests.
|
||||
*
|
||||
* Tests extending this base class can access files and the database, but the
|
||||
* entire environment is initially empty. Drupal runs in a minimal mocked
|
||||
* environment, comparable to the one in the early installer.
|
||||
* This base class should be useful for testing some types of integrations which
|
||||
* don't require the overhead of a fully-installed Drupal instance, but which
|
||||
* have many dependencies on parts of Drupal which can't or shouldn't be mocked.
|
||||
*
|
||||
* The module/hook system is functional and operates on a fixed module list.
|
||||
* Additional modules needed in a test may be loaded and added to the fixed
|
||||
* module list.
|
||||
* This base class partially boots a fixture Drupal. The state of the fixture
|
||||
* Drupal is comparable to the state of a system during the early part of the
|
||||
* installation process.
|
||||
*
|
||||
* Tests extending this base class can access services and the database, but the
|
||||
* system is initially empty. This Drupal runs in a minimal mocked filesystem
|
||||
* which operates within vfsStream.
|
||||
*
|
||||
* Modules specified in the $modules property are added to the service container
|
||||
* for each test. The module/hook system is functional. Additional modules
|
||||
* needed in a test should override $modules. Modules specified in this way will
|
||||
* be added to those specified in superclasses.
|
||||
*
|
||||
* Unlike \Drupal\Tests\BrowserTestBase, the modules are not installed. They are
|
||||
* loaded such that their services and hooks are available, but the install
|
||||
* process has not been performed.
|
||||
*
|
||||
* Other modules can be made available in this way using
|
||||
* KernelTestBase::enableModules().
|
||||
*
|
||||
* Some modules can be brought into a fully-installed state using
|
||||
* KernelTestBase::installConfig(), KernelTestBase::installSchema(), and
|
||||
* KernelTestBase::installEntitySchema(). Alternately, tests which need modules
|
||||
* to be fully installed could inherit from \Drupal\Tests\BrowserTestBase.
|
||||
*
|
||||
* @see \Drupal\Tests\KernelTestBase::$modules
|
||||
* @see \Drupal\Tests\KernelTestBase::enableModules()
|
||||
* @see \Drupal\Tests\KernelTestBase::installConfig()
|
||||
* @see \Drupal\Tests\KernelTestBase::installEntitySchema()
|
||||
* @see \Drupal\Tests\KernelTestBase::installSchema()
|
||||
* @see \Drupal\Tests\BrowserTestBase
|
||||
*
|
||||
* @deprecated in Drupal 8.0.x, will be removed before Drupal 9.0.0. Use
|
||||
* \Drupal\KernelTests\KernelTestBase instead.
|
||||
*
|
||||
* @see \Drupal\simpletest\KernelTestBase::$modules
|
||||
* @see \Drupal\simpletest\KernelTestBase::enableModules()
|
||||
*
|
||||
* @ingroup testing
|
||||
*/
|
||||
abstract class KernelTestBase extends TestBase {
|
||||
|
@ -76,7 +102,7 @@ abstract class KernelTestBase extends TestBase {
|
|||
/**
|
||||
* A KeyValueMemoryFactory instance to use when building the container.
|
||||
*
|
||||
* @var \Drupal\Core\KeyValueStore\KeyValueMemoryFactory.
|
||||
* @var \Drupal\Core\KeyValueStore\KeyValueMemoryFactory
|
||||
*/
|
||||
protected $keyValueFactory;
|
||||
|
||||
|
@ -121,7 +147,7 @@ abstract class KernelTestBase extends TestBase {
|
|||
$path = $this->siteDirectory . '/config_' . CONFIG_SYNC_DIRECTORY;
|
||||
$GLOBALS['config_directories'][CONFIG_SYNC_DIRECTORY] = $path;
|
||||
// Ensure the directory can be created and is writeable.
|
||||
if (!install_ensure_config_directory(CONFIG_SYNC_DIRECTORY)) {
|
||||
if (!file_prepare_directory($path, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS)) {
|
||||
throw new \RuntimeException("Failed to create '" . CONFIG_SYNC_DIRECTORY . "' config directory $path");
|
||||
}
|
||||
// Provide the already resolved path for tests.
|
||||
|
@ -173,7 +199,7 @@ EOD;
|
|||
|
||||
// Add this test class as a service provider.
|
||||
// @todo Remove the indirection; implement ServiceProviderInterface instead.
|
||||
$GLOBALS['conf']['container_service_providers']['TestServiceProvider'] = 'Drupal\simpletest\TestServiceProvider';
|
||||
$GLOBALS['conf']['container_service_providers']['TestServiceProvider'] = TestServiceProvider::class;
|
||||
|
||||
// Bootstrap a new kernel.
|
||||
$class_loader = require DRUPAL_ROOT . '/autoload.php';
|
||||
|
@ -201,7 +227,6 @@ EOD;
|
|||
$this->kernel->shutdown();
|
||||
$this->kernel->boot();
|
||||
|
||||
|
||||
// Save the original site directory path, so that extensions in the
|
||||
// site-specific directory can still be discovered in the test site
|
||||
// environment.
|
||||
|
@ -453,8 +478,6 @@ EOD;
|
|||
]));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Installs the storage schema for a specific entity type.
|
||||
*
|
||||
|
@ -476,7 +499,7 @@ EOD;
|
|||
$all_tables_exist = TRUE;
|
||||
foreach ($tables as $table) {
|
||||
if (!$db_schema->tableExists($table)) {
|
||||
$this->fail(SafeMarkup::format('Installed entity type table for the %entity_type entity type: %table', [
|
||||
$this->fail(new FormattableMarkup('Installed entity type table for the %entity_type entity type: %table', [
|
||||
'%entity_type' => $entity_type_id,
|
||||
'%table' => $table,
|
||||
]));
|
||||
|
@ -484,7 +507,7 @@ EOD;
|
|||
}
|
||||
}
|
||||
if ($all_tables_exist) {
|
||||
$this->pass(SafeMarkup::format('Installed entity type tables for the %entity_type entity type: %tables', [
|
||||
$this->pass(new FormattableMarkup('Installed entity type tables for the %entity_type entity type: %tables', [
|
||||
'%entity_type' => $entity_type_id,
|
||||
'%tables' => '{' . implode('}, {', $tables) . '}',
|
||||
]));
|
||||
|
|
|
@ -2,83 +2,20 @@
|
|||
|
||||
namespace Drupal\simpletest;
|
||||
|
||||
use Drupal\node\Entity\Node;
|
||||
use Drupal\Tests\node\Traits\NodeCreationTrait as BaseNodeCreationTrait;
|
||||
|
||||
/**
|
||||
* Provides methods to create node based on default settings.
|
||||
*
|
||||
* This trait is meant to be used only by test classes.
|
||||
*
|
||||
* @deprecated in Drupal 8.4.x. Will be removed before Drupal 9.0.0. Use
|
||||
* \Drupal\Tests\node\Traits\NodeCreationTrait instead.
|
||||
*
|
||||
* @see https://www.drupal.org/node/2884454
|
||||
*/
|
||||
trait NodeCreationTrait {
|
||||
|
||||
/**
|
||||
* Get a node from the database based on its title.
|
||||
*
|
||||
* @param string|\Drupal\Component\Render\MarkupInterface $title
|
||||
* A node title, usually generated by $this->randomMachineName().
|
||||
* @param $reset
|
||||
* (optional) Whether to reset the entity cache.
|
||||
*
|
||||
* @return \Drupal\node\NodeInterface
|
||||
* A node entity matching $title.
|
||||
*/
|
||||
public function getNodeByTitle($title, $reset = FALSE) {
|
||||
if ($reset) {
|
||||
\Drupal::entityTypeManager()->getStorage('node')->resetCache();
|
||||
}
|
||||
// Cast MarkupInterface objects to string.
|
||||
$title = (string) $title;
|
||||
$nodes = \Drupal::entityTypeManager()
|
||||
->getStorage('node')
|
||||
->loadByProperties(['title' => $title]);
|
||||
// Load the first node returned from the database.
|
||||
$returned_node = reset($nodes);
|
||||
return $returned_node;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a node based on default settings.
|
||||
*
|
||||
* @param array $settings
|
||||
* (optional) An associative array of settings for the node, as used in
|
||||
* entity_create(). Override the defaults by specifying the key and value
|
||||
* in the array, for example:
|
||||
* @code
|
||||
* $this->drupalCreateNode(array(
|
||||
* 'title' => t('Hello, world!'),
|
||||
* 'type' => 'article',
|
||||
* ));
|
||||
* @endcode
|
||||
* The following defaults are provided:
|
||||
* - body: Random string using the default filter format:
|
||||
* @code
|
||||
* $settings['body'][0] = array(
|
||||
* 'value' => $this->randomMachineName(32),
|
||||
* 'format' => filter_default_format(),
|
||||
* );
|
||||
* @endcode
|
||||
* - title: Random string.
|
||||
* - type: 'page'.
|
||||
* - uid: The currently logged in user, or anonymous.
|
||||
*
|
||||
* @return \Drupal\node\NodeInterface
|
||||
* The created node entity.
|
||||
*/
|
||||
protected function createNode(array $settings = []) {
|
||||
// Populate defaults array.
|
||||
$settings += [
|
||||
'body' => [[
|
||||
'value' => $this->randomMachineName(32),
|
||||
'format' => filter_default_format(),
|
||||
]],
|
||||
'title' => $this->randomMachineName(8),
|
||||
'type' => 'page',
|
||||
'uid' => \Drupal::currentUser()->id(),
|
||||
];
|
||||
$node = Node::create($settings);
|
||||
$node->save();
|
||||
|
||||
return $node;
|
||||
}
|
||||
use BaseNodeCreationTrait;
|
||||
|
||||
}
|
||||
|
|
|
@ -2,111 +2,15 @@
|
|||
|
||||
namespace Drupal\simpletest;
|
||||
|
||||
use Drupal\Core\Routing\PreloadableRouteProviderInterface;
|
||||
use Symfony\Cmf\Component\Routing\PagedRouteProviderInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Drupal\KernelTests\RouteProvider as CoreRouteProvider;
|
||||
|
||||
/**
|
||||
* Rebuilds the router when the provider is instantiated.
|
||||
*
|
||||
* @todo Move this outside of simpletest namespace to the Drupal\Tests, see
|
||||
* https://www.drupal.org/node/2672762
|
||||
* @deprecated in 8.6.0 for removal before 9.0.0. Use
|
||||
* Drupal\KernelTests\RouteProvider instead.
|
||||
*
|
||||
* @see https://www.drupal.org/node/2943146
|
||||
*/
|
||||
class RouteProvider implements PreloadableRouteProviderInterface, PagedRouteProviderInterface {
|
||||
|
||||
use \Drupal\Core\DependencyInjection\DependencySerializationTrait;
|
||||
|
||||
/**
|
||||
* Loads the real route provider from the container and rebuilds the router.
|
||||
*
|
||||
* @return \Drupal\Core\Routing\PreloadableRouteProviderInterface|\Symfony\Cmf\Component\Routing\PagedRouteProviderInterface|\Symfony\Component\EventDispatcher\EventSubscriberInterface
|
||||
* The route provider.
|
||||
*/
|
||||
protected function lazyLoadItself() {
|
||||
if (!isset($this->service)) {
|
||||
$container = \Drupal::getContainer();
|
||||
$this->service = $container->get('simpletest.router.route_provider');
|
||||
$container->get('router.builder')->rebuild();
|
||||
}
|
||||
|
||||
return $this->service;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getRouteCollectionForRequest(Request $request) {
|
||||
return $this->lazyLoadItself()->getRouteCollectionForRequest($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getRouteByName($name) {
|
||||
return $this->lazyLoadItself()->getRouteByName($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function preLoadRoutes($names){
|
||||
return $this->lazyLoadItself()->preLoadRoutes($names);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getRoutesByNames($names) {
|
||||
return $this->lazyLoadItself()->getRoutesByNames($names);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCandidateOutlines(array $parts) {
|
||||
return $this->lazyLoadItself()->getCandidateOutlines($parts);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getRoutesByPattern($pattern) {
|
||||
return $this->lazyLoadItself()->getRoutesByPattern($pattern);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function routeProviderRouteCompare(array $a, array $b) {
|
||||
return $this->lazyLoadItself()->routeProviderRouteCompare($a, $b);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getAllRoutes() {
|
||||
return $this->lazyLoadItself()->getAllRoutes();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function reset() {
|
||||
return $this->lazyLoadItself()->reset();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getRoutesPaged($offset, $length = NULL) {
|
||||
return $this->lazyLoadItself()->getRoutesPaged($offset, $length);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getRoutesCount() {
|
||||
return $this->lazyLoadItself()->getRoutesCount();
|
||||
}
|
||||
|
||||
class RouteProvider extends CoreRouteProvider {
|
||||
}
|
||||
|
|
|
@ -5,16 +5,16 @@ namespace Drupal\simpletest;
|
|||
use Drupal\Component\Assertion\Handle;
|
||||
use Drupal\Component\Render\MarkupInterface;
|
||||
use Drupal\Component\Utility\Crypt;
|
||||
use Drupal\Component\Utility\SafeMarkup;
|
||||
use Drupal\Component\Render\FormattableMarkup;
|
||||
use Drupal\Core\Database\Database;
|
||||
use Drupal\Core\Site\Settings;
|
||||
use Drupal\Core\StreamWrapper\PublicStream;
|
||||
use Drupal\Core\Test\TestDatabase;
|
||||
use Drupal\Core\Test\TestSetupTrait;
|
||||
use Drupal\Core\Utility\Error;
|
||||
use Drupal\Tests\AssertHelperTrait as BaseAssertHelperTrait;
|
||||
use Drupal\Tests\ConfigTestTrait;
|
||||
use Drupal\Tests\RandomGeneratorTrait;
|
||||
use Drupal\Tests\SessionTestTrait;
|
||||
use Drupal\Tests\Traits\Core\GeneratePermutationsTrait;
|
||||
|
||||
/**
|
||||
|
@ -24,12 +24,11 @@ use Drupal\Tests\Traits\Core\GeneratePermutationsTrait;
|
|||
*/
|
||||
abstract class TestBase {
|
||||
|
||||
use BaseAssertHelperTrait;
|
||||
use TestSetupTrait;
|
||||
use SessionTestTrait;
|
||||
use RandomGeneratorTrait;
|
||||
use AssertHelperTrait;
|
||||
use GeneratePermutationsTrait;
|
||||
// For backwards compatibility switch the visbility of the methods to public.
|
||||
// For backwards compatibility switch the visibility of the methods to public.
|
||||
use ConfigTestTrait {
|
||||
configImporter as public;
|
||||
copyConfig as public;
|
||||
|
@ -44,13 +43,15 @@ abstract class TestBase {
|
|||
|
||||
/**
|
||||
* Time limit for the test.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $timeLimit = 500;
|
||||
|
||||
/**
|
||||
* Current results of this test case.
|
||||
*
|
||||
* @var Array
|
||||
* @var array
|
||||
*/
|
||||
public $results = [
|
||||
'#pass' => 0,
|
||||
|
@ -62,7 +63,7 @@ abstract class TestBase {
|
|||
/**
|
||||
* Assertions thrown in that test case.
|
||||
*
|
||||
* @var Array
|
||||
* @var array
|
||||
*/
|
||||
protected $assertions = [];
|
||||
|
||||
|
@ -245,6 +246,20 @@ abstract class TestBase {
|
|||
$this->testId = $test_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fail the test if it belongs to a PHPUnit-based framework.
|
||||
*
|
||||
* This would probably be caused by automated test conversions such as those
|
||||
* in https://www.drupal.org/project/drupal/issues/2770921.
|
||||
*/
|
||||
public function checkTestHierarchyMismatch() {
|
||||
// We can use getPhpunitTestSuite() because it uses a regex on the class'
|
||||
// namespace to deduce the PHPUnit test suite.
|
||||
if (TestDiscovery::getPhpunitTestSuite(get_class($this)) !== FALSE) {
|
||||
$this->fail(get_class($this) . ' incorrectly subclasses ' . __CLASS__ . ', it should probably extend \Drupal\Tests\BrowserTestBase instead.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs setup tasks before each individual test method is run.
|
||||
*/
|
||||
|
@ -288,7 +303,7 @@ abstract class TestBase {
|
|||
* TRUE is a synonym for 'pass', FALSE for 'fail'.
|
||||
* @param string|\Drupal\Component\Render\MarkupInterface $message
|
||||
* (optional) A message to display with the assertion. Do not translate
|
||||
* messages: use \Drupal\Component\Utility\SafeMarkup::format() to embed
|
||||
* messages: use \Drupal\Component\Render\FormattableMarkup to embed
|
||||
* variables in the message text, not t(). If left blank, a default message
|
||||
* will be displayed.
|
||||
* @param $group
|
||||
|
@ -446,7 +461,7 @@ abstract class TestBase {
|
|||
* The value on which the assertion is to be done.
|
||||
* @param $message
|
||||
* (optional) A message to display with the assertion. Do not translate
|
||||
* messages: use \Drupal\Component\Utility\SafeMarkup::format() to embed
|
||||
* messages: use \Drupal\Component\Render\FormattableMarkup to embed
|
||||
* variables in the message text, not t(). If left blank, a default message
|
||||
* will be displayed.
|
||||
* @param $group
|
||||
|
@ -459,7 +474,7 @@ abstract class TestBase {
|
|||
* TRUE if the assertion succeeded, FALSE otherwise.
|
||||
*/
|
||||
protected function assertTrue($value, $message = '', $group = 'Other') {
|
||||
return $this->assert((bool) $value, $message ? $message : SafeMarkup::format('Value @value is TRUE.', ['@value' => var_export($value, TRUE)]), $group);
|
||||
return $this->assert((bool) $value, $message ? $message : new FormattableMarkup('Value @value is TRUE.', ['@value' => var_export($value, TRUE)]), $group);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -471,7 +486,7 @@ abstract class TestBase {
|
|||
* The value on which the assertion is to be done.
|
||||
* @param $message
|
||||
* (optional) A message to display with the assertion. Do not translate
|
||||
* messages: use \Drupal\Component\Utility\SafeMarkup::format() to embed
|
||||
* messages: use \Drupal\Component\Render\FormattableMarkup to embed
|
||||
* variables in the message text, not t(). If left blank, a default message
|
||||
* will be displayed.
|
||||
* @param $group
|
||||
|
@ -484,7 +499,7 @@ abstract class TestBase {
|
|||
* TRUE if the assertion succeeded, FALSE otherwise.
|
||||
*/
|
||||
protected function assertFalse($value, $message = '', $group = 'Other') {
|
||||
return $this->assert(!$value, $message ? $message : SafeMarkup::format('Value @value is FALSE.', ['@value' => var_export($value, TRUE)]), $group);
|
||||
return $this->assert(!$value, $message ? $message : new FormattableMarkup('Value @value is FALSE.', ['@value' => var_export($value, TRUE)]), $group);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -494,7 +509,7 @@ abstract class TestBase {
|
|||
* The value on which the assertion is to be done.
|
||||
* @param $message
|
||||
* (optional) A message to display with the assertion. Do not translate
|
||||
* messages: use \Drupal\Component\Utility\SafeMarkup::format() to embed
|
||||
* messages: use \Drupal\Component\Render\FormattableMarkup to embed
|
||||
* variables in the message text, not t(). If left blank, a default message
|
||||
* will be displayed.
|
||||
* @param $group
|
||||
|
@ -507,7 +522,7 @@ abstract class TestBase {
|
|||
* TRUE if the assertion succeeded, FALSE otherwise.
|
||||
*/
|
||||
protected function assertNull($value, $message = '', $group = 'Other') {
|
||||
return $this->assert(!isset($value), $message ? $message : SafeMarkup::format('Value @value is NULL.', ['@value' => var_export($value, TRUE)]), $group);
|
||||
return $this->assert(!isset($value), $message ? $message : new FormattableMarkup('Value @value is NULL.', ['@value' => var_export($value, TRUE)]), $group);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -517,7 +532,7 @@ abstract class TestBase {
|
|||
* The value on which the assertion is to be done.
|
||||
* @param $message
|
||||
* (optional) A message to display with the assertion. Do not translate
|
||||
* messages: use \Drupal\Component\Utility\SafeMarkup::format() to embed
|
||||
* messages: use \Drupal\Component\Render\FormattableMarkup to embed
|
||||
* variables in the message text, not t(). If left blank, a default message
|
||||
* will be displayed.
|
||||
* @param $group
|
||||
|
@ -530,7 +545,7 @@ abstract class TestBase {
|
|||
* TRUE if the assertion succeeded, FALSE otherwise.
|
||||
*/
|
||||
protected function assertNotNull($value, $message = '', $group = 'Other') {
|
||||
return $this->assert(isset($value), $message ? $message : SafeMarkup::format('Value @value is not NULL.', ['@value' => var_export($value, TRUE)]), $group);
|
||||
return $this->assert(isset($value), $message ? $message : new FormattableMarkup('Value @value is not NULL.', ['@value' => var_export($value, TRUE)]), $group);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -542,7 +557,7 @@ abstract class TestBase {
|
|||
* The second value to check.
|
||||
* @param $message
|
||||
* (optional) A message to display with the assertion. Do not translate
|
||||
* messages: use \Drupal\Component\Utility\SafeMarkup::format() to embed
|
||||
* messages: use \Drupal\Component\Render\FormattableMarkup to embed
|
||||
* variables in the message text, not t(). If left blank, a default message
|
||||
* will be displayed.
|
||||
* @param $group
|
||||
|
@ -562,7 +577,7 @@ abstract class TestBase {
|
|||
$second = $this->castSafeStrings($second);
|
||||
$is_equal = $first == $second;
|
||||
if (!$is_equal || !$message) {
|
||||
$default_message = SafeMarkup::format('Value @first is equal to value @second.', ['@first' => var_export($first, TRUE), '@second' => var_export($second, TRUE)]);
|
||||
$default_message = new FormattableMarkup('Value @first is equal to value @second.', ['@first' => var_export($first, TRUE), '@second' => var_export($second, TRUE)]);
|
||||
$message = $message ? $message . PHP_EOL . $default_message : $default_message;
|
||||
}
|
||||
return $this->assert($is_equal, $message, $group);
|
||||
|
@ -577,7 +592,7 @@ abstract class TestBase {
|
|||
* The second value to check.
|
||||
* @param $message
|
||||
* (optional) A message to display with the assertion. Do not translate
|
||||
* messages: use \Drupal\Component\Utility\SafeMarkup::format() to embed
|
||||
* messages: use \Drupal\Component\Render\FormattableMarkup to embed
|
||||
* variables in the message text, not t(). If left blank, a default message
|
||||
* will be displayed.
|
||||
* @param $group
|
||||
|
@ -597,7 +612,7 @@ abstract class TestBase {
|
|||
$second = $this->castSafeStrings($second);
|
||||
$not_equal = $first != $second;
|
||||
if (!$not_equal || !$message) {
|
||||
$default_message = SafeMarkup::format('Value @first is not equal to value @second.', ['@first' => var_export($first, TRUE), '@second' => var_export($second, TRUE)]);
|
||||
$default_message = new FormattableMarkup('Value @first is not equal to value @second.', ['@first' => var_export($first, TRUE), '@second' => var_export($second, TRUE)]);
|
||||
$message = $message ? $message . PHP_EOL . $default_message : $default_message;
|
||||
}
|
||||
return $this->assert($not_equal, $message, $group);
|
||||
|
@ -612,7 +627,7 @@ abstract class TestBase {
|
|||
* The second value to check.
|
||||
* @param $message
|
||||
* (optional) A message to display with the assertion. Do not translate
|
||||
* messages: use \Drupal\Component\Utility\SafeMarkup::format() to embed
|
||||
* messages: use \Drupal\Component\Render\FormattableMarkup to embed
|
||||
* variables in the message text, not t(). If left blank, a default message
|
||||
* will be displayed.
|
||||
* @param $group
|
||||
|
@ -627,7 +642,7 @@ abstract class TestBase {
|
|||
protected function assertIdentical($first, $second, $message = '', $group = 'Other') {
|
||||
$is_identical = $first === $second;
|
||||
if (!$is_identical || !$message) {
|
||||
$default_message = SafeMarkup::format('Value @first is identical to value @second.', ['@first' => var_export($first, TRUE), '@second' => var_export($second, TRUE)]);
|
||||
$default_message = new FormattableMarkup('Value @first is identical to value @second.', ['@first' => var_export($first, TRUE), '@second' => var_export($second, TRUE)]);
|
||||
$message = $message ? $message . PHP_EOL . $default_message : $default_message;
|
||||
}
|
||||
return $this->assert($is_identical, $message, $group);
|
||||
|
@ -642,7 +657,7 @@ abstract class TestBase {
|
|||
* The second value to check.
|
||||
* @param $message
|
||||
* (optional) A message to display with the assertion. Do not translate
|
||||
* messages: use \Drupal\Component\Utility\SafeMarkup::format() to embed
|
||||
* messages: use \Drupal\Component\Render\FormattableMarkup to embed
|
||||
* variables in the message text, not t(). If left blank, a default message
|
||||
* will be displayed.
|
||||
* @param $group
|
||||
|
@ -657,7 +672,7 @@ abstract class TestBase {
|
|||
protected function assertNotIdentical($first, $second, $message = '', $group = 'Other') {
|
||||
$not_identical = $first !== $second;
|
||||
if (!$not_identical || !$message) {
|
||||
$default_message = SafeMarkup::format('Value @first is not identical to value @second.', ['@first' => var_export($first, TRUE), '@second' => var_export($second, TRUE)]);
|
||||
$default_message = new FormattableMarkup('Value @first is not identical to value @second.', ['@first' => var_export($first, TRUE), '@second' => var_export($second, TRUE)]);
|
||||
$message = $message ? $message . PHP_EOL . $default_message : $default_message;
|
||||
}
|
||||
return $this->assert($not_identical, $message, $group);
|
||||
|
@ -672,7 +687,7 @@ abstract class TestBase {
|
|||
* The second object to check.
|
||||
* @param $message
|
||||
* (optional) A message to display with the assertion. Do not translate
|
||||
* messages: use \Drupal\Component\Utility\SafeMarkup::format() to embed
|
||||
* messages: use \Drupal\Component\Render\FormattableMarkup to embed
|
||||
* variables in the message text, not t(). If left blank, a default message
|
||||
* will be displayed.
|
||||
* @param $group
|
||||
|
@ -685,7 +700,7 @@ abstract class TestBase {
|
|||
* TRUE if the assertion succeeded, FALSE otherwise.
|
||||
*/
|
||||
protected function assertIdenticalObject($object1, $object2, $message = '', $group = 'Other') {
|
||||
$message = $message ?: SafeMarkup::format('@object1 is identical to @object2', [
|
||||
$message = $message ?: new FormattableMarkup('@object1 is identical to @object2', [
|
||||
'@object1' => var_export($object1, TRUE),
|
||||
'@object2' => var_export($object2, TRUE),
|
||||
]);
|
||||
|
@ -752,7 +767,7 @@ abstract class TestBase {
|
|||
*
|
||||
* @param $message
|
||||
* (optional) A message to display with the assertion. Do not translate
|
||||
* messages: use \Drupal\Component\Utility\SafeMarkup::format() to embed
|
||||
* messages: use \Drupal\Component\Render\FormattableMarkup to embed
|
||||
* variables in the message text, not t(). If left blank, a default message
|
||||
* will be displayed.
|
||||
* @param $group
|
||||
|
@ -773,7 +788,7 @@ abstract class TestBase {
|
|||
*
|
||||
* @param $message
|
||||
* (optional) A message to display with the assertion. Do not translate
|
||||
* messages: use \Drupal\Component\Utility\SafeMarkup::format() to embed
|
||||
* messages: use \Drupal\Component\Render\FormattableMarkup to embed
|
||||
* variables in the message text, not t(). If left blank, a default message
|
||||
* will be displayed.
|
||||
* @param $group
|
||||
|
@ -794,7 +809,7 @@ abstract class TestBase {
|
|||
*
|
||||
* @param $message
|
||||
* (optional) A message to display with the assertion. Do not translate
|
||||
* messages: use \Drupal\Component\Utility\SafeMarkup::format() to embed
|
||||
* messages: use \Drupal\Component\Render\FormattableMarkup to embed
|
||||
* variables in the message text, not t(). If left blank, a default message
|
||||
* will be displayed.
|
||||
* @param $group
|
||||
|
@ -861,6 +876,7 @@ abstract class TestBase {
|
|||
* methods during debugging.
|
||||
*/
|
||||
public function run(array $methods = []) {
|
||||
$this->checkTestHierarchyMismatch();
|
||||
$class = get_class($this);
|
||||
|
||||
if ($missing_requirements = $this->checkRequirements()) {
|
||||
|
@ -982,7 +998,7 @@ abstract class TestBase {
|
|||
|
||||
TestServiceProvider::$currentTest = NULL;
|
||||
// Clear out the error messages and restore error handler.
|
||||
drupal_get_messages();
|
||||
\Drupal::messenger()->deleteAll();
|
||||
restore_error_handler();
|
||||
}
|
||||
|
||||
|
@ -1323,7 +1339,7 @@ abstract class TestBase {
|
|||
]);
|
||||
$decoded_exception = Error::decodeException($exception);
|
||||
unset($decoded_exception['backtrace']);
|
||||
$message = SafeMarkup::format('%type: @message in %function (line %line of %file). <pre class="backtrace">@backtrace</pre>', $decoded_exception + [
|
||||
$message = new FormattableMarkup('%type: @message in %function (line %line of %file). <pre class="backtrace">@backtrace</pre>', $decoded_exception + [
|
||||
'@backtrace' => Error::formatBacktrace($verbose_backtrace),
|
||||
]);
|
||||
$this->error($message, 'Uncaught exception', Error::getLastCaller($backtrace));
|
||||
|
|
|
@ -6,7 +6,6 @@ use Doctrine\Common\Annotations\SimpleAnnotationReader;
|
|||
use Doctrine\Common\Reflection\StaticReflectionParser;
|
||||
use Drupal\Component\Annotation\Reflection\MockFileFinder;
|
||||
use Drupal\Component\Utility\NestedArray;
|
||||
use Drupal\Core\Cache\CacheBackendInterface;
|
||||
use Drupal\Core\Extension\ExtensionDiscovery;
|
||||
use Drupal\Core\Extension\ModuleHandlerInterface;
|
||||
use Drupal\simpletest\Exception\MissingGroupException;
|
||||
|
@ -25,11 +24,11 @@ class TestDiscovery {
|
|||
protected $classLoader;
|
||||
|
||||
/**
|
||||
* Backend for caching discovery results.
|
||||
* Statically cached list of test classes.
|
||||
*
|
||||
* @var \Drupal\Core\Cache\CacheBackendInterface
|
||||
* @var array
|
||||
*/
|
||||
protected $cacheBackend;
|
||||
protected $testClasses;
|
||||
|
||||
/**
|
||||
* Cached map of all test namespaces to respective directories.
|
||||
|
@ -70,14 +69,11 @@ class TestDiscovery {
|
|||
* \Symfony\Component\ClassLoader\ApcClassLoader.
|
||||
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
|
||||
* The module handler.
|
||||
* @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend
|
||||
* (optional) Backend for caching discovery results.
|
||||
*/
|
||||
public function __construct($root, $class_loader, ModuleHandlerInterface $module_handler, CacheBackendInterface $cache_backend = NULL) {
|
||||
public function __construct($root, $class_loader, ModuleHandlerInterface $module_handler) {
|
||||
$this->root = $root;
|
||||
$this->classLoader = $class_loader;
|
||||
$this->moduleHandler = $module_handler;
|
||||
$this->cacheBackend = $cache_backend;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -144,8 +140,8 @@ class TestDiscovery {
|
|||
* An array of tests keyed by the the group name.
|
||||
* @code
|
||||
* $groups['block'] => array(
|
||||
* 'Drupal\block\Tests\BlockTest' => array(
|
||||
* 'name' => 'Drupal\block\Tests\BlockTest',
|
||||
* 'Drupal\Tests\block\Functional\BlockTest' => array(
|
||||
* 'name' => 'Drupal\Tests\block\Functional\BlockTest',
|
||||
* 'description' => 'Tests block UI CRUD functionality.',
|
||||
* 'group' => 'block',
|
||||
* ),
|
||||
|
@ -159,9 +155,9 @@ class TestDiscovery {
|
|||
$reader = new SimpleAnnotationReader();
|
||||
$reader->addNamespace('Drupal\\simpletest\\Annotation');
|
||||
|
||||
if (!isset($extension)) {
|
||||
if ($this->cacheBackend && $cache = $this->cacheBackend->get('simpletest:discovery:classes')) {
|
||||
return $cache->data;
|
||||
if (!isset($extension) && empty($types)) {
|
||||
if (!empty($this->testClasses)) {
|
||||
return $this->testClasses;
|
||||
}
|
||||
}
|
||||
$list = [];
|
||||
|
@ -189,14 +185,17 @@ class TestDiscovery {
|
|||
// abstract class, trait or test fixture.
|
||||
continue;
|
||||
}
|
||||
// Skip this test class if it requires unavailable modules.
|
||||
// @todo PHPUnit skips tests with unmet requirements when executing a test
|
||||
// (instead of excluding them upfront). Refactor test runner to follow
|
||||
// that approach.
|
||||
// Skip this test class if it is a Simpletest-based test and requires
|
||||
// unavailable modules. TestDiscovery should not filter out module
|
||||
// requirements for PHPUnit-based test classes.
|
||||
// @todo Move this behavior to \Drupal\simpletest\TestBase so tests can be
|
||||
// marked as skipped, instead.
|
||||
// @see https://www.drupal.org/node/1273478
|
||||
if (!empty($info['requires']['module'])) {
|
||||
if (array_diff($info['requires']['module'], $this->availableExtensions['module'])) {
|
||||
continue;
|
||||
if ($info['type'] == 'Simpletest') {
|
||||
if (!empty($info['requires']['module'])) {
|
||||
if (array_diff($info['requires']['module'], $this->availableExtensions['module'])) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -210,12 +209,10 @@ class TestDiscovery {
|
|||
}
|
||||
|
||||
// Allow modules extending core tests to disable originals.
|
||||
$this->moduleHandler->alter('simpletest', $list);
|
||||
$this->moduleHandler->alterDeprecated('Convert your test to a PHPUnit-based one and implement test listeners. See: https://www.drupal.org/node/2939892', 'simpletest', $list);
|
||||
|
||||
if (!isset($extension)) {
|
||||
if ($this->cacheBackend) {
|
||||
$this->cacheBackend->set('simpletest:discovery:classes', $list);
|
||||
}
|
||||
if (!isset($extension) && empty($types)) {
|
||||
$this->testClasses = $list;
|
||||
}
|
||||
|
||||
if ($types) {
|
||||
|
@ -285,13 +282,21 @@ class TestDiscovery {
|
|||
$flags |= \FilesystemIterator::SKIP_DOTS;
|
||||
$flags |= \FilesystemIterator::FOLLOW_SYMLINKS;
|
||||
$flags |= \FilesystemIterator::CURRENT_AS_SELF;
|
||||
$flags |= \FilesystemIterator::KEY_AS_FILENAME;
|
||||
|
||||
$iterator = new \RecursiveDirectoryIterator($path, $flags);
|
||||
$filter = new \RecursiveCallbackFilterIterator($iterator, function ($current, $key, $iterator) {
|
||||
$filter = new \RecursiveCallbackFilterIterator($iterator, function ($current, $file_name, $iterator) {
|
||||
if ($iterator->hasChildren()) {
|
||||
return TRUE;
|
||||
}
|
||||
return $current->isFile() && $current->getExtension() === 'php';
|
||||
// We don't want to discover abstract TestBase classes, traits or
|
||||
// interfaces. They can be deprecated and will call @trigger_error()
|
||||
// during discovery.
|
||||
return
|
||||
substr($file_name, -4) === '.php' &&
|
||||
substr($file_name, -12) !== 'TestBase.php' &&
|
||||
substr($file_name, -9) !== 'Trait.php' &&
|
||||
substr($file_name, -13) !== 'Interface.php';
|
||||
});
|
||||
$files = new \RecursiveIteratorIterator($filter);
|
||||
$classes = [];
|
||||
|
@ -309,7 +314,7 @@ class TestDiscovery {
|
|||
/**
|
||||
* Retrieves information about a test class for UI purposes.
|
||||
*
|
||||
* @param string $class
|
||||
* @param string $classname
|
||||
* The test classname.
|
||||
* @param string $doc_comment
|
||||
* (optional) The class PHPDoc comment. If not passed in reflection will be
|
||||
|
@ -328,7 +333,7 @@ class TestDiscovery {
|
|||
* If the class does not have a @group annotation.
|
||||
*/
|
||||
public static function getTestInfo($classname, $doc_comment = NULL) {
|
||||
if (!$doc_comment) {
|
||||
if ($doc_comment === NULL) {
|
||||
$reflection = new \ReflectionClass($classname);
|
||||
$doc_comment = $reflection->getDocComment();
|
||||
}
|
||||
|
|
|
@ -2,51 +2,16 @@
|
|||
|
||||
namespace Drupal\simpletest;
|
||||
|
||||
use Drupal\Core\DependencyInjection\ContainerBuilder;
|
||||
use Drupal\Core\DependencyInjection\ServiceModifierInterface;
|
||||
use Drupal\Core\DependencyInjection\ServiceProviderInterface;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Drupal\KernelTests\TestServiceProvider as CoreTestServiceProvider;
|
||||
|
||||
class TestServiceProvider implements ServiceProviderInterface, ServiceModifierInterface {
|
||||
|
||||
/**
|
||||
* @var \Drupal\simpletest\TestBase;
|
||||
*/
|
||||
public static $currentTest;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function register(ContainerBuilder $container) {
|
||||
if (static::$currentTest && method_exists(static::$currentTest, 'containerBuild')) {
|
||||
static::$currentTest->containerBuild($container);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function alter(ContainerBuilder $container) {
|
||||
if (static::$currentTest instanceof KernelTestBase) {
|
||||
static::addRouteProvider($container);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the on demand rebuild route provider service.
|
||||
*
|
||||
* @param \Drupal\Core\DependencyInjection\ContainerBuilder $container
|
||||
*/
|
||||
public static function addRouteProvider(ContainerBuilder $container) {
|
||||
foreach (['router.route_provider' => 'RouteProvider'] as $original_id => $class) {
|
||||
// While $container->get() does a recursive resolve, getDefinition() does
|
||||
// not, so do it ourselves.
|
||||
for ($id = $original_id; $container->hasAlias($id); $id = (string) $container->getAlias($id));
|
||||
$definition = $container->getDefinition($id);
|
||||
$definition->clearTag('needs_destruction');
|
||||
$container->setDefinition("simpletest.$original_id", $definition);
|
||||
$container->setDefinition($id, new Definition('Drupal\simpletest\\' . $class));
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Provides special routing services for tests.
|
||||
*
|
||||
* @deprecated in 8.6.0 for removal before Drupal 9.0.0. Use
|
||||
* Drupal\KernelTests\TestServiceProvider instead.
|
||||
*
|
||||
* @see https://www.drupal.org/node/2943146
|
||||
*/
|
||||
class TestServiceProvider extends CoreTestServiceProvider {
|
||||
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ class InstallationProfileModuleTestsTest extends WebTestBase {
|
|||
public static $modules = ['simpletest'];
|
||||
|
||||
/**
|
||||
* An administrative user with permission to adminsiter unit tests.
|
||||
* An administrative user with permission to administer unit tests.
|
||||
*
|
||||
* @var \Drupal\user\UserInterface
|
||||
*/
|
||||
|
@ -35,7 +35,9 @@ class InstallationProfileModuleTestsTest extends WebTestBase {
|
|||
* - but still install the drupal_system_listing_compatible_test.module
|
||||
* contained in the Testing profile.
|
||||
*
|
||||
* @see \Drupal\drupal_system_listing_compatible_test\Tests\SystemListingCompatibleTest
|
||||
* @see \Drupal\Tests\drupal_system_listing_compatible_test\Kernel\SystemListingCrossProfileCompatibleTest
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $profile = 'testing';
|
||||
|
||||
|
@ -51,12 +53,18 @@ class InstallationProfileModuleTestsTest extends WebTestBase {
|
|||
*/
|
||||
public function testInstallationProfileTests() {
|
||||
$this->drupalGet('admin/config/development/testing');
|
||||
$this->assertText('Drupal\drupal_system_listing_compatible_test\Tests\SystemListingCompatibleTest');
|
||||
$this->assertText('Drupal\Tests\drupal_system_listing_compatible_test\Kernel\SystemListingCrossProfileCompatibleTest');
|
||||
$edit = [
|
||||
'tests[Drupal\drupal_system_listing_compatible_test\Tests\SystemListingCompatibleTest]' => TRUE,
|
||||
'tests[Drupal\Tests\drupal_system_listing_compatible_test\Kernel\SystemListingCrossProfileCompatibleTest]' => TRUE,
|
||||
];
|
||||
$this->drupalPostForm(NULL, $edit, t('Run tests'));
|
||||
$this->assertText('SystemListingCompatibleTest test executed.');
|
||||
|
||||
// Verifies that tests in installation profile modules are passed.
|
||||
$element = $this->xpath('//tr[contains(@class, :class)]/td[contains(text(), :value)]', [
|
||||
':class' => 'simpletest-pass',
|
||||
':value' => 'Drupal\Tests\drupal_system_listing_compatible_test\Kernel\SystemListingCrossProfileCompatibleTest',
|
||||
]);
|
||||
$this->assertTrue(!empty($element));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -62,7 +62,7 @@ EOS;
|
|||
$this->assertIdentical(\Drupal::moduleHandler()->getImplementations('entity_type_alter'), ['entity_test']);
|
||||
|
||||
// Verify that no modules have been installed.
|
||||
$this->assertFalse(db_table_exists($table), "'$table' database table not found.");
|
||||
$this->assertFalse(Database::getConnection()->schema()->tableExists($table), "'$table' database table not found.");
|
||||
|
||||
// Verify that the settings.testing.php got taken into account.
|
||||
$this->assertTrue(function_exists('simpletest_test_stub_settings_function'));
|
||||
|
@ -114,7 +114,7 @@ EOS;
|
|||
$list = \Drupal::moduleHandler()->getImplementations('hook_info');
|
||||
$this->assertFalse(in_array($module, $list), "{$module}_hook_info() in \Drupal::moduleHandler()->getImplementations() not found.");
|
||||
|
||||
$this->assertFalse(db_table_exists($table), "'$table' database table not found.");
|
||||
$this->assertFalse(Database::getConnection()->schema()->tableExists($table), "'$table' database table not found.");
|
||||
|
||||
// Install the module.
|
||||
\Drupal::service('module_installer')->install([$module]);
|
||||
|
@ -126,7 +126,7 @@ EOS;
|
|||
$list = \Drupal::moduleHandler()->getImplementations('hook_info');
|
||||
$this->assertTrue(in_array($module, $list), "{$module}_hook_info() in \Drupal::moduleHandler()->getImplementations() found.");
|
||||
|
||||
$this->assertTrue(db_table_exists($table), "'$table' database table found.");
|
||||
$this->assertTrue(Database::getConnection()->schema()->tableExists($table), "'$table' database table found.");
|
||||
$schema = drupal_get_module_schema($module, $table);
|
||||
$this->assertTrue($schema, "'$table' table schema found.");
|
||||
}
|
||||
|
@ -156,7 +156,7 @@ EOS;
|
|||
$table = 'entity_test_example';
|
||||
// Verify that we can install a table from the module schema.
|
||||
$this->installSchema($module, $table);
|
||||
$this->assertTrue(db_table_exists($table), "'$table' database table found.");
|
||||
$this->assertTrue(Database::getConnection()->schema()->tableExists($table), "'$table' database table found.");
|
||||
|
||||
// Verify that the schema is known to Schema API.
|
||||
$schema = drupal_get_module_schema($module, $table);
|
||||
|
@ -171,7 +171,7 @@ EOS;
|
|||
catch (\Exception $e) {
|
||||
$this->pass('Exception for non-retrievable schema found.');
|
||||
}
|
||||
$this->assertFalse(db_table_exists($table), "'$table' database table not found.");
|
||||
$this->assertFalse(Database::getConnection()->schema()->tableExists($table), "'$table' database table not found.");
|
||||
$schema = drupal_get_module_schema($module, $table);
|
||||
$this->assertFalse($schema, "'$table' table schema not found.");
|
||||
|
||||
|
@ -185,14 +185,14 @@ EOS;
|
|||
catch (\Exception $e) {
|
||||
$this->pass('Exception for non-retrievable schema found.');
|
||||
}
|
||||
$this->assertFalse(db_table_exists($table), "'$table' database table not found.");
|
||||
$this->assertFalse(Database::getConnection()->schema()->tableExists($table), "'$table' database table not found.");
|
||||
$schema = drupal_get_module_schema($module, $table);
|
||||
$this->assertTrue($schema, "'$table' table schema found.");
|
||||
|
||||
// Verify that the same table can be installed after enabling the module.
|
||||
$this->enableModules([$module]);
|
||||
$this->installSchema($module, $table);
|
||||
$this->assertTrue(db_table_exists($table), "'$table' database table found.");
|
||||
$this->assertTrue(Database::getConnection()->schema()->tableExists($table), "'$table' database table found.");
|
||||
$schema = drupal_get_module_schema($module, $table);
|
||||
$this->assertTrue($schema, "'$table' table schema found.");
|
||||
}
|
||||
|
@ -206,7 +206,7 @@ EOS;
|
|||
$this->enableModules(['user']);
|
||||
// Verity that the entity schema is created properly.
|
||||
$this->installEntitySchema($entity);
|
||||
$this->assertTrue(db_table_exists($entity), "'$entity' database table found.");
|
||||
$this->assertTrue(Database::getConnection()->schema()->tableExists($entity), "'$entity' database table found.");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -278,7 +278,7 @@ EOS;
|
|||
$field_storage = FieldStorageConfig::create([
|
||||
'field_name' => 'test_field',
|
||||
'entity_type' => 'entity_test',
|
||||
'type' => 'test_field'
|
||||
'type' => 'test_field',
|
||||
]);
|
||||
$field_storage->save();
|
||||
FieldConfig::create([
|
||||
|
@ -354,7 +354,7 @@ EOS;
|
|||
$info = Database::getConnectionInfo();
|
||||
$connection->query('ATTACH DATABASE :database AS :prefix', [
|
||||
':database' => $info['default']['database'] . '-' . $this->databasePrefix,
|
||||
':prefix' => $this->databasePrefix
|
||||
':prefix' => $this->databasePrefix,
|
||||
]);
|
||||
|
||||
$result = $connection->query("SELECT name FROM " . $this->databasePrefix . ".sqlite_master WHERE type = :type AND name LIKE :table_name AND name NOT LIKE :pattern", [
|
||||
|
|
|
@ -30,7 +30,7 @@ class MissingCheckedRequirementsTest extends WebTestBase {
|
|||
protected function checkRequirements() {
|
||||
if ($this->isInChildSite()) {
|
||||
return [
|
||||
'Test is not allowed to run.'
|
||||
'Test is not allowed to run.',
|
||||
];
|
||||
}
|
||||
return parent::checkRequirements();
|
||||
|
|
|
@ -59,7 +59,7 @@ class SimpleTestBrowserTest extends WebTestBase {
|
|||
$this->maximumRedirects = 1;
|
||||
$edit = [
|
||||
'name' => $user->getUsername(),
|
||||
'pass' => $user->pass_raw
|
||||
'pass' => $user->pass_raw,
|
||||
];
|
||||
$this->drupalPostForm('user/login', $edit, t('Log in'), [
|
||||
'query' => ['destination' => 'user/logout'],
|
||||
|
@ -87,7 +87,7 @@ class SimpleTestBrowserTest extends WebTestBase {
|
|||
$this->drupalLogout();
|
||||
|
||||
$system_path = $base_url . '/' . drupal_get_path('module', 'system');
|
||||
$HTTP_path = $system_path . '/tests/http.php/user/login';
|
||||
$http_path = $system_path . '/tests/http.php/user/login';
|
||||
$https_path = $system_path . '/tests/https.php/user/login';
|
||||
// Generate a valid simpletest User-Agent to pass validation.
|
||||
$this->assertTrue(preg_match('/test\d+/', $this->databasePrefix, $matches), 'Database prefix contains test prefix.');
|
||||
|
@ -95,14 +95,14 @@ class SimpleTestBrowserTest extends WebTestBase {
|
|||
$this->additionalCurlOptions = [CURLOPT_USERAGENT => $test_ua];
|
||||
|
||||
// Test pages only available for testing.
|
||||
$this->drupalGet($HTTP_path);
|
||||
$this->drupalGet($http_path);
|
||||
$this->assertResponse(200, 'Requesting http.php with a legitimate simpletest User-Agent returns OK.');
|
||||
$this->drupalGet($https_path);
|
||||
$this->assertResponse(200, 'Requesting https.php with a legitimate simpletest User-Agent returns OK.');
|
||||
|
||||
// Now slightly modify the HMAC on the header, which should not validate.
|
||||
$this->additionalCurlOptions = [CURLOPT_USERAGENT => $test_ua . 'X'];
|
||||
$this->drupalGet($HTTP_path);
|
||||
$this->drupalGet($http_path);
|
||||
$this->assertResponse(403, 'Requesting http.php with a bad simpletest User-Agent fails.');
|
||||
$this->drupalGet($https_path);
|
||||
$this->assertResponse(403, 'Requesting https.php with a bad simpletest User-Agent fails.');
|
||||
|
@ -110,7 +110,7 @@ class SimpleTestBrowserTest extends WebTestBase {
|
|||
// Use a real User-Agent and verify that the special files http.php and
|
||||
// https.php can't be accessed.
|
||||
$this->additionalCurlOptions = [CURLOPT_USERAGENT => 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12'];
|
||||
$this->drupalGet($HTTP_path);
|
||||
$this->drupalGet($http_path);
|
||||
$this->assertResponse(403, 'Requesting http.php with a normal User-Agent fails.');
|
||||
$this->drupalGet($https_path);
|
||||
$this->assertResponse(403, 'Requesting https.php with a normal User-Agent fails.');
|
||||
|
|
|
@ -0,0 +1,94 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\simpletest\Tests;
|
||||
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
|
||||
/**
|
||||
* Tests SimpleTest error and exception collector.
|
||||
*
|
||||
* @group WebTestBase
|
||||
*/
|
||||
class SimpleTestErrorCollectorTest extends WebTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['system_test', 'error_test'];
|
||||
|
||||
/**
|
||||
* Errors triggered during the test.
|
||||
*
|
||||
* Errors are intercepted by the overridden implementation
|
||||
* of Drupal\simpletest\WebTestBase::error() below.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $collectedErrors = [];
|
||||
|
||||
/**
|
||||
* Tests that simpletest collects errors from the tested site.
|
||||
*/
|
||||
public function testErrorCollect() {
|
||||
$this->collectedErrors = [];
|
||||
$this->drupalGet('error-test/generate-warnings-with-report');
|
||||
$this->assertEqual(count($this->collectedErrors), 3, 'Three errors were collected');
|
||||
|
||||
if (count($this->collectedErrors) == 3) {
|
||||
$this->assertError($this->collectedErrors[0], 'Notice', 'Drupal\error_test\Controller\ErrorTestController->generateWarnings()', 'ErrorTestController.php', 'Undefined variable: bananas');
|
||||
$this->assertError($this->collectedErrors[1], 'Warning', 'Drupal\error_test\Controller\ErrorTestController->generateWarnings()', 'ErrorTestController.php', 'Division by zero');
|
||||
$this->assertError($this->collectedErrors[2], 'User warning', 'Drupal\error_test\Controller\ErrorTestController->generateWarnings()', 'ErrorTestController.php', 'Drupal & awesome');
|
||||
}
|
||||
else {
|
||||
// Give back the errors to the log report.
|
||||
foreach ($this->collectedErrors as $error) {
|
||||
parent::error($error['message'], $error['group'], $error['caller']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores errors into an array.
|
||||
*
|
||||
* This test class is trying to verify that simpletest correctly sees errors
|
||||
* and warnings. However, it can't generate errors and warnings that
|
||||
* propagate up to the testing framework itself, or these tests would always
|
||||
* fail. So, this special copy of error() doesn't propagate the errors up
|
||||
* the class hierarchy. It just stuffs them into a protected collectedErrors
|
||||
* array for various assertions to inspect.
|
||||
*/
|
||||
protected function error($message = '', $group = 'Other', array $caller = NULL) {
|
||||
// Due to a WTF elsewhere, simpletest treats debug() and verbose()
|
||||
// messages as if they were an 'error'. But, we don't want to collect
|
||||
// those here. This function just wants to collect the real errors (PHP
|
||||
// notices, PHP fatal errors, etc.), and let all the 'errors' from the
|
||||
// 'User notice' group bubble up to the parent classes to be handled (and
|
||||
// eventually displayed) as normal.
|
||||
if ($group == 'User notice') {
|
||||
parent::error($message, $group, $caller);
|
||||
}
|
||||
// Everything else should be collected but not propagated.
|
||||
else {
|
||||
$this->collectedErrors[] = [
|
||||
'message' => $message,
|
||||
'group' => $group,
|
||||
'caller' => $caller,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that a collected error matches what we are expecting.
|
||||
*/
|
||||
public function assertError($error, $group, $function, $file, $message = NULL) {
|
||||
$this->assertEqual($error['group'], $group, format_string("Group was %group", ['%group' => $group]));
|
||||
$this->assertEqual($error['caller']['function'], $function, format_string("Function was %function", ['%function' => $function]));
|
||||
$this->assertEqual(drupal_basename($error['caller']['file']), $file, format_string("File was %file", ['%file' => $file]));
|
||||
if (isset($message)) {
|
||||
$this->assertEqual($error['message'], $message, format_string("Message was %message", ['%message' => $message]));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -175,7 +175,7 @@ EOD;
|
|||
// along by the rethrow.
|
||||
assert(FALSE, 'Lorem Ipsum');
|
||||
}
|
||||
catch ( \AssertionError $e ) {
|
||||
catch (\AssertionError $e) {
|
||||
$this->assertEqual($e->getMessage(), 'Lorem Ipsum', 'Runtime assertions Enabled and running.');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\simpletest\Tests;
|
||||
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
|
||||
/**
|
||||
* Tests if Simpletest-based tests are skipped based on module requirements.
|
||||
*
|
||||
* This test should always be skipped when TestDiscovery is used to discover it.
|
||||
* This means that if you specify this test to run-tests.sh with --class or
|
||||
* --file, this test will run and fail.
|
||||
*
|
||||
* @dependencies module_does_not_exist
|
||||
*
|
||||
* @group simpletest
|
||||
*
|
||||
* @todo Change or remove this test when Simpletest-based tests are able to skip
|
||||
* themselves based on requirements.
|
||||
* @see https://www.drupal.org/node/1273478
|
||||
*/
|
||||
class SkipRequiredModulesTest extends WebTestBase {
|
||||
|
||||
public function testModuleNotFound() {
|
||||
$this->fail('This test should have been skipped during discovery.');
|
||||
}
|
||||
|
||||
}
|
|
@ -35,9 +35,9 @@ class UiPhpUnitOutputTest extends WebTestBase {
|
|||
|
||||
// Check that there are <br> tags for the HTML output by
|
||||
// SimpletestUiPrinter.
|
||||
$this->assertEqual($output[18], 'HTML output was generated<br />');
|
||||
$this->assertEqual($output[19], 'HTML output was generated<br />');
|
||||
// Check that URLs are printed as HTML links.
|
||||
$this->assertIdentical(strpos($output[19], '<a href="http'), 0);
|
||||
$this->assertIdentical(strpos($output[20], '<a href="http'), 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,11 +2,7 @@
|
|||
|
||||
namespace Drupal\simpletest;
|
||||
|
||||
use Drupal\Component\Utility\SafeMarkup;
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
use Drupal\user\Entity\Role;
|
||||
use Drupal\user\Entity\User;
|
||||
use Drupal\user\RoleInterface;
|
||||
use Drupal\Tests\user\Traits\UserCreationTrait as BaseUserCreationTrait;
|
||||
|
||||
/**
|
||||
* Provides methods to create additional test users and switch the currently
|
||||
|
@ -14,201 +10,14 @@ use Drupal\user\RoleInterface;
|
|||
*
|
||||
* This trait is meant to be used only by test classes extending
|
||||
* \Drupal\simpletest\TestBase.
|
||||
*
|
||||
* @deprecated in Drupal 8.4.x. Will be removed before Drupal 9.0.0. Use
|
||||
* Drupal\Tests\user\Traits\UserCreationTrait instead.
|
||||
*
|
||||
* @see https://www.drupal.org/node/2884454
|
||||
*/
|
||||
trait UserCreationTrait {
|
||||
|
||||
/**
|
||||
* Switch the current logged in user.
|
||||
*
|
||||
* @param \Drupal\Core\Session\AccountInterface $account
|
||||
* The user account object.
|
||||
*/
|
||||
protected function setCurrentUser(AccountInterface $account) {
|
||||
\Drupal::currentUser()->setAccount($account);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a user with a given set of permissions.
|
||||
*
|
||||
* @param array $permissions
|
||||
* Array of permission names to assign to user. Note that the user always
|
||||
* has the default permissions derived from the "authenticated users" role.
|
||||
* @param string $name
|
||||
* The user name.
|
||||
* @param bool $admin
|
||||
* (optional) Whether the user should be an administrator
|
||||
* with all the available permissions.
|
||||
*
|
||||
* @return \Drupal\user\Entity\User|false
|
||||
* A fully loaded user object with pass_raw property, or FALSE if account
|
||||
* creation fails.
|
||||
*/
|
||||
protected function createUser(array $permissions = [], $name = NULL, $admin = FALSE) {
|
||||
// Create a role with the given permission set, if any.
|
||||
$rid = FALSE;
|
||||
if ($permissions) {
|
||||
$rid = $this->createRole($permissions);
|
||||
if (!$rid) {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
// Create a user assigned to that role.
|
||||
$edit = [];
|
||||
$edit['name'] = !empty($name) ? $name : $this->randomMachineName();
|
||||
$edit['mail'] = $edit['name'] . '@example.com';
|
||||
$edit['pass'] = user_password();
|
||||
$edit['status'] = 1;
|
||||
if ($rid) {
|
||||
$edit['roles'] = [$rid];
|
||||
}
|
||||
|
||||
if ($admin) {
|
||||
$edit['roles'][] = $this->createAdminRole();
|
||||
}
|
||||
|
||||
$account = User::create($edit);
|
||||
$account->save();
|
||||
|
||||
$this->assertTrue($account->id(), SafeMarkup::format('User created with name %name and pass %pass', ['%name' => $edit['name'], '%pass' => $edit['pass']]), 'User login');
|
||||
if (!$account->id()) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Add the raw password so that we can log in as this user.
|
||||
$account->pass_raw = $edit['pass'];
|
||||
// Support BrowserTestBase as well.
|
||||
$account->passRaw = $account->pass_raw;
|
||||
return $account;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an administrative role.
|
||||
*
|
||||
* @param string $rid
|
||||
* (optional) The role ID (machine name). Defaults to a random name.
|
||||
* @param string $name
|
||||
* (optional) The label for the role. Defaults to a random string.
|
||||
* @param int $weight
|
||||
* (optional) The weight for the role. Defaults NULL so that entity_create()
|
||||
* sets the weight to maximum + 1.
|
||||
*
|
||||
* @return string
|
||||
* Role ID of newly created role, or FALSE if role creation failed.
|
||||
*/
|
||||
protected function createAdminRole($rid = NULL, $name = NULL, $weight = NULL) {
|
||||
$rid = $this->createRole([], $rid, $name, $weight);
|
||||
if ($rid) {
|
||||
/** @var \Drupal\user\RoleInterface $role */
|
||||
$role = Role::load($rid);
|
||||
$role->setIsAdmin(TRUE);
|
||||
$role->save();
|
||||
}
|
||||
return $rid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a role with specified permissions.
|
||||
*
|
||||
* @param array $permissions
|
||||
* Array of permission names to assign to role.
|
||||
* @param string $rid
|
||||
* (optional) The role ID (machine name). Defaults to a random name.
|
||||
* @param string $name
|
||||
* (optional) The label for the role. Defaults to a random string.
|
||||
* @param int $weight
|
||||
* (optional) The weight for the role. Defaults NULL so that entity_create()
|
||||
* sets the weight to maximum + 1.
|
||||
*
|
||||
* @return string
|
||||
* Role ID of newly created role, or FALSE if role creation failed.
|
||||
*/
|
||||
protected function createRole(array $permissions, $rid = NULL, $name = NULL, $weight = NULL) {
|
||||
// Generate a random, lowercase machine name if none was passed.
|
||||
if (!isset($rid)) {
|
||||
$rid = strtolower($this->randomMachineName(8));
|
||||
}
|
||||
// Generate a random label.
|
||||
if (!isset($name)) {
|
||||
// In the role UI role names are trimmed and random string can start or
|
||||
// end with a space.
|
||||
$name = trim($this->randomString(8));
|
||||
}
|
||||
|
||||
// Check the all the permissions strings are valid.
|
||||
if (!$this->checkPermissions($permissions)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Create new role.
|
||||
$role = Role::create([
|
||||
'id' => $rid,
|
||||
'label' => $name,
|
||||
]);
|
||||
if (isset($weight)) {
|
||||
$role->set('weight', $weight);
|
||||
}
|
||||
$result = $role->save();
|
||||
|
||||
$this->assertIdentical($result, SAVED_NEW, SafeMarkup::format('Created role ID @rid with name @name.', [
|
||||
'@name' => var_export($role->label(), TRUE),
|
||||
'@rid' => var_export($role->id(), TRUE),
|
||||
]), 'Role');
|
||||
|
||||
if ($result === SAVED_NEW) {
|
||||
// Grant the specified permissions to the role, if any.
|
||||
if (!empty($permissions)) {
|
||||
$this->grantPermissions($role, $permissions);
|
||||
$assigned_permissions = Role::load($role->id())->getPermissions();
|
||||
$missing_permissions = array_diff($permissions, $assigned_permissions);
|
||||
if (!$missing_permissions) {
|
||||
$this->pass(SafeMarkup::format('Created permissions: @perms', ['@perms' => implode(', ', $permissions)]), 'Role');
|
||||
}
|
||||
else {
|
||||
$this->fail(SafeMarkup::format('Failed to create permissions: @perms', ['@perms' => implode(', ', $missing_permissions)]), 'Role');
|
||||
}
|
||||
}
|
||||
return $role->id();
|
||||
}
|
||||
else {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a given list of permission names is valid.
|
||||
*
|
||||
* @param array $permissions
|
||||
* The permission names to check.
|
||||
*
|
||||
* @return bool
|
||||
* TRUE if the permissions are valid, FALSE otherwise.
|
||||
*/
|
||||
protected function checkPermissions(array $permissions) {
|
||||
$available = array_keys(\Drupal::service('user.permissions')->getPermissions());
|
||||
$valid = TRUE;
|
||||
foreach ($permissions as $permission) {
|
||||
if (!in_array($permission, $available)) {
|
||||
$this->fail(SafeMarkup::format('Invalid permission %permission.', ['%permission' => $permission]), 'Role');
|
||||
$valid = FALSE;
|
||||
}
|
||||
}
|
||||
return $valid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Grant permissions to a user role.
|
||||
*
|
||||
* @param \Drupal\user\RoleInterface $role
|
||||
* The ID of a user role to alter.
|
||||
* @param array $permissions
|
||||
* (optional) A list of permission names to grant.
|
||||
*/
|
||||
protected function grantPermissions(RoleInterface $role, array $permissions) {
|
||||
foreach ($permissions as $permission) {
|
||||
$role->grantPermission($permission);
|
||||
}
|
||||
$role->trustData()->save();
|
||||
}
|
||||
use BaseUserCreationTrait;
|
||||
|
||||
}
|
||||
|
|
|
@ -7,8 +7,7 @@ use Drupal\Component\Serialization\Json;
|
|||
use Drupal\Component\Utility\Html;
|
||||
use Drupal\Component\Utility\NestedArray;
|
||||
use Drupal\Component\Utility\UrlHelper;
|
||||
use Drupal\Component\Utility\SafeMarkup;
|
||||
use Drupal\Core\Database\Database;
|
||||
use Drupal\Component\Render\FormattableMarkup;
|
||||
use Drupal\Core\EventSubscriber\AjaxResponseSubscriber;
|
||||
use Drupal\Core\EventSubscriber\MainContentViewSubscriber;
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
|
@ -18,8 +17,13 @@ use Drupal\Core\Test\FunctionalTestSetupTrait;
|
|||
use Drupal\Core\Url;
|
||||
use Drupal\system\Tests\Cache\AssertPageCacheContextsAndTagsTrait;
|
||||
use Drupal\Tests\EntityViewTrait;
|
||||
use Drupal\Tests\block\Traits\BlockCreationTrait as BaseBlockCreationTrait;
|
||||
use Drupal\Tests\Listeners\DeprecationListenerTrait;
|
||||
use Drupal\Tests\node\Traits\ContentTypeCreationTrait as BaseContentTypeCreationTrait;
|
||||
use Drupal\Tests\node\Traits\NodeCreationTrait as BaseNodeCreationTrait;
|
||||
use Drupal\Tests\Traits\Core\CronRunTrait;
|
||||
use Drupal\Tests\TestFileCreationTrait;
|
||||
use Drupal\Tests\user\Traits\UserCreationTrait as BaseUserCreationTrait;
|
||||
use Drupal\Tests\XdebugRequestTrait;
|
||||
use Zend\Diactoros\Uri;
|
||||
|
||||
|
@ -37,21 +41,21 @@ abstract class WebTestBase extends TestBase {
|
|||
compareFiles as drupalCompareFiles;
|
||||
}
|
||||
use AssertPageCacheContextsAndTagsTrait;
|
||||
use BlockCreationTrait {
|
||||
use BaseBlockCreationTrait {
|
||||
placeBlock as drupalPlaceBlock;
|
||||
}
|
||||
use ContentTypeCreationTrait {
|
||||
use BaseContentTypeCreationTrait {
|
||||
createContentType as drupalCreateContentType;
|
||||
}
|
||||
use CronRunTrait;
|
||||
use AssertMailTrait {
|
||||
getMails as drupalGetMails;
|
||||
}
|
||||
use NodeCreationTrait {
|
||||
use BaseNodeCreationTrait {
|
||||
getNodeByTitle as drupalGetNodeByTitle;
|
||||
createNode as drupalCreateNode;
|
||||
}
|
||||
use UserCreationTrait {
|
||||
use BaseUserCreationTrait {
|
||||
createUser as drupalCreateUser;
|
||||
createRole as drupalCreateRole;
|
||||
createAdminRole as drupalCreateAdminRole;
|
||||
|
@ -93,7 +97,7 @@ abstract class WebTestBase extends TestBase {
|
|||
/**
|
||||
* The headers of the page currently loaded in the internal browser.
|
||||
*
|
||||
* @var Array
|
||||
* @var array
|
||||
*/
|
||||
protected $headers;
|
||||
|
||||
|
@ -165,6 +169,8 @@ abstract class WebTestBase extends TestBase {
|
|||
|
||||
/**
|
||||
* The maximum number of redirects to follow when handling responses.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $maximumRedirects = 5;
|
||||
|
||||
|
@ -280,7 +286,7 @@ abstract class WebTestBase extends TestBase {
|
|||
|
||||
$edit = [
|
||||
'name' => $account->getUsername(),
|
||||
'pass' => $account->pass_raw
|
||||
'pass' => $account->pass_raw,
|
||||
];
|
||||
$this->drupalPostForm('user/login', $edit, t('Log in'));
|
||||
|
||||
|
@ -389,69 +395,6 @@ abstract class WebTestBase extends TestBase {
|
|||
$this->rebuildAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the parameters that will be used when Simpletest installs Drupal.
|
||||
*
|
||||
* @see install_drupal()
|
||||
* @see install_state_defaults()
|
||||
*
|
||||
* @return array
|
||||
* Array of parameters for use in install_drupal().
|
||||
*/
|
||||
protected function installParameters() {
|
||||
$connection_info = Database::getConnectionInfo();
|
||||
$driver = $connection_info['default']['driver'];
|
||||
$connection_info['default']['prefix'] = $connection_info['default']['prefix']['default'];
|
||||
unset($connection_info['default']['driver']);
|
||||
unset($connection_info['default']['namespace']);
|
||||
unset($connection_info['default']['pdo']);
|
||||
unset($connection_info['default']['init_commands']);
|
||||
// Remove database connection info that is not used by SQLite.
|
||||
if ($driver == 'sqlite') {
|
||||
unset($connection_info['default']['username']);
|
||||
unset($connection_info['default']['password']);
|
||||
unset($connection_info['default']['host']);
|
||||
unset($connection_info['default']['port']);
|
||||
}
|
||||
$parameters = [
|
||||
'interactive' => FALSE,
|
||||
'parameters' => [
|
||||
'profile' => $this->profile,
|
||||
'langcode' => 'en',
|
||||
],
|
||||
'forms' => [
|
||||
'install_settings_form' => [
|
||||
'driver' => $driver,
|
||||
$driver => $connection_info['default'],
|
||||
],
|
||||
'install_configure_form' => [
|
||||
'site_name' => 'Drupal',
|
||||
'site_mail' => 'simpletest@example.com',
|
||||
'account' => [
|
||||
'name' => $this->rootUser->name,
|
||||
'mail' => $this->rootUser->getEmail(),
|
||||
'pass' => [
|
||||
'pass1' => $this->rootUser->pass_raw,
|
||||
'pass2' => $this->rootUser->pass_raw,
|
||||
],
|
||||
],
|
||||
// \Drupal\Core\Render\Element\Checkboxes::valueCallback() requires
|
||||
// NULL instead of FALSE values for programmatic form submissions to
|
||||
// disable a checkbox.
|
||||
'enable_update_status_module' => NULL,
|
||||
'enable_update_status_emails' => NULL,
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
// If we only have one db driver available, we cannot set the driver.
|
||||
include_once DRUPAL_ROOT . '/core/includes/install.inc';
|
||||
if (count($this->getDatabaseTypes()) == 1) {
|
||||
unset($parameters['forms']['install_settings_form']['driver']);
|
||||
}
|
||||
return $parameters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Preserve the original batch, and instantiate the test batch.
|
||||
*/
|
||||
|
@ -479,21 +422,6 @@ abstract class WebTestBase extends TestBase {
|
|||
$batch = $this->originalBatch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all supported database driver installer objects.
|
||||
*
|
||||
* This wraps drupal_get_database_types() for use without a current container.
|
||||
*
|
||||
* @return \Drupal\Core\Database\Install\Tasks[]
|
||||
* An array of available database driver installer objects.
|
||||
*/
|
||||
protected function getDatabaseTypes() {
|
||||
\Drupal::setContainer($this->originalContainer);
|
||||
$database_types = drupal_get_database_types();
|
||||
\Drupal::unsetContainer();
|
||||
return $database_types;
|
||||
}
|
||||
|
||||
/**
|
||||
* Queues custom translations to be written to settings.php.
|
||||
*
|
||||
|
@ -732,9 +660,9 @@ abstract class WebTestBase extends TestBase {
|
|||
'@method' => !empty($curl_options[CURLOPT_NOBODY]) ? 'HEAD' : (empty($curl_options[CURLOPT_POSTFIELDS]) ? 'GET' : 'POST'),
|
||||
'@url' => isset($original_url) ? $original_url : $url,
|
||||
'@status' => $status,
|
||||
'@length' => format_size(strlen($this->getRawContent()))
|
||||
'@length' => format_size(strlen($this->getRawContent())),
|
||||
];
|
||||
$message = SafeMarkup::format('@method @url returned @status (@length).', $message_vars);
|
||||
$message = new FormattableMarkup('@method @url returned @status (@length).', $message_vars);
|
||||
$this->assertTrue($this->getRawContent() !== FALSE, $message, 'Browser');
|
||||
return $this->getRawContent();
|
||||
}
|
||||
|
@ -765,9 +693,22 @@ abstract class WebTestBase extends TestBase {
|
|||
// generated by _drupal_log_error() in the exact form required
|
||||
// by \Drupal\simpletest\WebTestBase::error().
|
||||
if (preg_match('/^X-Drupal-Assertion-[0-9]+: (.*)$/', $header, $matches)) {
|
||||
// Call \Drupal\simpletest\WebTestBase::error() with the parameters from
|
||||
// the header.
|
||||
call_user_func_array([&$this, 'error'], unserialize(urldecode($matches[1])));
|
||||
$parameters = unserialize(urldecode($matches[1]));
|
||||
// Handle deprecation notices triggered by system under test.
|
||||
if ($parameters[1] === 'User deprecated function') {
|
||||
if (getenv('SYMFONY_DEPRECATIONS_HELPER') !== 'disabled') {
|
||||
$message = (string) $parameters[0];
|
||||
$test_info = TestDiscovery::getTestInfo(get_called_class());
|
||||
if ($test_info['group'] !== 'legacy' && !in_array($message, DeprecationListenerTrait::getSkippedDeprecations())) {
|
||||
call_user_func_array([&$this, 'error'], $parameters);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Call \Drupal\simpletest\WebTestBase::error() with the parameters from
|
||||
// the header.
|
||||
call_user_func_array([&$this, 'error'], $parameters);
|
||||
}
|
||||
}
|
||||
|
||||
// Save cookies.
|
||||
|
@ -892,7 +833,7 @@ abstract class WebTestBase extends TestBase {
|
|||
* The result of the request.
|
||||
*/
|
||||
protected function drupalGetWithFormat($path, $format, array $options = [], array $headers = []) {
|
||||
$options += ['query' => ['_format' => $format]];
|
||||
$options = array_merge_recursive(['query' => ['_format' => $format]], $options);
|
||||
return $this->drupalGet($path, $options, $headers);
|
||||
}
|
||||
|
||||
|
@ -1113,7 +1054,7 @@ abstract class WebTestBase extends TestBase {
|
|||
}
|
||||
// We have not found a form which contained all fields of $edit.
|
||||
foreach ($edit as $name => $value) {
|
||||
$this->fail(SafeMarkup::format('Failed to set field @name to @value', ['@name' => $name, '@value' => $value]));
|
||||
$this->fail(new FormattableMarkup('Failed to set field @name to @value', ['@name' => $name, '@value' => $value]));
|
||||
}
|
||||
if (!$ajax && isset($submit)) {
|
||||
$this->assertTrue($submit_matches, format_string('Found the @submit button', ['@submit' => $submit]));
|
||||
|
@ -1785,10 +1726,10 @@ abstract class WebTestBase extends TestBase {
|
|||
$urls = $this->xpath($pattern, [':label' => $label]);
|
||||
if (isset($urls[$index])) {
|
||||
$url_target = $this->getAbsoluteUrl($urls[$index]['href']);
|
||||
$this->pass(SafeMarkup::format('Clicked link %label (@url_target) from @url_before', ['%label' => $label, '@url_target' => $url_target, '@url_before' => $url_before]), 'Browser');
|
||||
$this->pass(new FormattableMarkup('Clicked link %label (@url_target) from @url_before', ['%label' => $label, '@url_target' => $url_target, '@url_before' => $url_before]), 'Browser');
|
||||
return $this->drupalGet($url_target);
|
||||
}
|
||||
$this->fail(SafeMarkup::format('Link %label does not exist on @url_before', ['%label' => $label, '@url_before' => $url_before]), 'Browser');
|
||||
$this->fail(new FormattableMarkup('Link %label does not exist on @url_before', ['%label' => $label, '@url_before' => $url_before]), 'Browser');
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
@ -1964,7 +1905,7 @@ abstract class WebTestBase extends TestBase {
|
|||
* (optional) Any additional options to pass for $path to the url generator.
|
||||
* @param $message
|
||||
* (optional) A message to display with the assertion. Do not translate
|
||||
* messages: use \Drupal\Component\Utility\SafeMarkup::format() to embed
|
||||
* messages: use \Drupal\Component\Render\FormattableMarkup to embed
|
||||
* variables in the message text, not t(). If left blank, a default message
|
||||
* will be displayed.
|
||||
* @param $group
|
||||
|
@ -1991,7 +1932,7 @@ abstract class WebTestBase extends TestBase {
|
|||
}
|
||||
$url = $url_obj->setAbsolute()->toString();
|
||||
if (!$message) {
|
||||
$message = SafeMarkup::format('Expected @url matches current URL (@current_url).', [
|
||||
$message = new FormattableMarkup('Expected @url matches current URL (@current_url).', [
|
||||
'@url' => var_export($url, TRUE),
|
||||
'@current_url' => $this->getUrl(),
|
||||
]);
|
||||
|
@ -2011,7 +1952,7 @@ abstract class WebTestBase extends TestBase {
|
|||
* of all codes see http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html.
|
||||
* @param $message
|
||||
* (optional) A message to display with the assertion. Do not translate
|
||||
* messages: use \Drupal\Component\Utility\SafeMarkup::format() to embed
|
||||
* messages: use \Drupal\Component\Render\FormattableMarkup to embed
|
||||
* variables in the message text, not t(). If left blank, a default message
|
||||
* will be displayed.
|
||||
* @param $group
|
||||
|
@ -2026,7 +1967,7 @@ abstract class WebTestBase extends TestBase {
|
|||
protected function assertResponse($code, $message = '', $group = 'Browser') {
|
||||
$curl_code = curl_getinfo($this->curlHandle, CURLINFO_HTTP_CODE);
|
||||
$match = is_array($code) ? in_array($curl_code, $code) : $curl_code == $code;
|
||||
return $this->assertTrue($match, $message ? $message : SafeMarkup::format('HTTP response expected @code, actual @curl_code', ['@code' => $code, '@curl_code' => $curl_code]), $group);
|
||||
return $this->assertTrue($match, $message ? $message : new FormattableMarkup('HTTP response expected @code, actual @curl_code', ['@code' => $code, '@curl_code' => $curl_code]), $group);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2037,7 +1978,7 @@ abstract class WebTestBase extends TestBase {
|
|||
* of all codes see http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html.
|
||||
* @param $message
|
||||
* (optional) A message to display with the assertion. Do not translate
|
||||
* messages: use \Drupal\Component\Utility\SafeMarkup::format() to embed
|
||||
* messages: use \Drupal\Component\Render\FormattableMarkup to embed
|
||||
* variables in the message text, not t(). If left blank, a default message
|
||||
* will be displayed.
|
||||
* @param $group
|
||||
|
@ -2052,7 +1993,7 @@ abstract class WebTestBase extends TestBase {
|
|||
protected function assertNoResponse($code, $message = '', $group = 'Browser') {
|
||||
$curl_code = curl_getinfo($this->curlHandle, CURLINFO_HTTP_CODE);
|
||||
$match = is_array($code) ? in_array($curl_code, $code) : $curl_code == $code;
|
||||
return $this->assertFalse($match, $message ? $message : SafeMarkup::format('HTTP response not expected @code, actual @curl_code', ['@code' => $code, '@curl_code' => $curl_code]), $group);
|
||||
return $this->assertFalse($match, $message ? $message : new FormattableMarkup('HTTP response not expected @code, actual @curl_code', ['@code' => $code, '@curl_code' => $curl_code]), $group);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
namespace Drupal\Tests\simpletest\Unit;
|
||||
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
||||
/**
|
||||
* This test crashes PHP.
|
||||
*
|
||||
|
@ -11,7 +13,7 @@ namespace Drupal\Tests\simpletest\Unit;
|
|||
*
|
||||
* @see \Drupal\Tests\simpletest\Unit\SimpletestPhpunitRunCommandTest::testSimpletestPhpUnitRunCommand()
|
||||
*/
|
||||
class SimpletestPhpunitRunCommandTestWillDie extends \PHPUnit_Framework_TestCase {
|
||||
class SimpletestPhpunitRunCommandTestWillDie extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* Performs the status specified by SimpletestPhpunitRunCommandTestWillDie.
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
name: 'Simpletest deprecation test'
|
||||
type: module
|
||||
description: 'Support module for Simpletest deprecation tests.'
|
||||
package: Testing
|
||||
version: VERSION
|
||||
core: 8.x
|
|
@ -0,0 +1,15 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Mock module for testing simpletest.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_simpletest_alter().
|
||||
*
|
||||
* This hook is deprecated and should trigger a deprecation error when invoked.
|
||||
*/
|
||||
function simpletest_deprecation_test_simpletest_alter(&$groups) {
|
||||
// No-op.
|
||||
}
|
|
@ -5,4 +5,4 @@ package: Testing
|
|||
version: VERSION
|
||||
core: 8.x
|
||||
dependencies:
|
||||
- entity_test
|
||||
- drupal:entity_test
|
||||
|
|
|
@ -15,6 +15,7 @@ class MailCaptureTest extends BrowserTestBase {
|
|||
use AssertMailTrait {
|
||||
getMails as drupalGetMails;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test to see if the wrapper function is executed correctly.
|
||||
*/
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\simpletest\Functional;
|
||||
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* This test should not load since it requires a module that is not found.
|
||||
*
|
||||
* @group simpletest
|
||||
* @dependencies simpletest_missing_module
|
||||
*/
|
||||
class MissingDependentModuleUnitTest extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* Ensure that this test will not be loaded despite its dependency.
|
||||
*/
|
||||
public function testFail() {
|
||||
$this->fail('Running test with missing required module.');
|
||||
}
|
||||
|
||||
}
|
|
@ -8,7 +8,7 @@ use Drupal\Tests\BrowserTestBase;
|
|||
* Verifies that tests in other installation profiles are found.
|
||||
*
|
||||
* @group simpletest
|
||||
* @see SimpleTestInstallationProfileModuleTestsTestCase
|
||||
* @see \Drupal\simpletest\Tests\InstallationProfileModuleTestsTest
|
||||
*/
|
||||
class OtherInstallationProfileTestsTest extends BrowserTestBase {
|
||||
|
||||
|
@ -28,8 +28,10 @@ class OtherInstallationProfileTestsTest extends BrowserTestBase {
|
|||
* The Standard profile contains \Drupal\standard\Tests\StandardTest, which
|
||||
* should be found.
|
||||
*
|
||||
* @var string
|
||||
*
|
||||
* @see \Drupal\simpletest\Tests\InstallationProfileModuleTestsTest
|
||||
* @see \Drupal\drupal_system_listing_compatible_test\Tests\SystemListingCompatibleTest
|
||||
* @see \Drupal\Tests\drupal_system_listing_compatible_test\Kernel\SystemListingCrossProfileCompatibleTest
|
||||
*/
|
||||
protected $profile = 'minimal';
|
||||
|
||||
|
@ -58,7 +60,7 @@ class OtherInstallationProfileTestsTest extends BrowserTestBase {
|
|||
|
||||
// Assert the existence of a test for a module in a different installation
|
||||
// profile than the current.
|
||||
$this->assertText('Drupal\drupal_system_listing_compatible_test\Tests\SystemListingCompatibleTest');
|
||||
$this->assertText('Drupal\Tests\drupal_system_listing_compatible_test\Kernel\SystemListingCrossProfileCompatibleTest');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,65 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\simpletest\FunctionalJavascript;
|
||||
|
||||
use Drupal\FunctionalJavascriptTests\JavascriptTestBase;
|
||||
|
||||
/**
|
||||
* Tests if we can execute JavaScript in the browser.
|
||||
*
|
||||
* @group javascript
|
||||
*/
|
||||
class BrowserWithJavascriptTest extends JavascriptTestBase {
|
||||
|
||||
public function testJavascript() {
|
||||
$this->drupalGet('<front>');
|
||||
$session = $this->getSession();
|
||||
|
||||
$session->resizeWindow(400, 300);
|
||||
$javascript = <<<JS
|
||||
(function(){
|
||||
var w = window,
|
||||
d = document,
|
||||
e = d.documentElement,
|
||||
g = d.getElementsByTagName('body')[0],
|
||||
x = w.innerWidth || e.clientWidth || g.clientWidth,
|
||||
y = w.innerHeight || e.clientHeight|| g.clientHeight;
|
||||
return x == 400 && y == 300;
|
||||
}());
|
||||
JS;
|
||||
$this->assertJsCondition($javascript);
|
||||
}
|
||||
|
||||
public function testAssertJsCondition() {
|
||||
$this->drupalGet('<front>');
|
||||
$session = $this->getSession();
|
||||
|
||||
$session->resizeWindow(500, 300);
|
||||
$javascript = <<<JS
|
||||
(function(){
|
||||
var w = window,
|
||||
d = document,
|
||||
e = d.documentElement,
|
||||
g = d.getElementsByTagName('body')[0],
|
||||
x = w.innerWidth || e.clientWidth || g.clientWidth,
|
||||
y = w.innerHeight || e.clientHeight|| g.clientHeight;
|
||||
return x == 400 && y == 300;
|
||||
}());
|
||||
JS;
|
||||
|
||||
// We expected the following assertion to fail because the window has been
|
||||
// re-sized to have a width of 500 not 400.
|
||||
$this->setExpectedException(\PHPUnit_Framework_AssertionFailedError::class);
|
||||
$this->assertJsCondition($javascript, 100);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests creating screenshots.
|
||||
*/
|
||||
public function testCreateScreenshot() {
|
||||
$this->drupalGet('<front>');
|
||||
$this->createScreenshot('public://screenshot.jpg');
|
||||
$this->assertFileExists('public://screenshot.jpg');
|
||||
}
|
||||
|
||||
}
|
|
@ -1,46 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\simpletest\FunctionalJavascript;
|
||||
|
||||
use Drupal\FunctionalJavascriptTests\JavascriptTestBase;
|
||||
|
||||
/**
|
||||
* Tests Drupal settings retrieval in JavascriptTestBase tests.
|
||||
*
|
||||
* @group javascript
|
||||
*/
|
||||
class JavascriptGetDrupalSettingsTest extends JavascriptTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $modules = ['test_page_test'];
|
||||
|
||||
/**
|
||||
* Tests retrieval of Drupal settings.
|
||||
*
|
||||
* @see \Drupal\FunctionalJavascriptTests\JavascriptTestBase::getDrupalSettings()
|
||||
*/
|
||||
public function testGetDrupalSettings() {
|
||||
$this->drupalLogin($this->drupalCreateUser());
|
||||
$this->drupalGet('test-page');
|
||||
|
||||
// Check that we can read the JS settings.
|
||||
$js_settings = $this->getDrupalSettings();
|
||||
$this->assertSame('azAZ09();.,\\\/-_{}', $js_settings['test-setting']);
|
||||
|
||||
// Dynamically change the setting using Javascript.
|
||||
$script = <<<EndOfScript
|
||||
(function () {
|
||||
drupalSettings['test-setting'] = 'foo';
|
||||
})();
|
||||
EndOfScript;
|
||||
|
||||
$this->getSession()->evaluateScript($script);
|
||||
|
||||
// Check that the setting has been changed.
|
||||
$js_settings = $this->getDrupalSettings();
|
||||
$this->assertSame('foo', $js_settings['test-setting']);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\simpletest\Kernel\Cache\Context;
|
||||
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
use Drupal\simpletest\Cache\Context\TestDiscoveryCacheContext;
|
||||
use Drupal\simpletest\TestDiscovery;
|
||||
|
||||
/**
|
||||
* @group simpletest
|
||||
*/
|
||||
class TestDiscoveryCacheContextTest extends KernelTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['simpletest'];
|
||||
|
||||
/**
|
||||
* Tests that test context hashes are unique.
|
||||
*/
|
||||
public function testContext() {
|
||||
// Mock test discovery.
|
||||
$discovery = $this->getMockBuilder(TestDiscovery::class)
|
||||
->setMethods(['getTestClasses'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
// Set getTestClasses() to return different results on subsequent calls.
|
||||
// This emulates changed tests in the filesystem.
|
||||
$discovery->expects($this->any())
|
||||
->method('getTestClasses')
|
||||
->willReturnOnConsecutiveCalls(
|
||||
['group1' => ['Test']],
|
||||
['group2' => ['Test2']]
|
||||
);
|
||||
|
||||
// Make our cache context object.
|
||||
$cache_context = new TestDiscoveryCacheContext($discovery, $this->container->get('private_key'));
|
||||
|
||||
// Generate a context hash.
|
||||
$context_hash = $cache_context->getContext();
|
||||
|
||||
// Since the context stores the hash, we have to reset it.
|
||||
$hash_ref = new \ReflectionProperty($cache_context, 'hash');
|
||||
$hash_ref->setAccessible(TRUE);
|
||||
$hash_ref->setValue($cache_context, NULL);
|
||||
|
||||
// And then assert that we did not generate the same hash for different
|
||||
// content.
|
||||
$this->assertNotSame($context_hash, $cache_context->getContext());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\simpletest\Kernel;
|
||||
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
|
||||
/**
|
||||
* Verify deprecation of simpletest.
|
||||
*
|
||||
* @group simpletest
|
||||
* @group legacy
|
||||
*/
|
||||
class SimpletestDeprecationTest extends KernelTestBase {
|
||||
|
||||
public static $modules = ['simpletest'];
|
||||
|
||||
/**
|
||||
* @expectedDeprecation The simpletest_phpunit_configuration_filepath function is deprecated since version 8.4.x and will be removed in 9.0.0.
|
||||
* @expectedDeprecation The simpletest_test_get_all function is deprecated in version 8.3.x and will be removed in 9.0.0. Use \Drupal::service('test_discovery')->getTestClasses($extension, $types) instead.
|
||||
* @expectedDeprecation The simpletest_classloader_register function is deprecated in version 8.3.x and will be removed in 9.0.0. Use \Drupal::service('test_discovery')->registerTestNamespaces() instead.
|
||||
*/
|
||||
public function testDeprecatedFunctions() {
|
||||
$this->assertNotEmpty(simpletest_phpunit_configuration_filepath());
|
||||
$this->assertNotEmpty(simpletest_test_get_all());
|
||||
simpletest_classloader_register();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\simpletest\Kernel;
|
||||
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
|
||||
/**
|
||||
* @group simpletest
|
||||
* @group legacy
|
||||
*
|
||||
* @coversDefaultClass \Drupal\simpletest\TestDiscovery
|
||||
*/
|
||||
class TestDiscoveryDeprecationTest extends KernelTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['simpletest', 'simpletest_deprecation_test'];
|
||||
|
||||
/**
|
||||
* @expectedDeprecation The deprecated alter hook hook_simpletest_alter() is implemented in these functions: simpletest_deprecation_test_simpletest_alter. Convert your test to a PHPUnit-based one and implement test listeners. See: https://www.drupal.org/node/2939892
|
||||
* @covers ::getTestClasses
|
||||
*/
|
||||
public function testHookSimpletestAlter() {
|
||||
// The simpletest_test module implements hook_simpletest_alter(), which
|
||||
// should trigger a deprecation error during getTestClasses().
|
||||
$this->assertNotEmpty(
|
||||
$this->container->get('test_discovery')->getTestClasses()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,49 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\simpletest\Unit\AssertHelperTraitTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\simpletest\Unit;
|
||||
|
||||
use Drupal\Core\Render\Markup;
|
||||
use Drupal\simpletest\AssertHelperTrait;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\simpletest\AssertHelperTrait
|
||||
* @group simpletest
|
||||
*/
|
||||
class AssertHelperTraitTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* @covers ::castSafeStrings
|
||||
* @dataProvider providerCastSafeStrings
|
||||
*/
|
||||
public function testCastSafeStrings($expected, $value) {
|
||||
$class = new AssertHelperTestClass();
|
||||
$this->assertSame($expected, $class->testMethod($value));
|
||||
}
|
||||
|
||||
public function providerCastSafeStrings() {
|
||||
$safe_string = Markup::create('test safe string');
|
||||
return [
|
||||
['test simple string', 'test simple string'],
|
||||
[['test simple array', 'test simple array'], ['test simple array', 'test simple array']],
|
||||
['test safe string', $safe_string],
|
||||
[['test safe string', 'test safe string'], [$safe_string, $safe_string]],
|
||||
[['test safe string', 'mixed array', 'test safe string'], [$safe_string, 'mixed array', $safe_string]],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class AssertHelperTestClass {
|
||||
use AssertHelperTrait;
|
||||
|
||||
public function testMethod($value) {
|
||||
return $this->castSafeStrings($value);
|
||||
}
|
||||
|
||||
}
|
|
@ -2,17 +2,23 @@
|
|||
|
||||
namespace Drupal\Tests\simpletest\Unit;
|
||||
|
||||
use Drupal\Core\Database\Database;
|
||||
use Drupal\Core\DependencyInjection\ContainerBuilder;
|
||||
use Drupal\Core\File\FileSystemInterface;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Tests simpletest_run_phpunit_tests() handles PHPunit fatals correctly.
|
||||
*
|
||||
* We don't extend Drupal\Tests\UnitTestCase here because its $root property is
|
||||
* not static and we need it to be static here.
|
||||
*
|
||||
* @group simpletest
|
||||
*
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
*/
|
||||
class SimpletestPhpunitRunCommandTest extends \PHPUnit_Framework_TestCase {
|
||||
class SimpletestPhpunitRunCommandTest extends TestCase {
|
||||
|
||||
/**
|
||||
* Path to the app root.
|
||||
|
@ -81,6 +87,18 @@ class SimpletestPhpunitRunCommandTest extends \PHPUnit_Framework_TestCase {
|
|||
* @dataProvider provideStatusCodes
|
||||
*/
|
||||
public function testSimpletestPhpUnitRunCommand($status, $label) {
|
||||
// Add a default database connection in order for
|
||||
// Database::getConnectionInfoAsUrl() to return valid information.
|
||||
Database::addConnectionInfo('default', 'default', [
|
||||
'driver' => 'mysql',
|
||||
'username' => 'test_user',
|
||||
'password' => 'test_pass',
|
||||
'host' => 'test_host',
|
||||
'database' => 'test_database',
|
||||
'port' => 3306,
|
||||
'namespace' => 'Drupal\Core\Database\Driver\mysql',
|
||||
]
|
||||
);
|
||||
$test_id = basename(tempnam(sys_get_temp_dir(), 'xxx'));
|
||||
putenv('SimpletestPhpunitRunCommandTestWillDie=' . $status);
|
||||
$ret = simpletest_run_phpunit_tests($test_id, [SimpletestPhpunitRunCommandTestWillDie::class]);
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\simpletest\Unit\TestInfoParsingTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\simpletest\Unit;
|
||||
|
||||
use Composer\Autoload\ClassLoader;
|
||||
|
@ -19,7 +14,7 @@ use org\bovigo\vfs\vfsStream;
|
|||
* @coversDefaultClass \Drupal\simpletest\TestDiscovery
|
||||
* @group simpletest
|
||||
*/
|
||||
class TestInfoParsingTest extends UnitTestCase {
|
||||
class TestDiscoveryTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* @covers ::getTestInfo
|
||||
|
@ -35,13 +30,13 @@ class TestInfoParsingTest extends UnitTestCase {
|
|||
$tests[] = [
|
||||
// Expected result.
|
||||
[
|
||||
'name' => 'Drupal\Tests\simpletest\Unit\TestInfoParsingTest',
|
||||
'name' => 'Drupal\Tests\simpletest\Unit\TestDiscoveryTest',
|
||||
'group' => 'simpletest',
|
||||
'description' => 'Tests \Drupal\simpletest\TestDiscovery.',
|
||||
'type' => 'PHPUnit-Unit',
|
||||
],
|
||||
// Classname.
|
||||
'Drupal\Tests\simpletest\Unit\TestInfoParsingTest',
|
||||
'Drupal\Tests\simpletest\Unit\TestDiscoveryTest',
|
||||
];
|
||||
|
||||
// A core unit test.
|
||||
|
@ -286,6 +281,9 @@ EOF;
|
|||
],
|
||||
'Kernel' => [
|
||||
'KernelExampleTest3.php' => str_replace(['FunctionalExampleTest', '@group example'], ['KernelExampleTest3', '@group example2'], $test_file),
|
||||
'KernelExampleTestBase.php' => str_replace(['FunctionalExampleTest', '@group example'], ['KernelExampleTestBase', '@group example2'], $test_file),
|
||||
'KernelExampleTrait.php' => str_replace(['FunctionalExampleTest', '@group example'], ['KernelExampleTrait', '@group example2'], $test_file),
|
||||
'KernelExampleInterface.php' => str_replace(['FunctionalExampleTest', '@group example'], ['KernelExampleInterface', '@group example2'], $test_file),
|
||||
],
|
||||
],
|
||||
],
|
||||
|
@ -353,8 +351,7 @@ EOF;
|
|||
$result = $test_discovery->getTestClasses(NULL, ['PHPUnit-Kernel']);
|
||||
$this->assertCount(2, $result);
|
||||
$this->assertEquals([
|
||||
'example' => [
|
||||
],
|
||||
'example' => [],
|
||||
'example2' => [
|
||||
'Drupal\Tests\test_module\Kernel\KernelExampleTest3' => [
|
||||
'name' => 'Drupal\Tests\test_module\Kernel\KernelExampleTest3',
|
||||
|
@ -366,26 +363,6 @@ EOF;
|
|||
], $result);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class TestTestDiscovery extends TestDiscovery {
|
||||
|
||||
/**
|
||||
* @var \Drupal\Core\Extension\Extension[]
|
||||
*/
|
||||
protected $extensions = [];
|
||||
|
||||
public function setExtensions(array $extensions) {
|
||||
$this->extensions = $extensions;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getExtensions() {
|
||||
return $this->extensions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getPhpunitTestSuite
|
||||
* @dataProvider providerTestGetPhpunitTestSuite
|
||||
|
@ -411,6 +388,56 @@ class TestTestDiscovery extends TestDiscovery {
|
|||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure that classes are not reflected when the docblock is empty.
|
||||
*
|
||||
* @covers ::getTestInfo
|
||||
*/
|
||||
public function testGetTestInfoEmptyDocblock() {
|
||||
// If getTestInfo() performed reflection, it won't be able to find the
|
||||
// class we asked it to analyze, so it will throw a ReflectionException.
|
||||
// We want to make sure it didn't do that, because we already did some
|
||||
// analysis and already have an empty docblock. getTestInfo() will throw
|
||||
// MissingGroupException because the annotation is empty.
|
||||
$this->setExpectedException(MissingGroupException::class);
|
||||
TestDiscovery::getTestInfo('Drupal\Tests\simpletest\ThisTestDoesNotExistTest', '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure TestDiscovery::scanDirectory() ignores certain abstract file types.
|
||||
*
|
||||
* @covers ::scanDirectory
|
||||
*/
|
||||
public function testScanDirectoryNoAbstract() {
|
||||
$this->setupVfsWithTestClasses();
|
||||
$files = TestDiscovery::scanDirectory('Drupal\\Tests\\test_module\\Kernel\\', vfsStream::url('drupal/modules/test_module/tests/src/Kernel'));
|
||||
$this->assertNotEmpty($files);
|
||||
$this->assertArrayNotHasKey('Drupal\Tests\test_module\Kernel\KernelExampleTestBase', $files);
|
||||
$this->assertArrayNotHasKey('Drupal\Tests\test_module\Kernel\KernelExampleTrait', $files);
|
||||
$this->assertArrayNotHasKey('Drupal\Tests\test_module\Kernel\KernelExampleInterface', $files);
|
||||
$this->assertArrayHasKey('Drupal\Tests\test_module\Kernel\KernelExampleTest3', $files);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class TestTestDiscovery extends TestDiscovery {
|
||||
|
||||
/**
|
||||
* @var \Drupal\Core\Extension\Extension[]
|
||||
*/
|
||||
protected $extensions = [];
|
||||
|
||||
public function setExtensions(array $extensions) {
|
||||
$this->extensions = $extensions;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getExtensions() {
|
||||
return $this->extensions;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace Drupal\simpletest\Tests;
|
Reference in a new issue