diff --git a/composer.lock b/composer.lock index 99ea68c4e0cb4b511a74a9b33b60578db2b8ecb8..78c426b6b48b2576319a8a62cb21c59bf2e53e7d 100644 --- a/composer.lock +++ b/composer.lock @@ -602,7 +602,6 @@ "drupal/settings_tray": "self.version", "drupal/seven": "self.version", "drupal/shortcut": "self.version", - "drupal/simpletest": "self.version", "drupal/standard": "self.version", "drupal/stark": "self.version", "drupal/statistics": "self.version", @@ -4099,9 +4098,6 @@ "ext-zip": "Enabling the zip extension allows you to unzip archives", "ext-zlib": "Allow gzip compression of HTTP requests" }, - "bin": [ - "bin/composer" - ], "type": "library", "extra": { "branch-alias": { diff --git a/core/composer.json b/core/composer.json index 342aebcc7ff1d2b6c36fab3586eaf7bedeed0521..c315e9cf1163ea8daa7a6aa928068c2fd3299a97 100644 --- a/core/composer.json +++ b/core/composer.json @@ -148,7 +148,6 @@ "drupal/settings_tray": "self.version", "drupal/seven": "self.version", "drupal/shortcut": "self.version", - "drupal/simpletest": "self.version", "drupal/standard": "self.version", "drupal/stark": "self.version", "drupal/statistics": "self.version", diff --git a/core/lib/Drupal/Core/Test/TestRunnerKernel.php b/core/lib/Drupal/Core/Test/TestRunnerKernel.php index 963a6c4e4d8628fc2fbba46e157e4eae9f72969d..95d69464c1bc9b6b76fa73affe2020378d090f00 100644 --- a/core/lib/Drupal/Core/Test/TestRunnerKernel.php +++ b/core/lib/Drupal/Core/Test/TestRunnerKernel.php @@ -4,6 +4,7 @@ use Drupal\Core\DrupalKernel; use Drupal\Core\Extension\Extension; +use Drupal\Core\Extension\ExtensionDiscovery; use Drupal\Core\Site\Settings; use Symfony\Component\HttpFoundation\Request; @@ -35,12 +36,17 @@ public function __construct($environment, $class_loader, $allow_dumping = FALSE, // DateFormatter::formatInterval() cause a plugin not found exception. $this->moduleList = [ 'system' => 0, - 'simpletest' => 0, ]; $this->moduleData = [ 'system' => new Extension($this->root, 'module', 'core/modules/system/system.info.yml', 'system.module'), - 'simpletest' => new Extension($this->root, 'module', 'core/modules/simpletest/simpletest.info.yml', 'simpletest.module'), ]; + // In order to support Simpletest in Drupal 9 conditionally include the + // module. + $extensions = (new ExtensionDiscovery($this->root, FALSE, [], 'ignore_site_path_does_not_exist'))->scan('module', FALSE); + if (isset($extensions['simpletest'])) { + $this->moduleList['simpletest'] = 0; + $this->moduleData['simpletest'] = $extensions['simpletest']; + } } /** diff --git a/core/modules/migrate_drupal/tests/src/Kernel/StateFileExists.php b/core/modules/migrate_drupal/tests/src/Kernel/StateFileExists.php index fd2e20a0ac871c9901023e0f161c5c02eb71a2e0..ba078248e70c5bce2cd51d212d41e76a1fe859de 100644 --- a/core/modules/migrate_drupal/tests/src/Kernel/StateFileExists.php +++ b/core/modules/migrate_drupal/tests/src/Kernel/StateFileExists.php @@ -72,7 +72,6 @@ class StateFileExists extends MigrateDrupalTestBase { 'rdf', 'search', 'shortcut', - 'simpletest', 'statistics', 'syslog', 'system', diff --git a/core/modules/simpletest/config/install/simpletest.settings.yml b/core/modules/simpletest/config/install/simpletest.settings.yml deleted file mode 100644 index a2254cc06369483307700a99fec6e317cd594385..0000000000000000000000000000000000000000 --- a/core/modules/simpletest/config/install/simpletest.settings.yml +++ /dev/null @@ -1,6 +0,0 @@ -clear_results: true -httpauth: - method: 1 - password: '' - username: '' -verbose: true diff --git a/core/modules/simpletest/config/schema/simpletest.schema.yml b/core/modules/simpletest/config/schema/simpletest.schema.yml deleted file mode 100644 index 827ef560126b80acf19e841569350273fd7c3c76..0000000000000000000000000000000000000000 --- a/core/modules/simpletest/config/schema/simpletest.schema.yml +++ /dev/null @@ -1,25 +0,0 @@ -# Schema for the configuration files of the Simpletest module. - -simpletest.settings: - type: config_object - label: 'Testing' - mapping: - clear_results: - type: boolean - label: 'Clear results after each complete test suite run' - verbose: - type: boolean - label: 'Provide verbose information when running tests' - httpauth: - type: mapping - label: 'HTTP authentication' - mapping: - method: - type: integer - label: 'Method' - username: - type: string - label: 'Username' - password: - type: string - label: 'Password' diff --git a/core/modules/simpletest/css/simpletest.module.css b/core/modules/simpletest/css/simpletest.module.css deleted file mode 100644 index f7a932e2864eaf7d71dd236efafe71079a19a9fc..0000000000000000000000000000000000000000 --- a/core/modules/simpletest/css/simpletest.module.css +++ /dev/null @@ -1,93 +0,0 @@ - -/* Test Table */ -#simpletest-form-table th.select-all { - width: 1em; -} -th.simpletest-test-label { - width: 40%; -} - -.simpletest-image { - display: inline-block; - width: 1em; - cursor: pointer; -} -.simpletest-group-label label { - display: inline; - font-weight: bold; -} -.simpletest-test-label label { - margin-left: 1em; /* LTR */ -} -.simpletest-test-description .description { - margin: 0; -} -#simpletest-form-table tr td { - color: #494949; - background-color: white; -} -#simpletest-form-table tr.simpletest-group td { - color: #494949; - background-color: #edf5fa; -} - -table#simpletest-form-table tr.simpletest-group label { - display: inline; -} - -div.message > div.item-list { - font-weight: normal; -} - -div.simpletest-pass { - color: #33a333; -} -.simpletest-fail { - color: #981010; -} - -tr.simpletest-pass, -tr.simpletest-pass.odd { - background-color: #b6ffb6; -} -tr.simpletest-pass.even { - background-color: #9bff9b; -} -tr.simpletest-fail, -tr.simpletest-fail.odd { - background-color: #ffc9c9; -} -tr.simpletest-fail.even { - background-color: #ffacac; -} -tr.simpletest-exception, -tr.simpletest-exception.odd { - background-color: #f4ea71; -} -tr.simpletest-exception.even { - background-color: #f5e742; -} -tr.simpletest-debug, -tr.simpletest-debug.odd { - background-color: #eee; -} -tr.simpletest-debug.even { - background-color: #fff; -} - -a.simpletest-collapse { - position: absolute; - top: -99em; - width: 0; - height: 0; -} -a.simpletest-collapse:focus, -a.simpletest-collapse:hover { - position: relative; - z-index: 1000; - top: 0; - overflow: visible; - width: auto; - height: auto; - font-size: 80%; -} diff --git a/core/modules/simpletest/migrations/d6_simpletest_settings.yml b/core/modules/simpletest/migrations/d6_simpletest_settings.yml deleted file mode 100644 index 9fd70492cb8dc81a0f29be09bb9136c70da10508..0000000000000000000000000000000000000000 --- a/core/modules/simpletest/migrations/d6_simpletest_settings.yml +++ /dev/null @@ -1,23 +0,0 @@ -id: d6_simpletest_settings -label: Simpletest configuration -migration_tags: - - Drupal 6 - - Configuration -source: - plugin: variable - variables: - - simpletest_clear_results - - simpletest_httpauth_method - - simpletest_httpauth_password - - simpletest_httpauth_username - - simpletest_verbose - source_module: simpletest -process: - clear_results: simpletest_clear_results - 'httpauth/method': simpletest_httpauth_method - 'httpauth/password': simpletest_httpauth_password - 'httpauth/username': simpletest_httpauth_username - verbose: simpletest_verbose -destination: - plugin: config - config_name: simpletest.settings diff --git a/core/modules/simpletest/migrations/d7_simpletest_settings.yml b/core/modules/simpletest/migrations/d7_simpletest_settings.yml deleted file mode 100644 index cac99e8a92c9fa3b3a873469c76c6148158f025c..0000000000000000000000000000000000000000 --- a/core/modules/simpletest/migrations/d7_simpletest_settings.yml +++ /dev/null @@ -1,23 +0,0 @@ -id: d7_simpletest_settings -label: SimpleTest configuration -migration_tags: - - Drupal 7 - - Configuration -source: - plugin: variable - variables: - - simpletest_clear_results - - simpletest_httpauth_method - - simpletest_httpauth_password - - simpletest_httpauth_username - - simpletest_verbose - source_module: simpletest -process: - clear_results: simpletest_clear_results - 'httpauth/method': simpletest_httpauth_method - 'httpauth/password': simpletest_httpauth_password - 'httpauth/username': simpletest_httpauth_username - verbose: simpletest_verbose -destination: - plugin: config - config_name: simpletest.settings diff --git a/core/modules/simpletest/migrations/state/simpletest.migrate_drupal.yml b/core/modules/simpletest/migrations/state/simpletest.migrate_drupal.yml deleted file mode 100644 index f195ad82f3c77537ba21f6babf4f08ddb736a242..0000000000000000000000000000000000000000 --- a/core/modules/simpletest/migrations/state/simpletest.migrate_drupal.yml +++ /dev/null @@ -1,5 +0,0 @@ -finished: - 6: - simpletest: simpletest - 7: - simpletest: simpletest diff --git a/core/modules/simpletest/simpletest.api.php b/core/modules/simpletest/simpletest.api.php deleted file mode 100644 index 35802eaf5135209e46a18902024d5925a3d99b14..0000000000000000000000000000000000000000 --- a/core/modules/simpletest/simpletest.api.php +++ /dev/null @@ -1,90 +0,0 @@ -<?php - -/** - * @file - * Hooks provided by the SimpleTest module. - */ - -/** - * @addtogroup hooks - * @{ - */ - -/** - * 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.0 and is removed from 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 - // Session HTTPS handling test because it checks the sessions table in the - // database. - unset($groups['Session']['testHttpsSession']); -} - -/** - * A test group has started. - * - * This hook is called just once at the beginning of a test group. - * - * This hook is only invoked by the Simpletest UI form runner. It will not be - * invoked by run-tests.sh or the phpunit tool. - * - * @deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Convert your - * test to a PHPUnit-based one and implement test listeners. - * - * @see https://www.drupal.org/node/2934242 - */ -function hook_test_group_started() { -} - -/** - * A test group has finished. - * - * This hook is called just once at the end of a test group. - * - * This hook is only invoked by the Simpletest UI form runner. It will not be - * invoked by run-tests.sh or the phpunit tool. - * - * @deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Convert your - * test to a PHPUnit-based one and implement test listeners. - * - * @see https://www.drupal.org/node/2934242 - */ -function hook_test_group_finished() { -} - -/** - * An individual test has finished. - * - * This hook is called when an individual test has finished. - * - * This hook is only invoked by the Simpletest UI form runner. It will not be - * invoked by run-tests.sh or the phpunit tool. - * - * @param - * $results The results of the test as gathered by - * \Drupal\simpletest\WebTestBase. - * - * @deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Convert your - * test to a PHPUnit-based one and implement test listeners. - * - * @see https://www.drupal.org/node/2934242 - * @see _simpletest_batch_operation() - */ -function hook_test_finished($results) { -} - -/** - * @} End of "addtogroup hooks". - */ diff --git a/core/modules/simpletest/simpletest.es6.js b/core/modules/simpletest/simpletest.es6.js deleted file mode 100644 index 1961f0931ecf06b6b48e5598829cc5a1c42c85f1..0000000000000000000000000000000000000000 --- a/core/modules/simpletest/simpletest.es6.js +++ /dev/null @@ -1,143 +0,0 @@ -/** - * @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 = $(Drupal.theme('checkbox')).attr( - 'id', - `${$cell.attr('id')}-group-select-all`, - ); - 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); diff --git a/core/modules/simpletest/simpletest.info.yml b/core/modules/simpletest/simpletest.info.yml index 7304759932ec91788846f0c2f5f868a6351feab6..6cb3548cb13120a36e79bf2c5f34c35846cf9f15 100644 --- a/core/modules/simpletest/simpletest.info.yml +++ b/core/modules/simpletest/simpletest.info.yml @@ -1,6 +1,6 @@ name: Testing type: module -description: 'Provides a framework for unit and functional testing.' +description: 'Deprecated. SimpleTest has been removed from core.' package: Core version: VERSION -configure: simpletest.settings +hidden: true diff --git a/core/modules/simpletest/simpletest.install b/core/modules/simpletest/simpletest.install index 373876807bd7532a3bca580049aa3f8943105eb3..69ddb8a56ce280da1b88bdd2bbd814c97a0b5fc5 100644 --- a/core/modules/simpletest/simpletest.install +++ b/core/modules/simpletest/simpletest.install @@ -2,85 +2,13 @@ /** * @file - * Install, update and uninstall functions for the simpletest module. + * Uninstall functions for the simpletest module. */ -use Drupal\Component\FileSecurity\FileSecurity; -use Drupal\Component\Utility\Environment; +use Drupal\Core\Database\Database; use Drupal\Core\File\Exception\FileException; use Drupal\Core\Test\TestDatabase; -use PHPUnit\Framework\TestCase; - -/** - * Minimum value of PHP memory_limit for SimpleTest. - */ -const SIMPLETEST_MINIMUM_PHP_MEMORY_LIMIT = '128M'; - -/** - * Implements hook_requirements(). - */ -function simpletest_requirements($phase) { - $requirements = []; - - $requirements['deprecation'] = [ - 'title' => t('Testing (SimpleTest)'), - 'value' => t('The <em>Testing</em> (SimpleTest) module is deprecated for removal in Drupal 9. It should not be enabled on production sites. Read <a href="https://www.drupal.org/node/3091784">The Drupal core SimpleTest module is deprecated</a> for alternative ways to run tests during development.'), - 'severity' => $phase === 'runtime' ? REQUIREMENT_WARNING : REQUIREMENT_INFO, - ]; - - $has_phpunit = class_exists(TestCase::class); - $has_curl = function_exists('curl_init'); - - $requirements['phpunit'] = [ - 'title' => t('PHPUnit dependency'), - 'value' => $has_phpunit ? t('Found') : t('Not found'), - ]; - if (!$has_phpunit) { - $requirements['phpunit']['severity'] = REQUIREMENT_ERROR; - $requirements['phpunit']['description'] = t("The testing framework requires the PHPUnit package. Please run 'composer install' to ensure it is present."); - } - - $requirements['curl'] = [ - 'title' => t('cURL'), - 'value' => $has_curl ? t('Enabled') : t('Not found'), - ]; - if (!$has_curl) { - $requirements['curl']['severity'] = REQUIREMENT_ERROR; - $requirements['curl']['description'] = t('The testing framework requires the <a href="https://secure.php.net/manual/en/curl.setup.php">PHP cURL library</a>. For more information, see the <a href="https://www.drupal.org/requirements/php/curl">online information on installing the PHP cURL extension</a>.'); - } - - // Check the current memory limit. If it is set too low, SimpleTest will fail - // to load all tests and throw a fatal error. - $memory_limit = ini_get('memory_limit'); - if (!Environment::checkMemoryLimit(SIMPLETEST_MINIMUM_PHP_MEMORY_LIMIT, $memory_limit)) { - $requirements['php_memory_limit']['severity'] = REQUIREMENT_WARNING; - $requirements['php_memory_limit']['description'] = t('The testing framework requires the PHP memory limit to be at least %memory_minimum_limit. The current value is %memory_limit. <a href=":url">Follow these steps to continue</a>.', ['%memory_limit' => $memory_limit, '%memory_minimum_limit' => SIMPLETEST_MINIMUM_PHP_MEMORY_LIMIT, ':url' => 'https://www.drupal.org/node/207036']); - } - - $site_directory = 'sites/simpletest'; - if (!drupal_verify_install_file(\Drupal::root() . '/' . $site_directory, FILE_EXIST | FILE_READABLE | FILE_WRITABLE | FILE_EXECUTABLE, 'dir')) { - $requirements['simpletest_site_directory'] = [ - 'title' => t('Simpletest site directory'), - 'value' => is_dir(\Drupal::root() . '/' . $site_directory) ? t('Not writable') : t('Missing'), - 'severity' => REQUIREMENT_ERROR, - 'description' => t('The testing framework requires the %sites-simpletest directory to exist and be writable in order to run tests.', [ - '%sites-simpletest' => $site_directory, - ]), - ]; - } - elseif (!FileSecurity::writeHtaccess(\Drupal::root() . '/' . $site_directory, FALSE)) { - $requirements['simpletest_site_directory'] = [ - 'title' => t('Simpletest site directory'), - 'value' => t('Not protected'), - 'severity' => REQUIREMENT_ERROR, - 'description' => t('The file %file does not exist and could not be created automatically, which poses a security risk. Ensure that the directory is writable.', [ - '%file' => $site_directory . '/.htaccess', - ]), - ]; - } - - return $requirements; -} +use Symfony\Component\Console\Output\NullOutput; /** * Implements hook_schema(). @@ -94,11 +22,25 @@ function simpletest_schema() { */ function simpletest_uninstall() { // Do not clean the environment in case the Simpletest module is uninstalled - // in a (recursive) test for itself, since simpletest_clean_environment() - // would also delete the test site of the parent test process. + // in a (recursive) test for itself, since EnvironmentCleaner would also + // delete the test site of the parent test process. if (!drupal_valid_test_ua()) { - \Drupal::service('environment_cleaner')->cleanEnvironment(); + // Clean up left-over tables and directories. + $cleaner = new EnvironmentCleaner( + DRUPAL_ROOT, + Database::getConnection(), + TestDatabase::getConnection(), + new NullOutput(), + \Drupal::service('file_system') + ); + try { + $cleaner->cleanEnvironment(); + } + catch (Exception $e) { + // Ignore. + } } + // Delete verbose test output and any other testing framework files. try { \Drupal::service('file_system')->deleteRecursive('public://simpletest'); @@ -106,5 +48,4 @@ function simpletest_uninstall() { catch (FileException $e) { // Ignore. } - } diff --git a/core/modules/simpletest/simpletest.js b/core/modules/simpletest/simpletest.js deleted file mode 100644 index 54e0e4baf09b38e28604341d17968192e15d14ec..0000000000000000000000000000000000000000 --- a/core/modules/simpletest/simpletest.js +++ /dev/null @@ -1,86 +0,0 @@ -/** -* DO NOT EDIT THIS FILE. -* See the following change record for more information, -* https://www.drupal.org/node/2815083 -* @preserve -**/ - -(function ($, Drupal, drupalSettings) { - Drupal.behaviors.simpleTestGroupCollapse = { - 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]); - }); - }); - } - }; - Drupal.behaviors.simpleTestSelectAll = { - 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'); - var $groupCheckbox = $(Drupal.theme('checkbox')).attr('id', "".concat($cell.attr('id'), "-group-select-all")); - var $testCheckboxes = $group.nextUntil('.simpletest-group').find('input[type=checkbox]'); - $cell.append($groupCheckbox); - $groupCheckbox.on('change', function () { - var checked = $(this).prop('checked'); - $testCheckboxes.prop('checked', checked); - }); - - function updateGroupCheckbox() { - var allChecked = true; - $testCheckboxes.each(function () { - if (!$(this).prop('checked')) { - allChecked = false; - return false; - } - }); - $groupCheckbox.prop('checked', allChecked); - } - - $testCheckboxes.on('change', updateGroupCheckbox); - }); - } - }; - Drupal.behaviors.simpletestTableFilterByText = { - attach: function attach(context) { - var $input = $('input.table-filter-text').once('table-filter-text'); - var $table = $($input.attr('data-table')); - var $rows; - var searched = false; - - function filterTestList(e) { - var query = $(e.target).val().toLowerCase(); - - function showTestRow(index, row) { - var $row = $(row); - var $sources = $row.find('.table-filter-text-source'); - var textMatch = $sources.text().toLowerCase().indexOf(query) !== -1; - $row.closest('tr').toggle(textMatch); - } - - if (query.length >= 3) { - searched = true; - $('#simpletest-form-table thead th.select-all input').hide(); - $rows.each(showTestRow); - } else if (searched) { - searched = false; - $('#simpletest-form-table thead th.select-all input').show(); - $rows.css('display', ''); - } - } - - if ($table.length) { - $rows = $table.find('tbody tr'); - $input.trigger('focus').on('keyup', Drupal.debounce(filterTestList, 200)); - } - } - }; -})(jQuery, Drupal, drupalSettings); \ No newline at end of file diff --git a/core/modules/simpletest/simpletest.libraries.yml b/core/modules/simpletest/simpletest.libraries.yml deleted file mode 100644 index 7bcbc07de537d2aec2a74c8210eea495a33e5f17..0000000000000000000000000000000000000000 --- a/core/modules/simpletest/simpletest.libraries.yml +++ /dev/null @@ -1,14 +0,0 @@ -drupal.simpletest: - version: VERSION - js: - simpletest.js: {} - css: - component: - css/simpletest.module.css: {} - dependencies: - - core/jquery - - core/drupal - - core/drupalSettings - - core/jquery.once - - core/drupal.tableselect - - core/drupal.debounce diff --git a/core/modules/simpletest/simpletest.links.menu.yml b/core/modules/simpletest/simpletest.links.menu.yml deleted file mode 100644 index 1b6b2f9d89409eef711b797559775959650c4bc8..0000000000000000000000000000000000000000 --- a/core/modules/simpletest/simpletest.links.menu.yml +++ /dev/null @@ -1,6 +0,0 @@ -simpletest.test_form: - title: Testing - description: 'Run tests against the site''s core code and enabled modules to review your code.' - route_name: simpletest.test_form - parent: system.admin_config_development - weight: -5 diff --git a/core/modules/simpletest/simpletest.links.task.yml b/core/modules/simpletest/simpletest.links.task.yml deleted file mode 100644 index 4f1fd00d0fab3b076567cce6db3bd66098ffee08..0000000000000000000000000000000000000000 --- a/core/modules/simpletest/simpletest.links.task.yml +++ /dev/null @@ -1,9 +0,0 @@ -simpletest.test_form: - title: List - route_name: simpletest.test_form - base_route: simpletest.test_form -simpletest.settings: - title: Settings - route_name: simpletest.settings - base_route: simpletest.test_form - weight: 100 diff --git a/core/modules/simpletest/simpletest.module b/core/modules/simpletest/simpletest.module deleted file mode 100644 index a53857550387004cd1b4621af6e5be04d58cdd79..0000000000000000000000000000000000000000 --- a/core/modules/simpletest/simpletest.module +++ /dev/null @@ -1,828 +0,0 @@ -<?php - -/** - * @file - * Provides testing functionality. - */ - -use Drupal\Component\Uuid\Php; -use Drupal\Core\Asset\AttachedAssets; -use Drupal\Core\Asset\AttachedAssetsInterface; -use Drupal\Core\Database\Database; -use Drupal\Core\File\Exception\FileException; -use Drupal\Core\File\FileSystemInterface; -use Drupal\Core\Render\Element; -use Drupal\Core\Routing\RouteMatchInterface; -use Drupal\Core\StreamWrapper\PublicStream; -use Drupal\Core\Test\JUnitConverter; -use Drupal\Core\Test\PhpUnitTestRunner; -use Drupal\Core\Test\TestDatabase; -use Drupal\Core\Url; -use Drupal\simpletest\Form\SimpletestResultsForm; -use Drupal\simpletest\TestDiscovery; -use PHPUnit\Framework\TestCase; - -/** - * Implements hook_help(). - */ -function simpletest_help($route_name, RouteMatchInterface $route_match) { - switch ($route_name) { - case 'help.page.simpletest': - $output = ''; - $output .= '<h3>' . t('About') . '</h3>'; - $output .= '<p>' . t('The Testing module provides a framework for running automated tests. It can be used to verify a working state of Drupal before and after any code changes, or as a means for developers to write and execute tests for their modules. For more information, see the <a href=":simpletest">online documentation for the Testing module</a>.', [':simpletest' => 'https://www.drupal.org/documentation/modules/simpletest']) . '</p>'; - $output .= '<h3>' . t('Uses') . '</h3>'; - $output .= '<dl>'; - $output .= '<dt>' . t('Running tests') . '</dt>'; - $output .= '<dd><p>' . t('Visit the <a href=":admin-simpletest">Testing page</a> to display a list of available tests. For comprehensive testing, select <em>all</em> tests, or individually select tests for more targeted testing. Note that it might take several minutes for all tests to complete.', [':admin-simpletest' => Url::fromRoute('simpletest.test_form')->toString()]) . '</p>'; - $output .= '<p>' . t('After the tests run, a message will be displayed next to each test group indicating whether tests within it passed, failed, or had exceptions. A pass means that the test returned the expected results, while fail means that it did not. An exception normally indicates an error outside of the test, such as a PHP warning or notice. If there were failures or exceptions, the results will be expanded to show details, and the tests that had failures or exceptions will be indicated in red or pink rows. You can then use these results to refine your code and tests, until all tests pass.') . '</p></dd>'; - $output .= '</dl>'; - return $output; - - case 'simpletest.test_form': - $output = t('Select the test(s) or test group(s) you would like to run, and click <em>Run tests</em>.'); - return $output; - } -} - -/** - * Implements hook_theme(). - */ -function simpletest_theme() { - return [ - 'simpletest_result_summary' => [ - 'variables' => ['label' => NULL, 'items' => [], 'pass' => 0, 'fail' => 0, 'exception' => 0, 'debug' => 0], - ], - ]; -} - -/** - * Implements hook_js_alter(). - */ -function simpletest_js_alter(&$javascript, AttachedAssetsInterface $assets) { - // Since SimpleTest is a special use case for the table select, stick the - // SimpleTest JavaScript above the table select. - $simpletest = drupal_get_path('module', 'simpletest') . '/simpletest.js'; - if (array_key_exists($simpletest, $javascript) && array_key_exists('core/misc/tableselect.js', $javascript)) { - $javascript[$simpletest]['weight'] = $javascript['core/misc/tableselect.js']['weight'] - 1; - } -} - -/** - * Prepares variables for simpletest result summary templates. - * - * Default template: simpletest-result-summary.html.twig. - * - * @param array $variables - * An associative array containing: - * - label: An optional label to be rendered before the results. - * - ok: The overall group result pass or fail. - * - pass: The number of passes. - * - fail: The number of fails. - * - exception: The number of exceptions. - * - debug: The number of debug messages. - */ -function template_preprocess_simpletest_result_summary(&$variables) { - $variables['items'] = _simpletest_build_summary_line($variables); -} - -/** - * Formats each test result type pluralized summary. - * - * @param array $summary - * A summary of the test results. - * - * @return array - * The pluralized test summary items. - */ -function _simpletest_build_summary_line($summary) { - $translation = \Drupal::translation(); - $items['pass'] = $translation->formatPlural($summary['pass'], '1 pass', '@count passes'); - $items['fail'] = $translation->formatPlural($summary['fail'], '1 fail', '@count fails'); - $items['exception'] = $translation->formatPlural($summary['exception'], '1 exception', '@count exceptions'); - if ($summary['debug']) { - $items['debug'] = $translation->formatPlural($summary['debug'], '1 debug message', '@count debug messages'); - } - return $items; -} - -/** - * Formats test result summaries into a comma separated string for run-tests.sh. - * - * @param array $summary - * A summary of the test results. - * - * @return string - * A concatenated string of the formatted test results. - */ -function _simpletest_format_summary_line($summary) { - $parts = _simpletest_build_summary_line($summary); - return implode(', ', $parts); -} - -/** - * Runs tests. - * - * @param array[] $test_list - * List of tests to run. The top level is keyed by type of test, either - * 'simpletest' or 'phpunit'. Under that is an array of class names to run. - * - * @return string - * The test ID. - */ -function simpletest_run_tests($test_list) { - // We used to separate PHPUnit and Simpletest tests for a performance - // optimization. In order to support backwards compatibility check if these - // keys are set and create a single test list. - // @todo https://www.drupal.org/node/2748967 Remove BC support in Drupal 9. - if (isset($test_list['simpletest'])) { - $test_list = array_merge($test_list, $test_list['simpletest']); - unset($test_list['simpletest']); - } - if (isset($test_list['phpunit'])) { - $test_list = array_merge($test_list, $test_list['phpunit']); - unset($test_list['phpunit']); - } - - $test_id = \Drupal::database()->insert('simpletest_test_id') - ->useDefaults(['test_id']) - ->execute(); - - // Clear out the previous verbose files. - try { - \Drupal::service('file_system')->deleteRecursive('public://simpletest/verbose'); - } - catch (FileException $e) { - // Ignore failed deletes. - } - - // Get the info for the first test being run. - $first_test = reset($test_list); - $info = TestDiscovery::getTestInfo($first_test); - - $batch = [ - 'title' => t('Running tests'), - 'operations' => [ - ['_simpletest_batch_operation', [$test_list, $test_id]], - ], - 'finished' => '_simpletest_batch_finished', - 'progress_message' => '', - 'library' => ['simpletest/drupal.simpletest'], - 'init_message' => t('Processing test @num of @max - %test.', ['%test' => $info['name'], '@num' => '1', '@max' => count($test_list)]), - ]; - batch_set($batch); - - \Drupal::moduleHandler()->invokeAllDeprecated('Convert your test to a PHPUnit-based one and implement test listeners. See https://www.drupal.org/node/2934242', 'test_group_started'); - - return $test_id; -} - -/** - * Executes PHPUnit tests and returns the results of the run. - * - * @param $test_id - * The current test ID. - * @param $unescaped_test_classnames - * An array of test class names, including full namespaces, to be passed as - * a regular expression to PHPUnit's --filter option. - * @param int $status - * (optional) The exit status code of the PHPUnit process will be assigned to - * this variable. - * - * @return array - * The parsed results of PHPUnit's JUnit XML output, in the format of - * {simpletest}'s schema. - * - * @deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use - * \Drupal\Core\Test\PhpUnitTestRunner::runTests() instead. - * - * @see https://www.drupal.org/node/2948547 - */ -function simpletest_run_phpunit_tests($test_id, array $unescaped_test_classnames, &$status = NULL) { - $runner = PhpUnitTestRunner::create(\Drupal::getContainer()); - @trigger_error(__FUNCTION__ . ' is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Test\PhpUnitTestRunner::runTests() instead. See https://www.drupal.org/node/2948547', E_USER_DEPRECATED); - return $runner->runTests($test_id, $unescaped_test_classnames, $status); -} - -/** - * Inserts the parsed PHPUnit results into {simpletest}. - * - * @param array[] $phpunit_results - * An array of test results returned from simpletest_phpunit_xml_to_rows(). - * - * @deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use - * \Drupal\Core\Test\TestDatabase::processPhpUnitResults() instead. - * - * @see https://www.drupal.org/node/3075252 - */ -function simpletest_process_phpunit_results($phpunit_results) { - @trigger_error(__FUNCTION__ . '() is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Test\TestDatabase::processPhpUnitResults() instead. See https://www.drupal.org/node/3075252', E_USER_DEPRECATED); - TestDatabase::processPhpUnitResults($phpunit_results); -} - -/** - * Maps phpunit results to a data structure for batch messages and run-tests.sh. - * - * @param array $results - * The output from simpletest_run_phpunit_tests(). - * - * @return array - * The test result summary. A row per test class. - * - * @deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use - * \Drupal\Core\Test\PhpUnitTestRunner::summarizeResults() instead. - * - * @see https://www.drupal.org/node/2948547 - */ -function simpletest_summarize_phpunit_result($results) { - $runner = PhpUnitTestRunner::create(\Drupal::getContainer()); - @trigger_error(__FUNCTION__ . ' is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Test\PhpUnitTestRunner::summarizeResults() instead. See https://www.drupal.org/node/2948547', E_USER_DEPRECATED); - return $runner->summarizeResults($results); -} - -/** - * Returns the path to use for PHPUnit's --log-junit option. - * - * @param $test_id - * The current test ID. - * - * @return string - * Path to the PHPUnit XML file to use for the current $test_id. - * - * @deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use - * \Drupal\Core\Test\PhpUnitTestRunner::xmlLogFilepath() instead. - * - * @see https://www.drupal.org/node/2948547 - */ -function simpletest_phpunit_xml_filepath($test_id) { - $runner = PhpUnitTestRunner::create(\Drupal::getContainer()); - @trigger_error(__FUNCTION__ . ' is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Test\PhpUnitTestRunner::xmlLogFilepath() instead. See https://www.drupal.org/node/2948547', E_USER_DEPRECATED); - return $runner->xmlLogFilePath($test_id); -} - -/** - * Returns the path to core's phpunit.xml.dist configuration file. - * - * @return string - * The path to core's phpunit.xml.dist configuration file. - * - * @deprecated in drupal:8.4.0 and is removed from 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'; -} - -/** - * Executes the PHPUnit command. - * - * @param array $unescaped_test_classnames - * An array of test class names, including full namespaces, to be passed as - * a regular expression to PHPUnit's --filter option. - * @param string $phpunit_file - * A filepath to use for PHPUnit's --log-junit option. - * @param int $status - * (optional) The exit status code of the PHPUnit process will be assigned to - * this variable. - * @param string $output - * (optional) The output by running the phpunit command. - * - * @return string - * The results as returned by exec(). - * - * @deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use - * \Drupal\Core\Test\PhpUnitTestRunner::runCommand() instead. - * - * @see https://www.drupal.org/node/2948547 - */ -function simpletest_phpunit_run_command(array $unescaped_test_classnames, $phpunit_file, &$status = NULL, &$output = NULL) { - $runner = PhpUnitTestRunner::create(\Drupal::getContainer()); - @trigger_error(__FUNCTION__ . ' is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Test\PhpUnitTestRunner::runCommand() instead. See https://www.drupal.org/node/2948547', E_USER_DEPRECATED); - return $runner->runCommand($unescaped_test_classnames, $phpunit_file, $status, $output); -} - -/** - * Returns the command to run PHPUnit. - * - * @return string - * The command that can be run through exec(). - * - * @deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use - * \Drupal\Core\Test\PhpUnitTestRunner::phpUnitCommand() instead. - * - * @see https://www.drupal.org/node/2948547 - */ -function simpletest_phpunit_command() { - $runner = PhpUnitTestRunner::create(\Drupal::getContainer()); - @trigger_error(__FUNCTION__ . ' is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Test\PhpUnitTestRunner::phpUnitCommand() instead. See https://www.drupal.org/node/2948547', E_USER_DEPRECATED); - return $runner->phpUnitCommand(); -} - -/** - * Implements callback_batch_operation(). - */ -function _simpletest_batch_operation($test_list_init, $test_id, &$context) { - \Drupal::service('test_discovery')->registerTestNamespaces(); - // Get working values. - if (!isset($context['sandbox']['max'])) { - // First iteration: initialize working values. - $test_list = $test_list_init; - $context['sandbox']['max'] = count($test_list); - $test_results = ['#pass' => 0, '#fail' => 0, '#exception' => 0, '#debug' => 0]; - } - else { - // Nth iteration: get the current values where we last stored them. - $test_list = $context['sandbox']['tests']; - $test_results = $context['sandbox']['test_results']; - } - $max = $context['sandbox']['max']; - - // Perform the next test. - $test_class = array_shift($test_list); - if (is_subclass_of($test_class, TestCase::class)) { - $runner = PhpUnitTestRunner::create(\Drupal::getContainer()); - $phpunit_results = $runner->runTests($test_id, [$test_class]); - TestDatabase::processPhpUnitResults($phpunit_results); - $test_results[$test_class] = simpletest_summarize_phpunit_result($phpunit_results)[$test_class]; - } - else { - $test = new $test_class($test_id); - $test->run(); - \Drupal::moduleHandler()->invokeAllDeprecated('Convert your test to a PHPUnit-based one and implement test listeners. See https://www.drupal.org/node/2934242', 'test_finished', [$test->results]); - $test_results[$test_class] = $test->results; - } - $size = count($test_list); - $info = TestDiscovery::getTestInfo($test_class); - - // Gather results and compose the report. - foreach ($test_results[$test_class] as $key => $value) { - $test_results[$key] += $value; - } - $test_results[$test_class]['#name'] = $info['name']; - $items = []; - foreach (Element::children($test_results) as $class) { - $class_test_result = $test_results[$class] + [ - '#theme' => 'simpletest_result_summary', - '#label' => t($test_results[$class]['#name'] . ':'), - ]; - 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::service('renderer')->render($overall_results); - - $item_list = [ - '#theme' => 'item_list', - '#items' => $items, - ]; - $context['message'] .= \Drupal::service('renderer')->render($item_list); - - // Save working values for the next iteration. - $context['sandbox']['tests'] = $test_list; - $context['sandbox']['test_results'] = $test_results; - // The test_id is the only thing we need to save for the report page. - $context['results']['test_id'] = $test_id; - - // Multistep processing: report progress. - $context['finished'] = 1 - $size / $max; -} - -/** - * Implements callback_batch_finished(). - */ -function _simpletest_batch_finished($success, $results, $operations, $elapsed) { - if ($success) { - \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(). - $test_id = $operations[0][1][1]; - - // Retrieve the last database prefix used for testing and the last test - // class that was run from. Use the information to read the lgo file - // in case any fatal errors caused the test to crash. - $last_test = TestDatabase::lastTestGet($test_id); - (new TestDatabase($last_test['last_prefix']))->logRead($test_id, $last_test['test_class']); - - \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()->invokeAllDeprecated('Convert your test to a PHPUnit-based one and implement test listeners. See https://www.drupal.org/node/2934242', 'test_group_finished'); -} - -/** - * Get information about the last test that ran given a test ID. - * - * @param $test_id - * The test ID to get the last test from. - * @return array - * Array containing the last database prefix used and the last test class - * that ran. - * - * @deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use - * \Drupal\Core\Test\TestDatabase::lastTestGet() instead. - * - * @see https://www.drupal.org/node/3075252 - */ -function simpletest_last_test_get($test_id) { - @trigger_error(__FUNCTION__ . ' is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Test\TestDatabase::lastTestGet() instead. See https://www.drupal.org/node/3075252', E_USER_DEPRECATED); - return array_values(TestDatabase::lastTestGet($test_id)); -} - -/** - * Reads the error log and reports any errors as assertion failures. - * - * The errors in the log should only be fatal errors since any other errors - * will have been recorded by the error handler. - * - * @param $test_id - * The test ID to which the log relates. - * @param $database_prefix - * The database prefix to which the log relates. - * @param $test_class - * The test class to which the log relates. - * - * @return bool - * Whether any fatal errors were found. - * - * @deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use - * \Drupal\Core\Test\TestDatabase::logRead() instead. - * - * @see https://www.drupal.org/node/3075252 - */ -function simpletest_log_read($test_id, $database_prefix, $test_class) { - @trigger_error(__FUNCTION__ . ' is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Test\TestDatabase::logRead() instead. See https://www.drupal.org/node/3075252', E_USER_DEPRECATED); - $test_db = new TestDatabase($database_prefix); - return $test_db->logRead($test_id, $test_class); -} - -/** - * Store an assertion from outside the testing context. - * - * This is useful for inserting assertions that can only be recorded after - * the test case has been destroyed, such as PHP fatal errors. The caller - * information is not automatically gathered since the caller is most likely - * inserting the assertion on behalf of other code. In all other respects - * the method behaves just like \Drupal\simpletest\TestBase::assert() in terms - * of storing the assertion. - * - * @param string $test_id - * The test ID to which the assertion relates. - * @param string $test_class - * The test class to store an assertion for. - * @param bool|string $status - * A boolean or a string of 'pass' or 'fail'. TRUE means 'pass'. - * @param string $message - * The assertion message. - * @param string $group - * The assertion message group. - * @param array $caller - * The an array containing the keys 'file' and 'line' that represent the file - * and line number of that file that is responsible for the assertion. - * - * @return - * Message ID of the stored assertion. - * - * @deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use - * \Drupal\Core\Test\TestDatabase::insertAssert() instead. - * - * @see https://www.drupal.org/node/3075252 - */ -function simpletest_insert_assert($test_id, $test_class, $status, $message = '', $group = 'Other', array $caller = []) { - @trigger_error(__FUNCTION__ . ' is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Test\TestDatabase::insertAssert() instead. See https://www.drupal.org/node/3075252', E_USER_DEPRECATED); - TestDatabase::insertAssert($test_id, $test_class, $status, $message, $group, $caller); -} - -/** - * Gets a list of all of the tests provided by the system. - * - * The list of test classes is loaded by searching the designated directory for - * each module for files matching the PSR-4 standard. Once loaded the test list - * is cached and stored in a static variable. - * - * @param string $extension - * (optional) The name of an extension to limit discovery to; e.g., 'node'. - * @param string[] $types - * An array of included test types. - * - * @return array[] - * An array of tests keyed with the groups, and then keyed by test classes. - * For example: - * @code - * $groups['Block'] => array( - * 'BlockTestCase' => array( - * 'name' => 'Block functionality', - * 'description' => 'Add, edit and delete custom block.', - * 'group' => 'Block', - * ), - * ); - * @endcode - * - * @deprecated in drupal:8.3.0 and is removed from drupal:9.0.0. Use - * \Drupal::service('test_discovery')->getTestClasses($extension, $types) - * 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); -} - -/** - * Registers test namespaces of all extensions and core test classes. - * - * @deprecated in drupal:8.3.0 and is removed from drupal:9.0.0. Use - * \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(); -} - -/** - * Generates a test file. - * - * @param string $filename - * The name of the file, including the path. The suffix '.txt' is appended to - * the supplied file name and the file is put into the public:// files - * directory. - * @param int $width - * The number of characters on one line. - * @param int $lines - * The number of lines in the file. - * @param string $type - * (optional) The type, one of: - * - text: The generated file contains random ASCII characters. - * - binary: The generated file contains random characters whose codes are in - * the range of 0 to 31. - * - binary-text: The generated file contains random sequence of '0' and '1' - * values. - * - * @return string - * The name of the file, including the path. - * - * @deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use - * \Drupal\Tests\TestFileCreationTrait::generateFile() instead. - * - * @see https://www.drupal.org/node/3077768 - */ -function simpletest_generate_file($filename, $width, $lines, $type = 'binary-text') { - @trigger_error(__FUNCTION__ . '() is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use \Drupal\Tests\TestFileCreationTrait::generateFile() instead. See https://www.drupal.org/node/3077768', E_USER_DEPRECATED); - $text = ''; - for ($i = 0; $i < $lines; $i++) { - // Generate $width - 1 characters to leave space for the "\n" character. - for ($j = 0; $j < $width - 1; $j++) { - switch ($type) { - case 'text': - $text .= chr(rand(32, 126)); - break; - case 'binary': - $text .= chr(rand(0, 31)); - break; - case 'binary-text': - default: - $text .= rand(0, 1); - break; - } - } - $text .= "\n"; - } - - // Create filename. - file_put_contents('public://' . $filename . '.txt', $text); - return $filename; -} - -/** - * Removes all temporary database tables and directories. - * - * @deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Access the - * environment_cleaner service and call its cleanEnvironment() method, or use - * \Drupal\Core\Test\EnvironmentCleaner::cleanEnvironment() instead. - * - * @see https://www.drupal.org/node/3076634 - */ -function simpletest_clean_environment() { - @trigger_error(__FUNCTION__ . ' is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Access the environment_cleaner service and call its cleanEnvironment() method, or use \Drupal\Core\Test\EnvironmentCleaner::cleanEnvironment() instead.. See https://www.drupal.org/node/3076634', E_USER_DEPRECATED); - /* @var $cleaner \Drupal\simpletest\EnvironmentCleanerService */ - $cleaner = \Drupal::service('environment_cleaner'); - $cleaner->cleanEnvironment(); -} - -/** - * Removes prefixed tables from the database from crashed tests. - * - * @deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Access the - * environment_cleaner service and call its cleanDatabase() method, or use - * \Drupal\Core\Test\EnvironmentCleaner::cleanDatabase() instead. - * - * @see https://www.drupal.org/node/3076634 - */ -function simpletest_clean_database() { - @trigger_error(__FUNCTION__ . ' is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Access the environment_cleaner service and call its cleanDatabase() method, or use \Drupal\Core\Test\EnvironmentCleaner::cleanDatabase() instead. See https://www.drupal.org/node/3076634', E_USER_DEPRECATED); - /* @var $cleaner \Drupal\simpletest\EnvironmentCleanerService */ - $cleaner = \Drupal::service('environment_cleaner'); - $cleaner->cleanDatabase(); -} - -/** - * Finds all leftover temporary directories and removes them. - * - * @deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Access the - * environment_cleaner service and call its cleanTemporaryDirectories() - * method, or use - * \Drupal\Core\Test\EnvironmentCleaner::cleanTemporaryDirectories() instead. - * - * @see https://www.drupal.org/node/3076634 - */ -function simpletest_clean_temporary_directories() { - @trigger_error(__FUNCTION__ . ' is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Access the environment_cleaner service and call its cleanTemporaryDirectories() method, or use \Drupal\Core\Test\EnvironmentCleaner::cleanTemporaryDirectories() instead. See https://www.drupal.org/node/3076634', E_USER_DEPRECATED); - /* @var $cleaner \Drupal\simpletest\EnvironmentCleanerService */ - $cleaner = \Drupal::service('environment_cleaner'); - $cleaner->cleanTemporaryDirectories(); -} - -/** - * Clears the test result tables. - * - * @param $test_id - * Test ID to remove results for, or NULL to remove all results. - * - * @return int - * The number of results that were removed. - * - * @deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Access the - * environment_cleaner service and call its cleanResultsTable() method, or use - * \Drupal\Core\Test\EnvironmentCleaner::cleanResultsTable() instead. - * - * @see https://www.drupal.org/node/3076634 - */ -function simpletest_clean_results_table($test_id = NULL) { - @trigger_error(__FUNCTION__ . ' is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Access the environment_cleaner service and call its cleanResultsTable() method, or use \Drupal\Core\Test\EnvironmentCleaner::cleanResultsTable() instead. See https://www.drupal.org/node/3076634', E_USER_DEPRECATED); - $count = 0; - if (\Drupal::config('simpletest.settings')->get('clear_results')) { - /* @var $cleaner \Drupal\simpletest\EnvironmentCleanerService */ - $cleaner = \Drupal::service('environment_cleaner'); - $count = $cleaner->cleanResultsTable($test_id); - } - return $count; -} - -/** - * Converts PHPUnit's JUnit XML output to an array. - * - * @param $test_id - * The current test ID. - * @param $phpunit_xml_file - * Path to the PHPUnit XML file. - * - * @return array[]|null - * The results as array of rows in a format that can be inserted into - * {simpletest}. If the phpunit_xml_file does not have any contents then the - * function will return NULL. - * - * @deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use - * \Drupal\Core\Test\JUnitConverter::xmlToRows() instead. - * - * @see https://www.drupal.org/node/2948547 - */ -function simpletest_phpunit_xml_to_rows($test_id, $phpunit_xml_file) { - @trigger_error(__FUNCTION__ . ' is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Test\JUnitConverter::xmlToRows() instead. See https://www.drupal.org/node/2948547', E_USER_DEPRECATED); - return JUnitConverter::xmlToRows($test_id, $phpunit_xml_file) ?: NULL; -} - -/** - * Finds all test cases recursively from a test suite list. - * - * @param \SimpleXMLElement $element - * The PHPUnit xml to search for test cases. - * @param \SimpleXMLElement $parent - * (Optional) The parent of the current element. Defaults to NULL. - * - * @return array - * A list of all test cases. - * - * @deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use - * \Drupal\Core\Test\JUnitConverter::findTestCases() instead. - * - * @see https://www.drupal.org/node/2948547 - */ -function simpletest_phpunit_find_testcases(\SimpleXMLElement $element, \SimpleXMLElement $parent = NULL) { - @trigger_error(__FUNCTION__ . ' is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Test\JUnitConverter::findTestCases() instead. See https://www.drupal.org/node/2948547', E_USER_DEPRECATED); - return JUnitConverter::findTestCases($element, $parent); -} - -/** - * Converts a PHPUnit test case result to a {simpletest} result row. - * - * @param int $test_id - * The current test ID. - * @param \SimpleXMLElement $test_case - * The PHPUnit test case represented as XML element. - * - * @return array - * An array containing the {simpletest} result row. - * - * @deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use - * \Drupal\Core\Test\JUnitConverter::convertTestCaseToSimpletestRow() instead. - * - * @see https://www.drupal.org/node/2948547 - */ -function simpletest_phpunit_testcase_to_row($test_id, \SimpleXMLElement $test_case) { - @trigger_error(__FUNCTION__ . ' is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Test\JUnitConverter::convertTestCaseToSimpletestRow() instead. See https://www.drupal.org/node/2948547', E_USER_DEPRECATED); - return JUnitConverter::convertTestCaseToSimpletestRow($test_id, $test_case); -} - -/** - * Display test results from run-tests.sh in a browser. - * - * @internal - * This function is only used by run-tests.sh - * - * @deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. This function - * supports the --browser option in this script. Use the --verbose option - * instead. - * - * @see https://www.drupal.org/node/3083549 - */ -function _simpletest_run_tests_script_open_browser() { - global $test_ids; - - try { - $connection = Database::getConnection('default', 'test-runner'); - $results = $connection->select('simpletest') - ->fields('simpletest') - ->condition('test_id', $test_ids, 'IN') - ->orderBy('test_class') - ->orderBy('message_id') - ->execute() - ->fetchAll(); - } - catch (Exception $e) { - echo (string) $e; - exit(SIMPLETEST_SCRIPT_EXIT_EXCEPTION); - } - - // Get the results form. - $form = []; - SimpletestResultsForm::addResultForm($form, $results); - - // Get the assets to make the details element collapsible and theme the result - // form. - $assets = new AttachedAssets(); - $assets->setLibraries([ - 'core/drupal.collapse', - 'system/admin', - 'simpletest/drupal.simpletest', - ]); - $resolver = \Drupal::service('asset.resolver'); - list($js_assets_header, $js_assets_footer) = $resolver->getJsAssets($assets, FALSE); - $js_collection_renderer = \Drupal::service('asset.js.collection_renderer'); - $js_assets_header = $js_collection_renderer->render($js_assets_header); - $js_assets_footer = $js_collection_renderer->render($js_assets_footer); - $css_assets = \Drupal::service('asset.css.collection_renderer')->render($resolver->getCssAssets($assets, FALSE)); - - // Make the html page to write to disk. - $render_service = \Drupal::service('renderer'); - $html = '<head>' . $render_service->renderPlain($js_assets_header) . $render_service->renderPlain($css_assets) . '</head><body>' . $render_service->renderPlain($form) . $render_service->renderPlain($js_assets_footer) . '</body>'; - - // Ensure we have assets verbose directory - tests with no verbose output will - // not have created one. - $directory = PublicStream::basePath() . '/simpletest/verbose'; - \Drupal::service('file_system')->prepareDirectory($directory, FileSystemInterface::CREATE_DIRECTORY | FileSystemInterface::MODIFY_PERMISSIONS); - $php = new Php(); - $uuid = $php->generate(); - $filename = $directory . '/results-' . $uuid . '.html'; - $base_url = getenv('SIMPLETEST_BASE_URL'); - if (empty($base_url)) { - simpletest_script_print_error("--browser needs argument --url."); - } - $url = $base_url . '/' . PublicStream::basePath() . '/simpletest/verbose/results-' . $uuid . '.html'; - file_put_contents($filename, $html); - - // See if we can find an OS helper to open URLs in default browser. - $browser = FALSE; - if (shell_exec('which xdg-open')) { - $browser = 'xdg-open'; - } - elseif (shell_exec('which open')) { - $browser = 'open'; - } - elseif (substr(PHP_OS, 0, 3) == 'WIN') { - $browser = 'start'; - } - - if ($browser) { - shell_exec($browser . ' ' . escapeshellarg($url)); - } - else { - // Can't find assets valid browser. - print 'Open file://' . realpath($filename) . ' in your browser to see the verbose output.'; - } -} diff --git a/core/modules/simpletest/simpletest.permissions.yml b/core/modules/simpletest/simpletest.permissions.yml deleted file mode 100644 index a23e8c8548198435398e3861de5a6738c076d3a1..0000000000000000000000000000000000000000 --- a/core/modules/simpletest/simpletest.permissions.yml +++ /dev/null @@ -1,3 +0,0 @@ -administer unit tests: - title: 'Administer tests' - restrict access: true diff --git a/core/modules/simpletest/simpletest.routing.yml b/core/modules/simpletest/simpletest.routing.yml deleted file mode 100644 index b4e81e7a49663c1c33fa392aee68a3245133fd5b..0000000000000000000000000000000000000000 --- a/core/modules/simpletest/simpletest.routing.yml +++ /dev/null @@ -1,23 +0,0 @@ -simpletest.settings: - path: '/admin/config/development/testing/settings' - defaults: - _form: '\Drupal\simpletest\Form\SimpletestSettingsForm' - _title: 'Test settings' - requirements: - _permission: 'administer unit tests' - -simpletest.test_form: - path: '/admin/config/development/testing' - defaults: - _form: '\Drupal\simpletest\Form\SimpletestTestForm' - _title: 'Testing' - requirements: - _permission: 'administer unit tests' - -simpletest.result_form: - path: '/admin/config/development/testing/results/{test_id}' - defaults: - _form: '\Drupal\simpletest\Form\SimpletestResultsForm' - _title: 'Test result' - requirements: - _permission: 'administer unit tests' diff --git a/core/modules/simpletest/simpletest.services.yml b/core/modules/simpletest/simpletest.services.yml deleted file mode 100644 index afae7c4358c421bbea0c53cc4d2e247d28181d21..0000000000000000000000000000000000000000 --- a/core/modules/simpletest/simpletest.services.yml +++ /dev/null @@ -1,15 +0,0 @@ -services: - test_discovery: - class: Drupal\simpletest\TestDiscovery - arguments: ['@app.root', '@class_loader', '@module_handler'] - environment_cleaner_factory: - class: Drupal\simpletest\EnvironmentCleanerFactory - arguments: ['@service_container'] - environment_cleaner: - class: Drupal\simpletest\EnvironmentCleanerService - factory: 'environment_cleaner_factory:createCleaner' - cache_context.test_discovery: - class: Drupal\simpletest\Cache\Context\TestDiscoveryCacheContext - arguments: ['@test_discovery', '@private_key'] - tags: - - { name: cache.context} diff --git a/core/modules/simpletest/src/AssertContentTrait.php b/core/modules/simpletest/src/AssertContentTrait.php deleted file mode 100644 index 54a9c181117d3b977865483606cd45a8ecd98cc3..0000000000000000000000000000000000000000 --- a/core/modules/simpletest/src/AssertContentTrait.php +++ /dev/null @@ -1,21 +0,0 @@ -<?php - -namespace Drupal\simpletest; - -use Drupal\KernelTests\AssertContentTrait as CoreAssertContentTrait; - -@trigger_error('\Drupal\simpletest\AssertContentTrait is deprecated in Drupal 8.6.0 and will be removed before Drupal 9.0.0. Instead, use \Drupal\KernelTests\AssertContentTrait.', E_USER_DEPRECATED); - -/** - * Provides test methods to assert content. - * - * @deprecated in drupal:8.6.0 and is removed from drupal:9.0.0. Use - * Drupal\KernelTests\AssertContentTrait instead. - * - * @see https://www.drupal.org/node/2943146 - */ -trait AssertContentTrait { - - use CoreAssertContentTrait; - -} diff --git a/core/modules/simpletest/src/AssertHelperTrait.php b/core/modules/simpletest/src/AssertHelperTrait.php deleted file mode 100644 index 70262bef1ac0711fa6f07be3d4e203520ce50a0a..0000000000000000000000000000000000000000 --- a/core/modules/simpletest/src/AssertHelperTrait.php +++ /dev/null @@ -1,21 +0,0 @@ -<?php - -namespace Drupal\simpletest; - -@trigger_error(__NAMESPACE__ . '\AssertHelperTrait is 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.', E_USER_DEPRECATED); - -use Drupal\Tests\AssertHelperTrait as BaseAssertHelperTrait; - -/** - * Provides helper methods for assertions. - * - * @deprecated in drupal:8.4.0 and is removed from drupal:9.0.0. Use - * Drupal\Tests\AssertHelperTrait instead. - * - * @see https://www.drupal.org/node/2884454 - */ -trait AssertHelperTrait { - - use BaseAssertHelperTrait; - -} diff --git a/core/modules/simpletest/src/BlockCreationTrait.php b/core/modules/simpletest/src/BlockCreationTrait.php deleted file mode 100644 index 3b5043ddaf12825787f0c33174d118510cc24010..0000000000000000000000000000000000000000 --- a/core/modules/simpletest/src/BlockCreationTrait.php +++ /dev/null @@ -1,23 +0,0 @@ -<?php - -namespace Drupal\simpletest; - -@trigger_error(__NAMESPACE__ . '\BlockCreationTrait is 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.', E_USER_DEPRECATED); - -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.0 and is removed from drupal:9.0.0. Use - * \Drupal\Tests\block\Traits\BlockCreationTrait instead. - * - * @see https://www.drupal.org/node/2884454 - */ -trait BlockCreationTrait { - - use BaseBlockCreationTrait; - -} diff --git a/core/modules/simpletest/src/BrowserTestBase.php b/core/modules/simpletest/src/BrowserTestBase.php deleted file mode 100644 index cfed1dd424cda996958125f6097237a7ab7fe1b8..0000000000000000000000000000000000000000 --- a/core/modules/simpletest/src/BrowserTestBase.php +++ /dev/null @@ -1,25 +0,0 @@ -<?php - -namespace Drupal\simpletest; - -@trigger_error(__NAMESPACE__ . '\BrowserTestBase is deprecated in Drupal 8.1.x, will be removed before Drupal 9.0. Use Drupal\Tests\BrowserTestBase instead.', E_USER_DEPRECATED); - -use Drupal\Tests\BrowserTestBase as BaseBrowserTestBase; - -/** - * Provides a test case for functional Drupal tests. - * - * Tests extending BrowserTestBase must exist in the - * Drupal\Tests\yourmodule\Functional namespace and live in the - * modules/yourmodule/tests/src/Functional directory. - * - * @ingroup testing - * - * @see \Drupal\simpletest\WebTestBase - * @see \Drupal\Tests\BrowserTestBase - * - * @deprecated in drupal:8.1.0 and is removed from drupal:9.0.0. - * Use Drupal\Tests\BrowserTestBase instead. - */ -abstract class BrowserTestBase extends BaseBrowserTestBase { -} diff --git a/core/modules/simpletest/src/Cache/Context/TestDiscoveryCacheContext.php b/core/modules/simpletest/src/Cache/Context/TestDiscoveryCacheContext.php deleted file mode 100644 index e3d5cf351d62b47326afc790282ec25fd1ebc56f..0000000000000000000000000000000000000000 --- a/core/modules/simpletest/src/Cache/Context/TestDiscoveryCacheContext.php +++ /dev/null @@ -1,94 +0,0 @@ -<?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); - } - -} diff --git a/core/modules/simpletest/src/ContentTypeCreationTrait.php b/core/modules/simpletest/src/ContentTypeCreationTrait.php deleted file mode 100644 index f5f8396c15f23871a7573e0946b80201ce26b368..0000000000000000000000000000000000000000 --- a/core/modules/simpletest/src/ContentTypeCreationTrait.php +++ /dev/null @@ -1,23 +0,0 @@ -<?php - -namespace Drupal\simpletest; - -@trigger_error(__NAMESPACE__ . '\ContentTypeCreationTrait is 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.', E_USER_DEPRECATED); - -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.0 and is removed from drupal:9.0.0. Use - * \Drupal\Tests\node\Traits\ContentTypeCreationTrait instead. - * - * @see https://www.drupal.org/node/2884454 - */ -trait ContentTypeCreationTrait { - - use BaseContentTypeCreationTrait; - -} diff --git a/core/modules/simpletest/src/EnvironmentCleanerFactory.php b/core/modules/simpletest/src/EnvironmentCleanerFactory.php deleted file mode 100644 index dc48b50a214fed9844f0d58dcfc679ce5d472ab7..0000000000000000000000000000000000000000 --- a/core/modules/simpletest/src/EnvironmentCleanerFactory.php +++ /dev/null @@ -1,55 +0,0 @@ -<?php - -namespace Drupal\simpletest; - -use Drupal\Core\DependencyInjection\Container; -use Drupal\Core\Test\TestDatabase; -use Drupal\Core\Database\Database; - -/** - * Test environment cleaner factory. - * - * We use a factory pattern here so that we can inject the test results database - * which is not a service (and should not be). - */ -class EnvironmentCleanerFactory { - - /** - * The container. - * - * @var \Drupal\Core\DependencyInjection\Container - */ - protected $container; - - /** - * Construct an environment cleaner factory. - * - * @param \Drupal\Core\DependencyInjection\Container $container - * The container. - */ - public function __construct(Container $container) { - $this->container = $container; - } - - /** - * Factory method to create the environment cleaner service. - * - * @return \Drupal\simpletest\EnvironmentCleanerService - * The environment cleaner service. - */ - public function createCleaner() { - $cleaner = new EnvironmentCleanerService( - $this->container->get('app.root'), - Database::getConnection(), - TestDatabase::getConnection(), - $this->container->get('messenger'), - $this->container->get('string_translation'), - $this->container->get('config.factory'), - $this->container->get('cache.default'), - $this->container->get('file_system') - ); - - return $cleaner; - } - -} diff --git a/core/modules/simpletest/src/EnvironmentCleanerService.php b/core/modules/simpletest/src/EnvironmentCleanerService.php deleted file mode 100644 index b4de5789ea9bf420eb3e236a83177336684901ad..0000000000000000000000000000000000000000 --- a/core/modules/simpletest/src/EnvironmentCleanerService.php +++ /dev/null @@ -1,124 +0,0 @@ -<?php - -namespace Drupal\simpletest; - -use Drupal\Core\Database\Connection; -use Drupal\Core\Messenger\MessengerInterface; -use Drupal\Core\StringTranslation\TranslationInterface; -use Drupal\Core\Config\ConfigFactory; -use Drupal\Core\Cache\CacheBackendInterface; -use Drupal\Core\File\FileSystem; -use Drupal\Core\Test\EnvironmentCleaner; - -/** - * Uses containerized services to perform post-test cleanup. - */ -class EnvironmentCleanerService extends EnvironmentCleaner { - - /** - * Messenger service. - * - * @var \Drupal\Core\Messenger\MessengerInterface - */ - protected $messenger; - - /** - * The translation service. - * - * @var \Drupal\Core\StringTranslation\TranslationInterface - */ - protected $translation; - - /** - * The config factory. - * - * @var \Drupal\Core\Config\ConfigFactory - */ - protected $configFactory; - - /** - * Default cache. - * - * @var \Drupal\Core\Cache\CacheBackendInterface - */ - protected $cacheDefault; - - /** - * Construct an environment cleaner. - * - * @param string $root - * The path to the root of the Drupal installation. - * @param \Drupal\Core\Database\Connection $test_database - * Connection to the database against which tests were run. - * @param \Drupal\Core\Database\Connection $results_database - * Connection to the database where test results were stored. This could be - * the same as $test_database, or it could be different. - * @param \Drupal\Core\StringTranslation\TranslationInterface|null $translation - * (optional) The translation service. If none is supplied, this class will - * attempt to discover one using \Drupal. - */ - public function __construct($root, Connection $test_database, Connection $results_database, MessengerInterface $messenger, TranslationInterface $translation, ConfigFactory $config, CacheBackendInterface $cache_default, FileSystem $file_system) { - $this->root = $root; - $this->testDatabase = $test_database; - $this->resultsDatabase = $results_database; - $this->messenger = $messenger; - $this->translation = $translation; - $this->configFactory = $config; - $this->cacheDefault = $cache_default; - $this->fileSystem = $file_system; - } - - /** - * {@inheritdoc} - */ - public function cleanEnvironment($clear_results = TRUE, $clear_temp_directories = TRUE, $clear_database = TRUE) { - $results_removed = 0; - $clear_results = $this->configFactory->get('simpletest.settings')->get('clear_results'); - - if ($clear_database) { - $this->cleanDatabase(); - } - if ($clear_temp_directories) { - $this->cleanTemporaryDirectories(); - } - if ($clear_results) { - $results_removed = $this->cleanResultsTable(); - } - $this->cacheDefault->delete('simpletest'); - $this->cacheDefault->delete('simpletest_phpunit'); - - if ($clear_results) { - $this->messenger->addMessage($this->translation->formatPlural($results_removed, 'Removed 1 test result.', 'Removed @count test results.')); - } - else { - $this->messenger->addMessage($this->translation->translate('Clear results is disabled and the test results table will not be cleared.'), 'warning'); - } - } - - /** - * {@inheritdoc} - */ - public function cleanDatabase() { - $tables_removed = $this->doCleanDatabase(); - if ($tables_removed > 0) { - $this->messenger->addMessage($this->translation->formatPlural($tables_removed, 'Removed 1 leftover table.', 'Removed @count leftover tables.')); - } - else { - $this->messenger->addMessage($this->translation->translate('No leftover tables to remove.')); - } - } - - /** - * {@inheritdoc} - */ - public function cleanTemporaryDirectories() { - $directories_removed = $this->doCleanTemporaryDirectories(); - if ($directories_removed > 0) { - $this->messenger->addMessage($this->translation->formatPlural($directories_removed, 'Removed 1 temporary directory.', 'Removed @count temporary directories.')); - } - else { - $this->messenger->addMessage($this->translation->translate('No temporary directories to remove.')); - } - } - -} diff --git a/core/modules/simpletest/src/Exception/MissingGroupException.php b/core/modules/simpletest/src/Exception/MissingGroupException.php deleted file mode 100644 index c320304c9e1a42114d75e51f1fa9e0d5096c8496..0000000000000000000000000000000000000000 --- a/core/modules/simpletest/src/Exception/MissingGroupException.php +++ /dev/null @@ -1,18 +0,0 @@ -<?php - -namespace Drupal\simpletest\Exception; - -@trigger_error(__NAMESPACE__ . '\\MissingGroupException is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Test\Exception\MissingGroupException instead. See https://www.drupal.org/node/2949692', E_USER_DEPRECATED); - -use Drupal\Core\Test\Exception\MissingGroupException as CoreMissingGroupException; - -/** - * Exception thrown when a simpletest class is missing an @group annotation. - * - * @deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use - * \Drupal\Core\Test\Exception\MissingGroupException instead. - * - * @see https://www.drupal.org/node/2949692 - */ -class MissingGroupException extends CoreMissingGroupException { -} diff --git a/core/modules/simpletest/src/Form/SimpletestResultsForm.php b/core/modules/simpletest/src/Form/SimpletestResultsForm.php deleted file mode 100644 index adc1d4a5bbbe8deb252ea22c99f71e60b461de00..0000000000000000000000000000000000000000 --- a/core/modules/simpletest/src/Form/SimpletestResultsForm.php +++ /dev/null @@ -1,357 +0,0 @@ -<?php - -namespace Drupal\simpletest\Form; - -use Drupal\Core\Database\Connection; -use Drupal\Core\Form\FormBase; -use Drupal\Core\Form\FormState; -use Drupal\Core\Form\FormStateInterface; -use Drupal\Core\Test\EnvironmentCleanerInterface; -use Drupal\Core\Url; -use Drupal\simpletest\TestDiscovery; -use Symfony\Component\DependencyInjection\ContainerInterface; - -/** - * Test results form for $test_id. - * - * 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 - */ -class SimpletestResultsForm extends FormBase { - - /** - * Associative array of themed result images keyed by status. - * - * @var array - */ - protected $statusImageMap; - - /** - * The database connection service. - * - * @var \Drupal\Core\Database\Connection - */ - protected $database; - - /** - * The environment cleaner service. - * - * @var \Drupal\Core\Test\EnvironmentCleanerInterface - */ - protected $cleaner; - - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container) { - return new static( - $container->get('database'), - $container->get('environment_cleaner') - ); - } - - /** - * Constructs a \Drupal\simpletest\Form\SimpletestResultsForm object. - * - * @param \Drupal\Core\Database\Connection $database - * The database connection service. - */ - public function __construct(Connection $database, EnvironmentCleanerInterface $cleaner) { - $this->database = $database; - $this->cleaner = $cleaner; - } - - /** - * Builds the status image map. - */ - protected static function buildStatusImageMap() { - $image_pass = [ - '#theme' => 'image', - '#uri' => 'core/misc/icons/73b355/check.svg', - '#width' => 18, - '#height' => 18, - '#alt' => 'Pass', - ]; - $image_fail = [ - '#theme' => 'image', - '#uri' => 'core/misc/icons/e32700/error.svg', - '#width' => 18, - '#height' => 18, - '#alt' => 'Fail', - ]; - $image_exception = [ - '#theme' => 'image', - '#uri' => 'core/misc/icons/e29700/warning.svg', - '#width' => 18, - '#height' => 18, - '#alt' => 'Exception', - ]; - $image_debug = [ - '#theme' => 'image', - '#uri' => 'core/misc/icons/e29700/warning.svg', - '#width' => 18, - '#height' => 18, - '#alt' => 'Debug', - ]; - return [ - 'pass' => $image_pass, - 'fail' => $image_fail, - 'exception' => $image_exception, - 'debug' => $image_debug, - ]; - } - - /** - * {@inheritdoc} - */ - public function getFormId() { - return 'simpletest_results_form'; - } - - /** - * {@inheritdoc} - */ - public function buildForm(array $form, FormStateInterface $form_state, $test_id = NULL) { - // Make sure there are test results to display and a re-run is not being - // performed. - $results = []; - if (is_numeric($test_id) && !$results = $this->getResults($test_id)) { - $this->messenger()->addError($this->t('No test results to display.')); - return $this->redirect('simpletest.test_form'); - } - - // Load all classes and include CSS. - $form['#attached']['library'][] = 'simpletest/drupal.simpletest'; - // Add the results form. - $filter = static::addResultForm($form, $results, $this->getStringTranslation()); - - // Actions. - $form['#action'] = Url::fromRoute('simpletest.result_form', ['test_id' => 're-run'])->toString(); - $form['action'] = [ - '#type' => 'fieldset', - '#title' => $this->t('Actions'), - '#attributes' => ['class' => ['container-inline']], - '#weight' => -11, - ]; - - $form['action']['filter'] = [ - '#type' => 'select', - '#title' => 'Filter', - '#options' => [ - 'all' => $this->t('All (@count)', ['@count' => count($filter['pass']) + count($filter['fail'])]), - 'pass' => $this->t('Pass (@count)', ['@count' => count($filter['pass'])]), - 'fail' => $this->t('Fail (@count)', ['@count' => count($filter['fail'])]), - ], - ]; - $form['action']['filter']['#default_value'] = ($filter['fail'] ? 'fail' : 'all'); - - // Categorized test classes for to be used with selected filter value. - $form['action']['filter_pass'] = [ - '#type' => 'hidden', - '#default_value' => implode(',', $filter['pass']), - ]; - $form['action']['filter_fail'] = [ - '#type' => 'hidden', - '#default_value' => implode(',', $filter['fail']), - ]; - - $form['action']['op'] = [ - '#type' => 'submit', - '#value' => $this->t('Run tests'), - ]; - - $form['action']['return'] = [ - '#type' => 'link', - '#title' => $this->t('Return to list'), - '#url' => Url::fromRoute('simpletest.test_form'), - ]; - - if (is_numeric($test_id)) { - $this->cleaner->cleanResultsTable($test_id); - } - - return $form; - } - - /** - * {@inheritdoc} - */ - public function submitForm(array &$form, FormStateInterface $form_state) { - $pass = $form_state->getValue('filter_pass') ? explode(',', $form_state->getValue('filter_pass')) : []; - $fail = $form_state->getValue('filter_fail') ? explode(',', $form_state->getValue('filter_fail')) : []; - - if ($form_state->getValue('filter') == 'all') { - $classes = array_merge($pass, $fail); - } - elseif ($form_state->getValue('filter') == 'pass') { - $classes = $pass; - } - else { - $classes = $fail; - } - - if (!$classes) { - $form_state->setRedirect('simpletest.test_form'); - return; - } - - $form_execute = []; - $form_state_execute = new FormState(); - foreach ($classes as $class) { - $form_state_execute->setValue(['tests', $class], $class); - } - - // Submit the simpletest test form to rerun the tests. - // Under normal circumstances, a form object's submitForm() should never be - // called directly, FormBuilder::submitForm() should be called instead. - // However, it calls $form_state->setProgrammed(), which disables the Batch API. - $simpletest_test_form = SimpletestTestForm::create(\Drupal::getContainer()); - $simpletest_test_form->buildForm($form_execute, $form_state_execute); - $simpletest_test_form->submitForm($form_execute, $form_state_execute); - if ($redirect = $form_state_execute->getRedirect()) { - $form_state->setRedirectUrl($redirect); - } - } - - /** - * Get test results for $test_id. - * - * @param int $test_id - * The test_id to retrieve results of. - * - * @return array - * Array of results grouped by test_class. - */ - protected function getResults($test_id) { - return $this->database->select('simpletest') - ->fields('simpletest') - ->condition('test_id', $test_id) - ->orderBy('test_class') - ->orderBy('message_id') - ->execute() - ->fetchAll(); - } - - /** - * Adds the result form to a $form. - * - * This is a static method so that run-tests.sh can use it to generate a - * results page completely external to Drupal. This is why the UI strings are - * not wrapped in t(). - * - * @param array $form - * The form to attach the results to. - * @param array $results - * The simpletest results. - * - * @return array - * A list of tests the passed and failed. The array has two keys, 'pass' and - * 'fail'. Each contains a list of test classes. - * - * @see simpletest_script_open_browser() - * @see run-tests.sh - */ - public static function addResultForm(array &$form, array $results) { - // Transform the test results to be grouped by test class. - $test_results = []; - foreach ($results as $result) { - if (!isset($test_results[$result->test_class])) { - $test_results[$result->test_class] = []; - } - $test_results[$result->test_class][] = $result; - } - - $image_status_map = static::buildStatusImageMap(); - - // Keep track of which test cases passed or failed. - $filter = [ - 'pass' => [], - 'fail' => [], - ]; - - // Summary result widget. - $form['result'] = [ - '#type' => 'fieldset', - '#title' => 'Results', - // Because this is used in a theme-less situation need to provide a - // default. - '#attributes' => [], - ]; - $form['result']['summary'] = $summary = [ - '#theme' => 'simpletest_result_summary', - '#pass' => 0, - '#fail' => 0, - '#exception' => 0, - '#debug' => 0, - ]; - - \Drupal::service('test_discovery')->registerTestNamespaces(); - - // Cycle through each test group. - $header = [ - 'Message', - 'Group', - 'Filename', - 'Line', - 'Function', - ['colspan' => 2, 'data' => 'Status'], - ]; - $form['result']['results'] = []; - foreach ($test_results as $group => $assertions) { - // Create group details with summary information. - $info = TestDiscovery::getTestInfo($group); - $form['result']['results'][$group] = [ - '#type' => 'details', - '#title' => $info['name'], - '#open' => TRUE, - '#description' => $info['description'], - ]; - $form['result']['results'][$group]['summary'] = $summary; - $group_summary =& $form['result']['results'][$group]['summary']; - - // Create table of assertions for the group. - $rows = []; - foreach ($assertions as $assertion) { - $row = []; - $row[] = ['data' => ['#markup' => $assertion->message]]; - $row[] = $assertion->message_group; - $row[] = \Drupal::service('file_system')->basename(($assertion->file)); - $row[] = $assertion->line; - $row[] = $assertion->function; - $row[] = ['data' => $image_status_map[$assertion->status]]; - - $class = 'simpletest-' . $assertion->status; - if ($assertion->message_group == 'Debug') { - $class = 'simpletest-debug'; - } - $rows[] = ['data' => $row, 'class' => [$class]]; - - $group_summary['#' . $assertion->status]++; - $form['result']['summary']['#' . $assertion->status]++; - } - $form['result']['results'][$group]['table'] = [ - '#type' => 'table', - '#header' => $header, - '#rows' => $rows, - ]; - - // Set summary information. - $group_summary['#ok'] = $group_summary['#fail'] + $group_summary['#exception'] == 0; - $form['result']['results'][$group]['#open'] = !$group_summary['#ok']; - - // Store test group (class) as for use in filter. - $filter[$group_summary['#ok'] ? 'pass' : 'fail'][] = $group; - } - - // Overall summary status. - $form['result']['summary']['#ok'] = $form['result']['summary']['#fail'] + $form['result']['summary']['#exception'] == 0; - - return $filter; - } - -} diff --git a/core/modules/simpletest/src/Form/SimpletestSettingsForm.php b/core/modules/simpletest/src/Form/SimpletestSettingsForm.php deleted file mode 100644 index 20d2425a29fe9449916a3664d9182e0dc44246fb..0000000000000000000000000000000000000000 --- a/core/modules/simpletest/src/Form/SimpletestSettingsForm.php +++ /dev/null @@ -1,126 +0,0 @@ -<?php - -namespace Drupal\simpletest\Form; - -use Drupal\Core\Form\ConfigFormBase; -use Drupal\Core\Form\FormStateInterface; - -/** - * Configure simpletest settings for this site. - * - * @internal - */ -class SimpletestSettingsForm extends ConfigFormBase { - - /** - * {@inheritdoc} - */ - public function getFormId() { - return 'simpletest_settings_form'; - } - - /** - * {@inheritdoc} - */ - protected function getEditableConfigNames() { - return ['simpletest.settings']; - } - - /** - * {@inheritdoc} - */ - public function buildForm(array $form, FormStateInterface $form_state) { - $config = $this->config('simpletest.settings'); - $form['general'] = [ - '#type' => 'details', - '#title' => $this->t('General'), - '#open' => TRUE, - ]; - $form['general']['simpletest_clear_results'] = [ - '#type' => 'checkbox', - '#title' => $this->t('Clear results after each complete test suite run'), - '#description' => $this->t('By default SimpleTest will clear the results after they have been viewed on the results page, but in some cases it may be useful to leave the results in the database. The results can then be viewed at <em>admin/config/development/testing/results/[test_id]</em>. The test ID can be found in the database, simpletest table, or kept track of when viewing the results the first time. Additionally, some modules may provide more analysis or features that require this setting to be disabled.'), - '#default_value' => $config->get('clear_results'), - ]; - $form['general']['simpletest_verbose'] = [ - '#type' => 'checkbox', - '#title' => $this->t('Provide verbose information when running tests'), - '#description' => $this->t('The verbose data will be printed along with the standard assertions and is useful for debugging. The verbose data will be erased between each test suite run. The verbose data output is very detailed and should only be used when debugging.'), - '#default_value' => $config->get('verbose'), - ]; - - $form['httpauth'] = [ - '#type' => 'details', - '#title' => $this->t('HTTP authentication'), - '#description' => $this->t('HTTP auth settings to be used by the SimpleTest browser during testing. Useful when the site requires basic HTTP authentication.'), - ]; - $form['httpauth']['simpletest_httpauth_method'] = [ - '#type' => 'select', - '#title' => $this->t('Method'), - '#options' => [ - CURLAUTH_BASIC => $this->t('Basic'), - CURLAUTH_DIGEST => $this->t('Digest'), - CURLAUTH_GSSNEGOTIATE => $this->t('GSS negotiate'), - CURLAUTH_NTLM => $this->t('NTLM'), - CURLAUTH_ANY => $this->t('Any'), - CURLAUTH_ANYSAFE => $this->t('Any safe'), - ], - '#default_value' => $config->get('httpauth.method'), - ]; - $username = $config->get('httpauth.username'); - $password = $config->get('httpauth.password'); - $form['httpauth']['simpletest_httpauth_username'] = [ - '#type' => 'textfield', - '#title' => $this->t('Username'), - '#default_value' => $username, - ]; - if (!empty($username) && !empty($password)) { - $form['httpauth']['simpletest_httpauth_username']['#description'] = $this->t('Leave this blank to delete both the existing username and password.'); - } - $form['httpauth']['simpletest_httpauth_password'] = [ - '#type' => 'password', - '#title' => $this->t('Password'), - ]; - if ($password) { - $form['httpauth']['simpletest_httpauth_password']['#description'] = $this->t('To change the password, enter the new password here.'); - } - - return parent::buildForm($form, $form_state); - } - - /** - * {@inheritdoc} - */ - public function validateForm(array &$form, FormStateInterface $form_state) { - $config = $this->config('simpletest.settings'); - // If a username was provided but a password wasn't, preserve the existing - // password. - if (!$form_state->isValueEmpty('simpletest_httpauth_username') && $form_state->isValueEmpty('simpletest_httpauth_password')) { - $form_state->setValue('simpletest_httpauth_password', $config->get('httpauth.password')); - } - - // If a password was provided but a username wasn't, the credentials are - // incorrect, so throw an error. - if ($form_state->isValueEmpty('simpletest_httpauth_username') && !$form_state->isValueEmpty('simpletest_httpauth_password')) { - $form_state->setErrorByName('simpletest_httpauth_username', $this->t('HTTP authentication credentials must include a username in addition to a password.')); - } - - parent::validateForm($form, $form_state); - } - - /** - * {@inheritdoc} - */ - public function submitForm(array &$form, FormStateInterface $form_state) { - $this->config('simpletest.settings') - ->set('clear_results', $form_state->getValue('simpletest_clear_results')) - ->set('verbose', $form_state->getValue('simpletest_verbose')) - ->set('httpauth.method', $form_state->getValue('simpletest_httpauth_method')) - ->set('httpauth.username', $form_state->getValue('simpletest_httpauth_username')) - ->set('httpauth.password', $form_state->getValue('simpletest_httpauth_password')) - ->save(); - - parent::submitForm($form, $form_state); - } - -} diff --git a/core/modules/simpletest/src/Form/SimpletestTestForm.php b/core/modules/simpletest/src/Form/SimpletestTestForm.php deleted file mode 100644 index 69f31e4572eb8c394ef378370f0cb563c3e6ebc9..0000000000000000000000000000000000000000 --- a/core/modules/simpletest/src/Form/SimpletestTestForm.php +++ /dev/null @@ -1,247 +0,0 @@ -<?php - -namespace Drupal\simpletest\Form; - -use Drupal\Core\Form\FormBase; -use Drupal\Core\Form\FormStateInterface; -use Drupal\Core\Render\RendererInterface; -use Drupal\simpletest\TestDiscovery; -use Symfony\Component\DependencyInjection\ContainerInterface; - -/** - * List tests arranged in groups that can be selected and run. - * - * @internal - */ -class SimpletestTestForm extends FormBase { - - /** - * The renderer. - * - * @var \Drupal\Core\Render\RendererInterface - */ - protected $renderer; - - /** - * The test discovery service. - * - * @var \Drupal\simpletest\TestDiscovery - */ - protected $testDiscovery; - - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container) { - return new static( - $container->get('renderer'), - $container->get('test_discovery') - ); - } - - /** - * Constructs a new SimpletestTestForm. - * - * @param \Drupal\Core\Render\RendererInterface $renderer - * The renderer. - * @param \Drupal\simpletest\TestDiscovery $test_discovery - * The test discovery service. - */ - public function __construct(RendererInterface $renderer, TestDiscovery $test_discovery) { - $this->renderer = $renderer; - $this->testDiscovery = $test_discovery; - } - - /** - * {@inheritdoc} - */ - public function getFormId() { - return 'simpletest_test_form'; - } - - /** - * {@inheritdoc} - */ - public function buildForm(array $form, FormStateInterface $form_state) { - $form['actions'] = ['#type' => 'actions']; - $form['actions']['submit'] = [ - '#type' => 'submit', - '#value' => $this->t('Run tests'), - '#tableselect' => TRUE, - '#button_type' => 'primary', - ]; - $form['clean'] = [ - '#type' => 'fieldset', - '#title' => $this->t('Clean test environment'), - '#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'] = [ - '#type' => 'submit', - '#value' => $this->t('Clean environment'), - '#submit' => ['simpletest_clean_environment'], - ]; - - // Do not needlessly re-execute a full test discovery if the user input - // already contains an explicit list of test classes to run. - $user_input = $form_state->getUserInput(); - if (!empty($user_input['tests'])) { - return $form; - } - - // JavaScript-only table filters. - $form['filters'] = [ - '#type' => 'container', - '#attributes' => [ - 'class' => ['table-filter', 'js-show'], - ], - ]; - $form['filters']['text'] = [ - '#type' => 'search', - '#title' => $this->t('Search'), - '#size' => 30, - '#placeholder' => $this->t('Enter test name…'), - '#attributes' => [ - 'class' => ['table-filter-text'], - 'data-table' => '#simpletest-test-form', - 'autocomplete' => 'off', - 'title' => $this->t('Enter at least 3 characters of the test name or description to filter by.'), - ], - ]; - - $form['tests'] = [ - '#cache' => [ - 'keys' => ['simpletest_ui_table'], - 'contexts' => ['test_discovery'], - ], - '#type' => 'table', - '#id' => 'simpletest-form-table', - '#tableselect' => TRUE, - '#header' => [ - ['data' => $this->t('Test'), 'class' => ['simpletest-test-label']], - ['data' => $this->t('Description'), 'class' => ['simpletest-test-description']], - ], - '#empty' => $this->t('No tests to display.'), - '#attached' => [ - 'library' => [ - 'simpletest/drupal.simpletest', - ], - ], - ]; - - // Define the images used to expand/collapse the test groups. - $image_collapsed = [ - '#theme' => 'image', - '#uri' => 'core/misc/menu-collapsed.png', - '#width' => '7', - '#height' => '7', - '#alt' => $this->t('Expand'), - '#title' => $this->t('Expand'), - '#suffix' => '<a href="#" class="simpletest-collapse">(' . $this->t('Expand') . ')</a>', - ]; - $image_extended = [ - '#theme' => 'image', - '#uri' => 'core/misc/menu-expanded.png', - '#width' => '7', - '#height' => '7', - '#alt' => $this->t('Collapse'), - '#title' => $this->t('Collapse'), - '#suffix' => '<a href="#" class="simpletest-collapse">(' . $this->t('Collapse') . ')</a>', - ]; - $form['tests']['#attached']['drupalSettings']['simpleTest']['images'] = [ - (string) $this->renderer->renderPlain($image_collapsed), - (string) $this->renderer->renderPlain($image_extended), - ]; - - // Generate the list of tests arranged by group. - $groups = $this->testDiscovery->getTestClasses(); - foreach ($groups as $group => $tests) { - $form['tests'][$group] = [ - '#attributes' => ['class' => ['simpletest-group']], - ]; - - // Make the class name safe for output on the page by replacing all - // non-word/decimal characters with a dash (-). - $group_class = 'module-' . strtolower(trim(preg_replace("/[^\w\d]/", "-", $group))); - - // Override tableselect column with custom selector for this group. - // This group-select-all checkbox is injected via JavaScript. - $form['tests'][$group]['select'] = [ - '#wrapper_attributes' => [ - 'id' => $group_class, - 'class' => ['simpletest-group-select-all'], - ], - ]; - $form['tests'][$group]['title'] = [ - // Expand/collapse image. - '#prefix' => '<div class="simpletest-image" id="simpletest-test-group-' . $group_class . '"></div>', - '#markup' => '<label for="' . $group_class . '-group-select-all">' . $group . '</label>', - '#wrapper_attributes' => [ - 'class' => ['simpletest-group-label'], - ], - ]; - $form['tests'][$group]['description'] = [ - '#markup' => ' ', - '#wrapper_attributes' => [ - 'class' => ['simpletest-group-description'], - ], - ]; - - // Cycle through each test within the current group. - foreach ($tests as $class => $info) { - $form['tests'][$class] = [ - '#attributes' => ['class' => [$group_class . '-test', 'js-hide']], - ]; - $form['tests'][$class]['title'] = [ - '#type' => 'label', - '#title' => '\\' . $info['name'], - '#wrapper_attributes' => [ - 'class' => ['simpletest-test-label', 'table-filter-text-source'], - ], - ]; - $form['tests'][$class]['description'] = [ - '#prefix' => '<div class="description">', - '#plain_text' => $info['description'], - '#suffix' => '</div>', - '#wrapper_attributes' => [ - 'class' => ['simpletest-test-description', 'table-filter-text-source'], - ], - ]; - } - } - - return $form; - } - - /** - * {@inheritdoc} - */ - public function submitForm(array &$form, FormStateInterface $form_state) { - // Test discovery does not run upon form submission. - $this->testDiscovery->registerTestNamespaces(); - - // This form accepts arbitrary user input for 'tests'. - // An invalid value will cause the $class_name lookup below to die with a - // fatal error. Regular user access mechanisms to this form are intact. - // The only validation effectively being skipped is the validation of - // available checkboxes vs. submitted checkboxes. - // @todo Refactor Form API to allow to POST values without constructing the - // entire form more easily, BUT retaining routing access security and - // retaining Form API CSRF #token security validation, and without having - // to rely on form caching. - $user_input = $form_state->getUserInput(); - if ($form_state->isValueEmpty('tests') && !empty($user_input['tests'])) { - $form_state->setValue('tests', $user_input['tests']); - } - - $tests_list = array_filter($form_state->getValue('tests')); - if (!empty($tests_list)) { - $test_id = simpletest_run_tests($tests_list, 'drupal'); - $form_state->setRedirect( - 'simpletest.result_form', - ['test_id' => $test_id] - ); - } - } - -} diff --git a/core/modules/simpletest/src/InstallerTestBase.php b/core/modules/simpletest/src/InstallerTestBase.php deleted file mode 100644 index 747810e11c738000731bf68eb0bcb56445888cf4..0000000000000000000000000000000000000000 --- a/core/modules/simpletest/src/InstallerTestBase.php +++ /dev/null @@ -1,248 +0,0 @@ -<?php - -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; -use Drupal\Core\Site\Settings; -use Drupal\Tests\RequirementsPageTrait; -use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\DependencyInjection\Reference; -use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpFoundation\RequestStack; - -/** - * Base class for testing the interactive installer. - * - * @deprecated in drupal:8.6.0 and is removed from drupal:9.0.0. - * Use \Drupal\FunctionalTests\Installer\InstallerTestBase. See - * https://www.drupal.org/node/2988752 - */ -abstract class InstallerTestBase extends WebTestBase { - - use RequirementsPageTrait; - - /** - * Custom settings.php values to write for a test run. - * - * @var array - * An array of settings to write out, in the format expected by - * drupal_rewrite_settings(). - */ - protected $settings = []; - - /** - * The language code in which to install Drupal. - * - * @var string - */ - protected $langcode = 'en'; - - /** - * The installation profile to install. - * - * @var string - */ - protected $profile = 'testing'; - - /** - * Additional parameters to use for installer screens. - * - * @see WebTestBase::installParameters() - * - * @var array - */ - protected $parameters = []; - - /** - * A string translation map used for translated installer screens. - * - * Keys are English strings, values are translated strings. - * - * @var array - */ - protected $translations = [ - 'Save and continue' => 'Save and continue', - ]; - - /** - * Whether the installer has completed. - * - * @var bool - */ - protected $isInstalled = FALSE; - - /** - * {@inheritdoc} - */ - protected function setUp() { - $this->isInstalled = FALSE; - - // Define information about the user 1 account. - $this->rootUser = new UserSession([ - 'uid' => 1, - 'name' => 'admin', - 'mail' => 'admin@example.com', - 'pass_raw' => $this->randomMachineName(), - ]); - - // If any $settings are defined for this test, copy and prepare an actual - // settings.php, so as to resemble a regular installation. - if (!empty($this->settings)) { - // Not using File API; a potential error must trigger a PHP warning. - copy(DRUPAL_ROOT . '/sites/default/default.settings.php', DRUPAL_ROOT . '/' . $this->siteDirectory . '/settings.php'); - $this->writeSettings($this->settings); - } - - // Note that WebTestBase::installParameters() returns form input values - // suitable for a programmed \Drupal::formBuilder()->submitForm(). - // @see WebTestBase::translatePostValues() - $this->parameters = $this->installParameters(); - - // Set up a minimal container (required by WebTestBase). Set cookie and - // server information so that XDebug works. - // @see install_begin_request() - $request = Request::create($GLOBALS['base_url'] . '/core/install.php', 'GET', [], $_COOKIE, [], $_SERVER); - $this->container = new ContainerBuilder(); - $request_stack = new RequestStack(); - $request_stack->push($request); - $this->container - ->set('request_stack', $request_stack); - $this->container - ->setParameter('language.default_values', Language::$defaultValues); - $this->container - ->register('language.default', 'Drupal\Core\Language\LanguageDefault') - ->addArgument('%language.default_values%'); - $this->container - ->register('string_translation', 'Drupal\Core\StringTranslation\TranslationManager') - ->addArgument(new Reference('language.default')); - $this->container - ->set('app.root', DRUPAL_ROOT); - \Drupal::setContainer($this->container); - - $this->visitInstaller(); - - // Select language. - $this->setUpLanguage(); - - // Select profile. - $this->setUpProfile(); - - // Address the requirements problem screen, if any. - $this->setUpRequirementsProblem(); - - // Configure settings. - $this->setUpSettings(); - - // @todo Allow test classes based on this class to act on further installer - // screens. - - // Configure site. - $this->setUpSite(); - - if ($this->isInstalled) { - // Import new settings.php written by the installer. - $request = Request::createFromGlobals(); - $class_loader = require $this->container->get('app.root') . '/autoload.php'; - Settings::initialize($this->container->get('app.root'), DrupalKernel::findSitePath($request), $class_loader); - $this->configDirectories['sync'] = Settings::get('config_sync_directory'); - - // After writing settings.php, the installer removes write permissions - // from the site directory. To allow drupal_generate_test_ua() to write - // a file containing the private key for drupal_valid_test_ua(), the site - // directory has to be writable. - // WebTestBase::tearDown() will delete the entire test site directory. - // Not using File API; a potential error must trigger a PHP warning. - chmod($this->container->get('app.root') . '/' . $this->siteDirectory, 0777); - $this->kernel = DrupalKernel::createFromRequest($request, $class_loader, 'prod', FALSE); - $this->kernel->boot(); - $this->kernel->preHandle($request); - $this->container = $this->kernel->getContainer(); - // Ensure our request includes the session if appropriate. - if (PHP_SAPI !== 'cli') { - $request->setSession($this->container->get('session')); - } - - // Manually configure the test mail collector implementation to prevent - // tests from sending out emails and collect them in state instead. - $this->container->get('config.factory') - ->getEditable('system.mail') - ->set('interface.default', 'test_mail_collector') - ->save(); - } - } - - /** - * Visits the interactive installer. - */ - protected function visitInstaller() { - $this->drupalGet($GLOBALS['base_url'] . '/core/install.php'); - } - - /** - * Installer step: Select language. - */ - protected function setUpLanguage() { - $edit = [ - 'langcode' => $this->langcode, - ]; - $this->drupalPostForm(NULL, $edit, $this->translations['Save and continue']); - } - - /** - * Installer step: Select installation profile. - */ - protected function setUpProfile() { - $edit = [ - 'profile' => $this->profile, - ]; - $this->drupalPostForm(NULL, $edit, $this->translations['Save and continue']); - } - - /** - * Installer step: Configure settings. - */ - protected function setUpSettings() { - $edit = $this->translatePostValues($this->parameters['forms']['install_settings_form']); - $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() { - // Do nothing. - } - - /** - * Final installer step: Configure site. - */ - protected function setUpSite() { - $edit = $this->translatePostValues($this->parameters['forms']['install_configure_form']); - $this->drupalPostForm(NULL, $edit, $this->translations['Save and continue']); - // If we've got to this point the site is installed using the regular - // installation workflow. - $this->isInstalled = TRUE; - } - - /** - * {@inheritdoc} - * - * WebTestBase::refreshVariables() tries to operate on persistent storage, - * which is only available after the installer completed. - */ - protected function refreshVariables() { - if ($this->isInstalled) { - parent::refreshVariables(); - } - } - -} diff --git a/core/modules/simpletest/src/NodeCreationTrait.php b/core/modules/simpletest/src/NodeCreationTrait.php deleted file mode 100644 index aadbd5f7b42ab5ff7c34f857dfae8d104c15f790..0000000000000000000000000000000000000000 --- a/core/modules/simpletest/src/NodeCreationTrait.php +++ /dev/null @@ -1,23 +0,0 @@ -<?php - -namespace Drupal\simpletest; - -@trigger_error(__NAMESPACE__ . '\NodeCreationTrait is 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.', E_USER_DEPRECATED); - -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.0 and is removed from drupal:9.0.0. Use - * \Drupal\Tests\node\Traits\NodeCreationTrait instead. - * - * @see https://www.drupal.org/node/2884454 - */ -trait NodeCreationTrait { - - use BaseNodeCreationTrait; - -} diff --git a/core/modules/simpletest/src/RandomGeneratorTrait.php b/core/modules/simpletest/src/RandomGeneratorTrait.php deleted file mode 100644 index a3c874012bda33f1521658a91ccb2ff9ea81aaad..0000000000000000000000000000000000000000 --- a/core/modules/simpletest/src/RandomGeneratorTrait.php +++ /dev/null @@ -1,20 +0,0 @@ -<?php - -namespace Drupal\simpletest; - -@trigger_error(__NAMESPACE__ . '\RandomGeneratorTrait is deprecated in Drupal 8.1.1, will be removed before Drupal 9.0.0. Use \Drupal\Tests\RandomGeneratorTrait instead.', E_USER_DEPRECATED); - -use Drupal\Tests\RandomGeneratorTrait as BaseGeneratorTrait; - -/** - * Provides random generator utility methods. - * - * @deprecated in drupal:8.1.1 and is removed from drupal:9.0.0. Use - * \Drupal\Tests\RandomGeneratorTrait instead. - * - * @see \Drupal\Tests - */ -trait RandomGeneratorTrait { - use BaseGeneratorTrait; - -} diff --git a/core/modules/simpletest/src/RouteProvider.php b/core/modules/simpletest/src/RouteProvider.php deleted file mode 100644 index c733cb417b90f990dd67b37812cb870a4be54a23..0000000000000000000000000000000000000000 --- a/core/modules/simpletest/src/RouteProvider.php +++ /dev/null @@ -1,16 +0,0 @@ -<?php - -namespace Drupal\simpletest; - -use Drupal\KernelTests\RouteProvider as CoreRouteProvider; - -/** - * Rebuilds the router when the provider is instantiated. - * - * @deprecated in drupal:8.6.0 and is removed from drupal:9.0.0. Use - * Drupal\KernelTests\RouteProvider instead. - * - * @see https://www.drupal.org/node/2943146 - */ -class RouteProvider extends CoreRouteProvider { -} diff --git a/core/modules/simpletest/src/SessionTestTrait.php b/core/modules/simpletest/src/SessionTestTrait.php deleted file mode 100644 index cef07d90fd0727f0d8a5dd506316df3065c2d015..0000000000000000000000000000000000000000 --- a/core/modules/simpletest/src/SessionTestTrait.php +++ /dev/null @@ -1,21 +0,0 @@ -<?php - -namespace Drupal\simpletest; - -@trigger_error(__NAMESPACE__ . '\SessionTestTrait is deprecated in Drupal 8.1.1 will be removed before 9.0.0. Use \Drupal\Tests\SessionTestTrait instead.', E_USER_DEPRECATED); - -use Drupal\Tests\SessionTestTrait as BaseSessionTestTrait; - -/** - * Provides methods to generate and get session name in tests. - * - * @deprecated in drupal:8.1.1 and is removed from drupal:9.0.0. Use - * \Drupal\Tests\SessionTestTrait instead. - * - * @see \Drupal\Tests - */ -trait SessionTestTrait { - - use BaseSessionTestTrait; - -} diff --git a/core/modules/simpletest/src/TestBase.php b/core/modules/simpletest/src/TestBase.php deleted file mode 100644 index 67c36b8ead156f165edc463d44660d2b10d3a752..0000000000000000000000000000000000000000 --- a/core/modules/simpletest/src/TestBase.php +++ /dev/null @@ -1,1418 +0,0 @@ -<?php - -namespace Drupal\simpletest; - -use Drupal\Component\Assertion\Handle; -use Drupal\Component\Render\FormattableMarkup; -use Drupal\Component\Render\MarkupInterface; -use Drupal\Component\Utility\Crypt; -use Drupal\Component\Utility\Environment; -use Drupal\Core\Database\Database; -use Drupal\Core\File\FileSystemInterface; -use Drupal\Core\Site\Settings; -use Drupal\Core\StreamWrapper\PublicStream; -use Drupal\Core\Test\TestDatabase; -use Drupal\Core\Test\TestDiscovery; -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\Traits\Core\GeneratePermutationsTrait; - -/** - * Base class for Drupal tests. - * - * Do not extend this class directly; use \Drupal\simpletest\WebTestBase. - * - * @deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Instead, - * use one of the phpunit base test classes like - * Drupal\Tests\BrowserTestBase. See https://www.drupal.org/node/3030340. - */ -abstract class TestBase { - - use BaseAssertHelperTrait; - use TestSetupTrait; - use RandomGeneratorTrait; - use GeneratePermutationsTrait; - // For backwards compatibility switch the visibility of the methods to public. - use ConfigTestTrait { - configImporter as public; - copyConfig as public; - } - - /** - * The database prefix of this test run. - * - * @var string - */ - protected $databasePrefix = NULL; - - /** - * Time limit for the test. - * - * @var int - */ - protected $timeLimit = 500; - - /** - * Current results of this test case. - * - * @var array - */ - public $results = [ - '#pass' => 0, - '#fail' => 0, - '#exception' => 0, - '#debug' => 0, - ]; - - /** - * Assertions thrown in that test case. - * - * @var array - */ - protected $assertions = []; - - /** - * This class is skipped when looking for the source of an assertion. - * - * When displaying which function an assert comes from, it's not too useful - * to see "WebTestBase->drupalLogin()', we would like to see the test - * that called it. So we need to skip the classes defining these helper - * methods. - */ - protected $skipClasses = [__CLASS__ => TRUE]; - - /** - * TRUE if verbose debugging is enabled. - * - * @var bool - */ - public $verbose; - - /** - * Incrementing identifier for verbose output filenames. - * - * @var int - */ - protected $verboseId = 0; - - /** - * Safe class name for use in verbose output filenames. - * - * Namespaces separator (\) replaced with _. - * - * @var string - */ - protected $verboseClassName; - - /** - * Directory where verbose output files are put. - * - * @var string - */ - protected $verboseDirectory; - - /** - * URL to the verbose output file directory. - * - * @var string - */ - protected $verboseDirectoryUrl; - - /** - * The original configuration (variables), if available. - * - * @var string - * @todo Remove all remnants of $GLOBALS['conf']. - * @see https://www.drupal.org/node/2183323 - */ - protected $originalConf; - - /** - * The original configuration (variables). - * - * @var string - */ - protected $originalConfig; - - /** - * The original configuration directories. - * - * An array of paths keyed by the CONFIG_*_DIRECTORY constants defined by - * core/includes/bootstrap.inc. - * - * @var array - */ - protected $originalConfigDirectories; - - /** - * The original container. - * - * @var \Symfony\Component\DependencyInjection\ContainerInterface - */ - protected $originalContainer; - - /** - * The original file directory, before it was changed for testing purposes. - * - * @var string - */ - protected $originalFileDirectory = NULL; - - /** - * The original language. - * - * @var \Drupal\Core\Language\LanguageInterface - */ - protected $originalLanguage; - - /** - * The original database prefix when running inside Simpletest. - * - * @var string - */ - protected $originalPrefix; - - /** - * The name of the session cookie of the test-runner. - * - * @var string - */ - protected $originalSessionName; - - /** - * The settings array. - * - * @var array - */ - protected $originalSettings; - - /** - * The original array of shutdown function callbacks. - * - * @var array - */ - protected $originalShutdownCallbacks; - - /** - * The original user, before testing began. - * - * @var \Drupal\Core\Session\AccountProxyInterface - */ - protected $originalUser; - - /** - * The translation file directory for the test environment. - * - * This is set in TestBase::prepareEnvironment(). - * - * @var string - */ - protected $translationFilesDirectory; - - /** - * Whether to die in case any test assertion fails. - * - * @var bool - * - * @see run-tests.sh - */ - public $dieOnFail = FALSE; - - /** - * The config importer that can used in a test. - * - * @var \Drupal\Core\Config\ConfigImporter - */ - protected $configImporter; - - /** - * HTTP authentication method (specified as a CURLAUTH_* constant). - * - * @var int - * @see http://php.net/manual/function.curl-setopt.php - */ - protected $httpAuthMethod = CURLAUTH_BASIC; - - /** - * HTTP authentication credentials (<username>:<password>). - * - * @var string - */ - protected $httpAuthCredentials = NULL; - - /** - * Constructor for Test. - * - * @param $test_id - * Tests with the same id are reported together. - */ - public function __construct($test_id = NULL) { - $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. - */ - abstract protected function setUp(); - - /** - * Checks the matching requirements for Test. - * - * @return - * Array of errors containing a list of unmet requirements. - */ - protected function checkRequirements() { - return []; - } - - /** - * Helper method to store an assertion record in the configured database. - * - * This method decouples database access from assertion logic. - * - * @param array $assertion - * Keyed array representing an assertion, as generated by assert(). - * - * @see self::assert() - * - * @return \Drupal\Core\Database\StatementInterface|int|null - * The message ID. - */ - protected function storeAssertion(array $assertion) { - return self::getDatabaseConnection() - ->insert('simpletest', ['return' => Database::RETURN_INSERT_ID]) - ->fields($assertion) - ->execute(); - } - - /** - * Internal helper: stores the assert. - * - * @param $status - * Can be 'pass', 'fail', 'exception', 'debug'. - * 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\Render\FormattableMarkup to embed - * variables in the message text, not t(). If left blank, a default message - * will be displayed. - * @param $group - * (optional) The group this message is in, which is displayed in a column - * in test output. Use 'Debug' to indicate this is debugging output. Do not - * translate this string. Defaults to 'Other'; most tests do not override - * this default. - * @param $caller - * By default, the assert comes from a function whose name starts with - * 'test'. Instead, you can specify where this assert originates from - * by passing in an associative array as $caller. Key 'file' is - * the name of the source file, 'line' is the line number and 'function' - * is the caller function itself. - */ - protected function assert($status, $message = '', $group = 'Other', array $caller = NULL) { - if ($message instanceof MarkupInterface) { - $message = (string) $message; - } - // Convert boolean status to string status. - if (is_bool($status)) { - $status = $status ? 'pass' : 'fail'; - } - - // Increment summary result counter. - $this->results['#' . $status]++; - - // Get the function information about the call to the assertion method. - if (!$caller) { - $caller = $this->getAssertionCall(); - } - - // Creation assertion array that can be displayed while tests are running. - $assertion = [ - 'test_id' => $this->testId, - 'test_class' => get_class($this), - 'status' => $status, - 'message' => $message, - 'message_group' => $group, - 'function' => $caller['function'], - 'line' => $caller['line'], - 'file' => $caller['file'], - ]; - - // Store assertion for display after the test has completed. - $message_id = $this->storeAssertion($assertion); - $assertion['message_id'] = $message_id; - $this->assertions[] = $assertion; - - // We do not use a ternary operator here to allow a breakpoint on - // test failure. - if ($status == 'pass') { - return TRUE; - } - else { - if ($this->dieOnFail && ($status == 'fail' || $status == 'exception')) { - exit(1); - } - return FALSE; - } - } - - /** - * Store an assertion from outside the testing context. - * - * This is useful for inserting assertions that can only be recorded after - * the test case has been destroyed, such as PHP fatal errors. The caller - * information is not automatically gathered since the caller is most likely - * inserting the assertion on behalf of other code. In all other respects - * the method behaves just like \Drupal\simpletest\TestBase::assert() in terms - * of storing the assertion. - * - * @return - * Message ID of the stored assertion. - * - * @deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use - * simpletest_insert_assert() instead. - * - * @see https://www.drupal.org/node/3030340 - * @see \Drupal\simpletest\TestBase::assert() - * @see \Drupal\simpletest\TestBase::deleteAssert() - */ - public static function insertAssert($test_id, $test_class, $status, $message = '', $group = 'Other', array $caller = []) { - // Convert boolean status to string status. - if (is_bool($status)) { - $status = $status ? 'pass' : 'fail'; - } - - $caller += [ - 'function' => 'Unknown', - 'line' => 0, - 'file' => 'Unknown', - ]; - - $assertion = [ - 'test_id' => $test_id, - 'test_class' => $test_class, - 'status' => $status, - 'message' => $message, - 'message_group' => $group, - 'function' => $caller['function'], - 'line' => $caller['line'], - 'file' => $caller['file'], - ]; - - // We can't use storeAssertion() because this method is static. - return self::getDatabaseConnection() - ->insert('simpletest') - ->fields($assertion) - ->execute(); - } - - /** - * Delete an assertion record by message ID. - * - * @param $message_id - * Message ID of the assertion to delete. - * - * @return - * TRUE if the assertion was deleted, FALSE otherwise. - * - * @see \Drupal\simpletest\TestBase::insertAssert() - */ - public static function deleteAssert($message_id) { - // We can't use storeAssertion() because this method is static. - return (bool) self::getDatabaseConnection() - ->delete('simpletest') - ->condition('message_id', $message_id) - ->execute(); - } - - /** - * Cycles through backtrace until the first non-assertion method is found. - * - * @return - * Array representing the true caller. - */ - protected function getAssertionCall() { - $backtrace = debug_backtrace(); - - // The first element is the call. The second element is the caller. - // We skip calls that occurred in one of the methods of our base classes - // or in an assertion function. - while (($caller = $backtrace[1]) && - ((isset($caller['class']) && isset($this->skipClasses[$caller['class']])) || - substr($caller['function'], 0, 6) == 'assert')) { - // We remove that call. - array_shift($backtrace); - } - - return Error::getLastCaller($backtrace); - } - - /** - * Check to see if a value is not false. - * - * False values are: empty string, 0, NULL, and FALSE. - * - * @param $value - * 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\Render\FormattableMarkup to embed - * variables in the message text, not t(). If left blank, a default message - * will be displayed. - * @param $group - * (optional) The group this message is in, which is displayed in a column - * in test output. Use 'Debug' to indicate this is debugging output. Do not - * translate this string. Defaults to 'Other'; most tests do not override - * this default. - * - * @return - * TRUE if the assertion succeeded, FALSE otherwise. - */ - protected function assertTrue($value, $message = '', $group = 'Other') { - return $this->assert((bool) $value, $message ? $message : new FormattableMarkup('Value @value is TRUE.', ['@value' => var_export($value, TRUE)]), $group); - } - - /** - * Check to see if a value is false. - * - * False values are: empty string, 0, NULL, and FALSE. - * - * @param $value - * 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\Render\FormattableMarkup to embed - * variables in the message text, not t(). If left blank, a default message - * will be displayed. - * @param $group - * (optional) The group this message is in, which is displayed in a column - * in test output. Use 'Debug' to indicate this is debugging output. Do not - * translate this string. Defaults to 'Other'; most tests do not override - * this default. - * - * @return - * TRUE if the assertion succeeded, FALSE otherwise. - */ - protected function assertFalse($value, $message = '', $group = 'Other') { - return $this->assert(!$value, $message ? $message : new FormattableMarkup('Value @value is FALSE.', ['@value' => var_export($value, TRUE)]), $group); - } - - /** - * Check to see if a value is NULL. - * - * @param $value - * 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\Render\FormattableMarkup to embed - * variables in the message text, not t(). If left blank, a default message - * will be displayed. - * @param $group - * (optional) The group this message is in, which is displayed in a column - * in test output. Use 'Debug' to indicate this is debugging output. Do not - * translate this string. Defaults to 'Other'; most tests do not override - * this default. - * - * @return - * TRUE if the assertion succeeded, FALSE otherwise. - */ - protected function assertNull($value, $message = '', $group = 'Other') { - return $this->assert(!isset($value), $message ? $message : new FormattableMarkup('Value @value is NULL.', ['@value' => var_export($value, TRUE)]), $group); - } - - /** - * Check to see if a value is not NULL. - * - * @param $value - * 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\Render\FormattableMarkup to embed - * variables in the message text, not t(). If left blank, a default message - * will be displayed. - * @param $group - * (optional) The group this message is in, which is displayed in a column - * in test output. Use 'Debug' to indicate this is debugging output. Do not - * translate this string. Defaults to 'Other'; most tests do not override - * this default. - * - * @return - * TRUE if the assertion succeeded, FALSE otherwise. - */ - protected function assertNotNull($value, $message = '', $group = 'Other') { - return $this->assert(isset($value), $message ? $message : new FormattableMarkup('Value @value is not NULL.', ['@value' => var_export($value, TRUE)]), $group); - } - - /** - * Check to see if two values are equal. - * - * @param $first - * The first value to check. - * @param $second - * The second value to check. - * @param $message - * (optional) A message to display with the assertion. Do not translate - * 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 - * (optional) The group this message is in, which is displayed in a column - * in test output. Use 'Debug' to indicate this is debugging output. Do not - * translate this string. Defaults to 'Other'; most tests do not override - * this default. - * - * @return - * TRUE if the assertion succeeded, FALSE otherwise. - */ - protected function assertEqual($first, $second, $message = '', $group = 'Other') { - // Cast objects implementing MarkupInterface to string instead of - // relying on PHP casting them to string depending on what they are being - // comparing with. - $first = $this->castSafeStrings($first); - $second = $this->castSafeStrings($second); - $is_equal = $first == $second; - if (!$is_equal || !$message) { - $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); - } - - /** - * Check to see if two values are not equal. - * - * @param $first - * The first value to check. - * @param $second - * The second value to check. - * @param $message - * (optional) A message to display with the assertion. Do not translate - * 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 - * (optional) The group this message is in, which is displayed in a column - * in test output. Use 'Debug' to indicate this is debugging output. Do not - * translate this string. Defaults to 'Other'; most tests do not override - * this default. - * - * @return - * TRUE if the assertion succeeded, FALSE otherwise. - */ - protected function assertNotEqual($first, $second, $message = '', $group = 'Other') { - // Cast objects implementing MarkupInterface to string instead of - // relying on PHP casting them to string depending on what they are being - // comparing with. - $first = $this->castSafeStrings($first); - $second = $this->castSafeStrings($second); - $not_equal = $first != $second; - if (!$not_equal || !$message) { - $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); - } - - /** - * Check to see if two values are identical. - * - * @param $first - * The first value to check. - * @param $second - * The second value to check. - * @param $message - * (optional) A message to display with the assertion. Do not translate - * 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 - * (optional) The group this message is in, which is displayed in a column - * in test output. Use 'Debug' to indicate this is debugging output. Do not - * translate this string. Defaults to 'Other'; most tests do not override - * this default. - * - * @return - * TRUE if the assertion succeeded, FALSE otherwise. - */ - protected function assertIdentical($first, $second, $message = '', $group = 'Other') { - $is_identical = $first === $second; - if (!$is_identical || !$message) { - $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); - } - - /** - * Check to see if two values are not identical. - * - * @param $first - * The first value to check. - * @param $second - * The second value to check. - * @param $message - * (optional) A message to display with the assertion. Do not translate - * 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 - * (optional) The group this message is in, which is displayed in a column - * in test output. Use 'Debug' to indicate this is debugging output. Do not - * translate this string. Defaults to 'Other'; most tests do not override - * this default. - * - * @return - * TRUE if the assertion succeeded, FALSE otherwise. - */ - protected function assertNotIdentical($first, $second, $message = '', $group = 'Other') { - $not_identical = $first !== $second; - if (!$not_identical || !$message) { - $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); - } - - /** - * Checks to see if two objects are identical. - * - * @param object $object1 - * The first object to check. - * @param object $object2 - * The second object to check. - * @param $message - * (optional) A message to display with the assertion. Do not translate - * 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 - * (optional) The group this message is in, which is displayed in a column - * in test output. Use 'Debug' to indicate this is debugging output. Do not - * translate this string. Defaults to 'Other'; most tests do not override - * this default. - * - * @return - * TRUE if the assertion succeeded, FALSE otherwise. - */ - protected function assertIdenticalObject($object1, $object2, $message = '', $group = 'Other') { - $message = $message ?: new FormattableMarkup('@object1 is identical to @object2', [ - '@object1' => var_export($object1, TRUE), - '@object2' => var_export($object2, TRUE), - ]); - $identical = TRUE; - foreach ($object1 as $key => $value) { - $identical = $identical && isset($object2->$key) && $object2->$key === $value; - } - return $this->assertTrue($identical, $message, $group); - } - - /** - * Asserts that no errors have been logged to the PHP error.log thus far. - * - * @return bool - * TRUE if the assertion succeeded, FALSE otherwise. - * - * @see \Drupal\simpletest\TestBase::prepareEnvironment() - * @see \Drupal\Core\DrupalKernel::bootConfiguration() - */ - protected function assertNoErrorsLogged() { - // Since PHP only creates the error.log file when an actual error is - // triggered, it is sufficient to check whether the file exists. - return $this->assertFalse(file_exists(DRUPAL_ROOT . '/' . $this->siteDirectory . '/error.log'), 'PHP error.log is empty.'); - } - - /** - * Asserts that a specific error has been logged to the PHP error log. - * - * @param string $error_message - * The expected error message. - * - * @return bool - * TRUE if the assertion succeeded, FALSE otherwise. - * - * @see \Drupal\simpletest\TestBase::prepareEnvironment() - * @see \Drupal\Core\DrupalKernel::bootConfiguration() - */ - protected function assertErrorLogged($error_message) { - $error_log_filename = DRUPAL_ROOT . '/' . $this->siteDirectory . '/error.log'; - if (!file_exists($error_log_filename)) { - $this->error('No error logged yet.'); - } - - $content = file_get_contents($error_log_filename); - $rows = explode(PHP_EOL, $content); - - // We iterate over the rows in order to be able to remove the logged error - // afterwards. - $found = FALSE; - foreach ($rows as $row_index => $row) { - if (strpos($content, $error_message) !== FALSE) { - $found = TRUE; - unset($rows[$row_index]); - } - } - - file_put_contents($error_log_filename, implode("\n", $rows)); - - return $this->assertTrue($found, sprintf('The %s error message was logged.', $error_message)); - } - - /** - * Fire an assertion that is always positive. - * - * @param $message - * (optional) A message to display with the assertion. Do not translate - * 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 - * (optional) The group this message is in, which is displayed in a column - * in test output. Use 'Debug' to indicate this is debugging output. Do not - * translate this string. Defaults to 'Other'; most tests do not override - * this default. - * - * @return - * TRUE. - */ - protected function pass($message = NULL, $group = 'Other') { - return $this->assert(TRUE, $message, $group); - } - - /** - * Fire an assertion that is always negative. - * - * @param $message - * (optional) A message to display with the assertion. Do not translate - * 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 - * (optional) The group this message is in, which is displayed in a column - * in test output. Use 'Debug' to indicate this is debugging output. Do not - * translate this string. Defaults to 'Other'; most tests do not override - * this default. - * - * @return - * FALSE. - */ - protected function fail($message = NULL, $group = 'Other') { - return $this->assert(FALSE, $message, $group); - } - - /** - * Fire an error assertion. - * - * @param $message - * (optional) A message to display with the assertion. Do not translate - * 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 - * (optional) The group this message is in, which is displayed in a column - * in test output. Use 'Debug' to indicate this is debugging output. Do not - * translate this string. Defaults to 'Other'; most tests do not override - * this default. - * @param $caller - * The caller of the error. - * - * @return - * FALSE. - */ - protected function error($message = '', $group = 'Other', array $caller = NULL) { - if ($group == 'User notice') { - // Since 'User notice' is set by trigger_error() which is used for debug - // set the message to a status of 'debug'. - return $this->assert('debug', $message, 'Debug', $caller); - } - - return $this->assert('exception', $message, $group, $caller); - } - - /** - * Logs a verbose message in a text file. - * - * The link to the verbose message will be placed in the test results as a - * passing assertion with the text '[verbose message]'. - * - * @param $message - * The verbose message to be stored. - * - * @see simpletest_verbose() - */ - protected function verbose($message) { - // Do nothing if verbose debugging is disabled. - if (!$this->verbose) { - return; - } - - $message = '<hr />ID #' . $this->verboseId . ' (<a href="' . $this->verboseClassName . '-' . ($this->verboseId - 1) . '-' . $this->testId . '.html">Previous</a> | <a href="' . $this->verboseClassName . '-' . ($this->verboseId + 1) . '-' . $this->testId . '.html">Next</a>)<hr />' . $message; - $verbose_filename = $this->verboseClassName . '-' . $this->verboseId . '-' . $this->testId . '.html'; - if (file_put_contents($this->verboseDirectory . '/' . $verbose_filename, $message)) { - $url = $this->verboseDirectoryUrl . '/' . $verbose_filename; - // Not using \Drupal\Core\Utility\LinkGeneratorInterface::generate() - // to avoid invoking the theme system, so that unit tests - // can use verbose() as well. - $url = '<a href="' . $url . '" target="_blank">Verbose message</a>'; - $this->error($url, 'User notice'); - } - $this->verboseId++; - } - - /** - * Run all tests in this class. - * - * Regardless of whether $methods are passed or not, only method names - * starting with "test" are executed. - * - * @param $methods - * (optional) A list of method names in the test case class to run; e.g., - * array('testFoo', 'testBar'). By default, all methods of the class are - * taken into account, but it can be useful to only run a few selected test - * methods during debugging. - */ - public function run(array $methods = []) { - $this->checkTestHierarchyMismatch(); - $class = get_class($this); - - if ($missing_requirements = $this->checkRequirements()) { - $object_info = new \ReflectionObject($this); - $caller = [ - 'file' => $object_info->getFileName(), - ]; - foreach ($missing_requirements as $missing_requirement) { - TestBase::insertAssert($this->testId, $class, FALSE, $missing_requirement, 'Requirements check', $caller); - } - return; - } - - TestServiceProvider::$currentTest = $this; - $simpletest_config = $this->config('simpletest.settings'); - - // Unless preset from run-tests.sh, retrieve the current verbose setting. - if (!isset($this->verbose)) { - $this->verbose = $simpletest_config->get('verbose'); - } - - if ($this->verbose) { - // Initialize verbose debugging. - $this->verbose = TRUE; - $this->verboseDirectory = PublicStream::basePath() . '/simpletest/verbose'; - $this->verboseDirectoryUrl = file_create_url($this->verboseDirectory); - if (\Drupal::service('file_system')->prepareDirectory($this->verboseDirectory, FileSystemInterface::CREATE_DIRECTORY) && !file_exists($this->verboseDirectory . '/.htaccess')) { - file_put_contents($this->verboseDirectory . '/.htaccess', "<IfModule mod_expires.c>\nExpiresActive Off\n</IfModule>\n"); - } - $this->verboseClassName = str_replace("\\", "_", $class); - } - // HTTP auth settings (<username>:<password>) for the simpletest browser - // when sending requests to the test site. - $this->httpAuthMethod = (int) $simpletest_config->get('httpauth.method'); - $username = $simpletest_config->get('httpauth.username'); - $password = $simpletest_config->get('httpauth.password'); - if (!empty($username) && !empty($password)) { - $this->httpAuthCredentials = $username . ':' . $password; - } - - // Force assertion failures to be thrown as exceptions. - Handle::register(); - - set_error_handler([$this, 'errorHandler']); - // Iterate through all the methods in this class, unless a specific list of - // methods to run was passed. - $test_methods = array_filter(get_class_methods($class), function ($method) { - return strpos($method, 'test') === 0; - }); - if (empty($test_methods)) { - // Call $this->assert() here because we need to pass along custom caller - // information, lest the wrong originating code file/line be identified. - $this->assert(FALSE, 'No test methods found.', 'Requirements', ['function' => __METHOD__ . '()', 'file' => __FILE__, 'line' => __LINE__]); - } - if ($methods) { - $test_methods = array_intersect($test_methods, $methods); - } - foreach ($test_methods as $method) { - // Insert a fail record. This will be deleted on completion to ensure - // that testing completed. - $method_info = new \ReflectionMethod($class, $method); - $caller = [ - 'file' => $method_info->getFileName(), - 'line' => $method_info->getStartLine(), - 'function' => $class . '->' . $method . '()', - ]; - $test_completion_check_id = TestBase::insertAssert($this->testId, $class, FALSE, 'The test did not complete due to a fatal error.', 'Completion check', $caller); - - try { - $this->prepareEnvironment(); - } - catch (\Exception $e) { - $this->exceptionHandler($e); - // The prepareEnvironment() method isolates the test from the parent - // Drupal site by creating a random database prefix and test site - // directory. If this fails, a test would possibly operate in the - // parent site. Therefore, the entire test run for this test class - // has to be aborted. - // restoreEnvironment() cannot be called, because we do not know - // where exactly the environment setup failed. - break; - } - - try { - $this->setUp(); - } - catch (\Exception $e) { - $this->exceptionHandler($e); - // Abort if setUp() fails, since all test methods will fail. - // But ensure to clean up and restore the environment, since - // prepareEnvironment() succeeded. - $this->restoreEnvironment(); - break; - } - try { - $this->$method(); - } - catch (\Exception $e) { - $this->exceptionHandler($e); - } - try { - $this->tearDown(); - } - catch (\Exception $e) { - $this->exceptionHandler($e); - // If a test fails to tear down, abort the entire test class, since - // it is likely that all tests will fail in the same way and a - // failure here only results in additional test artifacts that have - // to be manually deleted. - $this->restoreEnvironment(); - break; - } - - $this->restoreEnvironment(); - // Remove the test method completion check record. - TestBase::deleteAssert($test_completion_check_id); - } - - TestServiceProvider::$currentTest = NULL; - // Clear out the error messages and restore error handler. - \Drupal::messenger()->deleteAll(); - restore_error_handler(); - } - - /** - * Generates a database prefix for running tests. - * - * The database prefix is used by prepareEnvironment() to setup a public files - * directory for the test to be run, which also contains the PHP error log, - * which is written to in case of a fatal error. Since that directory is based - * on the database prefix, all tests (even unit tests) need to have one, in - * order to access and read the error log. - * - * @see TestBase::prepareEnvironment() - * - * The generated database table prefix is used for the Drupal installation - * being performed for the test. It is also used as user agent HTTP header - * value by the cURL-based browser of WebTestBase, which is sent to the Drupal - * installation of the test. During early Drupal bootstrap, the user agent - * HTTP header is parsed, and if it matches, all database queries use the - * database table prefix that has been generated here. - * - * @see WebTestBase::curlInitialize() - * @see drupal_valid_test_ua() - */ - private function prepareDatabasePrefix() { - $test_db = new TestDatabase(); - $this->siteDirectory = $test_db->getTestSitePath(); - $this->databasePrefix = $test_db->getDatabasePrefix(); - - // As soon as the database prefix is set, the test might start to execute. - // All assertions as well as the SimpleTest batch operations are associated - // with the testId, so the database prefix has to be associated with it. - $affected_rows = self::getDatabaseConnection()->update('simpletest_test_id') - ->fields(['last_prefix' => $this->databasePrefix]) - ->condition('test_id', $this->testId) - ->execute(); - if (!$affected_rows) { - throw new \RuntimeException('Failed to set up database prefix.'); - } - } - - /** - * Act on global state information before the environment is altered for a test. - * - * Allows e.g. KernelTestBase to prime system/extension info from the - * parent site (and inject it into the test environment so as to improve - * performance). - */ - protected function beforePrepareEnvironment() { - } - - /** - * Prepares the current environment for running the test. - * - * Backups various current environment variables and resets them, so they do - * not interfere with the Drupal site installation in which tests are executed - * and can be restored in TestBase::restoreEnvironment(). - * - * Also sets up new resources for the testing environment, such as the public - * filesystem and configuration directories. - * - * This method is private as it must only be called once by TestBase::run() - * (multiple invocations for the same test would have unpredictable - * consequences) and it must not be callable or overridable by test classes. - * - * @see TestBase::beforePrepareEnvironment() - */ - private function prepareEnvironment() { - $user = \Drupal::currentUser(); - // Allow (base) test classes to backup global state information. - $this->beforePrepareEnvironment(); - - // Create the database prefix for this test. - $this->prepareDatabasePrefix(); - - $language_interface = \Drupal::languageManager()->getCurrentLanguage(); - - // When running the test runner within a test, back up the original database - // prefix. - if (DRUPAL_TEST_IN_CHILD_SITE) { - $this->originalPrefix = drupal_valid_test_ua(); - } - - // Backup current in-memory configuration. - $site_path = \Drupal::service('site.path'); - $this->originalSite = $site_path; - $this->originalSettings = Settings::getAll(); - $this->originalConfig = $GLOBALS['config']; - // @todo Remove all remnants of $GLOBALS['conf']. - // @see https://www.drupal.org/node/2183323 - $this->originalConf = isset($GLOBALS['conf']) ? $GLOBALS['conf'] : NULL; - - // Backup statics and globals. - $this->originalContainer = \Drupal::getContainer(); - $this->originalLanguage = $language_interface; - - // Save further contextual information. - // Use the original files directory to avoid nesting it within an existing - // simpletest directory if a test is executed within a test. - $this->originalFileDirectory = Settings::get('file_public_path', $site_path . '/files'); - $this->originalUser = isset($user) ? clone $user : NULL; - - // Prevent that session data is leaked into the UI test runner by closing - // the session and then setting the session-name (i.e. the name of the - // session cookie) to a random value. If a test starts a new session, then - // it will be associated with a different session-name. After the test-run - // it can be safely destroyed. - // @see TestBase::restoreEnvironment() - if (PHP_SAPI !== 'cli' && session_status() === PHP_SESSION_ACTIVE) { - session_write_close(); - } - $this->originalSessionName = session_name(); - session_name('SIMPLETEST' . Crypt::randomBytesBase64()); - - // Save and clean the shutdown callbacks array because it is static cached - // and will be changed by the test run. Otherwise it will contain callbacks - // from both environments and the testing environment will try to call the - // handlers defined by the original one. - $callbacks = &drupal_register_shutdown_function(); - $this->originalShutdownCallbacks = $callbacks; - $callbacks = []; - - // Create test directory ahead of installation so fatal errors and debug - // information can be logged during installation process. - \Drupal::service('file_system')->prepareDirectory($this->siteDirectory, FileSystemInterface::CREATE_DIRECTORY | FileSystemInterface::MODIFY_PERMISSIONS); - - // Prepare filesystem directory paths. - $this->publicFilesDirectory = $this->siteDirectory . '/files'; - $this->privateFilesDirectory = $this->siteDirectory . '/private'; - $this->tempFilesDirectory = $this->siteDirectory . '/temp'; - $this->translationFilesDirectory = $this->siteDirectory . '/translations'; - - $this->generatedTestFiles = FALSE; - - // Ensure the configImporter is refreshed for each test. - $this->configImporter = NULL; - - // Unregister all custom stream wrappers of the parent site. - // Availability of Drupal stream wrappers varies by test base class: - // - KernelTestBase supports and maintains stream wrappers in a custom - // way. - // - WebTestBase re-initializes Drupal stream wrappers after installation. - // The original stream wrappers are restored after the test run. - // @see TestBase::restoreEnvironment() - $this->originalContainer->get('stream_wrapper_manager')->unregister(); - - // Reset statics. - drupal_static_reset(); - - // Ensure there is no service container. - $this->container = NULL; - \Drupal::unsetContainer(); - - // Unset globals. - unset($GLOBALS['config']); - unset($GLOBALS['conf']); - - // Log fatal errors. - ini_set('log_errors', 1); - ini_set('error_log', DRUPAL_ROOT . '/' . $this->siteDirectory . '/error.log'); - - // Change the database prefix. - $this->changeDatabasePrefix(); - - // After preparing the environment and changing the database prefix, we are - // in a valid test environment. - drupal_valid_test_ua($this->databasePrefix); - - // Reset settings. - new Settings([ - // For performance, simply use the database prefix as hash salt. - 'hash_salt' => $this->databasePrefix, - 'container_yamls' => [], - ]); - - Environment::setTimeLimit($this->timeLimit); - } - - /** - * Performs cleanup tasks after each individual test method has been run. - */ - protected function tearDown() { - } - - /** - * Cleans up the test environment and restores the original environment. - * - * Deletes created files, database tables, and reverts environment changes. - * - * This method needs to be invoked for both unit and integration tests. - * - * @see TestBase::prepareDatabasePrefix() - * @see TestBase::changeDatabasePrefix() - * @see TestBase::prepareEnvironment() - */ - private function restoreEnvironment() { - // Destroy the session if one was started during the test-run. - $_SESSION = []; - if (PHP_SAPI !== 'cli' && session_status() === PHP_SESSION_ACTIVE) { - session_destroy(); - $params = session_get_cookie_params(); - setcookie(session_name(), '', REQUEST_TIME - 3600, $params['path'], $params['domain'], $params['secure'], $params['httponly']); - } - session_name($this->originalSessionName); - - // Reset all static variables. - // Unsetting static variables will potentially invoke destruct methods, - // which might call into functions that prime statics and caches again. - // In that case, all functions are still operating on the test environment, - // which means they may need to access its filesystem and database. - drupal_static_reset(); - - if ($this->container && $this->container->has('state') && $state = $this->container->get('state')) { - $captured_emails = $state->get('system.test_mail_collector') ?: []; - $emailCount = count($captured_emails); - if ($emailCount) { - $message = $emailCount == 1 ? '1 email was sent during this test.' : $emailCount . ' emails were sent during this test.'; - $this->pass($message, 'Email'); - } - } - - // Sleep for 50ms to allow shutdown functions and terminate events to - // complete. Further information: https://www.drupal.org/node/2194357. - usleep(50000); - - // Remove all prefixed tables. - $original_connection_info = Database::getConnectionInfo('simpletest_original_default'); - $original_prefix = $original_connection_info['default']['prefix']['default']; - $test_connection_info = Database::getConnectionInfo('default'); - $test_prefix = $test_connection_info['default']['prefix']['default']; - if ($original_prefix != $test_prefix) { - $tables = Database::getConnection()->schema()->findTables('%'); - foreach ($tables as $table) { - if (Database::getConnection()->schema()->dropTable($table)) { - unset($tables[$table]); - } - } - } - - // In case a fatal error occurred that was not in the test process read the - // log to pick up any fatal errors. - (new TestDatabase($this->databasePrefix))->logRead($this->testId, get_class($this)); - - // Restore original dependency injection container. - $this->container = $this->originalContainer; - \Drupal::setContainer($this->originalContainer); - - // Delete test site directory. - \Drupal::service('file_system')->deleteRecursive($this->siteDirectory, [$this, 'filePreDeleteCallback']); - - // Restore original database connection. - Database::removeConnection('default'); - Database::renameConnection('simpletest_original_default', 'default'); - - // Reset all static variables. - // All destructors of statically cached objects have been invoked above; - // this second reset is guaranteed to reset everything to nothing. - drupal_static_reset(); - - // Restore original in-memory configuration. - $GLOBALS['config'] = $this->originalConfig; - $GLOBALS['conf'] = $this->originalConf; - new Settings($this->originalSettings); - - // Re-initialize original stream wrappers of the parent site. - // This must happen after static variables have been reset and the original - // container and settings are restored, as simpletest_log_read() uses the - // public stream wrapper to locate the error.log. - $this->originalContainer->get('stream_wrapper_manager')->register(); - - if (isset($this->originalPrefix)) { - drupal_valid_test_ua($this->originalPrefix); - } - else { - drupal_valid_test_ua(FALSE); - } - - // Restore original shutdown callbacks. - $callbacks = &drupal_register_shutdown_function(); - $callbacks = $this->originalShutdownCallbacks; - } - - /** - * Handle errors during test runs. - * - * Because this is registered in set_error_handler(), it has to be public. - * - * @see set_error_handler - */ - public function errorHandler($severity, $message, $file = NULL, $line = NULL) { - if ($severity & error_reporting()) { - $error_map = [ - E_STRICT => 'Run-time notice', - E_WARNING => 'Warning', - E_NOTICE => 'Notice', - E_CORE_ERROR => 'Core error', - E_CORE_WARNING => 'Core warning', - E_USER_ERROR => 'User error', - E_USER_WARNING => 'User warning', - E_USER_NOTICE => 'User notice', - E_RECOVERABLE_ERROR => 'Recoverable error', - E_DEPRECATED => 'Deprecated', - E_USER_DEPRECATED => 'User deprecated', - ]; - - $backtrace = debug_backtrace(); - - // Add verbose backtrace for errors, but not for debug() messages. - if ($severity !== E_USER_NOTICE) { - $verbose_backtrace = $backtrace; - array_shift($verbose_backtrace); - $message .= '<pre class="backtrace">' . Error::formatBacktrace($verbose_backtrace) . '</pre>'; - } - - $this->error($message, $error_map[$severity], Error::getLastCaller($backtrace)); - } - return TRUE; - } - - /** - * Handle exceptions. - * - * @see set_exception_handler - */ - protected function exceptionHandler($exception) { - $backtrace = $exception->getTrace(); - $verbose_backtrace = $backtrace; - // Push on top of the backtrace the call that generated the exception. - array_unshift($backtrace, [ - 'line' => $exception->getLine(), - 'file' => $exception->getFile(), - ]); - $decoded_exception = Error::decodeException($exception); - unset($decoded_exception['backtrace']); - $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)); - } - - /** - * Changes in memory settings. - * - * @param $name - * The name of the setting to return. - * @param $value - * The value of the setting. - * - * @see \Drupal\Core\Site\Settings::get() - */ - protected function settingsSet($name, $value) { - $settings = Settings::getAll(); - $settings[$name] = $value; - new Settings($settings); - } - - /** - * Ensures test files are deletable. - * - * Some tests chmod generated files to be read only. During - * TestBase::restoreEnvironment() and other cleanup operations, these files - * need to get deleted too. - * - * @see \Drupal\Core\File\FileSystemInterface::deleteRecursive() - */ - public static function filePreDeleteCallback($path) { - // When the webserver runs with the same system user as the test runner, we - // can make read-only files writable again. If not, chmod will fail while - // the file deletion still works if file permissions have been configured - // correctly. Thus, we ignore any problems while running chmod. - @chmod($path, 0700); - } - - /** - * Configuration accessor for tests. Returns non-overridden configuration. - * - * @param $name - * Configuration name. - * - * @return \Drupal\Core\Config\Config - * The configuration object with original configuration data. - */ - protected function config($name) { - return \Drupal::configFactory()->getEditable($name); - } - - /** - * Gets the database prefix. - * - * @return string - * The database prefix - */ - public function getDatabasePrefix() { - return $this->databasePrefix; - } - - /** - * Gets the temporary files directory. - * - * @return string - * The temporary files directory. - */ - public function getTempFilesDirectory() { - return $this->tempFilesDirectory; - } - -} diff --git a/core/modules/simpletest/src/TestDiscovery.php b/core/modules/simpletest/src/TestDiscovery.php deleted file mode 100644 index 8ce8b7de464cbdc75b7257956733131c6e463382..0000000000000000000000000000000000000000 --- a/core/modules/simpletest/src/TestDiscovery.php +++ /dev/null @@ -1,150 +0,0 @@ -<?php - -namespace Drupal\simpletest; - -@trigger_error(__NAMESPACE__ . '\\TestDiscovery is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Test\TestDiscovery instead. See https://www.drupal.org/node/2949692', E_USER_DEPRECATED); - -use Doctrine\Common\Reflection\StaticReflectionParser; -use Drupal\Component\Annotation\Reflection\MockFileFinder; -use Drupal\Component\Utility\NestedArray; -use Drupal\Core\Extension\ModuleHandlerInterface; -use Drupal\Core\Test\Exception\MissingGroupException; -use Drupal\Core\Test\TestDiscovery as CoreTestDiscovery; - -/** - * Discovers available tests. - * - * This class provides backwards compatibility for code which uses the legacy - * \Drupal\simpletest\TestDiscovery. - * - * @deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use - * \Drupal\Core\Test\TestDiscovery instead. - * - * @see https://www.drupal.org/node/2949692 - */ -class TestDiscovery extends CoreTestDiscovery { - - /** - * The module handler. - * - * @var \Drupal\Core\Extension\ModuleHandlerInterface - */ - protected $moduleHandler; - - /** - * Constructs a new test discovery. - * - * @param string $root - * The app root. - * @param $class_loader - * The class loader. Normally Composer's ClassLoader, as included by the - * front controller, but may also be decorated; e.g., - * \Symfony\Component\ClassLoader\ApcClassLoader. - * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler - * The module handler. - */ - public function __construct($root, $class_loader, ModuleHandlerInterface $module_handler) { - parent::__construct($root, $class_loader); - $this->moduleHandler = $module_handler; - } - - /** - * Discovers all available tests in all extensions. - * - * This method is a near-duplicate of - * \Drupal\Core\Tests\TestDiscovery::getTestClasses(). It exists so that we - * can provide a BC invocation of hook_simpletest_alter(). - * - * @param string $extension - * (optional) The name of an extension to limit discovery to; e.g., 'node'. - * @param string[] $types - * An array of included test types. - * - * @return array - * An array of tests keyed by the the group name. If a test is annotated to - * belong to multiple groups, it will appear under all group keys it belongs - * to. - * @code - * $groups['block'] => array( - * 'Drupal\Tests\block\Functional\BlockTest' => array( - * 'name' => 'Drupal\Tests\block\Functional\BlockTest', - * 'description' => 'Tests block UI CRUD functionality.', - * 'group' => 'block', - * 'groups' => ['block', 'group2', 'group3'], - * ), - * ); - * @endcode - */ - public function getTestClasses($extension = NULL, array $types = []) { - if (!isset($extension) && empty($types)) { - if (!empty($this->testClasses)) { - return $this->testClasses; - } - } - $list = []; - - $classmap = $this->findAllClassFiles($extension); - - // Prevent expensive class loader lookups for each reflected test class by - // registering the complete classmap of test classes to the class loader. - // This also ensures that test classes are loaded from the discovered - // pathnames; a namespace/classname mismatch will throw an exception. - $this->classLoader->addClassMap($classmap); - - foreach ($classmap as $classname => $pathname) { - $finder = MockFileFinder::create($pathname); - $parser = new StaticReflectionParser($classname, $finder, TRUE); - try { - $info = static::getTestInfo($classname, $parser->getDocComment()); - } - catch (MissingGroupException $e) { - // If the class name ends in Test and is not a migrate table dump. - if (preg_match('/Test$/', $classname) && strpos($classname, 'migrate_drupal\Tests\Table') === FALSE) { - throw $e; - } - // If the class is @group annotation just skip it. Most likely it is an - // abstract class, trait or test fixture. - continue; - } - // 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 ($info['type'] == 'Simpletest') { - if (!empty($info['requires']['module'])) { - if (array_diff($info['requires']['module'], $this->availableExtensions['module'])) { - continue; - } - } - } - - foreach ($info['groups'] as $group) { - $list[$group][$classname] = $info; - } - } - - // Sort the groups and tests within the groups by name. - uksort($list, 'strnatcasecmp'); - foreach ($list as &$tests) { - uksort($tests, 'strnatcasecmp'); - } - - // Allow modules extending core tests to disable originals. - $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) && empty($types)) { - $this->testClasses = $list; - } - - if ($types) { - $list = NestedArray::filter($list, function ($element) use ($types) { - return !(is_array($element) && isset($element['type']) && !in_array($element['type'], $types)); - }); - } - - return $list; - } - -} diff --git a/core/modules/simpletest/src/TestServiceProvider.php b/core/modules/simpletest/src/TestServiceProvider.php deleted file mode 100644 index 79fc2847ad74ada86f2ba6557dce701b7c8cedf6..0000000000000000000000000000000000000000 --- a/core/modules/simpletest/src/TestServiceProvider.php +++ /dev/null @@ -1,17 +0,0 @@ -<?php - -namespace Drupal\simpletest; - -use Drupal\KernelTests\TestServiceProvider as CoreTestServiceProvider; - -/** - * Provides special routing services for tests. - * - * @deprecated in drupal:8.6.0 and is removed from drupal:9.0.0. Use - * Drupal\KernelTests\TestServiceProvider instead. - * - * @see https://www.drupal.org/node/2943146 - */ -class TestServiceProvider extends CoreTestServiceProvider { - -} diff --git a/core/modules/simpletest/src/Tests/BrokenSetUpTest.php b/core/modules/simpletest/src/Tests/BrokenSetUpTest.php deleted file mode 100644 index fab44d00c820b62e54c823ec02bbe344f998f433..0000000000000000000000000000000000000000 --- a/core/modules/simpletest/src/Tests/BrokenSetUpTest.php +++ /dev/null @@ -1,122 +0,0 @@ -<?php - -namespace Drupal\simpletest\Tests; - -use Drupal\simpletest\WebTestBase; - -/** - * Tests a test case that does not call parent::setUp(). - * - * If a test case does not call parent::setUp(), running - * \Drupal\simpletest\WebTestBase::tearDown() would destroy the main site's - * database tables. Therefore, we ensure that tests which are not set up - * properly are skipped. - * - * @group WebTestBase - * @group legacy - * - * @see \Drupal\simpletest\WebTestBase - */ -class BrokenSetUpTest extends WebTestBase { - - /** - * Modules to enable. - * - * @var array - */ - public static $modules = ['simpletest']; - - /** - * The path to the shared trigger file. - * - * @var string - */ - protected $sharedTriggerFile; - - protected function setUp() { - // If the test is being run from the main site, set up normally. - if (!$this->isInChildSite()) { - parent::setUp(); - - $this->sharedTriggerFile = $this->publicFilesDirectory . '/trigger'; - - // Create and log in user. - $admin_user = $this->drupalCreateUser(['administer unit tests']); - $this->drupalLogin($admin_user); - } - // If the test is being run from within simpletest, set up the broken test. - else { - $this->sharedTriggerFile = $this->originalFileDirectory . '/trigger'; - - if (file_get_contents($this->sharedTriggerFile) === 'setup') { - throw new \Exception('Broken setup'); - } - $this->pass('The setUp() method has run.'); - } - } - - protected function tearDown() { - // If the test is being run from the main site, tear down normally. - if (!$this->isInChildSite()) { - unlink($this->sharedTriggerFile); - parent::tearDown(); - } - // If the test is being run from within simpletest, output a message. - else { - if (file_get_contents($this->sharedTriggerFile) === 'teardown') { - throw new \Exception('Broken teardown'); - } - $this->pass('The tearDown() method has run.'); - } - } - - /** - * Runs this test case from within the simpletest child site. - */ - public function testMethod() { - // If the test is being run from the main site, run it again from the web - // interface within the simpletest child site. - if (!$this->isInChildSite()) { - // Verify that a broken setUp() method is caught. - file_put_contents($this->sharedTriggerFile, 'setup'); - $edit['tests[Drupal\simpletest\Tests\BrokenSetUpTest]'] = TRUE; - $this->drupalPostForm('admin/config/development/testing', $edit, t('Run tests')); - $this->assertRaw('Broken setup'); - $this->assertNoRaw('The setUp() method has run.'); - $this->assertNoRaw('Broken test'); - $this->assertNoRaw('The test method has run.'); - $this->assertNoRaw('Broken teardown'); - $this->assertNoRaw('The tearDown() method has run.'); - - // Verify that a broken tearDown() method is caught. - file_put_contents($this->sharedTriggerFile, 'teardown'); - $edit['tests[Drupal\simpletest\Tests\BrokenSetUpTest]'] = TRUE; - $this->drupalPostForm('admin/config/development/testing', $edit, t('Run tests')); - $this->assertNoRaw('Broken setup'); - $this->assertRaw('The setUp() method has run.'); - $this->assertNoRaw('Broken test'); - $this->assertRaw('The test method has run.'); - $this->assertRaw('Broken teardown'); - $this->assertNoRaw('The tearDown() method has run.'); - - // Verify that a broken test method is caught. - file_put_contents($this->sharedTriggerFile, 'test'); - $edit['tests[Drupal\simpletest\Tests\BrokenSetUpTest]'] = TRUE; - $this->drupalPostForm('admin/config/development/testing', $edit, t('Run tests')); - $this->assertNoRaw('Broken setup'); - $this->assertRaw('The setUp() method has run.'); - $this->assertRaw('Broken test'); - $this->assertNoRaw('The test method has run.'); - $this->assertNoRaw('Broken teardown'); - $this->assertRaw('The tearDown() method has run.'); - } - // If the test is being run from within simpletest, output a message. - else { - if (file_get_contents($this->sharedTriggerFile) === 'test') { - throw new \Exception('Broken test'); - } - $this->pass('The test method has run.'); - } - } - -} diff --git a/core/modules/simpletest/src/Tests/BrowserTest.php b/core/modules/simpletest/src/Tests/BrowserTest.php deleted file mode 100644 index a1059dd375236454e8ea9f6d7b4119dafbd8783b..0000000000000000000000000000000000000000 --- a/core/modules/simpletest/src/Tests/BrowserTest.php +++ /dev/null @@ -1,129 +0,0 @@ -<?php - -namespace Drupal\simpletest\Tests; - -use Drupal\Core\Url; -use Drupal\simpletest\WebTestBase; - -/** - * Tests the internal browser of the testing framework. - * - * @group simpletest - * @group WebTestBase - */ -class BrowserTest extends WebTestBase { - - /** - * A flag indicating whether a cookie has been set in a test. - * - * @var bool - */ - protected static $cookieSet = FALSE; - - /** - * Modules to enable. - * - * @var string[] - */ - public static $modules = ['block']; - - /** - * {@inheritdoc} - */ - protected function setUp() { - parent::setUp(); - - $this->drupalPlaceBlock('local_tasks_block'); - } - - /** - * Test \Drupal\simpletest\WebTestBase::getAbsoluteUrl(). - */ - public function testGetAbsoluteUrl() { - $url = 'user/login'; - - $this->drupalGet($url); - $absolute = Url::fromRoute('user.login', [], ['absolute' => TRUE])->toString(); - $this->assertEqual($absolute, $this->url, 'Passed and requested URL are equal.'); - $this->assertEqual($this->url, $this->getAbsoluteUrl($this->url), 'Requested and returned absolute URL are equal.'); - - $this->drupalPostForm(NULL, [], t('Log in')); - $this->assertEqual($absolute, $this->url, 'Passed and requested URL are equal.'); - $this->assertEqual($this->url, $this->getAbsoluteUrl($this->url), 'Requested and returned absolute URL are equal.'); - - $this->clickLink('Create new account'); - $absolute = Url::fromRoute('user.register', [], ['absolute' => TRUE])->toString(); - $this->assertEqual($absolute, $this->url, 'Passed and requested URL are equal.'); - $this->assertEqual($this->url, $this->getAbsoluteUrl($this->url), 'Requested and returned absolute URL are equal.'); - } - - /** - * Tests XPath escaping. - */ - public function testXPathEscaping() { - $testpage = <<< EOF -<html> -<body> -<a href="link1">A "weird" link, just to bother the dumb "XPath 1.0"</a> -<a href="link2">A second "even more weird" link, in memory of George O'Malley</a> -<a href="link3">A \$third$ link, so weird it's worth $1 million</a> -<a href="link4">A fourth link, containing alternative \\1 regex backreferences \\2</a> -</body> -</html> -EOF; - $this->setRawContent($testpage); - - // Matches the first link. - $urls = $this->xpath('//a[text()=:text]', [':text' => 'A "weird" link, just to bother the dumb "XPath 1.0"']); - $this->assertEqual($urls[0]['href'], 'link1', 'Match with quotes.'); - - $urls = $this->xpath('//a[text()=:text]', [':text' => 'A second "even more weird" link, in memory of George O\'Malley']); - $this->assertEqual($urls[0]['href'], 'link2', 'Match with mixed single and double quotes.'); - - $urls = $this->xpath('//a[text()=:text]', [':text' => 'A $third$ link, so weird it\'s worth $1 million']); - $this->assertEqual($urls[0]['href'], 'link3', 'Match with a regular expression back reference symbol (dollar sign).'); - - $urls = $this->xpath('//a[text()=:text]', [':text' => 'A fourth link, containing alternative \\1 regex backreferences \\2']); - $this->assertEqual($urls[0]['href'], 'link4', 'Match with another regular expression back reference symbol (double backslash).'); - } - - /** - * Tests that cookies set during a request are available for testing. - */ - public function testCookies() { - // Check that the $this->cookies property is populated when a user logs in. - $user = $this->drupalCreateUser(); - $edit = ['name' => $user->getAccountName(), 'pass' => $user->pass_raw]; - $this->drupalPostForm('<front>', $edit, t('Log in')); - $this->assertEqual(count($this->cookies), 1, 'A cookie is set when the user logs in.'); - - // Check that the name and value of the cookie match the request data. - $cookie_header = $this->drupalGetHeader('set-cookie', TRUE); - - // The name and value are located at the start of the string, separated by - // an equals sign and ending in a semicolon. - preg_match('/^([^=]+)=([^;]+)/', $cookie_header, $matches); - $name = $matches[1]; - $value = $matches[2]; - - $this->assertTrue(array_key_exists($name, $this->cookies), 'The cookie name is correct.'); - $this->assertEqual($value, $this->cookies[$name]['value'], 'The cookie value is correct.'); - - // Set a flag indicating that a cookie has been set in this test. - // @see testCookieDoesNotBleed() - static::$cookieSet = TRUE; - } - - /** - * Tests that the cookies from a previous test do not bleed into a new test. - * - * @see static::testCookies() - */ - public function testCookieDoesNotBleed() { - // In order for this test to be effective it should always run after the - // testCookies() test. - $this->assertTrue(static::$cookieSet, 'Tests have been executed in the expected order.'); - $this->assertEqual(count($this->cookies), 0, 'No cookies are present at the start of a new test.'); - } - -} diff --git a/core/modules/simpletest/src/Tests/MissingCheckedRequirementsTest.php b/core/modules/simpletest/src/Tests/MissingCheckedRequirementsTest.php deleted file mode 100644 index 4bf7c7b6cc0ddf678e298a6e757f495f90164c7e..0000000000000000000000000000000000000000 --- a/core/modules/simpletest/src/Tests/MissingCheckedRequirementsTest.php +++ /dev/null @@ -1,59 +0,0 @@ -<?php - -namespace Drupal\simpletest\Tests; - -use Drupal\simpletest\WebTestBase; - -/** - * Tests a test case with missing requirements. - * - * @group simpletest - * @group WebTestBase - * @group legacy - */ -class MissingCheckedRequirementsTest extends WebTestBase { - - /** - * Modules to enable. - * - * @var array - */ - public static $modules = ['simpletest']; - - protected function setUp() { - parent::setUp(); - $admin_user = $this->drupalCreateUser(['administer unit tests']); - $this->drupalLogin($admin_user); - } - - /** - * Overrides checkRequirements(). - */ - protected function checkRequirements() { - if ($this->isInChildSite()) { - return [ - 'Test is not allowed to run.', - ]; - } - return parent::checkRequirements(); - } - - /** - * Ensures test will not run when requirements are missing. - */ - public function testCheckRequirements() { - // If this is the main request, run the web test script and then assert - // that the child tests did not run. - if (!$this->isInChildSite()) { - // Run this test from web interface. - $edit['tests[Drupal\simpletest\Tests\MissingCheckedRequirementsTest]'] = TRUE; - $this->drupalPostForm('admin/config/development/testing', $edit, t('Run tests')); - $this->assertRaw('Test is not allowed to run.', 'Test check for requirements came up.'); - $this->assertNoText('Test ran when it failed requirements check.', 'Test requirements stopped test from running.'); - } - else { - $this->fail('Test ran when it failed requirements check.'); - } - } - -} diff --git a/core/modules/simpletest/src/Tests/SimpleTestBrowserTest.php b/core/modules/simpletest/src/Tests/SimpleTestBrowserTest.php deleted file mode 100644 index 0aeceaf58cba73cd2752bb9144d7e0b5efec6762..0000000000000000000000000000000000000000 --- a/core/modules/simpletest/src/Tests/SimpleTestBrowserTest.php +++ /dev/null @@ -1,119 +0,0 @@ -<?php - -namespace Drupal\simpletest\Tests; - -use Drupal\Core\Url; -use Drupal\simpletest\WebTestBase; - -/** - * Tests the WebTestBase internal browser. - * - * @group simpletest - * @group WebTestBase - */ -class SimpleTestBrowserTest extends WebTestBase { - - /** - * Modules to enable. - * - * @var array - */ - public static $modules = ['simpletest', 'test_page_test']; - - protected function setUp() { - parent::setUp(); - // Create and log in an admin user. - $this->drupalLogin($this->drupalCreateUser(['administer unit tests'])); - } - - /** - * Test the internal browsers functionality. - */ - public function testInternalBrowser() { - // Retrieve the test page and check its title and headers. - $this->drupalGet('test-page'); - $this->assertTrue($this->drupalGetHeader('Date'), 'An HTTP header was received.'); - $this->assertTitle(t('Test page | @site-name', [ - '@site-name' => $this->config('system.site')->get('name'), - ])); - $this->assertNoTitle('Foo'); - - $old_user_id = $this->container->get('current_user')->id(); - $user = $this->drupalCreateUser(); - $this->drupalLogin($user); - // Check that current user service updated. - $this->assertNotEqual($old_user_id, $this->container->get('current_user')->id(), 'Current user service updated.'); - $headers = $this->drupalGetHeaders(TRUE); - $this->assertEqual(count($headers), 2, 'There was one intermediate request.'); - $this->assertTrue(strpos($headers[0][':status'], '303') !== FALSE, 'Intermediate response code was 303.'); - $this->assertFalse(empty($headers[0]['location']), 'Intermediate request contained a Location header.'); - $this->assertEqual($this->getUrl(), $headers[0]['location'], 'HTTP redirect was followed'); - $this->assertFalse($this->drupalGetHeader('Location'), 'Headers from intermediate request were reset.'); - $this->assertResponse(200, 'Response code from intermediate request was reset.'); - - $this->drupalLogout(); - // Check that current user service updated to anonymous user. - $this->assertEqual(0, $this->container->get('current_user')->id(), 'Current user service updated.'); - - // Test the maximum redirection option. - $this->maximumRedirects = 1; - $edit = [ - 'name' => $user->getAccountName(), - 'pass' => $user->pass_raw, - ]; - $this->drupalPostForm('user/login', $edit, t('Log in'), [ - 'query' => ['destination' => 'user/logout'], - ]); - $headers = $this->drupalGetHeaders(TRUE); - $this->assertEqual(count($headers), 2, 'Simpletest stopped following redirects after the first one.'); - - // Remove the Simpletest private key file so we can test the protection - // against requests that forge a valid testing user agent to gain access - // to the installer. - // @see drupal_valid_test_ua() - // Not using File API; a potential error must trigger a PHP warning. - unlink($this->siteDirectory . '/.htkey'); - $this->drupalGet(Url::fromUri('base:core/install.php', ['external' => TRUE, 'absolute' => TRUE])->toString()); - $this->assertResponse(403, 'Cannot access install.php.'); - } - - /** - * Test validation of the User-Agent header we use to perform test requests. - */ - public function testUserAgentValidation() { - global $base_url; - - // Logout the user which was logged in during test-setup. - $this->drupalLogout(); - - $system_path = $base_url . '/' . drupal_get_path('module', 'system'); - $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.'); - $test_ua = drupal_generate_test_ua($matches[0]); - $this->additionalCurlOptions = [CURLOPT_USERAGENT => $test_ua]; - - // Test pages only available for testing. - $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->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.'); - - // 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->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.'); - } - -} diff --git a/core/modules/simpletest/src/Tests/SimpleTestErrorCollectorTest.php b/core/modules/simpletest/src/Tests/SimpleTestErrorCollectorTest.php deleted file mode 100644 index 59456fa1b0d7bb5a77c48403042f54d50dba18ae..0000000000000000000000000000000000000000 --- a/core/modules/simpletest/src/Tests/SimpleTestErrorCollectorTest.php +++ /dev/null @@ -1,95 +0,0 @@ -<?php - -namespace Drupal\simpletest\Tests; - -use Drupal\Component\Render\FormattableMarkup; -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, new FormattableMarkup("Group was %group", ['%group' => $group])); - $this->assertEqual($error['caller']['function'], $function, new FormattableMarkup("Function was %function", ['%function' => $function])); - $this->assertEqual(\Drupal::service('file_system')->basename($error['caller']['file']), $file, new FormattableMarkup("File was %file", ['%file' => $file])); - if (isset($message)) { - $this->assertEqual($error['message'], $message, new FormattableMarkup("Message was %message", ['%message' => $message])); - } - } - -} diff --git a/core/modules/simpletest/src/Tests/SimpleTestInstallBatchTest.php b/core/modules/simpletest/src/Tests/SimpleTestInstallBatchTest.php deleted file mode 100644 index 18f86bef2fa080fcc4c3c41cca355ad3a1c8b3ca..0000000000000000000000000000000000000000 --- a/core/modules/simpletest/src/Tests/SimpleTestInstallBatchTest.php +++ /dev/null @@ -1,39 +0,0 @@ -<?php - -namespace Drupal\simpletest\Tests; - -use Drupal\entity_test\Entity\EntityTest; -use Drupal\simpletest\WebTestBase; - -/** - * Tests batch operations during tests execution. - * - * This demonstrates that a batch will be successfully executed during module - * installation when running tests. - * - * @group simpletest - * @group WebTestBase - * @group FunctionalTestSetupTrait - * - * @see \Drupal\FunctionalTests\Core\Test\ModuleInstallBatchTest - */ -class SimpleTestInstallBatchTest extends WebTestBase { - - /** - * Modules to enable. - * - * @var array - */ - public static $modules = ['test_batch_test', 'entity_test']; - - /** - * Tests loading entities created in a batch in test_batch_test_install(). - */ - public function testLoadingEntitiesCreatedInBatch() { - $entity1 = EntityTest::load(1); - $this->assertNotNull($entity1, 'Successfully loaded entity 1.'); - $entity2 = EntityTest::load(2); - $this->assertNotNull($entity2, 'Successfully loaded entity 2.'); - } - -} diff --git a/core/modules/simpletest/src/Tests/SimpleTestTest.php b/core/modules/simpletest/src/Tests/SimpleTestTest.php deleted file mode 100644 index ea10bcef71249be41b572b9ed2578d3c47c45afb..0000000000000000000000000000000000000000 --- a/core/modules/simpletest/src/Tests/SimpleTestTest.php +++ /dev/null @@ -1,379 +0,0 @@ -<?php - -namespace Drupal\simpletest\Tests; - -use Drupal\Component\Render\FormattableMarkup; -use Drupal\Component\Utility\Crypt; -use Drupal\Core\Test\TestDatabase; -use Drupal\simpletest\WebTestBase; - -/** - * Tests SimpleTest's web interface: check that the intended tests were run and - * ensure that test reports display the intended results. Also test SimpleTest's - * internal browser and APIs implicitly. - * - * @group simpletest - * @group WebTestBase - * @group legacy - */ -class SimpleTestTest extends WebTestBase { - - /** - * Modules to enable. - * - * @var array - */ - public static $modules = ['simpletest']; - - /** - * The results array that has been parsed by getTestResults(). - * - * @var array - */ - protected $childTestResults; - - /** - * Stores the test ID from each test run for comparison. - * - * Used to ensure they are incrementing. - */ - protected $testIds = []; - - /** - * Translated fail message. - * - * @var string - */ - private $failMessage = ''; - - /** - * Translated pass message. - * @var string - */ - private $passMessage = ''; - - /** - * A valid and recognized permission. - * - * @var string - */ - protected $validPermission; - - /** - * An invalid or unrecognized permission. - * - * @var string - */ - protected $invalidPermission; - - protected function setUp() { - if (!$this->isInChildSite()) { - $php = <<<'EOD' -<?php - -# Make sure that the $test_class variable is defined when this file is included. -if ($test_class) { -} - -# Define a function to be able to check that this file was loaded with -# function_exists(). -if (!function_exists('simpletest_test_stub_settings_function')) { - function simpletest_test_stub_settings_function() {} -} -EOD; - - file_put_contents($this->siteDirectory . '/' . 'settings.testing.php', $php); - // @see \Drupal\system\Tests\DrupalKernel\DrupalKernelSiteTest - $class = __CLASS__; - $yaml = <<<EOD -services: - # Add a new service. - site.service.yml: - class: $class - # Swap out a core service. - cache.backend.database: - class: Drupal\Core\Cache\MemoryBackendFactory -EOD; - file_put_contents($this->siteDirectory . '/testing.services.yml', $yaml); - - $original_container = $this->originalContainer; - parent::setUp(); - $this->assertNotIdentical(\Drupal::getContainer(), $original_container, 'WebTestBase test creates a new container.'); - // Create and log in an admin user. - $this->drupalLogin($this->drupalCreateUser(['administer unit tests'])); - } - else { - // This causes three of the five fails that are asserted in - // confirmStubResults(). - self::$modules = ['non_existent_module']; - parent::setUp(); - } - } - - /** - * Ensures the tests selected through the web interface are run and displayed. - */ - public function testWebTestRunner() { - $this->passMessage = t('SimpleTest pass.'); - $this->failMessage = t('SimpleTest fail.'); - $this->validPermission = 'access administration pages'; - $this->invalidPermission = 'invalid permission'; - - if ($this->isInChildSite()) { - // Only run following code if this test is running itself through a CURL - // request. - $this->stubTest(); - } - else { - // Run twice so test_ids can be accumulated. - for ($i = 0; $i < 2; $i++) { - // Run this test from web interface. - $this->drupalGet('admin/config/development/testing'); - - $edit = []; - $edit['tests[Drupal\simpletest\Tests\SimpleTestTest]'] = TRUE; - $this->drupalPostForm(NULL, $edit, t('Run tests')); - - // Parse results and confirm that they are correct. - $this->getTestResults(); - $this->confirmStubTestResults(); - } - - // Regression test for #290316. - // Check that test_id is incrementing. - $this->assertTrue($this->testIds[0] != $this->testIds[1], 'Test ID is incrementing.'); - } - } - - /** - * Test to be run and the results confirmed. - * - * Here we force test results which must match the expected results from - * confirmStubResults(). - */ - public function stubTest() { - // Ensure the .htkey file exists since this is only created just before a - // request. This allows the stub test to make requests. The event does not - // fire here and drupal_generate_test_ua() can not generate a key for a - // test in a test since the prefix has changed. - // @see \Drupal\Core\Test\HttpClientMiddleware\TestHttpClientMiddleware::onBeforeSendRequest() - // @see drupal_generate_test_ua(); - $test_db = new TestDatabase($this->databasePrefix); - $key_file = DRUPAL_ROOT . '/' . $test_db->getTestSitePath() . '/.htkey'; - $private_key = Crypt::randomBytesBase64(55); - $site_path = $this->container->get('site.path'); - file_put_contents($key_file, $private_key); - - // Check to see if runtime assertions are indeed on, if successful this - // will be the first of sixteen passes asserted in confirmStubResults() - try { - // Test with minimum possible arguments to make sure no notice for - // missing argument is thrown. - assert(FALSE); - $this->fail('Runtime assertions are not working.'); - } - catch (\AssertionError $e) { - try { - // Now test with an error message to ensure it is correctly passed - // along by the rethrow. - assert(FALSE, 'Lorem Ipsum'); - } - catch (\AssertionError $e) { - $this->assertEqual($e->getMessage(), 'Lorem Ipsum', 'Runtime assertions Enabled and running.'); - } - } - // This causes the second of the sixteen passes asserted in - // confirmStubResults(). - $this->pass($this->passMessage); - - // The first three fails are caused by enabling a non-existent module in - // setUp(). - - // This causes the fourth of the five fails asserted in - // confirmStubResults(). - $this->fail($this->failMessage); - - // This causes the third to fifth of the sixteen passes asserted in - // confirmStubResults(). - $user = $this->drupalCreateUser([$this->validPermission], 'SimpleTestTest'); - - // This causes the fifth of the five fails asserted in confirmStubResults(). - $this->drupalCreateUser([$this->invalidPermission]); - - // Test logging in as a user. - // This causes the sixth to tenth of the sixteen passes asserted in - // confirmStubResults(). - $this->drupalLogin($user); - - // This causes the eleventh of the sixteen passes asserted in - // confirmStubResults(). - $this->pass('Test ID is ' . $this->testId . '.'); - - // These cause the twelfth to fifteenth of the sixteen passes asserted in - // confirmStubResults(). - $this->assertTrue(file_exists($site_path . '/settings.testing.php')); - // Check the settings.testing.php file got included. - $this->assertTrue(function_exists('simpletest_test_stub_settings_function')); - // Check that the test-specific service file got loaded. - $this->assertTrue($this->container->has('site.service.yml')); - $this->assertIdentical(get_class($this->container->get('cache.backend.database')), 'Drupal\Core\Cache\MemoryBackendFactory'); - - // These cause the two exceptions asserted in confirmStubResults(). - // Call trigger_error() without the required argument to trigger an E_WARNING. - trigger_error(); - // Generates a warning inside a PHP function. - array_key_exists(NULL, NULL); - - // This causes the sixteenth of the sixteen passes asserted in - // confirmStubResults(). - $this->assertNothing(); - - // This causes the debug message asserted in confirmStubResults(). - debug('Foo', 'Debug', FALSE); - } - - /** - * Assert nothing. - */ - public function assertNothing() { - $this->pass('This is nothing.'); - } - - /** - * Confirm that the stub test produced the desired results. - */ - public function confirmStubTestResults() { - $this->assertAssertion(t('Unable to install modules %modules due to missing modules %missing.', ['%modules' => 'non_existent_module', '%missing' => 'non_existent_module']), 'Other', 'Fail', 'SimpleTestTest.php', 'Drupal\simpletest\Tests\SimpleTestTest->setUp()'); - - $this->assertAssertion($this->passMessage, 'Other', 'Pass', 'SimpleTestTest.php', 'Drupal\simpletest\Tests\SimpleTestTest->stubTest()'); - $this->assertAssertion($this->failMessage, 'Other', 'Fail', 'SimpleTestTest.php', 'Drupal\simpletest\Tests\SimpleTestTest->stubTest()'); - - $this->assertAssertion(t('Created permissions: @perms', ['@perms' => $this->validPermission]), 'Role', 'Pass', 'SimpleTestTest.php', 'Drupal\simpletest\Tests\SimpleTestTest->stubTest()'); - $this->assertAssertion(t('Invalid permission %permission.', ['%permission' => $this->invalidPermission]), 'Role', 'Fail', 'SimpleTestTest.php', 'Drupal\simpletest\Tests\SimpleTestTest->stubTest()'); - - // Check that the user was logged in successfully. - $this->assertAssertion('User SimpleTestTest successfully logged in.', 'User login', 'Pass', 'SimpleTestTest.php', 'Drupal\simpletest\Tests\SimpleTestTest->stubTest()'); - - // Check that a warning is caught by simpletest. The exact error message - // differs between PHP versions so only the function name is checked. - $this->assertAssertion('trigger_error()', 'Warning', 'Fail', 'SimpleTestTest.php', 'Drupal\simpletest\Tests\SimpleTestTest->stubTest()'); - - // Check that the backtracing code works for specific assert function. - $this->assertAssertion('This is nothing.', 'Other', 'Pass', 'SimpleTestTest.php', 'Drupal\simpletest\Tests\SimpleTestTest->stubTest()'); - - // Check that errors that occur inside PHP internal functions are correctly - // reported. The exact error message differs between PHP versions so we - // check only the function name 'array_key_exists'. - $this->assertAssertion('array_key_exists', 'Warning', 'Fail', 'SimpleTestTest.php', 'Drupal\simpletest\Tests\SimpleTestTest->stubTest()'); - - $this->assertAssertion("Debug: 'Foo'", 'Debug', 'Fail', 'SimpleTestTest.php', 'Drupal\simpletest\Tests\SimpleTestTest->stubTest()'); - - $this->assertEqual('16 passes, 3 fails, 2 exceptions, 3 debug messages', $this->childTestResults['summary']); - - $this->testIds[] = $test_id = $this->getTestIdFromResults(); - $this->assertTrue($test_id, 'Found test ID in results.'); - } - - /** - * Fetch the test id from the test results. - */ - public function getTestIdFromResults() { - foreach ($this->childTestResults['assertions'] as $assertion) { - if (preg_match('@^Test ID is ([0-9]*)\.$@', $assertion['message'], $matches)) { - return $matches[1]; - } - } - return NULL; - } - - /** - * Asserts that an assertion with specified values is displayed in results. - * - * @param string $message - * Assertion message. - * @param string $type - * Assertion type. - * @param string $status - * Assertion status. - * @param string $file - * File where the assertion originated. - * @param string $function - * Function where the assertion originated. - * - * @return Assertion result. - */ - public function assertAssertion($message, $type, $status, $file, $function) { - $message = trim(strip_tags($message)); - $found = FALSE; - foreach ($this->childTestResults['assertions'] as $assertion) { - if ((strpos($assertion['message'], $message) !== FALSE) && - $assertion['type'] == $type && - $assertion['status'] == $status && - $assertion['file'] == $file && - $assertion['function'] == $function) { - $found = TRUE; - break; - } - } - return $this->assertTrue($found, new FormattableMarkup('Found assertion {"@message", "@type", "@status", "@file", "@function"}.', ['@message' => $message, '@type' => $type, '@status' => $status, "@file" => $file, "@function" => $function])); - } - - /** - * Get the results from a test and store them in the class array $results. - */ - public function getTestResults() { - $results = []; - if ($this->parse()) { - if ($details = $this->getResultFieldSet()) { - // Code assumes this is the only test in group. - $results['summary'] = $this->asText($details->div->div[1]); - $results['name'] = $this->asText($details->summary); - - $results['assertions'] = []; - $tbody = $details->div->table->tbody; - foreach ($tbody->tr as $row) { - $assertion = []; - $assertion['message'] = $this->asText($row->td[0]); - $assertion['type'] = $this->asText($row->td[1]); - $assertion['file'] = $this->asText($row->td[2]); - $assertion['line'] = $this->asText($row->td[3]); - $assertion['function'] = $this->asText($row->td[4]); - $ok_url = file_url_transform_relative(file_create_url('core/misc/icons/73b355/check.svg')); - $assertion['status'] = ($row->td[5]->img['src'] == $ok_url) ? 'Pass' : 'Fail'; - $results['assertions'][] = $assertion; - } - } - } - $this->childTestResults = $results; - } - - /** - * Get the details containing the results for group this test is in. - */ - public function getResultFieldSet() { - $all_details = $this->xpath('//details'); - foreach ($all_details as $details) { - if ($this->asText($details->summary) == __CLASS__) { - return $details; - } - } - return FALSE; - } - - /** - * Extract the text contained by the element. - * - * @param $element - * Element to extract text from. - * - * @return - * Extracted text. - */ - public function asText(\SimpleXMLElement $element) { - if (!is_object($element)) { - return $this->fail('The element is not an element.'); - } - return trim(html_entity_decode(strip_tags($element->asXML()))); - } - -} diff --git a/core/modules/simpletest/src/Tests/SkipRequiredModulesTest.php b/core/modules/simpletest/src/Tests/SkipRequiredModulesTest.php deleted file mode 100644 index 907d4672e53576ff9376bcae5597fb2a302c59f7..0000000000000000000000000000000000000000 --- a/core/modules/simpletest/src/Tests/SkipRequiredModulesTest.php +++ /dev/null @@ -1,32 +0,0 @@ -<?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. - * - * Only WebTestBase tests are skipped by TestDiscovery. Other tests use the - * PHPUnit @-require module annotation. - * - * @dependencies module_does_not_exist - * - * @group simpletest - * @group WebTestBase - * - * @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.'); - } - -} diff --git a/core/modules/simpletest/src/Tests/TimeZoneTest.php b/core/modules/simpletest/src/Tests/TimeZoneTest.php deleted file mode 100644 index 8f16ec5d9410b036852f5826a8a013c52038f07f..0000000000000000000000000000000000000000 --- a/core/modules/simpletest/src/Tests/TimeZoneTest.php +++ /dev/null @@ -1,38 +0,0 @@ -<?php - -namespace Drupal\simpletest\Tests; - -use Drupal\simpletest\WebTestBase; - -/** - * This test will check WebTestBase's default time zone handling. - * - * @group simpletest - * @group WebTestBase - */ -class TimeZoneTest extends WebTestBase { - - /** - * A user with administrative privileges. - */ - protected $adminUser; - - /** - * {@inheritdoc} - */ - protected function setUp() { - parent::setUp(); - - $this->adminUser = $this->drupalCreateUser(['administer site configuration']); - } - - /** - * Tests that user accounts have the default time zone set. - */ - public function testAccountTimeZones() { - $expected = 'Australia/Sydney'; - $this->assertEqual($this->rootUser->getTimeZone(), $expected, 'Root user has correct time zone.'); - $this->assertEqual($this->adminUser->getTimeZone(), $expected, 'Admin user has correct time zone.'); - } - -} diff --git a/core/modules/simpletest/src/Tests/UiPhpUnitOutputTest.php b/core/modules/simpletest/src/Tests/UiPhpUnitOutputTest.php deleted file mode 100644 index cdbae0603a59e4f0c753f6e407a72aa6389624ef..0000000000000000000000000000000000000000 --- a/core/modules/simpletest/src/Tests/UiPhpUnitOutputTest.php +++ /dev/null @@ -1,44 +0,0 @@ -<?php - -namespace Drupal\simpletest\Tests; - -use Drupal\simpletest\WebTestBase; -use Drupal\Tests\simpletest\Functional\SimpletestPhpunitBrowserTest; - -/** - * Test PHPUnit output for the Simpletest UI. - * - * @group simpletest - * @group legacy - * - * @see \Drupal\Tests\Listeners\SimpletestUiPrinter - */ -class UiPhpUnitOutputTest extends WebTestBase { - - /** - * Modules to enable. - * - * @var string[] - */ - public static $modules = ['simpletest']; - - /** - * Tests that PHPUnit output in the Simpletest UI looks good. - */ - public function testOutput() { - require_once __DIR__ . '/../../tests/fixtures/simpletest_phpunit_browsertest.php'; - $phpunit_junit_file = $this->container->get('file_system')->realpath('public://phpunit_junit.xml'); - // Prepare the default browser test output directory in the child site. - $this->container->get('file_system')->mkdir('public://simpletest'); - $status = 0; - $output = []; - simpletest_phpunit_run_command([SimpletestPhpunitBrowserTest::class], $phpunit_junit_file, $status, $output); - - // Check that there are <br> tags for the HTML output by - // SimpletestUiPrinter. - $this->assertEqual($output[20], 'HTML output was generated<br />'); - // Check that URLs are printed as HTML links. - $this->assertIdentical(strpos($output[21], '<a href="http'), 0); - } - -} diff --git a/core/modules/simpletest/src/Tests/WebTestBaseInstallTest.php b/core/modules/simpletest/src/Tests/WebTestBaseInstallTest.php deleted file mode 100644 index bfb1e0c9e6d3d99482f846c7197eb041bafaaabb..0000000000000000000000000000000000000000 --- a/core/modules/simpletest/src/Tests/WebTestBaseInstallTest.php +++ /dev/null @@ -1,23 +0,0 @@ -<?php - -namespace Drupal\simpletest\Tests; - -use Drupal\simpletest\WebTestBase; - -/** - * Tests the test-specifics customisations done in the installation. - * - * @group simpletest - * @group WebTestBase - */ -class WebTestBaseInstallTest extends WebTestBase { - - /** - * Tests the Drupal install done in \Drupal\simpletest\WebTestBase::setUp(). - */ - public function testInstall() { - $htaccess_filename = $this->getTempFilesDirectory() . '/.htaccess'; - $this->assertTrue(file_exists($htaccess_filename), "$htaccess_filename exists"); - } - -} diff --git a/core/modules/simpletest/src/UserCreationTrait.php b/core/modules/simpletest/src/UserCreationTrait.php deleted file mode 100644 index 52a0aaf8e2a9d1946d192ab5e2491b20705a71b6..0000000000000000000000000000000000000000 --- a/core/modules/simpletest/src/UserCreationTrait.php +++ /dev/null @@ -1,25 +0,0 @@ -<?php - -namespace Drupal\simpletest; - -@trigger_error(__NAMESPACE__ . '\UserCreationTrait is 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.', E_USER_DEPRECATED); - -use Drupal\Tests\user\Traits\UserCreationTrait as BaseUserCreationTrait; - -/** - * Provides methods to create additional test users and switch the currently - * logged in one. - * - * This trait is meant to be used only by test classes extending - * \Drupal\simpletest\TestBase. - * - * @deprecated in drupal:8.4.0 and is removed from drupal:9.0.0. Use - * Drupal\Tests\user\Traits\UserCreationTrait instead. - * - * @see https://www.drupal.org/node/2884454 - */ -trait UserCreationTrait { - - use BaseUserCreationTrait; - -} diff --git a/core/modules/simpletest/src/WebAssert.php b/core/modules/simpletest/src/WebAssert.php deleted file mode 100644 index 97a4ee8e6bd4e13768465057b5f1dfb1e741865e..0000000000000000000000000000000000000000 --- a/core/modules/simpletest/src/WebAssert.php +++ /dev/null @@ -1,16 +0,0 @@ -<?php - -namespace Drupal\simpletest; - -use Drupal\Tests\WebAssert as BaseWebAssert; - -/** - * Defines a class with methods for asserting presence of elements during tests. - * - * @deprecated in drupal:8.1.1 and is removed from drupal:9.0.0. - * This was moved to another namespace. - * - * @see \Drupal\Tests - */ -class WebAssert extends BaseWebAssert { -} diff --git a/core/modules/simpletest/src/WebTestBase.php b/core/modules/simpletest/src/WebTestBase.php deleted file mode 100644 index 03e5e12b0d80e49d54709b0faedd7f402ca58465..0000000000000000000000000000000000000000 --- a/core/modules/simpletest/src/WebTestBase.php +++ /dev/null @@ -1,2084 +0,0 @@ -<?php - -namespace Drupal\simpletest; - -use Drupal\block\Entity\Block; -use Drupal\Component\Serialization\Json; -use Drupal\Component\Utility\Html; -use Drupal\Component\Utility\NestedArray; -use Drupal\Component\Utility\UrlHelper; -use Drupal\Component\Render\FormattableMarkup; -use Drupal\Core\EventSubscriber\AjaxResponseSubscriber; -use Drupal\Core\EventSubscriber\MainContentViewSubscriber; -use Drupal\Core\Session\AccountInterface; -use Drupal\Core\Session\AnonymousUserSession; -use Drupal\Core\Test\AssertMailTrait; -use Drupal\Core\Test\FunctionalTestSetupTrait; -use Drupal\Core\Test\TestDiscovery; -use Drupal\Core\Url; -use Drupal\KernelTests\AssertContentTrait as CoreAssertContentTrait; -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 Laminas\Diactoros\Uri; - -/** - * Test case for typical Drupal tests. - * - * @ingroup testing - * - * @deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Instead, - * use \Drupal\Tests\BrowserTestBase. See https://www.drupal.org/node/3030340. - */ -abstract class WebTestBase extends TestBase { - - use FunctionalTestSetupTrait; - use CoreAssertContentTrait; - use TestFileCreationTrait { - getTestFiles as drupalGetTestFiles; - compareFiles as drupalCompareFiles; - } - use AssertPageCacheContextsAndTagsTrait; - use BaseBlockCreationTrait { - placeBlock as drupalPlaceBlock; - } - use BaseContentTypeCreationTrait { - createContentType as drupalCreateContentType; - } - use CronRunTrait; - use AssertMailTrait { - getMails as drupalGetMails; - } - use BaseNodeCreationTrait { - getNodeByTitle as drupalGetNodeByTitle; - createNode as drupalCreateNode; - } - use BaseUserCreationTrait { - createUser as drupalCreateUser; - createRole as drupalCreateRole; - createAdminRole as drupalCreateAdminRole; - } - - use XdebugRequestTrait; - use EntityViewTrait { - buildEntityView as drupalBuildEntityView; - } - - /** - * The profile to install as a basis for testing. - * - * @var string - */ - protected $profile = 'testing'; - - /** - * The URL currently loaded in the internal browser. - * - * @var string - */ - protected $url; - - /** - * The handle of the current cURL connection. - * - * @var resource - */ - protected $curlHandle; - - /** - * Whether or not to assert the presence of the X-Drupal-Ajax-Token. - * - * @var bool - */ - protected $assertAjaxHeader = TRUE; - - /** - * The headers of the page currently loaded in the internal browser. - * - * @var array - */ - protected $headers; - - /** - * The cookies of the page currently loaded in the internal browser. - * - * @var array - */ - protected $cookies = []; - - /** - * Indicates that headers should be dumped if verbose output is enabled. - * - * Headers are dumped to verbose by drupalGet(), drupalHead(), and - * drupalPostForm(). - * - * @var bool - */ - protected $dumpHeaders = FALSE; - - /** - * The current user logged in using the internal browser. - * - * @var \Drupal\Core\Session\AccountInterface|bool - */ - protected $loggedInUser = FALSE; - - /** - * The current cookie file used by cURL. - * - * We do not reuse the cookies in further runs, so we do not need a file - * but we still need cookie handling, so we set the jar to NULL. - */ - protected $cookieFile = NULL; - - /** - * Additional cURL options. - * - * \Drupal\simpletest\WebTestBase itself never sets this but always obeys what - * is set. - */ - protected $additionalCurlOptions = []; - - /** - * The original batch, before it was changed for testing purposes. - * - * @var array - */ - protected $originalBatch; - - /** - * The original user, before it was changed to a clean uid = 1 for testing. - * - * @var object - */ - protected $originalUser = NULL; - - /** - * The original shutdown handlers array, before it was cleaned for testing. - * - * @var array - */ - protected $originalShutdownCallbacks = []; - - /** - * The current session ID, if available. - */ - protected $sessionId = NULL; - - /** - * The maximum number of redirects to follow when handling responses. - * - * @var int - */ - protected $maximumRedirects = 5; - - /** - * The number of redirects followed during the handling of a request. - * - * @var int - */ - protected $redirectCount; - - - /** - * The number of meta refresh redirects to follow, or NULL if unlimited. - * - * @var null|int - */ - protected $maximumMetaRefreshCount = NULL; - - /** - * The number of meta refresh redirects followed during ::drupalGet(). - * - * @var int - */ - protected $metaRefreshCount = 0; - - /** - * Cookies to set on curl requests. - * - * @var array - */ - protected $curlCookies = []; - - /** - * An array of custom translations suitable for drupal_rewrite_settings(). - * - * @var array - */ - protected $customTranslations; - - /** - * Constructor for \Drupal\simpletest\WebTestBase. - */ - public function __construct($test_id = NULL) { - parent::__construct($test_id); - $this->skipClasses[__CLASS__] = TRUE; - $this->classLoader = require DRUPAL_ROOT . '/autoload.php'; - } - - /** - * Checks to see whether a block appears on the page. - * - * @param \Drupal\block\Entity\Block $block - * The block entity to find on the page. - */ - protected function assertBlockAppears(Block $block) { - $result = $this->findBlockInstance($block); - $this->assertTrue(!empty($result), new FormattableMarkup('Ensure the block @id appears on the page', ['@id' => $block->id()])); - } - - /** - * Checks to see whether a block does not appears on the page. - * - * @param \Drupal\block\Entity\Block $block - * The block entity to find on the page. - */ - protected function assertNoBlockAppears(Block $block) { - $result = $this->findBlockInstance($block); - $this->assertFalse(!empty($result), new FormattableMarkup('Ensure the block @id does not appear on the page', ['@id' => $block->id()])); - } - - /** - * Find a block instance on the page. - * - * @param \Drupal\block\Entity\Block $block - * The block entity to find on the page. - * - * @return array - * The result from the xpath query. - */ - protected function findBlockInstance(Block $block) { - return $this->xpath('//div[@id = :id]', [':id' => 'block-' . $block->id()]); - } - - /** - * Log in a user with the internal browser. - * - * If a user is already logged in, then the current user is logged out before - * logging in the specified user. - * - * Please note that neither the current user nor the passed-in user object is - * populated with data of the logged in user. If you need full access to the - * user object after logging in, it must be updated manually. If you also need - * access to the plain-text password of the user (set by drupalCreateUser()), - * e.g. to log in the same user again, then it must be re-assigned manually. - * For example: - * @code - * // Create a user. - * $account = $this->drupalCreateUser(array()); - * $this->drupalLogin($account); - * // Load real user object. - * $pass_raw = $account->pass_raw; - * $account = User::load($account->id()); - * $account->pass_raw = $pass_raw; - * @endcode - * - * @param \Drupal\Core\Session\AccountInterface $account - * User object representing the user to log in. - * - * @see drupalCreateUser() - */ - protected function drupalLogin(AccountInterface $account) { - if ($this->loggedInUser) { - $this->drupalLogout(); - } - - $edit = [ - 'name' => $account->getAccountName(), - 'pass' => $account->pass_raw, - ]; - $this->drupalPostForm('user/login', $edit, t('Log in')); - - // @see WebTestBase::drupalUserIsLoggedIn() - if (isset($this->sessionId)) { - $account->session_id = $this->sessionId; - } - $pass = $this->assert($this->drupalUserIsLoggedIn($account), new FormattableMarkup('User %name successfully logged in.', ['%name' => $account->getAccountName()]), 'User login'); - if ($pass) { - $this->loggedInUser = $account; - $this->container->get('current_user')->setAccount($account); - } - } - - /** - * Returns whether a given user account is logged in. - * - * @param \Drupal\user\UserInterface $account - * The user account object to check. - */ - protected function drupalUserIsLoggedIn($account) { - $logged_in = FALSE; - - if (isset($account->session_id)) { - $session_handler = $this->container->get('session_handler.storage'); - $logged_in = (bool) $session_handler->read($account->session_id); - } - - return $logged_in; - } - - /** - * Logs a user out of the internal browser and confirms. - * - * Confirms logout by checking the login page. - */ - protected function drupalLogout() { - // Make a request to the logout page, and redirect to the user page, the - // idea being if you were properly logged out you should be seeing a login - // screen. - $this->drupalGet('user/logout', ['query' => ['destination' => 'user/login']]); - $this->assertResponse(200, 'User was logged out.'); - $pass = $this->assertField('name', 'Username field found.', 'Logout'); - $pass = $pass && $this->assertField('pass', 'Password field found.', 'Logout'); - - if ($pass) { - // @see WebTestBase::drupalUserIsLoggedIn() - unset($this->loggedInUser->session_id); - $this->loggedInUser = FALSE; - $this->container->get('current_user')->setAccount(new AnonymousUserSession()); - } - } - - /** - * Sets up a Drupal site for running functional and integration tests. - * - * Installs Drupal with the installation profile specified in - * \Drupal\simpletest\WebTestBase::$profile into the prefixed database. - * - * Afterwards, installs any additional modules specified in the static - * \Drupal\simpletest\WebTestBase::$modules property of each class in the - * class hierarchy. - * - * After installation all caches are flushed and several configuration values - * are reset to the values of the parent site executing the test, since the - * default values may be incompatible with the environment in which tests are - * being executed. - */ - protected function setUp() { - // Set an explicit time zone to not rely on the system one, which may vary - // from setup to setup. The Australia/Sydney time zone is chosen so all - // tests are run using an edge case scenario (UTC+10 and DST). This choice - // is made to prevent time zone related regressions and reduce the - // fragility of the testing system in general. This is also set in config in - // \Drupal\simpletest\WebTestBase::initConfig(). - date_default_timezone_set('Australia/Sydney'); - - // Preserve original batch for later restoration. - $this->setBatch(); - - // Initialize user 1 and session name. - $this->initUserSession(); - - // Prepare the child site settings. - $this->prepareSettings(); - - // Execute the non-interactive installer. - $this->doInstall(); - - // Import new settings.php written by the installer. - $this->initSettings(); - - // Initialize the request and container post-install. - $container = $this->initKernel(\Drupal::request()); - - // Initialize and override certain configurations. - $this->initConfig($container); - - $this->installDefaultThemeFromClassProperty($container); - - // Collect modules to install. - $this->installModulesFromClassProperty($container); - - // Restore the original batch. - $this->restoreBatch(); - - // Reset/rebuild everything. - $this->rebuildAll(); - } - - /** - * Preserve the original batch, and instantiate the test batch. - */ - protected function setBatch() { - // When running tests through the Simpletest UI (vs. on the command line), - // Simpletest's batch conflicts with the installer's batch. Batch API does - // not support the concept of nested batches (in which the nested is not - // progressive), so we need to temporarily pretend there was no batch. - // Backup the currently running Simpletest batch. - $this->originalBatch = batch_get(); - - // Reset the static batch to remove Simpletest's batch operations. - $batch = &batch_get(); - $batch = []; - } - - /** - * Restore the original batch. - * - * @see ::setBatch - */ - protected function restoreBatch() { - // Restore the original Simpletest batch. - $batch = &batch_get(); - $batch = $this->originalBatch; - } - - /** - * Queues custom translations to be written to settings.php. - * - * Use WebTestBase::writeCustomTranslations() to apply and write the queued - * translations. - * - * @param string $langcode - * The langcode to add translations for. - * @param array $values - * Array of values containing the untranslated string and its translation. - * For example: - * @code - * array( - * '' => array('Sunday' => 'domingo'), - * 'Long month name' => array('March' => 'marzo'), - * ); - * @endcode - * Pass an empty array to remove all existing custom translations for the - * given $langcode. - */ - protected function addCustomTranslations($langcode, array $values) { - // If $values is empty, then the test expects all custom translations to be - // cleared. - if (empty($values)) { - $this->customTranslations[$langcode] = []; - } - // Otherwise, $values are expected to be merged into previously passed - // values, while retaining keys that are not explicitly set. - else { - foreach ($values as $context => $translations) { - foreach ($translations as $original => $translation) { - $this->customTranslations[$langcode][$context][$original] = $translation; - } - } - } - } - - /** - * Writes custom translations to the test site's settings.php. - * - * Use TestBase::addCustomTranslations() to queue custom translations before - * calling this method. - */ - protected function writeCustomTranslations() { - $settings = []; - foreach ($this->customTranslations as $langcode => $values) { - $settings_key = 'locale_custom_strings_' . $langcode; - - // Update in-memory settings directly. - $this->settingsSet($settings_key, $values); - - $settings['settings'][$settings_key] = (object) [ - 'value' => $values, - 'required' => TRUE, - ]; - } - // Only rewrite settings if there are any translation changes to write. - if (!empty($settings)) { - $this->writeSettings($settings); - } - } - - /** - * Cleans up after testing. - * - * Deletes created files and temporary files directory, deletes the tables - * created by setUp(), and resets the database prefix. - */ - protected function tearDown() { - // Destroy the testing kernel. - if (isset($this->kernel)) { - $this->kernel->shutdown(); - } - parent::tearDown(); - - // Ensure that the maximum meta refresh count is reset. - $this->maximumMetaRefreshCount = NULL; - - // Ensure that internal logged in variable and cURL options are reset. - $this->loggedInUser = FALSE; - $this->additionalCurlOptions = []; - - // Close the CURL handler and reset the cookies array used for upgrade - // testing so test classes containing multiple tests are not polluted. - $this->curlClose(); - $this->curlCookies = []; - $this->cookies = []; - } - - /** - * Initializes the cURL connection. - * - * If the simpletest_httpauth_credentials variable is set, this function will - * add HTTP authentication headers. This is necessary for testing sites that - * are protected by login credentials from public access. - * See the description of $curl_options for other options. - */ - protected function curlInitialize() { - global $base_url; - - if (!isset($this->curlHandle)) { - $this->curlHandle = curl_init(); - - // Some versions/configurations of cURL break on a NULL cookie jar, so - // supply a real file. - if (empty($this->cookieFile)) { - $this->cookieFile = $this->publicFilesDirectory . '/cookie.jar'; - } - - $curl_options = [ - CURLOPT_COOKIEJAR => $this->cookieFile, - CURLOPT_URL => $base_url, - CURLOPT_FOLLOWLOCATION => FALSE, - CURLOPT_RETURNTRANSFER => TRUE, - // Required to make the tests run on HTTPS. - CURLOPT_SSL_VERIFYPEER => FALSE, - // Required to make the tests run on HTTPS. - CURLOPT_SSL_VERIFYHOST => FALSE, - CURLOPT_HEADERFUNCTION => [&$this, 'curlHeaderCallback'], - CURLOPT_USERAGENT => $this->databasePrefix, - // Disable support for the @ prefix for uploading files. - CURLOPT_SAFE_UPLOAD => TRUE, - ]; - if (isset($this->httpAuthCredentials)) { - $curl_options[CURLOPT_HTTPAUTH] = $this->httpAuthMethod; - $curl_options[CURLOPT_USERPWD] = $this->httpAuthCredentials; - } - // curl_setopt_array() returns FALSE if any of the specified options - // cannot be set, and stops processing any further options. - $result = curl_setopt_array($this->curlHandle, $this->additionalCurlOptions + $curl_options); - if (!$result) { - throw new \UnexpectedValueException('One or more cURL options could not be set.'); - } - } - // We set the user agent header on each request so as to use the current - // time and a new uniqid. - curl_setopt($this->curlHandle, CURLOPT_USERAGENT, drupal_generate_test_ua($this->databasePrefix)); - } - - /** - * Initializes and executes a cURL request. - * - * @param $curl_options - * An associative array of cURL options to set, where the keys are constants - * defined by the cURL library. For a list of valid options, see - * http://php.net/manual/function.curl-setopt.php - * @param $redirect - * FALSE if this is an initial request, TRUE if this request is the result - * of a redirect. - * - * @return - * The content returned from the call to curl_exec(). - * - * @see curlInitialize() - */ - protected function curlExec($curl_options, $redirect = FALSE) { - $this->curlInitialize(); - - if (!empty($curl_options[CURLOPT_URL])) { - // cURL incorrectly handles URLs with a fragment by including the - // fragment in the request to the server, causing some web servers - // to reject the request citing "400 - Bad Request". To prevent - // this, we strip the fragment from the request. - // TODO: Remove this for Drupal 8, since fixed in curl 7.20.0. - if (strpos($curl_options[CURLOPT_URL], '#')) { - $original_url = $curl_options[CURLOPT_URL]; - $curl_options[CURLOPT_URL] = strtok($curl_options[CURLOPT_URL], '#'); - } - } - - $url = empty($curl_options[CURLOPT_URL]) ? curl_getinfo($this->curlHandle, CURLINFO_EFFECTIVE_URL) : $curl_options[CURLOPT_URL]; - - if (!empty($curl_options[CURLOPT_POST])) { - // This is a fix for the Curl library to prevent Expect: 100-continue - // headers in POST requests, that may cause unexpected HTTP response - // codes from some webservers (like lighttpd that returns a 417 error - // code). It is done by setting an empty "Expect" header field that is - // not overwritten by Curl. - $curl_options[CURLOPT_HTTPHEADER][] = 'Expect:'; - } - - $cookies = []; - if (!empty($this->curlCookies)) { - $cookies = $this->curlCookies; - } - - foreach ($this->extractCookiesFromRequest(\Drupal::request()) as $cookie_name => $values) { - foreach ($values as $value) { - $cookies[] = $cookie_name . '=' . $value; - } - } - - // Merge additional cookies in. - if (!empty($cookies)) { - $curl_options += [ - CURLOPT_COOKIE => '', - ]; - // Ensure any existing cookie data string ends with the correct separator. - if (!empty($curl_options[CURLOPT_COOKIE])) { - $curl_options[CURLOPT_COOKIE] = rtrim($curl_options[CURLOPT_COOKIE], '; ') . '; '; - } - $curl_options[CURLOPT_COOKIE] .= implode('; ', $cookies) . ';'; - } - - curl_setopt_array($this->curlHandle, $this->additionalCurlOptions + $curl_options); - - if (!$redirect) { - // Reset headers, the session ID and the redirect counter. - $this->sessionId = NULL; - $this->headers = []; - $this->redirectCount = 0; - } - - $content = curl_exec($this->curlHandle); - $status = curl_getinfo($this->curlHandle, CURLINFO_HTTP_CODE); - - // cURL incorrectly handles URLs with fragments, so instead of - // letting cURL handle redirects we take of them ourselves to - // to prevent fragments being sent to the web server as part - // of the request. - // TODO: Remove this for Drupal 8, since fixed in curl 7.20.0. - if (in_array($status, [300, 301, 302, 303, 305, 307]) && $this->redirectCount < $this->maximumRedirects) { - if ($this->drupalGetHeader('location')) { - $this->redirectCount++; - $curl_options = []; - $curl_options[CURLOPT_URL] = $this->drupalGetHeader('location'); - $curl_options[CURLOPT_HTTPGET] = TRUE; - return $this->curlExec($curl_options, TRUE); - } - } - - $this->setRawContent($content); - $this->url = isset($original_url) ? $original_url : curl_getinfo($this->curlHandle, CURLINFO_EFFECTIVE_URL); - - $message_vars = [ - '@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())), - ]; - $message = new FormattableMarkup('@method @url returned @status (@length).', $message_vars); - $this->assertTrue($this->getRawContent() !== FALSE, $message, 'Browser'); - return $this->getRawContent(); - } - - /** - * Reads headers and registers errors received from the tested site. - * - * @param $curlHandler - * The cURL handler. - * @param $header - * An header. - * - * @see _drupal_log_error() - */ - protected function curlHeaderCallback($curlHandler, $header) { - // Header fields can be extended over multiple lines by preceding each - // extra line with at least one SP or HT. They should be joined on receive. - // Details are in RFC2616 section 4. - if ($header[0] == ' ' || $header[0] == "\t") { - // Normalize whitespace between chucks. - $this->headers[] = array_pop($this->headers) . ' ' . trim($header); - } - else { - $this->headers[] = $header; - } - - // Errors are being sent via X-Drupal-Assertion-* headers, - // 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)) { - $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 (!in_array('legacy', $test_info['groups']) && !DeprecationListenerTrait::isDeprecationSkipped($message)) { - 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. - if (preg_match('/^Set-Cookie: ([^=]+)=(.+)/', $header, $matches)) { - $name = $matches[1]; - $parts = array_map('trim', explode(';', $matches[2])); - $value = array_shift($parts); - $this->cookies[$name] = ['value' => $value, 'secure' => in_array('secure', $parts)]; - if ($name === $this->getSessionName()) { - if ($value != 'deleted') { - $this->sessionId = $value; - } - else { - $this->sessionId = NULL; - } - } - } - - // This is required by cURL. - return strlen($header); - } - - /** - * Close the cURL handler and unset the handler. - */ - protected function curlClose() { - if (isset($this->curlHandle)) { - curl_close($this->curlHandle); - unset($this->curlHandle); - } - } - - /** - * Returns whether the test is being executed from within a test site. - * - * Mainly used by recursive tests (i.e. to test the testing framework). - * - * @return bool - * TRUE if this test was instantiated in a request within the test site, - * FALSE otherwise. - * - * @see \Drupal\Core\DrupalKernel::bootConfiguration() - */ - protected function isInChildSite() { - return DRUPAL_TEST_IN_CHILD_SITE; - } - - /** - * Retrieves a Drupal path or an absolute path. - * - * @param \Drupal\Core\Url|string $path - * Drupal path or URL to load into internal browser - * @param $options - * Options to be forwarded to the url generator. - * @param $headers - * An array containing additional HTTP request headers, each formatted as - * "name: value". - * - * @return string - * The retrieved HTML string, also available as $this->getRawContent() - */ - protected function drupalGet($path, array $options = [], array $headers = []) { - // We re-using a CURL connection here. If that connection still has certain - // options set, it might change the GET into a POST. Make sure we clear out - // previous options. - $out = $this->curlExec([CURLOPT_HTTPGET => TRUE, CURLOPT_URL => $this->buildUrl($path, $options), CURLOPT_NOBODY => FALSE, CURLOPT_HTTPHEADER => $headers]); - // Ensure that any changes to variables in the other thread are picked up. - $this->refreshVariables(); - - // Replace original page output with new output from redirected page(s). - if ($new = $this->checkForMetaRefresh()) { - $out = $new; - // We are finished with all meta refresh redirects, so reset the counter. - $this->metaRefreshCount = 0; - } - - if ($path instanceof Url) { - $path = $path->setAbsolute()->toString(TRUE)->getGeneratedUrl(); - } - - $verbose = 'GET request to: ' . $path . - '<hr />Ending URL: ' . $this->getUrl(); - if ($this->dumpHeaders) { - $verbose .= '<hr />Headers: <pre>' . Html::escape(var_export(array_map('trim', $this->headers), TRUE)) . '</pre>'; - } - $verbose .= '<hr />' . $out; - - $this->verbose($verbose); - return $out; - } - - /** - * Retrieves a Drupal path or an absolute path and JSON decodes the result. - * - * @param \Drupal\Core\Url|string $path - * Drupal path or URL to request AJAX from. - * @param array $options - * Array of URL options. - * @param array $headers - * Array of headers. Eg array('Accept: application/vnd.drupal-ajax'). - * - * @return array - * Decoded json. - */ - protected function drupalGetJSON($path, array $options = [], array $headers = []) { - return Json::decode($this->drupalGetWithFormat($path, 'json', $options, $headers)); - } - - /** - * Retrieves a Drupal path or an absolute path for a given format. - * - * @param \Drupal\Core\Url|string $path - * Drupal path or URL to request given format from. - * @param string $format - * The wanted request format. - * @param array $options - * Array of URL options. - * @param array $headers - * Array of headers. - * - * @return mixed - * The result of the request. - */ - protected function drupalGetWithFormat($path, $format, array $options = [], array $headers = []) { - $options = array_merge_recursive(['query' => ['_format' => $format]], $options); - return $this->drupalGet($path, $options, $headers); - } - - /** - * Requests a path or URL in drupal_ajax format and JSON-decodes the response. - * - * @param \Drupal\Core\Url|string $path - * Drupal path or URL to request from. - * @param array $options - * Array of URL options. - * @param array $headers - * Array of headers. - * - * @return array - * Decoded JSON. - */ - protected function drupalGetAjax($path, array $options = [], array $headers = []) { - if (!isset($options['query'][MainContentViewSubscriber::WRAPPER_FORMAT])) { - $options['query'][MainContentViewSubscriber::WRAPPER_FORMAT] = 'drupal_ajax'; - } - return Json::decode($this->drupalGetXHR($path, $options, $headers)); - } - - /** - * Requests a Drupal path or an absolute path as if it is a XMLHttpRequest. - * - * @param \Drupal\Core\Url|string $path - * Drupal path or URL to request from. - * @param array $options - * Array of URL options. - * @param array $headers - * Array of headers. - * - * @return string - * The retrieved content. - */ - protected function drupalGetXHR($path, array $options = [], array $headers = []) { - $headers[] = 'X-Requested-With: XMLHttpRequest'; - return $this->drupalGet($path, $options, $headers); - } - - /** - * Executes a form submission. - * - * It will be done as usual POST request with SimpleBrowser. - * - * @param \Drupal\Core\Url|string $path - * Location of the post form. Either a Drupal path or an absolute path or - * NULL to post to the current page. For multi-stage forms you can set the - * path to NULL and have it post to the last received page. Example: - * - * @code - * // First step in form. - * $edit = array(...); - * $this->drupalPostForm('some_url', $edit, t('Save')); - * - * // Second step in form. - * $edit = array(...); - * $this->drupalPostForm(NULL, $edit, t('Save')); - * @endcode - * @param $edit - * Field data in an associative array. Changes the current input fields - * (where possible) to the values indicated. - * - * When working with form tests, the keys for an $edit element should match - * the 'name' parameter of the HTML of the form. For example, the 'body' - * field for a node has the following HTML: - * @code - * <textarea id="edit-body-und-0-value" class="text-full form-textarea - * resize-vertical" placeholder="" cols="60" rows="9" - * name="body[0][value]"></textarea> - * @endcode - * When testing this field using an $edit parameter, the code becomes: - * @code - * $edit["body[0][value]"] = 'My test value'; - * @endcode - * - * A checkbox can be set to TRUE to be checked and should be set to FALSE to - * be unchecked. Multiple select fields can be tested using 'name[]' and - * setting each of the desired values in an array: - * @code - * $edit = array(); - * $edit['name[]'] = array('value1', 'value2'); - * @endcode - * @param $submit - * Value of the submit button whose click is to be emulated. For example, - * t('Save'). The processing of the request depends on this value. For - * example, a form may have one button with the value t('Save') and another - * button with the value t('Delete'), and execute different code depending - * on which one is clicked. - * - * This function can also be called to emulate an Ajax submission. In this - * case, this value needs to be an array with the following keys: - * - path: A path to submit the form values to for Ajax-specific processing. - * - triggering_element: If the value for the 'path' key is a generic Ajax - * processing path, this needs to be set to the name of the element. If - * the name doesn't identify the element uniquely, then this should - * instead be an array with a single key/value pair, corresponding to the - * element name and value. The \Drupal\Core\Form\FormAjaxResponseBuilder - * uses this to find the #ajax information for the element, including - * which specific callback to use for processing the request. - * - * This can also be set to NULL in order to emulate an Internet Explorer - * submission of a form with a single text field, and pressing ENTER in that - * textfield: under these conditions, no button information is added to the - * POST data. - * @param $options - * Options to be forwarded to the url generator. - * @param $headers - * An array containing additional HTTP request headers, each formatted as - * "name: value". - * @param $form_html_id - * (optional) HTML ID of the form to be submitted. On some pages - * there are many identical forms, so just using the value of the submit - * button is not enough. For example: 'trigger-node-presave-assign-form'. - * Note that this is not the Drupal $form_id, but rather the HTML ID of the - * form, which is typically the same thing but with hyphens replacing the - * underscores. - * @param $extra_post - * (optional) A string of additional data to append to the POST submission. - * This can be used to add POST data for which there are no HTML fields, as - * is done by drupalPostAjaxForm(). This string is literally appended to the - * POST data, so it must already be urlencoded and contain a leading "&" - * (e.g., "&extra_var1=hello+world&extra_var2=you%26me"). - */ - protected function drupalPostForm($path, $edit, $submit, array $options = [], array $headers = [], $form_html_id = NULL, $extra_post = NULL) { - if (is_object($submit)) { - // Cast MarkupInterface objects to string. - $submit = (string) $submit; - } - if (is_array($edit)) { - $edit = $this->castSafeStrings($edit); - } - - $submit_matches = FALSE; - $ajax = is_array($submit); - if (isset($path)) { - $this->drupalGet($path, $options); - } - - if ($this->parse()) { - $edit_save = $edit; - // Let's iterate over all the forms. - $xpath = "//form"; - if (!empty($form_html_id)) { - $xpath .= "[@id='" . $form_html_id . "']"; - } - $forms = $this->xpath($xpath); - foreach ($forms as $form) { - // We try to set the fields of this form as specified in $edit. - $edit = $edit_save; - $post = []; - $upload = []; - $submit_matches = $this->handleForm($post, $edit, $upload, $ajax ? NULL : $submit, $form); - $action = isset($form['action']) ? $this->getAbsoluteUrl((string) $form['action']) : $this->getUrl(); - if ($ajax) { - if (empty($submit['path'])) { - throw new \Exception('No #ajax path specified.'); - } - $action = $this->getAbsoluteUrl($submit['path']); - // Ajax callbacks verify the triggering element if necessary, so while - // we may eventually want extra code that verifies it in the - // handleForm() function, it's not currently a requirement. - $submit_matches = TRUE; - } - // We post only if we managed to handle every field in edit and the - // submit button matches. - if (!$edit && ($submit_matches || !isset($submit))) { - $post_array = $post; - if ($upload) { - foreach ($upload as $key => $file) { - if (is_array($file) && count($file)) { - // There seems to be no way via php's API to cURL to upload - // several files with the same post field name. However, Drupal - // still sees array-index syntax in a similar way. - for ($i = 0; $i < count($file); $i++) { - $postfield = str_replace('[]', '', $key) . '[' . $i . ']'; - $file_path = $this->container->get('file_system')->realpath($file[$i]); - $post[$postfield] = curl_file_create($file_path); - } - } - else { - $file = $this->container->get('file_system')->realpath($file); - if ($file && is_file($file)) { - $post[$key] = curl_file_create($file); - } - } - } - } - else { - $post = $this->serializePostValues($post) . $extra_post; - } - $out = $this->curlExec([CURLOPT_URL => $action, CURLOPT_POST => TRUE, CURLOPT_POSTFIELDS => $post, CURLOPT_HTTPHEADER => $headers]); - // Ensure that any changes to variables in the other thread are picked - // up. - $this->refreshVariables(); - - // Replace original page output with new output from redirected - // page(s). - if ($new = $this->checkForMetaRefresh()) { - $out = $new; - } - - if ($path instanceof Url) { - $path = $path->toString(); - } - $verbose = 'POST request to: ' . $path; - $verbose .= '<hr />Ending URL: ' . $this->getUrl(); - if ($this->dumpHeaders) { - $verbose .= '<hr />Headers: <pre>' . Html::escape(var_export(array_map('trim', $this->headers), TRUE)) . '</pre>'; - } - $verbose .= '<hr />Fields: ' . highlight_string('<?php ' . var_export($post_array, TRUE), TRUE); - $verbose .= '<hr />' . $out; - - $this->verbose($verbose); - return $out; - } - } - // We have not found a form which contained all fields of $edit. - foreach ($edit as $name => $value) { - $this->fail(new FormattableMarkup('Failed to set field @name to @value', ['@name' => $name, '@value' => $value])); - } - if (!$ajax && isset($submit)) { - $this->assertTrue($submit_matches, new FormattableMarkup('Found the @submit button', ['@submit' => $submit])); - } - $this->fail(new FormattableMarkup('Found the requested form fields at @path', ['@path' => ($path instanceof Url) ? $path->toString() : $path])); - } - } - - /** - * Executes an Ajax form submission. - * - * This executes a POST as ajax.js does. The returned JSON data is used to - * update $this->content via drupalProcessAjaxResponse(). It also returns - * the array of AJAX commands received. - * - * @param \Drupal\Core\Url|string $path - * Location of the form containing the Ajax enabled element to test. Can be - * either a Drupal path or an absolute path or NULL to use the current page. - * @param $edit - * Field data in an associative array. Changes the current input fields - * (where possible) to the values indicated. - * @param $triggering_element - * The name of the form element that is responsible for triggering the Ajax - * functionality to test. May be a string or, if the triggering element is - * a button, an associative array where the key is the name of the button - * and the value is the button label. i.e.) array('op' => t('Refresh')). - * @param $ajax_path - * (optional) Override the path set by the Ajax settings of the triggering - * element. - * @param $options - * (optional) Options to be forwarded to the url generator. - * @param $headers - * (optional) An array containing additional HTTP request headers, each - * formatted as "name: value". Forwarded to drupalPostForm(). - * @param $form_html_id - * (optional) HTML ID of the form to be submitted, use when there is more - * than one identical form on the same page and the value of the triggering - * element is not enough to identify the form. Note this is not the Drupal - * ID of the form but rather the HTML ID of the form. - * @param $ajax_settings - * (optional) An array of Ajax settings which if specified will be used in - * place of the Ajax settings of the triggering element. - * - * @return - * An array of Ajax commands. - * - * @see drupalPostForm() - * @see drupalProcessAjaxResponse() - * @see ajax.js - */ - protected function drupalPostAjaxForm($path, $edit, $triggering_element, $ajax_path = NULL, array $options = [], array $headers = [], $form_html_id = NULL, $ajax_settings = NULL) { - - // Get the content of the initial page prior to calling drupalPostForm(), - // since drupalPostForm() replaces $this->content. - if (isset($path)) { - // Avoid sending the wrapper query argument to drupalGet so we can fetch - // the form and populate the internal WebTest values. - $get_options = $options; - unset($get_options['query'][MainContentViewSubscriber::WRAPPER_FORMAT]); - $this->drupalGet($path, $get_options); - } - $content = $this->content; - $drupal_settings = $this->drupalSettings; - - // Provide a default value for the wrapper envelope. - $options['query'][MainContentViewSubscriber::WRAPPER_FORMAT] = - isset($options['query'][MainContentViewSubscriber::WRAPPER_FORMAT]) ? - $options['query'][MainContentViewSubscriber::WRAPPER_FORMAT] : - 'drupal_ajax'; - - // Get the Ajax settings bound to the triggering element. - if (!isset($ajax_settings)) { - if (is_array($triggering_element)) { - $xpath = '//*[@name="' . key($triggering_element) . '" and @value="' . current($triggering_element) . '"]'; - } - else { - $xpath = '//*[@name="' . $triggering_element . '"]'; - } - if (isset($form_html_id)) { - $xpath = '//form[@id="' . $form_html_id . '"]' . $xpath; - } - $element = $this->xpath($xpath); - $element_id = (string) $element[0]['id']; - $ajax_settings = $drupal_settings['ajax'][$element_id]; - } - - // Add extra information to the POST data as ajax.js does. - $extra_post = []; - if (isset($ajax_settings['submit'])) { - foreach ($ajax_settings['submit'] as $key => $value) { - $extra_post[$key] = $value; - } - } - $extra_post[AjaxResponseSubscriber::AJAX_REQUEST_PARAMETER] = 1; - $extra_post += $this->getAjaxPageStatePostData(); - // Now serialize all the $extra_post values, and prepend it with an '&'. - $extra_post = '&' . $this->serializePostValues($extra_post); - - // Unless a particular path is specified, use the one specified by the - // Ajax settings. - if (!isset($ajax_path)) { - if (isset($ajax_settings['url'])) { - // In order to allow to set for example the wrapper envelope query - // parameter we need to get the system path again. - $parsed_url = UrlHelper::parse($ajax_settings['url']); - $options['query'] = $parsed_url['query'] + $options['query']; - $options += ['fragment' => $parsed_url['fragment']]; - - // We know that $parsed_url['path'] is already with the base path - // attached. - $ajax_path = preg_replace( - '/^' . preg_quote(base_path(), '/') . '/', - '', - $parsed_url['path'] - ); - } - } - - if (empty($ajax_path)) { - throw new \Exception('No #ajax path specified.'); - } - - $ajax_path = $this->container->get('unrouted_url_assembler')->assemble('base://' . $ajax_path, $options); - - // Submit the POST request. - $return = Json::decode($this->drupalPostForm(NULL, $edit, ['path' => $ajax_path, 'triggering_element' => $triggering_element], $options, $headers, $form_html_id, $extra_post)); - if ($this->assertAjaxHeader) { - $this->assertIdentical($this->drupalGetHeader('X-Drupal-Ajax-Token'), '1', 'Ajax response header found.'); - } - - // Change the page content by applying the returned commands. - if (!empty($ajax_settings) && !empty($return)) { - $this->drupalProcessAjaxResponse($content, $return, $ajax_settings, $drupal_settings); - } - - $verbose = 'AJAX POST request to: ' . $path; - $verbose .= '<br />AJAX controller path: ' . $ajax_path; - $verbose .= '<hr />Ending URL: ' . $this->getUrl(); - $verbose .= '<hr />' . $this->content; - - $this->verbose($verbose); - - return $return; - } - - /** - * Processes an AJAX response into current content. - * - * This processes the AJAX response as ajax.js does. It uses the response's - * JSON data, an array of commands, to update $this->content using equivalent - * DOM manipulation as is used by ajax.js. - * It does not apply custom AJAX commands though, because emulation is only - * implemented for the AJAX commands that ship with Drupal core. - * - * @param string $content - * The current HTML content. - * @param array $ajax_response - * An array of AJAX commands. - * @param array $ajax_settings - * An array of AJAX settings which will be used to process the response. - * @param array $drupal_settings - * An array of settings to update the value of drupalSettings for the - * currently-loaded page. - * - * @see drupalPostAjaxForm() - * @see ajax.js - */ - protected function drupalProcessAjaxResponse($content, array $ajax_response, array $ajax_settings, array $drupal_settings) { - - // ajax.js applies some defaults to the settings object, so do the same - // for what's used by this function. - $ajax_settings += [ - 'method' => 'replaceWith', - ]; - // DOM can load HTML soup. But, HTML soup can throw warnings, suppress - // them. - $dom = new \DOMDocument(); - @$dom->loadHTML($content); - // XPath allows for finding wrapper nodes better than DOM does. - $xpath = new \DOMXPath($dom); - foreach ($ajax_response as $command) { - // Error messages might be not commands. - if (!is_array($command)) { - continue; - } - switch ($command['command']) { - case 'settings': - $drupal_settings = NestedArray::mergeDeepArray([$drupal_settings, $command['settings']], TRUE); - break; - - case 'insert': - $wrapperNode = NULL; - // When a command doesn't specify a selector, use the - // #ajax['wrapper'] which is always an HTML ID. - if (!isset($command['selector'])) { - $wrapperNode = $xpath->query('//*[@id="' . $ajax_settings['wrapper'] . '"]')->item(0); - } - // @todo Ajax commands can target any jQuery selector, but these are - // hard to fully emulate with XPath. For now, just handle 'head' - // and 'body', since these are used by the Ajax renderer. - elseif (in_array($command['selector'], ['head', 'body'])) { - $wrapperNode = $xpath->query('//' . $command['selector'])->item(0); - } - if ($wrapperNode) { - // ajax.js adds an enclosing DIV to work around a Safari bug. - $newDom = new \DOMDocument(); - // DOM can load HTML soup. But, HTML soup can throw warnings, - // suppress them. - @$newDom->loadHTML('<div>' . $command['data'] . '</div>'); - // Suppress warnings thrown when duplicate HTML IDs are encountered. - // This probably means we are replacing an element with the same ID. - $newNode = @$dom->importNode($newDom->documentElement->firstChild->firstChild, TRUE); - $method = isset($command['method']) ? $command['method'] : $ajax_settings['method']; - // The "method" is a jQuery DOM manipulation function. Emulate - // each one using PHP's DOMNode API. - switch ($method) { - case 'replaceWith': - $wrapperNode->parentNode->replaceChild($newNode, $wrapperNode); - break; - case 'append': - $wrapperNode->appendChild($newNode); - break; - case 'prepend': - // If no firstChild, insertBefore() falls back to - // appendChild(). - $wrapperNode->insertBefore($newNode, $wrapperNode->firstChild); - break; - case 'before': - $wrapperNode->parentNode->insertBefore($newNode, $wrapperNode); - break; - case 'after': - // If no nextSibling, insertBefore() falls back to - // appendChild(). - $wrapperNode->parentNode->insertBefore($newNode, $wrapperNode->nextSibling); - break; - case 'html': - foreach ($wrapperNode->childNodes as $childNode) { - $wrapperNode->removeChild($childNode); - } - $wrapperNode->appendChild($newNode); - break; - } - } - break; - - // @todo Add suitable implementations for these commands in order to - // have full test coverage of what ajax.js can do. - case 'remove': - break; - case 'changed': - break; - case 'css': - break; - case 'data': - break; - case 'restripe': - break; - case 'add_css': - break; - case 'update_build_id': - $buildId = $xpath->query('//input[@name="form_build_id" and @value="' . $command['old'] . '"]')->item(0); - if ($buildId) { - $buildId->setAttribute('value', $command['new']); - } - break; - } - } - $content = $dom->saveHTML(); - $this->setRawContent($content); - $this->setDrupalSettings($drupal_settings); - } - - /** - * Perform a POST HTTP request. - * - * @param string|\Drupal\Core\Url $path - * Drupal path or absolute path where the request should be POSTed. - * @param string $accept - * The value for the "Accept" header. Usually either 'application/json' or - * 'application/vnd.drupal-ajax'. - * @param array $post - * The POST data. When making a 'application/vnd.drupal-ajax' request, the - * Ajax page state data should be included. Use getAjaxPageStatePostData() - * for that. - * @param array $options - * (optional) Options to be forwarded to the url generator. The 'absolute' - * option will automatically be enabled. - * - * @return - * The content returned from the call to curl_exec(). - * - * @see WebTestBase::getAjaxPageStatePostData() - * @see WebTestBase::curlExec() - */ - protected function drupalPost($path, $accept, array $post, $options = []) { - return $this->curlExec([ - CURLOPT_URL => $this->buildUrl($path, $options), - CURLOPT_POST => TRUE, - CURLOPT_POSTFIELDS => $this->serializePostValues($post), - CURLOPT_HTTPHEADER => [ - 'Accept: ' . $accept, - 'Content-Type: application/x-www-form-urlencoded', - ], - ]); - } - - /** - * Performs a POST HTTP request with a specific format. - * - * @param string|\Drupal\Core\Url $path - * Drupal path or absolute path where the request should be POSTed. - * @param string $format - * The request format. - * @param array $post - * The POST data. When making a 'application/vnd.drupal-ajax' request, the - * Ajax page state data should be included. Use getAjaxPageStatePostData() - * for that. - * @param array $options - * (optional) Options to be forwarded to the url generator. The 'absolute' - * option will automatically be enabled. - * - * @return string - * The content returned from the call to curl_exec(). - * - * @see WebTestBase::drupalPost - * @see WebTestBase::getAjaxPageStatePostData() - * @see WebTestBase::curlExec() - */ - protected function drupalPostWithFormat($path, $format, array $post, $options = []) { - $options['query']['_format'] = $format; - return $this->drupalPost($path, '', $post, $options); - } - - /** - * Get the Ajax page state from drupalSettings and prepare it for POSTing. - * - * @return array - * The Ajax page state POST data. - */ - protected function getAjaxPageStatePostData() { - $post = []; - $drupal_settings = $this->drupalSettings; - if (isset($drupal_settings['ajaxPageState']['theme'])) { - $post['ajax_page_state[theme]'] = $drupal_settings['ajaxPageState']['theme']; - } - if (isset($drupal_settings['ajaxPageState']['theme_token'])) { - $post['ajax_page_state[theme_token]'] = $drupal_settings['ajaxPageState']['theme_token']; - } - if (isset($drupal_settings['ajaxPageState']['libraries'])) { - $post['ajax_page_state[libraries]'] = $drupal_settings['ajaxPageState']['libraries']; - } - return $post; - } - - /** - * Serialize POST HTTP request values. - * - * Encode according to application/x-www-form-urlencoded. Both names and - * values needs to be urlencoded, according to - * http://www.w3.org/TR/html4/interact/forms.html#h-17.13.4.1 - * - * @param array $post - * The array of values to be POSTed. - * - * @return string - * The serialized result. - */ - protected function serializePostValues($post = []) { - foreach ($post as $key => $value) { - $post[$key] = urlencode($key) . '=' . urlencode($value); - } - return implode('&', $post); - } - - /** - * Transforms a nested array into a flat array suitable for WebTestBase::drupalPostForm(). - * - * @param array $values - * A multi-dimensional form values array to convert. - * - * @return array - * The flattened $edit array suitable for WebTestBase::drupalPostForm(). - */ - protected function translatePostValues(array $values) { - $edit = []; - // The easiest and most straightforward way to translate values suitable for - // WebTestBase::drupalPostForm() is to actually build the POST data string - // and convert the resulting key/value pairs back into a flat array. - $query = http_build_query($values); - foreach (explode('&', $query) as $item) { - list($key, $value) = explode('=', $item); - $edit[urldecode($key)] = urldecode($value); - } - return $edit; - } - - /** - * Checks for meta refresh tag and if found call drupalGet() recursively. - * - * This function looks for the http-equiv attribute to be set to "Refresh" and - * is case-sensitive. - * - * @return - * Either the new page content or FALSE. - */ - protected function checkForMetaRefresh() { - if (strpos($this->getRawContent(), '<meta ') && $this->parse() && (!isset($this->maximumMetaRefreshCount) || $this->metaRefreshCount < $this->maximumMetaRefreshCount)) { - $refresh = $this->xpath('//meta[@http-equiv="Refresh"]'); - if (!empty($refresh)) { - // Parse the content attribute of the meta tag for the format: - // "[delay]: URL=[page_to_redirect_to]". - if (preg_match('/\d+;\s*URL=(?<url>.*)/i', $refresh[0]['content'], $match)) { - $this->metaRefreshCount++; - return $this->drupalGet($this->getAbsoluteUrl(Html::decodeEntities($match['url']))); - } - } - } - return FALSE; - } - - /** - * Retrieves only the headers for a Drupal path or an absolute path. - * - * @param $path - * Drupal path or URL to load into internal browser - * @param $options - * Options to be forwarded to the url generator. - * @param $headers - * An array containing additional HTTP request headers, each formatted as - * "name: value". - * - * @return - * The retrieved headers, also available as $this->getRawContent() - */ - protected function drupalHead($path, array $options = [], array $headers = []) { - $options['absolute'] = TRUE; - $url = $this->buildUrl($path, $options); - $out = $this->curlExec([CURLOPT_NOBODY => TRUE, CURLOPT_URL => $url, CURLOPT_HTTPHEADER => $headers]); - // Ensure that any changes to variables in the other thread are picked up. - $this->refreshVariables(); - - if ($this->dumpHeaders) { - $this->verbose('GET request to: ' . $path . - '<hr />Ending URL: ' . $this->getUrl() . - '<hr />Headers: <pre>' . Html::escape(var_export(array_map('trim', $this->headers), TRUE)) . '</pre>'); - } - - return $out; - } - - /** - * Handles form input related to drupalPostForm(). - * - * Ensure that the specified fields exist and attempt to create POST data in - * the correct manner for the particular field type. - * - * @param $post - * Reference to array of post values. - * @param $edit - * Reference to array of edit values to be checked against the form. - * @param $submit - * Form submit button value. - * @param $form - * Array of form elements. - * - * @return - * Submit value matches a valid submit input in the form. - */ - protected function handleForm(&$post, &$edit, &$upload, $submit, $form) { - // Retrieve the form elements. - $elements = $form->xpath('.//input[not(@disabled)]|.//textarea[not(@disabled)]|.//select[not(@disabled)]'); - $submit_matches = FALSE; - foreach ($elements as $element) { - // SimpleXML objects need string casting all the time. - $name = (string) $element['name']; - // This can either be the type of <input> or the name of the tag itself - // for <select> or <textarea>. - $type = isset($element['type']) ? (string) $element['type'] : $element->getName(); - $value = isset($element['value']) ? (string) $element['value'] : ''; - $done = FALSE; - if (isset($edit[$name])) { - switch ($type) { - case 'text': - case 'tel': - case 'textarea': - case 'url': - case 'number': - case 'range': - case 'color': - case 'hidden': - case 'password': - case 'email': - case 'search': - case 'date': - case 'time': - case 'datetime': - case 'datetime-local'; - $post[$name] = $edit[$name]; - unset($edit[$name]); - break; - case 'radio': - if ($edit[$name] == $value) { - $post[$name] = $edit[$name]; - unset($edit[$name]); - } - break; - case 'checkbox': - // To prevent checkbox from being checked.pass in a FALSE, - // otherwise the checkbox will be set to its value regardless - // of $edit. - if ($edit[$name] === FALSE) { - unset($edit[$name]); - continue 2; - } - else { - unset($edit[$name]); - $post[$name] = $value; - } - break; - case 'select': - $new_value = $edit[$name]; - $options = $this->getAllOptions($element); - if (is_array($new_value)) { - // Multiple select box. - if (!empty($new_value)) { - $index = 0; - $key = preg_replace('/\[\]$/', '', $name); - foreach ($options as $option) { - $option_value = (string) $option['value']; - if (in_array($option_value, $new_value)) { - $post[$key . '[' . $index++ . ']'] = $option_value; - $done = TRUE; - unset($edit[$name]); - } - } - } - else { - // No options selected: do not include any POST data for the - // element. - $done = TRUE; - unset($edit[$name]); - } - } - else { - // Single select box. - foreach ($options as $option) { - if ($new_value == $option['value']) { - $post[$name] = $new_value; - unset($edit[$name]); - $done = TRUE; - break; - } - } - } - break; - case 'file': - $upload[$name] = $edit[$name]; - unset($edit[$name]); - break; - } - } - if (!isset($post[$name]) && !$done) { - switch ($type) { - case 'textarea': - $post[$name] = (string) $element; - break; - case 'select': - $single = empty($element['multiple']); - $first = TRUE; - $index = 0; - $key = preg_replace('/\[\]$/', '', $name); - $options = $this->getAllOptions($element); - foreach ($options as $option) { - // For single select, we load the first option, if there is a - // selected option that will overwrite it later. - if ($option['selected'] || ($first && $single)) { - $first = FALSE; - if ($single) { - $post[$name] = (string) $option['value']; - } - else { - $post[$key . '[' . $index++ . ']'] = (string) $option['value']; - } - } - } - break; - case 'file': - break; - case 'submit': - case 'image': - if (isset($submit) && $submit == $value) { - $post[$name] = $value; - $submit_matches = TRUE; - } - break; - case 'radio': - case 'checkbox': - if (!isset($element['checked'])) { - break; - } - // Deliberate no break. - default: - $post[$name] = $value; - } - } - } - // An empty name means the value is not sent. - unset($post['']); - return $submit_matches; - } - - /** - * Follows a link by complete name. - * - * Will click the first link found with this link text by default, or a later - * one if an index is given. Match is case sensitive with normalized space. - * The label is translated label. - * - * If the link is discovered and clicked, the test passes. Fail otherwise. - * - * @param string|\Drupal\Component\Render\MarkupInterface $label - * Text between the anchor tags. - * @param int $index - * Link position counting from zero. - * - * @return string|bool - * Page contents on success, or FALSE on failure. - */ - protected function clickLink($label, $index = 0) { - return $this->clickLinkHelper($label, $index, '//a[normalize-space()=:label]'); - } - - /** - * Follows a link by partial name. - * - * If the link is discovered and clicked, the test passes. Fail otherwise. - * - * @param string|\Drupal\Component\Render\MarkupInterface $label - * Text between the anchor tags, uses starts-with(). - * @param int $index - * Link position counting from zero. - * - * @return string|bool - * Page contents on success, or FALSE on failure. - * - * @see ::clickLink() - */ - protected function clickLinkPartialName($label, $index = 0) { - return $this->clickLinkHelper($label, $index, '//a[starts-with(normalize-space(), :label)]'); - } - - /** - * Provides a helper for ::clickLink() and ::clickLinkPartialName(). - * - * @param string|\Drupal\Component\Render\MarkupInterface $label - * Text between the anchor tags, uses starts-with(). - * @param int $index - * Link position counting from zero. - * @param string $pattern - * A pattern to use for the XPath. - * - * @return bool|string - * Page contents on success, or FALSE on failure. - */ - protected function clickLinkHelper($label, $index, $pattern) { - // Cast MarkupInterface objects to string. - $label = (string) $label; - $url_before = $this->getUrl(); - $urls = $this->xpath($pattern, [':label' => $label]); - if (isset($urls[$index])) { - $url_target = $this->getAbsoluteUrl($urls[$index]['href']); - $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(new FormattableMarkup('Link %label does not exist on @url_before', ['%label' => $label, '@url_before' => $url_before]), 'Browser'); - return FALSE; - } - - /** - * Takes a path and returns an absolute path. - * - * This method is implemented in the way that browsers work, see - * https://url.spec.whatwg.org/#relative-state for more information about the - * possible cases. - * - * @param string $path - * A path from the internal browser content. - * - * @return string - * The $path with $base_url prepended, if necessary. - */ - protected function getAbsoluteUrl($path) { - global $base_url, $base_path; - - $parts = parse_url($path); - - // In case the $path has a host, it is already an absolute URL and we are - // done. - if (!empty($parts['host'])) { - return $path; - } - - // In case the $path contains just a query, we turn it into an absolute URL - // with the same scheme, host and path, see - // https://url.spec.whatwg.org/#relative-state. - if (array_keys($parts) === ['query']) { - $current_uri = new Uri($this->getUrl()); - return (string) $current_uri->withQuery($parts['query']); - } - - if (empty($parts['host'])) { - // Ensure that we have a string (and no xpath object). - $path = (string) $path; - // Strip $base_path, if existent. - $length = strlen($base_path); - if (substr($path, 0, $length) === $base_path) { - $path = substr($path, $length); - } - // Ensure that we have an absolute path. - if (empty($path) || $path[0] !== '/') { - $path = '/' . $path; - } - // Finally, prepend the $base_url. - $path = $base_url . $path; - } - return $path; - } - - /** - * Gets the HTTP response headers of the requested page. - * - * Normally we are only interested in the headers returned by the last - * request. However, if a page is redirected or HTTP authentication is in use, - * multiple requests will be required to retrieve the page. Headers from all - * requests may be requested by passing TRUE to this function. - * - * @param $all_requests - * Boolean value specifying whether to return headers from all requests - * instead of just the last request. Defaults to FALSE. - * - * @return - * A name/value array if headers from only the last request are requested. - * If headers from all requests are requested, an array of name/value - * arrays, one for each request. - * - * The pseudonym ":status" is used for the HTTP status line. - * - * Values for duplicate headers are stored as a single comma-separated list. - */ - protected function drupalGetHeaders($all_requests = FALSE) { - $request = 0; - $headers = [$request => []]; - foreach ($this->headers as $header) { - $header = trim($header); - if ($header === '') { - $request++; - } - else { - if (strpos($header, 'HTTP/') === 0) { - $name = ':status'; - $value = $header; - } - else { - list($name, $value) = explode(':', $header, 2); - $name = strtolower($name); - } - if (isset($headers[$request][$name])) { - $headers[$request][$name] .= ',' . trim($value); - } - else { - $headers[$request][$name] = trim($value); - } - } - } - if (!$all_requests) { - $headers = array_pop($headers); - } - return $headers; - } - - /** - * Gets the value of an HTTP response header. - * - * If multiple requests were required to retrieve the page, only the headers - * from the last request will be checked by default. However, if TRUE is - * passed as the second argument, all requests will be processed from last to - * first until the header is found. - * - * @param $name - * The name of the header to retrieve. Names are case-insensitive (see RFC - * 2616 section 4.2). - * @param $all_requests - * Boolean value specifying whether to check all requests if the header is - * not found in the last request. Defaults to FALSE. - * - * @return - * The HTTP header value or FALSE if not found. - */ - protected function drupalGetHeader($name, $all_requests = FALSE) { - $name = strtolower($name); - $header = FALSE; - if ($all_requests) { - foreach (array_reverse($this->drupalGetHeaders(TRUE)) as $headers) { - if (isset($headers[$name])) { - $header = $headers[$name]; - break; - } - } - } - else { - $headers = $this->drupalGetHeaders(); - if (isset($headers[$name])) { - $header = $headers[$name]; - } - } - return $header; - } - - /** - * Check if a HTTP response header exists and has the expected value. - * - * @param string $header - * The header key, example: Content-Type - * @param string $value - * The header value. - * @param string $message - * (optional) A message to display with the assertion. - * @param string $group - * (optional) The group this message is in, which is displayed in a column - * in test output. Use 'Debug' to indicate this is debugging output. Do not - * translate this string. Defaults to 'Other'; most tests do not override - * this default. - * - * @return bool - * TRUE if the assertion succeeded, FALSE otherwise. - */ - protected function assertHeader($header, $value, $message = '', $group = 'Browser') { - $header_value = $this->drupalGetHeader($header); - return $this->assertTrue($header_value == $value, $message ? $message : 'HTTP response header ' . $header . ' with value ' . $value . ' found, actual value: ' . $header_value, $group); - } - - /** - * Passes if the internal browser's URL matches the given path. - * - * @param \Drupal\Core\Url|string $path - * The expected system path or URL. - * @param $options - * (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\Render\FormattableMarkup to embed - * variables in the message text, not t(). If left blank, a default message - * will be displayed. - * @param $group - * (optional) The group this message is in, which is displayed in a column - * in test output. Use 'Debug' to indicate this is debugging output. Do not - * translate this string. Defaults to 'Other'; most tests do not override - * this default. - * - * @return - * TRUE on pass, FALSE on fail. - */ - protected function assertUrl($path, array $options = [], $message = '', $group = 'Other') { - if ($path instanceof Url) { - $url_obj = $path; - } - elseif (UrlHelper::isExternal($path)) { - $url_obj = Url::fromUri($path, $options); - } - else { - $uri = $path === '<front>' ? 'base:/' : 'base:/' . $path; - // This is needed for language prefixing. - $options['path_processing'] = TRUE; - $url_obj = Url::fromUri($uri, $options); - } - $url = $url_obj->setAbsolute()->toString(); - if (!$message) { - $message = new FormattableMarkup('Expected @url matches current URL (@current_url).', [ - '@url' => var_export($url, TRUE), - '@current_url' => $this->getUrl(), - ]); - } - // Paths in query strings can be encoded or decoded with no functional - // difference, decode them for comparison purposes. - $actual_url = urldecode($this->getUrl()); - $expected_url = urldecode($url); - return $this->assertEqual($actual_url, $expected_url, $message, $group); - } - - /** - * Asserts the page responds with the specified response code. - * - * @param $code - * Response code. For example 200 is a successful page request. For a list - * 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\Render\FormattableMarkup to embed - * variables in the message text, not t(). If left blank, a default message - * will be displayed. - * @param $group - * (optional) The group this message is in, which is displayed in a column - * in test output. Use 'Debug' to indicate this is debugging output. Do not - * translate this string. Defaults to 'Browser'; most tests do not override - * this default. - * - * @return - * Assertion result. - */ - 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 : new FormattableMarkup('HTTP response expected @code, actual @curl_code', ['@code' => $code, '@curl_code' => $curl_code]), $group); - } - - /** - * Asserts the page did not return the specified response code. - * - * @param $code - * Response code. For example 200 is a successful page request. For a list - * 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\Render\FormattableMarkup to embed - * variables in the message text, not t(). If left blank, a default message - * will be displayed. - * @param $group - * (optional) The group this message is in, which is displayed in a column - * in test output. Use 'Debug' to indicate this is debugging output. Do not - * translate this string. Defaults to 'Browser'; most tests do not override - * this default. - * - * @return - * Assertion result. - */ - 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 : new FormattableMarkup('HTTP response not expected @code, actual @curl_code', ['@code' => $code, '@curl_code' => $curl_code]), $group); - } - - /** - * Builds an a absolute URL from a system path or a URL object. - * - * @param string|\Drupal\Core\Url $path - * A system path or a URL. - * @param array $options - * Options to be passed to Url::fromUri(). - * - * @return string - * An absolute URL string. - */ - protected function buildUrl($path, array $options = []) { - if ($path instanceof Url) { - $url_options = $path->getOptions(); - $options = $url_options + $options; - $path->setOptions($options); - return $path->setAbsolute()->toString(TRUE)->getGeneratedUrl(); - } - // The URL generator service is not necessarily available yet; e.g., in - // interactive installer tests. - elseif ($this->container->has('url_generator')) { - $force_internal = isset($options['external']) && $options['external'] == FALSE; - if (!$force_internal && UrlHelper::isExternal($path)) { - return Url::fromUri($path, $options)->toString(); - } - else { - $uri = $path === '<front>' ? 'base:/' : 'base:/' . $path; - // Path processing is needed for language prefixing. Skip it when a - // path that may look like an external URL is being used as internal. - $options['path_processing'] = !$force_internal; - return Url::fromUri($uri, $options) - ->setAbsolute() - ->toString(); - } - } - else { - return $this->getAbsoluteUrl($path); - } - } - - /** - * Asserts whether an expected cache tag was present in the last response. - * - * @param string $expected_cache_tag - * The expected cache tag. - */ - protected function assertCacheTag($expected_cache_tag) { - $cache_tags = explode(' ', $this->drupalGetHeader('X-Drupal-Cache-Tags')); - $this->assertTrue(in_array($expected_cache_tag, $cache_tags), "'" . $expected_cache_tag . "' is present in the X-Drupal-Cache-Tags header."); - } - - /** - * Asserts whether an expected cache tag was absent in the last response. - * - * @param string $cache_tag - * The cache tag to check. - */ - protected function assertNoCacheTag($cache_tag) { - $cache_tags = explode(' ', $this->drupalGetHeader('X-Drupal-Cache-Tags')); - $this->assertFalse(in_array($cache_tag, $cache_tags), "'" . $cache_tag . "' is absent in the X-Drupal-Cache-Tags header."); - } - - /** - * Enables/disables the cacheability headers. - * - * Sets the http.response.debug_cacheability_headers container parameter. - * - * @param bool $value - * (optional) Whether the debugging cacheability headers should be sent. - */ - protected function setHttpResponseDebugCacheabilityHeaders($value = TRUE) { - $this->setContainerParameter('http.response.debug_cacheability_headers', $value); - $this->rebuildContainer(); - $this->resetAll(); - } - -} diff --git a/core/modules/simpletest/templates/simpletest-result-summary.html.twig b/core/modules/simpletest/templates/simpletest-result-summary.html.twig deleted file mode 100644 index 2f87ed07b4209a8c838eb739f521a0250c8359cf..0000000000000000000000000000000000000000 --- a/core/modules/simpletest/templates/simpletest-result-summary.html.twig +++ /dev/null @@ -1,22 +0,0 @@ -{# -/** - * @file - * Default theme implementation for simpletest result summaries. - * - * Available variables: - * - label: An optional label to be rendered before the results. - * - items: Pluralized summaries for each result type (number of passes, fails, - * exceptions, and debug messages). - * - pass: The number of passes. - * - fail: The number of fails. - * - exception: The number of exceptions. - * - debug: The number of debug messages. - * - * @see template_preprocess_simpletest_result_summary() - * - * @ingroup themeable - */ -#} -<div class="simpletest-{{ fail + exception == 0 ? 'pass' : 'fail' }}"> - {{ label }} {{ items|join(', ') }} -</div> diff --git a/core/modules/simpletest/tests/fixtures/phpunit_error.xml b/core/modules/simpletest/tests/fixtures/phpunit_error.xml deleted file mode 100644 index 6a6a1cbc20f204066c515f66325955196b171aeb..0000000000000000000000000000000000000000 --- a/core/modules/simpletest/tests/fixtures/phpunit_error.xml +++ /dev/null @@ -1,43 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<testsuites> - <testsuite name="Drupal Unit Test Suite" tests="1" assertions="0" failures="0" errors="1" time="0.002680"> - <testsuite name="Drupal\Tests\Component\PhpStorage\FileStorageTest" file="/home/chx/www/system/core/tests/Drupal/Tests/Component/PhpStorage/FileStorageTest.php" namespace="Drupal\Tests\Component\PhpStorage" fullPackage="Drupal.Tests.Component.PhpStorage" tests="0" assertions="0" failures="0" errors="0" time="0.000000"/> - <testsuite name="Drupal\Tests\Component\PhpStorage\MTimeProtectedFastFileStorageTest" file="/home/chx/www/system/core/tests/Drupal/Tests/Component/PhpStorage/MTimeProtectedFastFileStorageTest.php" namespace="Drupal\Tests\Component\PhpStorage" fullPackage="Drupal.Tests.Component.PhpStorage" tests="0" assertions="0" failures="0" errors="0" time="0.000000"/> - <testsuite name="Drupal\Tests\Core\Cache\BackendChainImplementationUnitTest" file="/home/chx/www/system/core/tests/Drupal/Tests/Core/Cache/BackendChainImplementationUnitTest.php" namespace="Drupal\Tests\Core\Cache" fullPackage="Drupal.Tests.Core.Cache" tests="0" assertions="0" failures="0" errors="0" time="0.000000"/> - <testsuite name="Drupal\Tests\Core\Cache\NullBackendTest" file="/home/chx/www/system/core/tests/Drupal/Tests/Core/Cache/NullBackendTest.php" namespace="Drupal\Tests\Core\Cache" fullPackage="Drupal.Tests.Core.Cache" tests="0" assertions="0" failures="0" errors="0" time="0.000000"/> - <testsuite name="Drupal\Tests\Core\Extension\ModuleHandlerUnitTest" file="/home/chx/www/system/core/tests/Drupal/Tests/Core/Extension/ModuleHandlerUnitTest.php" namespace="Drupal\Tests\Core\Extension" fullPackage="Drupal.Tests.Core.Extension" tests="1" assertions="0" failures="0" errors="1" time="0.002680"> - <testcase name="testloadInclude" class="Drupal\Tests\Core\Extension\ModuleHandlerUnitTest" file="/home/chx/www/system/core/tests/Drupal/Tests/Core/Extension/ModuleHandlerUnitTest.php" line="37" assertions="0" time="0.002680"> - <error type="PHPUnit\Framework\Error\Notice">Drupal\Tests\Core\Extension\ModuleHandlerUnitTest::testloadInclude -Undefined index: foo - -/home/chx/www/system/core/lib/Drupal/Core/Extension/ModuleHandler.php:219 -/home/chx/www/system/core/tests/Drupal/Tests/Core/Extension/ModuleHandlerUnitTest.php:40 -</error> - </testcase> - </testsuite> - <testsuite name="Drupal\Tests\Core\NestedArrayUnitTest" file="/home/chx/www/system/core/tests/Drupal/Tests/Core/NestedArrayUnitTest.php" namespace="Drupal\Tests\Core" fullPackage="Drupal.Tests.Core" tests="0" assertions="0" failures="0" errors="0" time="0.000000"/> - <testsuite name="Drupal\breakpoint\Tests\BreakpointMediaQueryTest" file="/home/chx/www/system/core/modules/breakpoint/tests/Drupal/breakpoint/Tests/BreakpointMediaQueryTest.php" namespace="Drupal\breakpoint\Tests" fullPackage="Drupal.breakpoint.Tests" tests="0" assertions="0" failures="0" errors="0" time="0.000000"/> - <testsuite name="Drupal\Tests\Core\Route\RoleAccessCheckTest" file="/var/www/d8/core/tests/Drupal/Tests/Core/Route/RoleAccessCheckTestkTest.php" namespace="Drupal\Tests\Core\Route" fullPackage="Drupal.Tests.Core.Route" tests="3" assertions="3" failures="3" errors="0" time="0.009176"> - <testsuite name="Drupal\Tests\Core\Route\RoleAccessCheckTest::testRoleAccess" tests="3" assertions="3" failures="3" errors="0" time="0.009176"> - <testcase name="testRoleAccess with data set #0" assertions="1" time="0.004519"> - <failure type="PHPUnit\Framework\ExpectationFailedException">Drupal\Tests\Core\Route\RoleAccessCheckTest::testRoleAccess with data set #0 ('role_test_1', array(Drupal\user\Entity\User, Drupal\user\Entity\User)) - Access granted for user with the roles role_test_1 on path: role_test_1 - Failed asserting that false is true. - </failure> - </testcase> - <testcase name="testRoleAccess with data set #1" assertions="1" time="0.002354"> - <failure type="PHPUnit\Framework\ExpectationFailedException">Drupal\Tests\Core\Route\RoleAccessCheckTest::testRoleAccess with data set #1 ('role_test_2', array(Drupal\user\Entity\User, Drupal\user\Entity\User)) - Access granted for user with the roles role_test_2 on path: role_test_2 - Failed asserting that false is true. - </failure> - </testcase> - <testcase name="testRoleAccess with data set #2" assertions="1" time="0.002303"> - <failure type="PHPUnit\Framework\ExpectationFailedException">Drupal\Tests\Core\Route\RoleAccessCheckTest::testRoleAccess with data set #2 ('role_test_3', array(Drupal\user\Entity\User)) - Access granted for user with the roles role_test_1, role_test_2 on path: role_test_3 - Failed asserting that false is true. - </failure> - </testcase> - </testsuite> - </testsuite> - </testsuite> -</testsuites> diff --git a/core/modules/simpletest/tests/fixtures/select_2nd_selected.html b/core/modules/simpletest/tests/fixtures/select_2nd_selected.html deleted file mode 100644 index ec30bd6eaace06faabecf585e28c60f9cb05346f..0000000000000000000000000000000000000000 --- a/core/modules/simpletest/tests/fixtures/select_2nd_selected.html +++ /dev/null @@ -1,4 +0,0 @@ -<select name="test"> - <option value="1">One</option> - <option value="2" selected="selected">Two</option> -</select> diff --git a/core/modules/simpletest/tests/fixtures/select_none_selected.html b/core/modules/simpletest/tests/fixtures/select_none_selected.html deleted file mode 100644 index a6c87499684b94039212d88d061fc89cdc44a8d3..0000000000000000000000000000000000000000 --- a/core/modules/simpletest/tests/fixtures/select_none_selected.html +++ /dev/null @@ -1,4 +0,0 @@ -<select name="test"> - <option value="1">One</option> - <option value="2">Two</option> -</select> diff --git a/core/modules/simpletest/tests/fixtures/simpletest_phpunit_browsertest.php b/core/modules/simpletest/tests/fixtures/simpletest_phpunit_browsertest.php deleted file mode 100644 index 0e9c4165a20c3a62df05bb839ce2730bf5fc0371..0000000000000000000000000000000000000000 --- a/core/modules/simpletest/tests/fixtures/simpletest_phpunit_browsertest.php +++ /dev/null @@ -1,24 +0,0 @@ -<?php - -namespace Drupal\Tests\simpletest\Functional; - -use Drupal\Tests\BrowserTestBase; - -/** - * A PHPUnit-based browser test that will be run from Simpletest. - * - * To avoid accidentally running it is not in a normal PSR-4 directory. - * - * @group simpletest - */ -class SimpletestPhpunitBrowserTest extends BrowserTestBase { - - /** - * Dummy test that logs the visited front page for HTML output. - */ - public function testOutput() { - $this->drupalGet('<front>'); - $this->assertSession()->responseContains('<h2>TEST escaping</h2>'); - } - -} diff --git a/core/modules/simpletest/tests/fixtures/simpletest_phpunit_run_command_test.php b/core/modules/simpletest/tests/fixtures/simpletest_phpunit_run_command_test.php deleted file mode 100644 index 42dadfdb3620451343ce04e30da59173a53c61a3..0000000000000000000000000000000000000000 --- a/core/modules/simpletest/tests/fixtures/simpletest_phpunit_run_command_test.php +++ /dev/null @@ -1,30 +0,0 @@ -<?php - -namespace Drupal\Tests\simpletest\Unit; - -use Drupal\Tests\UnitTestCase; - -/** - * This test crashes PHP. - * - * To avoid accidentally running, it is not in a normal PSR-4 directory, the - * file name does not adhere to PSR-4 and an environment variable also needs to - * be set for the crash to happen. - * - * @see \Drupal\Tests\simpletest\Unit\SimpletestPhpunitRunCommandTest::testSimpletestPhpUnitRunCommand() - */ -class SimpletestPhpunitRunCommandTestWillDie extends UnitTestCase { - - /** - * Performs the status specified by SimpletestPhpunitRunCommandTestWillDie. - */ - public function testWillDie() { - $status = (int) getenv('SimpletestPhpunitRunCommandTestWillDie'); - if ($status == 0) { - $this->assertTrue(TRUE, 'Assertion to ensure test pass'); - return; - } - exit($status); - } - -} diff --git a/core/modules/simpletest/tests/modules/simpletest_deprecation_test/simpletest_deprecation_test.info.yml b/core/modules/simpletest/tests/modules/simpletest_deprecation_test/simpletest_deprecation_test.info.yml deleted file mode 100644 index ab5d1f278f1938d8b222598c733e8931f961e147..0000000000000000000000000000000000000000 --- a/core/modules/simpletest/tests/modules/simpletest_deprecation_test/simpletest_deprecation_test.info.yml +++ /dev/null @@ -1,5 +0,0 @@ -name: 'Simpletest deprecation test' -type: module -description: 'Support module for Simpletest deprecation tests.' -package: Testing -version: VERSION diff --git a/core/modules/simpletest/tests/modules/simpletest_deprecation_test/simpletest_deprecation_test.module b/core/modules/simpletest/tests/modules/simpletest_deprecation_test/simpletest_deprecation_test.module deleted file mode 100644 index d0f01eb7a62098d48d5e0443bbdffc5732e28e6d..0000000000000000000000000000000000000000 --- a/core/modules/simpletest/tests/modules/simpletest_deprecation_test/simpletest_deprecation_test.module +++ /dev/null @@ -1,42 +0,0 @@ -<?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. -} - -/** - * Implements hook_test_group_started(). - * - * This hook is deprecated and should trigger a deprecation error when invoked. - */ -function simpletest_deprecation_test_test_group_started() { - // No-op. -} - -/** - * Implements hook_test_group_finished(). - * - * This hook is deprecated and should trigger a deprecation error when invoked. - */ -function simpletest_deprecation_test_test_group_finished() { - // No-op. -} - -/** - * Implements hook_test_finished(). - * - * This hook is deprecated and should trigger a deprecation error when invoked. - */ -function simpletest_deprecation_test_test_finished($results) { - // No-op. -} diff --git a/core/modules/simpletest/tests/src/Functional/OtherInstallationProfileTestsTest.php b/core/modules/simpletest/tests/src/Functional/OtherInstallationProfileTestsTest.php deleted file mode 100644 index 8a9ba18281a0359696291d328b982ee285054721..0000000000000000000000000000000000000000 --- a/core/modules/simpletest/tests/src/Functional/OtherInstallationProfileTestsTest.php +++ /dev/null @@ -1,71 +0,0 @@ -<?php - -namespace Drupal\Tests\simpletest\Functional; - -use Drupal\Tests\BrowserTestBase; -use Drupal\Core\Url; - -/** - * Verifies that tests in other installation profiles are found. - * - * @group simpletest - * @group legacy - * - * @see \Drupal\simpletest\Tests\InstallationProfileModuleTestsTest - */ -class OtherInstallationProfileTestsTest extends BrowserTestBase { - - /** - * Modules to enable. - * - * @var array - */ - public static $modules = ['simpletest']; - - /** - * Use the Minimal profile. - * - * The Testing profile contains drupal_system_listing_compatible_test.test, - * which should be found. - * - * The Standard profile contains \Drupal\standard\Tests\StandardTest, which - * should be found. - * - * @var string - * - * @see \Drupal\simpletest\Tests\InstallationProfileModuleTestsTest - * @see \Drupal\Tests\drupal_system_listing_compatible_test\Kernel\SystemListingCrossProfileCompatibleTest - */ - protected $profile = 'minimal'; - - /** - * An administrative user with permission to administer unit tests. - * - * @var \Drupal\user\UserInterface - */ - protected $adminUser; - - protected function setUp() { - parent::setUp(); - - $this->adminUser = $this->drupalCreateUser(['administer unit tests']); - $this->drupalLogin($this->adminUser); - } - - /** - * Tests that tests located in another installation profile appear. - * - * @expectedDeprecation Drupal\simpletest\TestDiscovery is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Test\TestDiscovery instead. See https://www.drupal.org/node/2949692 - */ - public function testOtherInstallationProfile() { - // Assert the existence of a test in a different installation profile than - // the current. - $this->drupalGet(Url::fromRoute('simpletest.test_form')); - $this->assertText('Tests Standard installation profile expectations.'); - - // Assert the existence of a test for a module in a different installation - // profile than the current. - $this->assertText('Drupal\Tests\drupal_system_listing_compatible_test\Kernel\SystemListingCrossProfileCompatibleTest'); - } - -} diff --git a/core/modules/simpletest/tests/src/Functional/SimpletestTest.php b/core/modules/simpletest/tests/src/Functional/SimpletestTest.php deleted file mode 100644 index 781a1bae30ac53a0542be272a840aedf4f2fe5f3..0000000000000000000000000000000000000000 --- a/core/modules/simpletest/tests/src/Functional/SimpletestTest.php +++ /dev/null @@ -1,41 +0,0 @@ -<?php - -namespace Drupal\Tests\simpletest\Functional; - -use Drupal\Tests\BrowserTestBase; - -/** - * Basic functionality of the Testing module. - * - * @group simpletest - */ -class SimpletestTest extends BrowserTestBase { - - /** - * Modules to enable. - * - * @var array - */ - public static $modules = ['simpletest']; - - /** - * {@inheritdoc} - */ - protected $defaultTheme = 'stark'; - - /** - * Test that we can uninstall the module without mishap. - * - * Upon uninstall, simpletest will clean up after itself. This should neither - * break the test runner's expectations, nor cause any kind of exception. - * - * Note that this might break run-tests.sh test runs that don't use the - * --sqlite argument. - */ - public function testUninstallModule() { - /* @var $installer \Drupal\Core\Extension\ModuleInstallerInterface */ - $installer = $this->container->get('module_installer'); - $this->assertTrue($installer->uninstall(['simpletest'])); - } - -} diff --git a/core/modules/simpletest/tests/src/Functional/SimpletestUiTest.php b/core/modules/simpletest/tests/src/Functional/SimpletestUiTest.php deleted file mode 100644 index 9103cb8aad6dab712f5591ad342109610b7b2cd9..0000000000000000000000000000000000000000 --- a/core/modules/simpletest/tests/src/Functional/SimpletestUiTest.php +++ /dev/null @@ -1,66 +0,0 @@ -<?php - -namespace Drupal\Tests\simpletest\Functional; - -use Drupal\Core\Url; -use Drupal\KernelTests\KernelTestBaseTest; -use Drupal\Tests\action\Unit\Menu\ActionLocalTasksTest; -use Drupal\Tests\BrowserTestBase; - -/** - * Test various aspects of testing through the UI form. - * - * @group #slow - * @group simpletest - * @group legacy - */ -class SimpletestUiTest extends BrowserTestBase { - - /** - * {@inheritdoc} - */ - public static $modules = ['simpletest']; - - /** - * {@inheritdoc} - */ - protected function setUp() { - parent::setUp(); - $this->drupalLogin($this->createUser(['administer unit tests'])); - } - - /** - * Tests that unit, kernel, and functional tests work through the UI. - * - * @expectedDeprecation Drupal\simpletest\TestDiscovery is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Test\TestDiscovery instead. See https://www.drupal.org/node/2949692 - */ - public function testTestingThroughUI() { - $url = Url::fromRoute('simpletest.test_form'); - $assertion = $this->assertSession(); - - $this->drupalGet($url); - $settings = $this->getDrupalSettings(); - $this->assertTrue(strpos($settings['simpleTest']['images'][0], 'core/misc/menu-collapsed.png') > 0, 'drupalSettings contains a link to core/misc/menu-collapsed.png.'); - - // We can not test WebTestBase tests here since they require a valid .htkey - // to be created. However this scenario is covered by the testception of - // \Drupal\simpletest\Tests\SimpleTestTest. - $tests = [ - // A KernelTestBase test. - KernelTestBaseTest::class, - // A PHPUnit unit test. - ActionLocalTasksTest::class, - // A PHPUnit functional test. - ThroughUITest::class, - ]; - - foreach ($tests as $test) { - $edit = [ - "tests[$test]" => TRUE, - ]; - $this->drupalPostForm($url, $edit, t('Run tests')); - $assertion->pageTextContains('0 fails, 0 exceptions'); - } - } - -} diff --git a/core/modules/simpletest/tests/src/Functional/ThroughUITest.php b/core/modules/simpletest/tests/src/Functional/ThroughUITest.php deleted file mode 100644 index 1e325e4c55241656442b5adf996ffbada2fc8297..0000000000000000000000000000000000000000 --- a/core/modules/simpletest/tests/src/Functional/ThroughUITest.php +++ /dev/null @@ -1,24 +0,0 @@ -<?php - -namespace Drupal\Tests\simpletest\Functional; - -use Drupal\Tests\BrowserTestBase; - -/** - * Fixture test that is executed during Simpletest UI testing. - * - * @see \Drupal\simpletest\Tests::testTestingThroughUI() - * - * @group simpletest - * @group legacy - */ -class ThroughUITest extends BrowserTestBase { - - /** - * This test method must always pass. - */ - public function testThroughUi() { - $this->pass('Success!'); - } - -} diff --git a/core/modules/simpletest/tests/src/Kernel/Cache/Context/TestDiscoveryCacheContextTest.php b/core/modules/simpletest/tests/src/Kernel/Cache/Context/TestDiscoveryCacheContextTest.php deleted file mode 100644 index 00d83581cfd66f1c5160975fe56f69df90bbff79..0000000000000000000000000000000000000000 --- a/core/modules/simpletest/tests/src/Kernel/Cache/Context/TestDiscoveryCacheContextTest.php +++ /dev/null @@ -1,56 +0,0 @@ -<?php - -namespace Drupal\Tests\simpletest\Kernel\Cache\Context; - -use Drupal\KernelTests\KernelTestBase; -use Drupal\simpletest\Cache\Context\TestDiscoveryCacheContext; -use Drupal\simpletest\TestDiscovery; - -/** - * @group simpletest - * @group legacy - */ -class TestDiscoveryCacheContextTest extends KernelTestBase { - - /** - * {@inheritdoc} - */ - public static $modules = ['simpletest']; - - /** - * Tests that test context hashes are unique. - * - * @expectedDeprecation Drupal\simpletest\TestDiscovery is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Test\TestDiscovery instead. See https://www.drupal.org/node/2949692 - */ - 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()); - } - -} diff --git a/core/modules/simpletest/tests/src/Kernel/DeprecatedCleanupTest.php b/core/modules/simpletest/tests/src/Kernel/DeprecatedCleanupTest.php deleted file mode 100644 index ec29a7676868e9f887646ee5c8e757f4456f5980..0000000000000000000000000000000000000000 --- a/core/modules/simpletest/tests/src/Kernel/DeprecatedCleanupTest.php +++ /dev/null @@ -1,65 +0,0 @@ -<?php - -namespace Drupal\Tests\simpletest\Kernel; - -use Drupal\Core\DependencyInjection\ContainerBuilder; -use Drupal\Core\Test\EnvironmentCleanerInterface; -use Drupal\KernelTests\KernelTestBase; -use Symfony\Component\DependencyInjection\Definition; - -/** - * Verify deprecation errors for the cleanup functions. - * - * @group simpletest - * @group legacy - */ -class DeprecatedCleanupTest extends KernelTestBase { - - public static $modules = ['simpletest']; - - /** - * {@inheritdoc} - */ - public function register(ContainerBuilder $container) { - parent::register($container); - $cleaner_definition = new Definition(StubEnvironmentCleanerService::class); - $container->setDefinition('environment_cleaner', $cleaner_definition); - } - - /** - * @expectedDeprecation simpletest_clean_environment is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Access the environment_cleaner service and call its cleanEnvironment() method, or use \Drupal\Core\Test\EnvironmentCleaner::cleanEnvironment() instead.. See https://www.drupal.org/node/3076634 - * @expectedDeprecation simpletest_clean_database is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Access the environment_cleaner service and call its cleanDatabase() method, or use \Drupal\Core\Test\EnvironmentCleaner::cleanDatabase() instead. See https://www.drupal.org/node/3076634 - * @expectedDeprecation simpletest_clean_temporary_directories is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Access the environment_cleaner service and call its cleanTemporaryDirectories() method, or use \Drupal\Core\Test\EnvironmentCleaner::cleanTemporaryDirectories() instead. See https://www.drupal.org/node/3076634 - * @expectedDeprecation simpletest_clean_results_table is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Access the environment_cleaner service and call its cleanResultsTable() method, or use \Drupal\Core\Test\EnvironmentCleaner::cleanResultsTable() instead. See https://www.drupal.org/node/3076634 - */ - public function testDeprecatedCleanFunctions() { - $this->assertNull(simpletest_clean_environment()); - $this->assertNull(simpletest_clean_database()); - $this->assertNull(simpletest_clean_temporary_directories()); - $this->assertEquals(0, simpletest_clean_results_table()); - } - -} - -/** - * Mock environment_cleaner service that does not perform any cleaning. - */ -class StubEnvironmentCleanerService implements EnvironmentCleanerInterface { - - public function cleanDatabase() { - - } - - public function cleanEnvironment($clear_results = TRUE, $clear_temp_directories = TRUE, $clear_database = TRUE) { - - } - - public function cleanResultsTable($test_id = NULL) { - - } - - public function cleanTemporaryDirectories() { - - } - -} diff --git a/core/modules/simpletest/tests/src/Kernel/Migrate/d6/MigrateSimpletestConfigsTest.php b/core/modules/simpletest/tests/src/Kernel/Migrate/d6/MigrateSimpletestConfigsTest.php deleted file mode 100644 index f8f9ffb02ceb041f3c5f949b362d357a9899d8c1..0000000000000000000000000000000000000000 --- a/core/modules/simpletest/tests/src/Kernel/Migrate/d6/MigrateSimpletestConfigsTest.php +++ /dev/null @@ -1,46 +0,0 @@ -<?php - -namespace Drupal\Tests\simpletest\Kernel\Migrate\d6; - -use Drupal\Tests\SchemaCheckTestTrait; -use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase; - -/** - * Upgrade variables to simpletest.settings.yml. - * - * @group migrate_drupal_6 - */ -class MigrateSimpletestConfigsTest extends MigrateDrupal6TestBase { - - use SchemaCheckTestTrait; - - /** - * {@inheritdoc} - */ - public static $modules = ['simpletest']; - - /** - * {@inheritdoc} - */ - protected function setUp() { - parent::setUp(); - $this->installConfig(['simpletest']); - $this->executeMigration('d6_simpletest_settings'); - } - - /** - * Tests migration of simpletest variables to simpletest.settings.yml. - */ - public function testSimpletestSettings() { - $config = $this->config('simpletest.settings'); - $this->assertIdentical(TRUE, $config->get('clear_results')); - $this->assertIdentical(CURLAUTH_BASIC, $config->get('httpauth.method')); - // NULL in the dump means defaults which is empty string. Same as omitting - // them. - $this->assertIdentical('', $config->get('httpauth.password')); - $this->assertIdentical('', $config->get('httpauth.username')); - $this->assertIdentical(TRUE, $config->get('verbose')); - $this->assertConfigSchema(\Drupal::service('config.typed'), 'simpletest.settings', $config->get()); - } - -} diff --git a/core/modules/simpletest/tests/src/Kernel/Migrate/d7/MigrateSimpletestSettingsTest.php b/core/modules/simpletest/tests/src/Kernel/Migrate/d7/MigrateSimpletestSettingsTest.php deleted file mode 100644 index 6eba6339c840e03f9c3e6d068bf5c006a5557ac6..0000000000000000000000000000000000000000 --- a/core/modules/simpletest/tests/src/Kernel/Migrate/d7/MigrateSimpletestSettingsTest.php +++ /dev/null @@ -1,37 +0,0 @@ -<?php - -namespace Drupal\Tests\simpletest\Kernel\Migrate\d7; - -use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase; - -/** - * Tests migration of SimpleTest's variables to configuration. - * - * @group simpletest - */ -class MigrateSimpletestSettingsTest extends MigrateDrupal7TestBase { - - public static $modules = ['simpletest']; - - /** - * {@inheritdoc} - */ - protected function setUp() { - parent::setUp(); - $this->installConfig(static::$modules); - $this->executeMigration('d7_simpletest_settings'); - } - - /** - * Tests migration of SimpleTest settings to configuration. - */ - public function testMigration() { - $config = \Drupal::config('simpletest.settings')->get(); - $this->assertTrue($config['clear_results']); - $this->assertIdentical(CURLAUTH_BASIC, $config['httpauth']['method']); - $this->assertIdentical('testbot', $config['httpauth']['username']); - $this->assertIdentical('foobaz', $config['httpauth']['password']); - $this->assertTrue($config['verbose']); - } - -} diff --git a/core/modules/simpletest/tests/src/Kernel/PhpUnitErrorTest.php b/core/modules/simpletest/tests/src/Kernel/PhpUnitErrorTest.php deleted file mode 100644 index 4f01936eeb05b0a048dc8365af4a19da2c9d8243..0000000000000000000000000000000000000000 --- a/core/modules/simpletest/tests/src/Kernel/PhpUnitErrorTest.php +++ /dev/null @@ -1,46 +0,0 @@ -<?php - -namespace Drupal\Tests\simpletest\Kernel; - -use Drupal\KernelTests\KernelTestBase; - -/** - * Tests PHPUnit errors are getting converted to Simpletest errors. - * - * @group simpletest - * @group legacy - */ -class PhpUnitErrorTest extends KernelTestBase { - - /** - * Enable the simpletest module. - * - * @var string[] - */ - protected static $modules = ['simpletest']; - - /** - * Test errors reported. - * - * @expectedDeprecation simpletest_phpunit_xml_to_rows is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Test\JUnitConverter::xmlToRows() instead. See https://www.drupal.org/node/2948547 - */ - public function testPhpUnitXmlParsing() { - $phpunit_error_xml = __DIR__ . '/../../fixtures/phpunit_error.xml'; - - $res = simpletest_phpunit_xml_to_rows(1, $phpunit_error_xml); - $this->assertEquals(count($res), 4, 'All testcases got extracted'); - $this->assertNotEquals($res[0]['status'], 'pass'); - $this->assertEquals($res[0]['status'], 'fail'); - - // Test nested testsuites, which appear when you use @dataProvider. - for ($i = 0; $i < 3; $i++) { - $this->assertNotEquals($res[$i + 1]['status'], 'pass'); - $this->assertEquals($res[$i + 1]['status'], 'fail'); - } - - // Make sure simpletest_phpunit_xml_to_rows() does not balk if the test - // didn't run. - $this->assertNull(simpletest_phpunit_xml_to_rows(1, 'does_not_exist')); - } - -} diff --git a/core/modules/simpletest/tests/src/Kernel/SimpletestDeprecationTest.php b/core/modules/simpletest/tests/src/Kernel/SimpletestDeprecationTest.php deleted file mode 100644 index 4ef09a903357e5ec977ba0d37e13be6f050c59c1..0000000000000000000000000000000000000000 --- a/core/modules/simpletest/tests/src/Kernel/SimpletestDeprecationTest.php +++ /dev/null @@ -1,104 +0,0 @@ -<?php - -namespace Drupal\Tests\simpletest\Kernel; - -use Drupal\KernelTests\KernelTestBase; -use Drupal\simpletest\TestDiscovery; - -/** - * Verify deprecations within the simpletest module. - * - * @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(); - } - - /** - * @expectedDeprecation Drupal\simpletest\TestDiscovery is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Test\TestDiscovery instead. See https://www.drupal.org/node/2949692 - * @expectedDeprecation The "test_discovery" service relies on the deprecated "Drupal\simpletest\TestDiscovery" class. It should either be deprecated or its implementation upgraded. - */ - public function testDeprecatedServices() { - $this->assertInstanceOf(TestDiscovery::class, $this->container->get('test_discovery')); - } - - /** - * @expectedDeprecation simpletest_phpunit_xml_filepath is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Test\PhpUnitTestRunner::xmlLogFilepath() instead. See https://www.drupal.org/node/2948547 - * @expectedDeprecation simpletest_phpunit_command is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Test\PhpUnitTestRunner::phpUnitCommand() instead. See https://www.drupal.org/node/2948547 - * @expectedDeprecation simpletest_phpunit_find_testcases is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Test\JUnitConverter::findTestCases() instead. See https://www.drupal.org/node/2948547 - * @expectedDeprecation simpletest_phpunit_testcase_to_row is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Test\JUnitConverter::convertTestCaseToSimpletestRow() instead. See https://www.drupal.org/node/2948547 - * @expectedDeprecation simpletest_summarize_phpunit_result is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Test\PhpUnitTestRunner::summarizeResults() instead. See https://www.drupal.org/node/2948547 - */ - public function testDeprecatedPhpUnitFunctions() { - // We can't test the deprecation errors for the following functions because - // they cannot be mocked, and calling them would change the test results: - // - simpletest_run_phpunit_tests(). - // - simpletest_phpunit_run_command(). - // - simpletest_phpunit_xml_to_rows(). - $this->assertStringEndsWith('/phpunit-23.xml', simpletest_phpunit_xml_filepath(23)); - - $this->assertInternalType('string', simpletest_phpunit_command()); - - $this->assertEquals([], simpletest_phpunit_find_testcases(new \SimpleXMLElement('<not_testcase></not_testcase>'))); - - $this->assertEquals([ - 'test_id' => 23, - 'test_class' => '', - 'status' => 'pass', - 'message' => '', - 'message_group' => 'Other', - 'function' => '->()', - 'line' => 0, - 'file' => NULL, - ], simpletest_phpunit_testcase_to_row(23, new \SimpleXMLElement('<not_testcase></not_testcase>'))); - - $this->assertEquals( - [ - static::class => [ - '#pass' => 0, - '#fail' => 0, - '#exception' => 0, - '#debug' => 1, - ], - ], - simpletest_summarize_phpunit_result([ - [ - 'test_class' => static::class, - 'status' => 'debug', - ], - ]) - ); - } - - /** - * @expectedDeprecation simpletest_generate_file() is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use \Drupal\Tests\TestFileCreationTrait::generateFile() instead. See https://www.drupal.org/node/3077768 - */ - public function testDeprecatedSimpletestGenerateFile() { - $file = simpletest_generate_file('foo', 40, 10); - $public_file = 'public://' . $file . '.txt'; - $this->assertFileExists($public_file); - $this->assertTrue(unlink($public_file)); - } - - /** - * @expectedDeprecation simpletest_process_phpunit_results() is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Test\TestDatabase::processPhpUnitResults() instead. See https://www.drupal.org/node/3075252 - */ - public function testProcessPhpUnitResults() { - // The only safe way to test this deprecation is to call it with an empty - // result set. This should not touch the results database. - $this->assertNull(simpletest_process_phpunit_results([])); - } - -} diff --git a/core/modules/simpletest/tests/src/Kernel/TestDeprecatedTestHooks.php b/core/modules/simpletest/tests/src/Kernel/TestDeprecatedTestHooks.php deleted file mode 100644 index c578de6991f1857e95bc44e4b3ce5280ba4dc127..0000000000000000000000000000000000000000 --- a/core/modules/simpletest/tests/src/Kernel/TestDeprecatedTestHooks.php +++ /dev/null @@ -1,146 +0,0 @@ -<?php - -namespace Drupal\Tests\simpletest\Kernel; - -use Drupal\Core\Database\Connection; -use Drupal\Core\Database\Query\Insert; -use Drupal\Core\Render\Renderer; -use Drupal\Core\StreamWrapper\PublicStream; -use Drupal\KernelTests\KernelTestBase; -use Drupal\simpletest\TestDiscovery; -use Drupal\simpletest\WebTestBase; - -/** - * Test the deprecation messages for Simpletest test hooks. - * - * @group simpletest - * @group legacy - */ -class TestDeprecatedTestHooks extends KernelTestBase { - - /** - * {@inheritdoc} - */ - public static $modules = ['simpletest', 'simpletest_deprecation_test']; - - /** - * @expectedDeprecation The deprecated hook hook_test_group_finished() is implemented in these functions: simpletest_deprecation_test_test_group_finished(). Convert your test to a PHPUnit-based one and implement test listeners. See https://www.drupal.org/node/2934242 - */ - public function testHookTestGroupFinished() { - // @todo Mock the messenger service and add expectations when - // \Drupal::messenger() actually uses the service. - // @see https://www.drupal.org/node/2928994 - $this->assertNull(_simpletest_batch_finished(TRUE, [], [], 10)); - } - - /** - * @expectedDeprecation The deprecated hook hook_test_group_started() is implemented in these functions: simpletest_deprecation_test_test_group_started(). Convert your test to a PHPUnit-based one and implement test listeners. See https://www.drupal.org/node/2934242 - */ - public function testHookTestGroupStarted() { - // Mock a database connection enough for simpletest_run_tests(). - $insert = $this->getMockBuilder(Insert::class) - ->disableOriginalConstructor() - ->setMethods(['execute', 'useDefaults']) - ->getMock(); - $insert->expects($this->any()) - ->method('useDefaults') - ->willReturn($insert); - $insert->expects($this->any()) - ->method('execute') - // Return an arbitrary test ID. - ->willReturn(__METHOD__); - - $connection = $this->getMockBuilder(Connection::class) - ->disableOriginalConstructor() - ->setMethods(['insert']) - ->getMockForAbstractClass(); - $connection->expects($this->once()) - ->method('insert') - ->willReturn($insert); - - // Mock public stream wrapper enough for simpletest_run_tests(). - $public = $this->getMockBuilder(PublicStream::class) - ->disableOriginalConstructor() - // Mock all methods to do nothing and return NULL. - ->setMethods([]) - ->getMock(); - - // Set up the container. - $this->container->set('database', $connection); - $this->container->set('stream_wrapper.public', $public); - - // Make sure our mocked database is in use by expecting a test ID that is - // __METHOD__. - $this->assertEquals(__METHOD__, simpletest_run_tests([static::class])); - } - - /** - * @expectedDeprecation The deprecated hook hook_test_finished() is implemented in these functions: simpletest_deprecation_test_test_finished(). Convert your test to a PHPUnit-based one and implement test listeners. See https://www.drupal.org/node/2934242 - */ - public function testHookTestFinished() { - // Mock test_discovery. - $discovery = $this->getMockBuilder(TestDiscovery::class) - ->disableOriginalConstructor() - ->setMethods(['registerTestNamespaces']) - ->getMock(); - $discovery->expects($this->once()) - ->method('registerTestNamespaces') - ->willReturn([]); - - // Mock renderer. - $renderer = $this->getMockBuilder(Renderer::class) - ->disableOriginalConstructor() - ->setMethods(['render']) - ->getMock(); - // We don't care what the rendered batch elements look like. - $renderer->expects($this->any()) - ->method('render') - ->willReturn(''); - - // Set up the container. - $this->container->set('test_discovery', $discovery); - $this->container->set('renderer', $renderer); - - // A mock batch. - $context = []; - - // InnocuousTest is a WebTestBase test class which passes and never touches - // the database. - _simpletest_batch_operation([InnocuousTest::class], __METHOD__, $context); - } - -} - -/** - * A very simple WebTestBase test that never touches the database. - * - * @group WebTestBase - * @group legacy - */ -class InnocuousTest extends WebTestBase { - - /** - * Override to prevent any environmental side-effects. - */ - protected function prepareEnvironment() { - } - - /** - * Override run() since it uses TestBase. - */ - public function run(array $methods = []) { - } - - /** - * Override to prevent any assertions from being stored. - */ - protected function storeAssertion(array $assertion) { - } - - /** - * Override to prevent any assertions from being stored. - */ - public static function insertAssert($test_id, $test_class, $status, $message = '', $group = 'Other', array $caller = []) { - } - -} diff --git a/core/modules/simpletest/tests/src/Kernel/TestDiscoveryDeprecationTest.php b/core/modules/simpletest/tests/src/Kernel/TestDiscoveryDeprecationTest.php deleted file mode 100644 index c9c781d278cabaa32bbcf7f770c22709507bb07a..0000000000000000000000000000000000000000 --- a/core/modules/simpletest/tests/src/Kernel/TestDiscoveryDeprecationTest.php +++ /dev/null @@ -1,35 +0,0 @@ -<?php - -namespace Drupal\Tests\simpletest\Kernel; - -use Drupal\KernelTests\KernelTestBase; -use Drupal\simpletest\TestDiscovery; - -/** - * @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() { - $test_discovery = $this->container->get('test_discovery'); - - $this->assertEquals(TestDiscovery::class, get_class($test_discovery)); - - // The simpletest_test module implements hook_simpletest_alter(), which - // should trigger a deprecation error during getTestClasses(). - $this->assertNotEmpty($test_discovery->getTestClasses()); - } - -} diff --git a/core/modules/simpletest/tests/src/Unit/SimpletestPhpunitRunCommandTest.php b/core/modules/simpletest/tests/src/Unit/SimpletestPhpunitRunCommandTest.php deleted file mode 100644 index 4f90438d1da8d22db133566dec967aee5fc75cde..0000000000000000000000000000000000000000 --- a/core/modules/simpletest/tests/src/Unit/SimpletestPhpunitRunCommandTest.php +++ /dev/null @@ -1,152 +0,0 @@ -<?php - -namespace Drupal\Tests\simpletest\Unit; - -use Drupal\Core\Database\Database; -use Drupal\Core\DependencyInjection\ContainerBuilder; -use Drupal\Core\File\FileSystemInterface; -use Drupal\Core\Test\PhpUnitTestRunner; -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. - * - * The file simpletest_phpunit_run_command_test.php contains the test class - * \Drupal\Tests\simpletest\Unit\SimpletestPhpunitRunCommandTestWillDie which - * can be made to exit with result code 2. It lives in a file which won't be - * autoloaded, so that it won't fail test runs. - * - * Here, we run SimpletestPhpunitRunCommandTestWillDie, make it die, and see - * what happens. - * - * @group simpletest - * @group legacy - * - * @runTestsInSeparateProcesses - * @preserveGlobalState disabled - */ -class SimpletestPhpunitRunCommandTest extends TestCase { - - /** - * Path to the app root. - * - * @var string - */ - protected static $root; - - /** - * A fixture container. - * - * @var \Symfony\Component\DependencyInjection\ContainerInterface - */ - protected $fixtureContainer; - - /** - * {@inheritdoc} - */ - public static function setUpBeforeClass() { - parent::setUpBeforeClass(); - // Figure out our app root. - self::$root = dirname(dirname(dirname(dirname(dirname(dirname(__DIR__)))))); - // Include the files we need for tests. The stub test we will run is - // SimpletestPhpunitRunCommandTestWillDie which is located in - // simpletest_phpunit_run_command_test.php. - include_once self::$root . '/core/modules/simpletest/tests/fixtures/simpletest_phpunit_run_command_test.php'; - // Since we're testing simpletest_run_phpunit_tests(), we need to include - // simpletest.module. - include_once self::$root . '/core/modules/simpletest/simpletest.module'; - } - - /** - * {@inheritdoc} - */ - protected function setUp() { - parent::setUp(); - // Organize our mock container. - $container = new ContainerBuilder(); - $container->set('app.root', self::$root); - $file_system = $this->prophesize(FileSystemInterface::class); - // The simpletest directory wrapper will always point to /tmp. - $file_system->realpath('public://simpletest')->willReturn(sys_get_temp_dir()); - $container->set('file_system', $file_system->reveal()); - \Drupal::setContainer($container); - $this->fixtureContainer = $container; - } - - /** - * Data provider for testSimpletestPhpUnitRunCommand(). - * - * @return array - * Arrays of status codes and the label they're expected to have. - */ - public function provideStatusCodes() { - $data = [ - [0, 'pass'], - [1, 'fail'], - [2, 'exception'], - ]; - // All status codes 3 and above should be labeled 'error'. - // @todo: The valid values here would be 3 to 127. But since the test - // touches the file system a lot, we only have 3, 4, and 127 for speed. - foreach ([3, 4, 127] as $status) { - $data[] = [$status, 'error']; - } - return $data; - } - - /** - * Test the round trip for PHPUnit execution status codes. - * - * Also tests backwards-compatibility of PhpUnitTestRunner::runTests(). - * - * @covers ::simpletest_run_phpunit_tests - * - * @dataProvider provideStatusCodes - * - * @expectedDeprecation simpletest_run_phpunit_tests is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Test\PhpUnitTestRunner::runTests() instead. See https://www.drupal.org/node/2948547 - * @expectedDeprecation simpletest_phpunit_xml_filepath is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Test\PhpUnitTestRunner::xmlLogFilepath() instead. See https://www.drupal.org/node/2948547 - */ - 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); - - // Test against simpletest_run_phpunit_tests(). - $bc_ret = simpletest_run_phpunit_tests($test_id, [SimpletestPhpunitRunCommandTestWillDie::class]); - $this->assertSame($bc_ret[0]['status'], $label); - - // Test against PhpUnitTestRunner::runTests(). - $runner = PhpUnitTestRunner::create($this->fixtureContainer); - $ret = $runner->runTests($test_id, [SimpletestPhpunitRunCommandTestWillDie::class]); - $this->assertSame($ret[0]['status'], $label); - - // Unset our environmental variable. - putenv('SimpletestPhpunitRunCommandTestWillDie'); - unlink(simpletest_phpunit_xml_filepath($test_id)); - } - - /** - * {@inheritdoc} - */ - protected function tearDown() { - // We unset the $base_url global, since the test code sets it as a - // side-effect. - unset($GLOBALS['base_url']); - parent::tearDown(); - } - -} diff --git a/core/modules/simpletest/tests/src/Unit/SimpletestUiPrinterTest.php b/core/modules/simpletest/tests/src/Unit/SimpletestUiPrinterTest.php deleted file mode 100644 index d9c4730f296c1e1744e0aac178b02de61692753a..0000000000000000000000000000000000000000 --- a/core/modules/simpletest/tests/src/Unit/SimpletestUiPrinterTest.php +++ /dev/null @@ -1,45 +0,0 @@ -<?php - -namespace Drupal\Tests\simpletest\Unit; - -use Drupal\Tests\Listeners\SimpletestUiPrinter; -use Drupal\Tests\UnitTestCase; - -/** - * @coversDefaultClass \Drupal\Tests\Listeners\SimpletestUiPrinter - * - * @group simpletest - */ -class SimpletestUiPrinterTest extends UnitTestCase { - - /** - * Data provider for testWrite(). - * - * @return string[] - * Array of data for testWrite(). - * - Expected output from SimpletestUiPrinter->write(). - * - Buffer to pass into SimpletestUiPrinter->write(). - */ - public function provideBuffer() { - return [ - ['&"'<>', '&"\'<>'], - ['<a href="http:////www.example.com" target="_blank" title="http:////www.example.com">http:////www.example.com</a>', 'http:////www.example.com'], - ['this is some text <a href="http://www.example.com/" target="_blank" title="http://www.example.com/">http://www.example.com/</a> with a link in it.', 'this is some text http://www.example.com/ with a link in it.'], - ["HTML output was generated<br />\n", "HTML output was generated\n"], - ]; - } - - /** - * @covers ::write - * - * @dataProvider provideBuffer - */ - public function testWrite($expected, $buffer) { - $printer = new SimpletestUiPrinter(); - // Set up our expectation. - $this->expectOutputString($expected); - // Write the buffer. - $printer->write($buffer); - } - -} diff --git a/core/modules/simpletest/tests/src/Unit/TestBaseTest.php b/core/modules/simpletest/tests/src/Unit/TestBaseTest.php deleted file mode 100644 index 12deceb997e16869617be93204524092f1efeadc..0000000000000000000000000000000000000000 --- a/core/modules/simpletest/tests/src/Unit/TestBaseTest.php +++ /dev/null @@ -1,470 +0,0 @@ -<?php - -namespace Drupal\Tests\simpletest\Unit; - -use Drupal\Tests\UnitTestCase; - -/** - * @requires extension curl - * @coversDefaultClass \Drupal\simpletest\TestBase - * @group simpletest - * @group TestBase - */ -class TestBaseTest extends UnitTestCase { - - /** - * Helper method for constructing a mock TestBase object. - * - * TestBase is abstract, so we have to mock it. We'll also - * mock the storeAssertion() method so we don't need the database. - * - * @param string $test_id - * An identifying name for the mocked test. - * - * @return object - * Mock of Drupal\simpletest\TestBase. - */ - public function getTestBaseForAssertionTests($test_id) { - $mock_test_base = $this->getMockBuilder('Drupal\simpletest\TestBase') - ->setConstructorArgs([$test_id]) - ->setMethods(['storeAssertion']) - ->getMockForAbstractClass(); - // Override storeAssertion() so we don't need a database. - $mock_test_base->expects($this->any()) - ->method('storeAssertion') - ->will($this->returnValue(NULL)); - return $mock_test_base; - } - - /** - * Invoke methods that are protected or private. - * - * @param object $object - * Object on which to invoke the method. - * @param string $method_name - * Name of the method to invoke. - * @param array $arguments - * Array of arguments to be passed to the method. - * - * @return mixed - * Value returned by the invoked method. - */ - public function invokeProtectedMethod($object, $method_name, array $arguments) { - $ref_method = new \ReflectionMethod($object, $method_name); - $ref_method->setAccessible(TRUE); - return $ref_method->invokeArgs($object, $arguments); - } - - /** - * Provides data for the random string validation test. - * - * @return array - * - The expected result of the validation. - * - The string to validate. - */ - public function providerRandomStringValidate() { - return [ - [FALSE, ' curry paste'], - [FALSE, 'curry paste '], - [FALSE, 'curry paste'], - [FALSE, 'curry paste'], - [TRUE, 'curry paste'], - [TRUE, 'thai green curry paste'], - [TRUE, '@startswithat'], - [TRUE, 'contains@at'], - ]; - } - - /** - * @covers ::randomStringValidate - * @dataProvider providerRandomStringValidate - */ - public function testRandomStringValidate($expected, $string) { - $mock_test_base = $this->getMockForAbstractClass('Drupal\simpletest\TestBase'); - $actual = $mock_test_base->randomStringValidate($string); - $this->assertEquals($expected, $actual); - } - - /** - * Provides data for testRandomString() and others. - * - * @return array - * - The number of items (characters, object properties) we expect any of - * the random functions to give us. - */ - public function providerRandomItems() { - return [ - [NULL], - [0], - [1], - [2], - [3], - [4], - [7], - ]; - } - - /** - * @covers ::randomString - * @dataProvider providerRandomItems - */ - public function testRandomString($length) { - $mock_test_base = $this->getMockForAbstractClass('Drupal\simpletest\TestBase'); - $string = $mock_test_base->randomString($length); - $this->assertEquals($length, strlen($string)); - // randomString() should always include an ampersand ('&') and a - // greater than ('>') if $length is greater than 3. - if ($length > 4) { - $this->assertContains('&', $string); - $this->assertContains('>', $string); - } - } - - /** - * @covers ::randomObject - * @dataProvider providerRandomItems - */ - public function testRandomObject($size) { - $test_base = $this->getTestBaseForAssertionTests('test_id'); - // Note: count((array)object) works for now, maybe not later. - $this->assertEquals($size, count((array) $test_base->randomObject($size))); - } - - /** - * @covers ::checkRequirements - */ - public function testCheckRequirements() { - $test_base = $this->getTestBaseForAssertionTests('test_id'); - $this->assertInternalType( - 'array', - $this->invokeProtectedMethod($test_base, 'checkRequirements', []) - ); - } - - /** - * Data provider for testAssert(). - * - * @return array - * Standard dataProvider array of arrays: - * - Expected result from assert(). - * - Expected status stored in TestBase->assertions. - * - Status, passed to assert(). - * - Message, passed to assert(). - * - Group, passed to assert(). - * - Caller, passed to assert(). - */ - public function providerAssert() { - return [ - [TRUE, 'pass', TRUE, 'Yay pass', 'test', []], - [FALSE, 'fail', FALSE, 'Boo fail', 'test', []], - [TRUE, 'pass', 'pass', 'Yay pass', 'test', []], - [FALSE, 'fail', 'fail', 'Boo fail', 'test', []], - [FALSE, 'exception', 'exception', 'Boo fail', 'test', []], - [FALSE, 'debug', 'debug', 'Boo fail', 'test', []], - ]; - } - - /** - * @covers ::assert - * @dataProvider providerAssert - */ - public function testAssert($expected, $assertion_status, $status, $message, $group, $caller) { - $test_id = 'luke_i_am_your_' . $assertion_status; - $test_base = $this->getTestBaseForAssertionTests($test_id); - - // Verify some startup values. - $this->assertAttributeEmpty('assertions', $test_base); - if (is_string($status)) { - $this->assertEquals(0, $test_base->results['#' . $status]); - } - - // assert() is protected so we have to make it accessible. - $ref_assert = new \ReflectionMethod($test_base, 'assert'); - $ref_assert->setAccessible(TRUE); - - // Call assert() from within our hall of mirrors. - $this->assertEquals( - $expected, - $ref_assert->invokeArgs($test_base, - [$status, $message, $group, $caller] - ) - ); - - // Check the side-effects of assert(). - if (is_string($status)) { - $this->assertEquals(1, $test_base->results['#' . $status]); - } - $this->assertAttributeNotEmpty('assertions', $test_base); - // Make a ReflectionProperty for the assertions property, - // since it's protected. - $ref_assertions = new \ReflectionProperty($test_base, 'assertions'); - $ref_assertions->setAccessible(TRUE); - $assertions = $ref_assertions->getValue($test_base); - $assertion = reset($assertions); - $this->assertEquals($assertion_status, $assertion['status']); - $this->assertEquals($test_id, $assertion['test_id']); - $this->assertEquals(get_class($test_base), $assertion['test_class']); - $this->assertEquals($message, $assertion['message']); - $this->assertEquals($group, $assertion['message_group']); - } - - /** - * Data provider for assertTrue(). - */ - public function providerAssertTrue() { - return [ - [TRUE, TRUE], - [FALSE, FALSE], - ]; - } - - /** - * @covers ::assertTrue - * @dataProvider providerAssertTrue - */ - public function testAssertTrue($expected, $value) { - $test_base = $this->getTestBaseForAssertionTests('test_id'); - $this->assertEquals( - $expected, - $this->invokeProtectedMethod($test_base, 'assertTrue', [$value]) - ); - } - - /** - * @covers ::assertFalse - * @dataProvider providerAssertTrue - */ - public function testAssertFalse($expected, $value) { - $test_base = $this->getTestBaseForAssertionTests('test_id'); - $this->assertEquals( - (!$expected), - $this->invokeProtectedMethod($test_base, 'assertFalse', [$value]) - ); - } - - /** - * Data provider for assertNull(). - */ - public function providerAssertNull() { - return [ - [TRUE, NULL], - [FALSE, ''], - ]; - } - - /** - * @covers ::assertNull - * @dataProvider providerAssertNull - */ - public function testAssertNull($expected, $value) { - $test_base = $this->getTestBaseForAssertionTests('test_id'); - $this->assertEquals( - $expected, - $this->invokeProtectedMethod($test_base, 'assertNull', [$value]) - ); - } - - /** - * @covers ::assertNotNull - * @dataProvider providerAssertNull - */ - public function testAssertNotNull($expected, $value) { - $test_base = $this->getTestBaseForAssertionTests('test_id'); - $this->assertEquals( - (!$expected), - $this->invokeProtectedMethod($test_base, 'assertNotNull', [$value]) - ); - } - - /** - * Data provider for tests of equality assertions. - * - * Used by testAssertIdentical(), testAssertEqual(), testAssertNotIdentical(), - * and testAssertNotEqual(). - * - * @return - * Array of test data. - * - Expected assertion value for identical comparison. - * - Expected assertion value for equal comparison. - * - First value to compare. - * - Second value to compare. - */ - public function providerEqualityAssertions() { - return [ - // Integers and floats. - [TRUE, TRUE, 0, 0], - [FALSE, TRUE, 0, 0.0], - [FALSE, TRUE, '0', 0], - [FALSE, TRUE, '0.0', 0.0], - [FALSE, FALSE, 23, 77], - [TRUE, TRUE, 23.0, 23.0], - // Strings. - [FALSE, FALSE, 'foof', 'yay'], - [TRUE, TRUE, 'yay', 'yay'], - // Bools with type conversion. - [TRUE, TRUE, TRUE, TRUE], - [TRUE, TRUE, FALSE, FALSE], - [FALSE, TRUE, NULL, FALSE], - [FALSE, TRUE, 'TRUE', TRUE], - [FALSE, FALSE, 'FALSE', FALSE], - [FALSE, TRUE, 0, FALSE], - [FALSE, TRUE, 1, TRUE], - [FALSE, TRUE, -1, TRUE], - [FALSE, TRUE, '1', TRUE], - [FALSE, TRUE, '1.3', TRUE], - // Null. - [FALSE, FALSE, 'NULL', NULL], - [TRUE, TRUE, NULL, NULL], - ]; - } - - /** - * @covers ::assertIdentical - * @dataProvider providerEqualityAssertions - */ - public function testAssertIdentical($expected_identical, $expected_equal, $first, $second) { - $test_base = $this->getTestBaseForAssertionTests('test_id'); - $this->assertEquals( - $expected_identical, - $this->invokeProtectedMethod($test_base, 'assertIdentical', [$first, $second]) - ); - } - - /** - * @covers ::assertNotIdentical - * @dataProvider providerEqualityAssertions - */ - public function testAssertNotIdentical($expected_identical, $expected_equal, $first, $second) { - $test_base = $this->getTestBaseForAssertionTests('test_id'); - $this->assertEquals( - (!$expected_identical), - $this->invokeProtectedMethod($test_base, 'assertNotIdentical', [$first, $second]) - ); - } - - /** - * @covers ::assertEqual - * @dataProvider providerEqualityAssertions - */ - public function testAssertEqual($expected_identical, $expected_equal, $first, $second) { - $test_base = $this->getTestBaseForAssertionTests('test_id'); - $this->assertEquals( - $expected_equal, - $this->invokeProtectedMethod($test_base, 'assertEqual', [$first, $second]) - ); - } - - /** - * @covers ::assertNotEqual - * @dataProvider providerEqualityAssertions - */ - public function testAssertNotEqual($expected_identical, $expected_equal, $first, $second) { - $test_base = $this->getTestBaseForAssertionTests('test_id'); - $this->assertEquals( - (!$expected_equal), - $this->invokeProtectedMethod($test_base, 'assertNotEqual', [$first, $second]) - ); - } - - /** - * Data provider for testAssertIdenticalObject(). - */ - public function providerAssertIdenticalObject() { - $obj1 = new \stdClass(); - $obj1->foof = 'yay'; - $obj2 = $obj1; - $obj3 = clone $obj1; - $obj4 = new \stdClass(); - return [ - [TRUE, $obj1, $obj2], - [TRUE, $obj1, $obj3], - [FALSE, $obj1, $obj4], - ]; - } - - /** - * @covers ::assertIdenticalObject - * @dataProvider providerAssertIdenticalObject - */ - public function testAssertIdenticalObject($expected, $first, $second) { - $test_base = $this->getTestBaseForAssertionTests('test_id'); - $this->assertEquals( - $expected, - $this->invokeProtectedMethod($test_base, 'assertIdenticalObject', [$first, $second]) - ); - } - - /** - * @covers ::pass - */ - public function testPass() { - $test_base = $this->getTestBaseForAssertionTests('test_id'); - $this->assertEquals( - TRUE, - $this->invokeProtectedMethod($test_base, 'pass', []) - ); - } - - /** - * @covers ::fail - */ - public function testFail() { - $test_base = $this->getTestBaseForAssertionTests('test_id'); - $this->assertEquals( - FALSE, - $this->invokeProtectedMethod($test_base, 'fail', []) - ); - } - - /** - * Data provider for testError(). - * - * @return array - * - Expected status for assertion. - * - Group for use in assert(). - */ - public function providerError() { - return [ - ['debug', 'User notice'], - ['exception', 'Not User notice'], - ]; - } - - /** - * @covers ::error - * @dataProvider providerError - */ - public function testError($status, $group) { - // Mock up a TestBase object. - $mock_test_base = $this->getMockBuilder('Drupal\simpletest\TestBase') - ->setMethods(['assert']) - ->getMockForAbstractClass(); - - // Set expectations for assert(). - $mock_test_base->expects($this->once()) - ->method('assert') - // The first argument to assert() should be the expected $status. This is - // the most important expectation of this test. - ->with($status) - // Arbitrary return value. - ->willReturn("$status:$group"); - - // Invoke error(). - $this->assertEquals( - "$status:$group", - $this->invokeProtectedMethod($mock_test_base, 'error', ['msg', $group]) - ); - } - - /** - * @covers ::getRandomGenerator - */ - public function testGetRandomGenerator() { - $test_base = $this->getTestBaseForAssertionTests('test_id'); - $this->assertInstanceOf( - 'Drupal\Component\Utility\Random', - $this->invokeProtectedMethod($test_base, 'getRandomGenerator', []) - ); - } - -} diff --git a/core/modules/simpletest/tests/src/Unit/TestDiscoveryTest.php b/core/modules/simpletest/tests/src/Unit/TestDiscoveryTest.php deleted file mode 100644 index eb0278950aa61380891474ec769ade9ab49ee6bc..0000000000000000000000000000000000000000 --- a/core/modules/simpletest/tests/src/Unit/TestDiscoveryTest.php +++ /dev/null @@ -1,231 +0,0 @@ -<?php - -namespace Drupal\Tests\simpletest\Unit; - -use Composer\Autoload\ClassLoader; -use Drupal\Core\DependencyInjection\Container; -use Drupal\Core\DrupalKernel; -use Drupal\Core\Extension\Extension; -use Drupal\Core\Extension\ModuleHandlerInterface; -use Drupal\simpletest\TestDiscovery; -use Drupal\Tests\UnitTestCase; -use org\bovigo\vfs\vfsStream; - -/** - * @coversDefaultClass \Drupal\simpletest\TestDiscovery - * - * @group simpletest - * @group legacy - */ -class TestDiscoveryTest extends UnitTestCase { - - protected function setupVfsWithTestClasses() { - vfsStream::setup('drupal'); - - $test_file = <<<EOF -<?php - -/** - * Test description - * @group example - */ -class FunctionalExampleTest {} -EOF; - - $test_profile_info = <<<EOF -name: Testing -type: profile -core: 8.x -EOF; - - $test_module_info = <<<EOF -name: Testing -type: module -core: 8.x -EOF; - - vfsStream::create([ - 'modules' => [ - 'test_module' => [ - 'test_module.info.yml' => $test_module_info, - 'tests' => [ - 'src' => [ - 'Functional' => [ - 'FunctionalExampleTest.php' => $test_file, - 'FunctionalExampleTest2.php' => str_replace(['FunctionalExampleTest', '@group example'], ['FunctionalExampleTest2', '@group example2'], $test_file), - ], - 'Kernel' => [ - 'KernelExampleTest3.php' => str_replace(['FunctionalExampleTest', '@group example'], ['KernelExampleTest3', "@group example2\n * @group kernel\n"], $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), - ], - ], - ], - ], - ], - 'profiles' => [ - 'test_profile' => [ - 'test_profile.info.yml' => $test_profile_info, - 'modules' => [ - 'test_profile_module' => [ - 'test_profile_module.info.yml' => $test_module_info, - 'tests' => [ - 'src' => [ - 'Kernel' => [ - 'KernelExampleTest4.php' => str_replace(['FunctionalExampleTest', '@group example'], ['KernelExampleTest4', '@group example3'], $test_file), - ], - ], - ], - ], - ], - ], - ], - ]); - } - - /** - * Mock a TestDiscovery object to return specific extension values. - */ - protected function getTestDiscoveryMock($app_root, $extensions) { - $class_loader = $this->prophesize(ClassLoader::class); - $module_handler = $this->prophesize(ModuleHandlerInterface::class); - - $test_discovery = $this->getMockBuilder(TestDiscovery::class) - ->setConstructorArgs([$app_root, $class_loader->reveal(), $module_handler->reveal()]) - ->setMethods(['getExtensions']) - ->getMock(); - - $test_discovery->expects($this->any()) - ->method('getExtensions') - ->willReturn($extensions); - - return $test_discovery; - } - - /** - * @covers ::getTestClasses - */ - public function testGetTestClasses() { - $this->setupVfsWithTestClasses(); - $extensions = [ - 'test_module' => new Extension('vfs://drupal', 'module', 'modules/test_module/test_module.info.yml'), - ]; - $test_discovery = $this->getTestDiscoveryMock('vfs://drupal', $extensions); - - $result = $test_discovery->getTestClasses(); - $this->assertCount(3, $result); - $this->assertEquals([ - 'example' => [ - 'Drupal\Tests\test_module\Functional\FunctionalExampleTest' => [ - 'name' => 'Drupal\Tests\test_module\Functional\FunctionalExampleTest', - 'description' => 'Test description', - 'group' => 'example', - 'groups' => ['example'], - 'type' => 'PHPUnit-Functional', - ], - ], - 'example2' => [ - 'Drupal\Tests\test_module\Functional\FunctionalExampleTest2' => [ - 'name' => 'Drupal\Tests\test_module\Functional\FunctionalExampleTest2', - 'description' => 'Test description', - 'group' => 'example2', - 'groups' => ['example2'], - 'type' => 'PHPUnit-Functional', - ], - 'Drupal\Tests\test_module\Kernel\KernelExampleTest3' => [ - 'name' => 'Drupal\Tests\test_module\Kernel\KernelExampleTest3', - 'description' => 'Test description', - 'group' => 'example2', - 'groups' => ['example2', 'kernel'], - 'type' => 'PHPUnit-Kernel', - ], - ], - 'kernel' => [ - 'Drupal\Tests\test_module\Kernel\KernelExampleTest3' => [ - 'name' => 'Drupal\Tests\test_module\Kernel\KernelExampleTest3', - 'description' => 'Test description', - 'group' => 'example2', - 'groups' => ['example2', 'kernel'], - 'type' => 'PHPUnit-Kernel', - ], - ], - ], $result); - } - - /** - * @covers ::getTestClasses - */ - public function testGetTestClassesWithSelectedTypes() { - $this->setupVfsWithTestClasses(); - $extensions = [ - 'test_module' => new Extension('vfs://drupal', 'module', 'modules/test_module/test_module.info.yml'), - 'test_profile_module' => new Extension('vfs://drupal', 'profile', 'profiles/test_profile/modules/test_profile_module/test_profile_module.info.yml'), - ]; - $test_discovery = $this->getTestDiscoveryMock('vfs://drupal', $extensions); - - $result = $test_discovery->getTestClasses(NULL, ['PHPUnit-Kernel']); - $this->assertCount(4, $result); - $this->assertEquals([ - 'example' => [], - 'example2' => [ - 'Drupal\Tests\test_module\Kernel\KernelExampleTest3' => [ - 'name' => 'Drupal\Tests\test_module\Kernel\KernelExampleTest3', - 'description' => 'Test description', - 'group' => 'example2', - 'groups' => ['example2', 'kernel'], - 'type' => 'PHPUnit-Kernel', - ], - ], - 'kernel' => [ - 'Drupal\Tests\test_module\Kernel\KernelExampleTest3' => [ - 'name' => 'Drupal\Tests\test_module\Kernel\KernelExampleTest3', - 'description' => 'Test description', - 'group' => 'example2', - 'groups' => ['example2', 'kernel'], - 'type' => 'PHPUnit-Kernel', - ], - ], - 'example3' => [ - 'Drupal\Tests\test_profile_module\Kernel\KernelExampleTest4' => [ - 'name' => 'Drupal\Tests\test_profile_module\Kernel\KernelExampleTest4', - 'description' => 'Test description', - 'group' => 'example3', - 'groups' => ['example3'], - 'type' => 'PHPUnit-Kernel', - ], - ], - ], $result); - } - - /** - * @covers ::getTestClasses - */ - public function testGetTestsInProfiles() { - $this->setupVfsWithTestClasses(); - $class_loader = $this->prophesize(ClassLoader::class); - $module_handler = $this->prophesize(ModuleHandlerInterface::class); - - $container = new Container(); - $container->set('kernel', new DrupalKernel('prod', new ClassLoader())); - $container->set('site.path', 'sites/default'); - \Drupal::setContainer($container); - - $test_discovery = new TestDiscovery('vfs://drupal', $class_loader->reveal(), $module_handler->reveal()); - - $result = $test_discovery->getTestClasses('test_profile_module', ['PHPUnit-Kernel']); - $expected = [ - 'example3' => [ - 'Drupal\Tests\test_profile_module\Kernel\KernelExampleTest4' => [ - 'name' => 'Drupal\Tests\test_profile_module\Kernel\KernelExampleTest4', - 'description' => 'Test description', - 'group' => 'example3', - 'groups' => ['example3'], - 'type' => 'PHPUnit-Kernel', - ], - ], - ]; - $this->assertEquals($expected, $result); - } - -} diff --git a/core/modules/simpletest/tests/src/Unit/WebTestBaseTest.php b/core/modules/simpletest/tests/src/Unit/WebTestBaseTest.php deleted file mode 100644 index c55c3e215fc65b46750c76045e3961c4ad83c133..0000000000000000000000000000000000000000 --- a/core/modules/simpletest/tests/src/Unit/WebTestBaseTest.php +++ /dev/null @@ -1,236 +0,0 @@ -<?php - -namespace Drupal\Tests\simpletest\Unit; - -use Drupal\Tests\UnitTestCase; - -/** - * @requires extension curl - * @coversDefaultClass \Drupal\simpletest\WebTestBase - * @group simpletest - * @group WebTestBase - */ -class WebTestBaseTest extends UnitTestCase { - - /** - * Provides data for testing the assertFieldByName() helper. - * - * @return array - * An array of values passed to the test method. - */ - public function providerAssertFieldByName() { - $data = []; - $data[] = ['select_2nd_selected', 'test', '1', FALSE]; - $data[] = ['select_2nd_selected', 'test', '2', TRUE]; - $data[] = ['select_none_selected', 'test', '', FALSE]; - $data[] = ['select_none_selected', 'test', '1', TRUE]; - $data[] = ['select_none_selected', 'test', NULL, TRUE]; - - return $data; - } - - /** - * Tests the assertFieldByName() helper. - * - * @param string $filename - * Name of file containing the output to test. - * @param string $name - * Name of field to assert. - * @param string $value - * Value of the field to assert. - * @param bool $expected - * The expected result of the assert. - * - * @see \Drupal\simpletest\WebTestBase::assertFieldByName() - * - * @dataProvider providerAssertFieldByName - * @covers ::assertFieldByName - */ - public function testAssertFieldByName($filename, $name, $value, $expected) { - $content = file_get_contents(__DIR__ . '/../../fixtures/' . $filename . '.html'); - - $web_test = $this->getMockBuilder('Drupal\simpletest\WebTestBase') - ->disableOriginalConstructor() - ->setMethods(['getRawContent', 'assertTrue', 'pass']) - ->getMock(); - - $web_test->expects($this->any()) - ->method('getRawContent') - ->will($this->returnValue($content)); - - $web_test->expects($this->once()) - ->method('assertTrue') - ->with($this->identicalTo($expected), - $this->identicalTo('message'), - $this->identicalTo('Browser')); - - $test_method = new \ReflectionMethod('Drupal\simpletest\WebTestBase', 'assertFieldByName'); - $test_method->setAccessible(TRUE); - $test_method->invokeArgs($web_test, [$name, $value, 'message']); - } - - /** - * Data provider for testClickLink(). - * - * In the test method, we mock drupalGet() to return a known string: - * 'This Text Returned By drupalGet()'. Since clickLink() can only return - * either the value of drupalGet() or FALSE, our expected return value is the - * same as this mocked return value when we expect a link to be found. - * - * @see https://www.drupal.org/node/1452896 - * - * @return array - * Array of arrays of test data. Test data is structured as follows: - * - Expected return value of clickLink(). - * - Parameter $label to clickLink(). - * - Parameter $index to clickLink(). - * - Test data to be returned by mocked xpath(). Return an empty array here - * to mock no link found on the page. - */ - public function providerTestClickLink() { - return [ - // Test for a non-existent label. - [ - FALSE, - 'does_not_exist', - 0, - [], - ], - // Test for an existing label. - [ - 'This Text Returned By drupalGet()', - 'exists', - 0, - [0 => ['href' => 'this_is_a_url']], - ], - // Test for an existing label that isn't the first one. - [ - 'This Text Returned By drupalGet()', - 'exists', - 1, - [ - 0 => ['href' => 'this_is_a_url'], - 1 => ['href' => 'this_is_another_url'], - ], - ], - ]; - } - - /** - * Test WebTestBase::clickLink(). - * - * @param mixed $expected - * Expected return value of clickLink(). - * @param string $label - * Parameter $label to clickLink(). - * @param int $index - * Parameter $index to clickLink(). - * @param array $xpath_data - * Test data to be returned by mocked xpath(). - * - * @dataProvider providerTestClickLink - * @covers ::clickLink - */ - public function testClickLink($expected, $label, $index, $xpath_data) { - // Mock a WebTestBase object and some of its methods. - $web_test = $this->getMockBuilder('Drupal\simpletest\WebTestBase') - ->disableOriginalConstructor() - ->setMethods([ - 'pass', - 'fail', - 'getUrl', - 'xpath', - 'drupalGet', - 'getAbsoluteUrl', - ]) - ->getMock(); - - // Mocked getUrl() is only used for reporting so we just return a string. - $web_test->expects($this->any()) - ->method('getUrl') - ->will($this->returnValue('url_before')); - - // Mocked xpath() should return our test data. - $web_test->expects($this->any()) - ->method('xpath') - ->will($this->returnValue($xpath_data)); - - if ($expected === FALSE) { - // If link does not exist clickLink() will not try to do a drupalGet() or - // a getAbsoluteUrl() - $web_test->expects($this->never()) - ->method('drupalGet'); - $web_test->expects($this->never()) - ->method('getAbsoluteUrl'); - // The test should fail and not pass. - $web_test->expects($this->never()) - ->method('pass'); - $web_test->expects($this->once()) - ->method('fail') - ->will($this->returnValue(NULL)); - } - else { - // Mocked getAbsoluteUrl() should return whatever comes in. - $web_test->expects($this->once()) - ->method('getAbsoluteUrl') - ->with($xpath_data[$index]['href']) - ->will($this->returnArgument(0)); - // We're only testing clickLink(), so drupalGet() always returns a string. - $web_test->expects($this->once()) - ->method('drupalGet') - ->with($xpath_data[$index]['href']) - ->will($this->returnValue('This Text Returned By drupalGet()')); - // The test should pass and not fail. - $web_test->expects($this->never()) - ->method('fail'); - $web_test->expects($this->once()) - ->method('pass') - ->will($this->returnValue(NULL)); - } - - // Set the clickLink() method to public so we can test it. - $clicklink_method = new \ReflectionMethod($web_test, 'clickLink'); - $clicklink_method->setAccessible(TRUE); - - $this->assertSame($expected, $clicklink_method->invoke($web_test, $label, $index)); - } - - /** - * @dataProvider providerTestGetAbsoluteUrl - */ - public function testGetAbsoluteUrl($href, $expected_absolute_path) { - $web_test = $this->getMockBuilder('Drupal\simpletest\WebTestBase') - ->disableOriginalConstructor() - ->setMethods(['getUrl']) - ->getMock(); - - $web_test->expects($this->any()) - ->method('getUrl') - ->willReturn('http://example.com/drupal/current-path?foo=baz'); - - $GLOBALS['base_url'] = 'http://example.com'; - $GLOBALS['base_path'] = 'drupal'; - - $get_absolute_url_method = new \ReflectionMethod($web_test, 'getAbsoluteUrl'); - $get_absolute_url_method->setAccessible(TRUE); - - $this->assertSame($expected_absolute_path, $get_absolute_url_method->invoke($web_test, $href)); - unset($GLOBALS['base_url'], $GLOBALS['base_path']); - } - - /** - * Provides test data for testGetAbsoluteUrl. - * - * @return array - */ - public function providerTestGetAbsoluteUrl() { - $data = []; - $data['host'] = ['http://example.com/drupal/test-example', 'http://example.com/drupal/test-example']; - $data['path'] = ['/drupal/test-example', 'http://example.com/drupal/test-example']; - $data['path-with-query'] = ['/drupal/test-example?foo=bar', 'http://example.com/drupal/test-example?foo=bar']; - $data['just-query'] = ['?foo=bar', 'http://example.com/drupal/current-path?foo=bar']; - - return $data; - } - -} diff --git a/core/modules/system/system.post_update.php b/core/modules/system/system.post_update.php index 242ad9d1b551687c34b794504cd2e07084df40cc..a6a308bf7b94cc559c77158a37f3a8ae3bfaacfb 100644 --- a/core/modules/system/system.post_update.php +++ b/core/modules/system/system.post_update.php @@ -267,3 +267,12 @@ function system_post_update_entity_reference_autocomplete_match_limit(&$sandbox $config_entity_updater->update($sandbox, 'entity_form_display', $callback); } + +/** + * Uninstall SimpleTest. + * + * @see https://www.drupal.org/project/drupal/issues/3110862 + */ +function system_post_update_uninstall_simpletest() { + \Drupal::service('module_installer')->uninstall(['simpletest']); +} diff --git a/core/modules/system/tests/modules/common_test/common_test.libraries.yml b/core/modules/system/tests/modules/common_test/common_test.libraries.yml index e4fc8243a78ae36b414ca8f99bd2f896b1cd9977..9406493b4092baca150b3efeb93c1704a9f9fdf4 100644 --- a/core/modules/system/tests/modules/common_test/common_test.libraries.yml +++ b/core/modules/system/tests/modules/common_test/common_test.libraries.yml @@ -97,6 +97,14 @@ weight: lighter.js: { weight: -1 } before-jquery.js: { weight: -21 } +# Library to test hook_js_alter(). +hook_js_alter: + version: VERSION + js: + alter.js: {} + dependencies: + - core/drupal.tableselect + browsers: js: old-ie.js: diff --git a/core/modules/system/tests/modules/common_test/common_test.module b/core/modules/system/tests/modules/common_test/common_test.module index 040e40a4e4c3664f5e7488c316f52505fc3dad85..2f94691f2752ed90f2a0bce92a9663eca11ed045 100644 --- a/core/modules/system/tests/modules/common_test/common_test.module +++ b/core/modules/system/tests/modules/common_test/common_test.module @@ -263,6 +263,19 @@ function common_test_page_attachments_alter(array &$page) { } } +/** + * Implements hook_js_alter(). + * + * @see \Drupal\KernelTests\Core\Asset\AttachedAssetsTest::testAlter() + */ +function common_test_js_alter(&$javascript, AttachedAssetsInterface $assets) { + // Attach alter.js above tableselect.js. + $alterjs = drupal_get_path('module', 'common_test') . '/alter.js'; + if (array_key_exists($alterjs, $javascript) && array_key_exists('core/misc/tableselect.js', $javascript)) { + $javascript[$alterjs]['weight'] = $javascript['core/misc/tableselect.js']['weight'] - 1; + } +} + /** * Implements hook_js_settings_alter(). * diff --git a/core/modules/system/tests/src/Functional/Form/ModulesListFormWebTest.php b/core/modules/system/tests/src/Functional/Form/ModulesListFormWebTest.php index a210cd37a94dd4ed33265827c6cdd021d42658ad..90a05e5fbd12da066b88df76352ef6b2e21c02ff 100644 --- a/core/modules/system/tests/src/Functional/Form/ModulesListFormWebTest.php +++ b/core/modules/system/tests/src/Functional/Form/ModulesListFormWebTest.php @@ -50,10 +50,10 @@ public function testModuleListForm() { // Check that system_test's help link was rendered correctly. $this->assertFieldByXPath("//a[contains(@href, '/admin/help/system_test') and @title='Help']"); - // Ensure that the Testing module's machine name is printed. Testing module - // is used because its machine name is different than its human readable - // name. - $this->assertText('simpletest'); + // Ensure that the Database Logging module's machine name is printed. This + // module is used because its machine name is different than its human + // readable name. + $this->assertText('dblog'); } public function testModulesListFormWithInvalidInfoFile() { diff --git a/core/scripts/run-tests.sh b/core/scripts/run-tests.sh index 10475af24bd1b8acf9ccdbc4a547d16f94b9f6b8..d155284ebdbf10e6c6c6bb3b986db9dbaadf4df9 100755 --- a/core/scripts/run-tests.sh +++ b/core/scripts/run-tests.sh @@ -65,10 +65,12 @@ // Display all available tests organized by one @group annotation. echo "\nAvailable test groups & classes\n"; echo "-------------------------------\n\n"; + $test_discovery = new TestDiscovery( + \Drupal::service('app.root'), + \Drupal::service('class_loader') + ); try { - // @todo Use \Drupal\Core\Test\TestDiscovery when we no longer need BC for - // hook_simpletest_alter(). - $groups = \Drupal::service('test_discovery')->getTestClasses($args['module']); + $groups = $test_discovery->getTestClasses($args['module']); } catch (Exception $e) { error_log((string) $e); @@ -96,17 +98,10 @@ // @see https://www.drupal.org/node/2569585 if ($args['list-files'] || $args['list-files-json']) { // List all files which could be run as tests. - $test_discovery = NULL; - try { - // @todo Use \Drupal\Core\Test\TestDiscovery when we no longer need BC for - // hook_simpletest_alter(). - $test_discovery = \Drupal::service('test_discovery'); - } - catch (Exception $e) { - error_log((string) $e); - echo (string) $e; - exit(SIMPLETEST_SCRIPT_EXIT_EXCEPTION); - } + $test_discovery = new TestDiscovery( + \Drupal::service('app.root'), + \Drupal::service('class_loader') + ); // TestDiscovery::findAllClassFiles() gives us a classmap similar to a // Composer 'classmap' array. $test_classes = $test_discovery->findAllClassFiles(); @@ -1040,10 +1035,10 @@ function simpletest_script_cleanup($test_id, $test_class, $exitcode) { function simpletest_script_get_test_list() { global $args; - // @todo Use \Drupal\Core\Test\TestDiscovery when we no longer need BC for - // hook_simpletest_alter(). - /** $test_discovery \Drupal\simpletest\TestDiscovery */ - $test_discovery = \Drupal::service('test_discovery'); + $test_discovery = new TestDiscovery( + \Drupal::service('app.root'), + \Drupal::service('class_loader') + ); $types_processed = empty($args['types']); $test_list = []; if ($args['all'] || $args['module']) { diff --git a/core/tests/Drupal/KernelTests/Core/Asset/AttachedAssetsTest.php b/core/tests/Drupal/KernelTests/Core/Asset/AttachedAssetsTest.php index b25a224f903aa3503639784a2bb09ca3b79e1c83..5dad7286fb2351f589db168e806c65659f58b4c5 100644 --- a/core/tests/Drupal/KernelTests/Core/Asset/AttachedAssetsTest.php +++ b/core/tests/Drupal/KernelTests/Core/Asset/AttachedAssetsTest.php @@ -38,7 +38,7 @@ class AttachedAssetsTest extends KernelTestBase { /** * {@inheritdoc} */ - public static $modules = ['language', 'simpletest', 'common_test', 'system']; + public static $modules = ['language', 'common_test', 'system']; /** * {@inheritdoc} @@ -383,21 +383,21 @@ public function testRenderDifferentWeight() { /** * Tests altering a JavaScript's weight via hook_js_alter(). * - * @see simpletest_js_alter() + * @see common_test_js_alter() */ public function testAlter() { - // Add both tableselect.js and simpletest.js. + // Add both tableselect.js and alter.js. $build['#attached']['library'][] = 'core/drupal.tableselect'; - $build['#attached']['library'][] = 'simpletest/drupal.simpletest'; + $build['#attached']['library'][] = 'common_test/hook_js_alter'; $assets = AttachedAssets::createFromRenderArray($build); - // Render the JavaScript, testing if simpletest.js was altered to be before - // tableselect.js. See simpletest_js_alter() to see where this alteration + // Render the JavaScript, testing if alter.js was altered to be before + // tableselect.js. See common_test_js_alter() to see where this alteration // takes place. $js = $this->assetResolver->getJsAssets($assets, FALSE)[1]; $js_render_array = \Drupal::service('asset.js.collection_renderer')->render($js); $rendered_js = $this->renderer->renderPlain($js_render_array); - $this->assertTrue(strpos($rendered_js, 'simpletest.js') < strpos($rendered_js, 'core/misc/tableselect.js'), 'Altering JavaScript weight through the alter hook.'); + $this->assertTrue(strpos($rendered_js, 'alter.js') < strpos($rendered_js, 'core/misc/tableselect.js'), 'Altering JavaScript weight through the alter hook.'); } /** diff --git a/core/tests/Drupal/Tests/ComposerIntegrationTest.php b/core/tests/Drupal/Tests/ComposerIntegrationTest.php index a7eaa6fff4d3f11b961013eea04a7514852b7137..860201de8745bc6ee2c9fb863ce23bc209267324 100644 --- a/core/tests/Drupal/Tests/ComposerIntegrationTest.php +++ b/core/tests/Drupal/Tests/ComposerIntegrationTest.php @@ -3,6 +3,7 @@ namespace Drupal\Tests; use Drupal\Tests\Composer\ComposerIntegrationTrait; +use Symfony\Component\Yaml\Yaml; /** * Tests Composer integration. @@ -84,9 +85,18 @@ public function testAllModulesReplaced() { $discard = ['.', '..']; foreach ($folders as $file_name) { if ((!in_array($file_name, $discard)) && is_dir($module_path . '/' . $file_name)) { + // Skip any modules marked as hidden. + $info_yml = $module_path . '/' . $file_name . '/' . $file_name . '.info.yml'; + if (file_exists($info_yml)) { + $info = Yaml::parseFile($info_yml); + if (!empty($info['hidden'])) { + continue; + } + } $module_names[] = $file_name; } } + $this->assertNotEmpty($module_names); // Assert that each core module has a corresponding 'replace' in // composer.json. diff --git a/core/tests/Drupal/Tests/Core/Test/RunTests/TestFileParserTest.php b/core/tests/Drupal/Tests/Core/Test/RunTests/TestFileParserTest.php index 5ba0f83c489afc8f38b7a16f43382cce2b8041bc..4086368f276d1af89aa389b01dbf991ae7011a7f 100644 --- a/core/tests/Drupal/Tests/Core/Test/RunTests/TestFileParserTest.php +++ b/core/tests/Drupal/Tests/Core/Test/RunTests/TestFileParserTest.php @@ -85,10 +85,9 @@ public function testGetTestListFromFile() { ['Drupal\Tests\Core\Test\RunTests\TestFileParserTest'], $parser->getTestListFromFile(__FILE__) ); - // This WebTestBase test will eventually move, so we'll need to update it. $this->assertArrayEquals( - ['Drupal\simpletest\Tests\TimeZoneTest'], - $parser->getTestListFromFile(__DIR__ . '/../../../../../../modules/simpletest/src/Tests/TimeZoneTest.php') + ['Drupal\KernelTests\Core\Datetime\Element\TimezoneTest'], + $parser->getTestListFromFile(__DIR__ . '/../../../../KernelTests/Core/Datetime/Element/TimezoneTest.php') ); // Not a test. $this->assertEmpty( diff --git a/core/tests/Drupal/Tests/Core/Test/TestRunnerKernelTest.php b/core/tests/Drupal/Tests/Core/Test/TestRunnerKernelTest.php new file mode 100644 index 0000000000000000000000000000000000000000..3fe432b18695b9edb6d190aefdc1bac5e716f732 --- /dev/null +++ b/core/tests/Drupal/Tests/Core/Test/TestRunnerKernelTest.php @@ -0,0 +1,104 @@ +<?php + +namespace Drupal\Tests\Core\Test; + +use Composer\Autoload\ClassLoader; +use Drupal\Core\Extension\Extension; +use Drupal\Core\Test\TestRunnerKernel; +use org\bovigo\vfs\vfsStream; +use PHPUnit\Framework\TestCase; + +/** + * @coversDefaultClass \Drupal\Core\Test\TestRunnerKernel + * @runTestsInSeparateProcesses + * @preserveGlobalState disabled + * @group Test + * @group simpletest + */ +class TestRunnerKernelTest extends TestCase { + + /** + * Data provider for self::testConstructor(). + */ + public function providerTestConstructor() { + $core = [ + 'core' => [ + 'modules' => [ + 'system' => [ + 'system.info.yml' => 'type: module', + ], + ], + ], + ]; + $tests = []; + $tests['simpletest-in-contrib'] = [ + $core + [ + 'modules' => [ + 'contrib' => [ + 'simpletest' => [ + 'simpletest.info.yml' => 'type: module', + ], + ], + ], + ], + 'modules/contrib/simpletest', + ]; + + $tests['simpletest-simpletest-in-contrib'] = [ + $core + [ + 'modules' => [ + 'contrib' => [ + 'simpletest-simpletest' => [ + 'simpletest.info.yml' => 'type: module', + ], + ], + ], + ], + 'modules/contrib/simpletest-simpletest', + ]; + + $tests['simpletest-no-contrib'] = [ + $core + [ + 'modules' => [ + 'simpletest' => [ + 'simpletest.info.yml' => 'type: module', + ], + ], + ], + 'modules/simpletest', + ]; + + $tests['no-simpletest'] = [ + $core, + FALSE, + ]; + + return $tests; + } + + /** + * @covers ::__construct + * @dataProvider providerTestConstructor + */ + public function testConstructor($file_system, $expected) { + // Set up the file system. + $vfs = vfsStream::setup('root'); + vfsStream::create($file_system, $vfs); + + $kernel = new TestRunnerKernel('prod', new ClassLoader(), FALSE, vfsStream::url('root')); + $class = new \ReflectionClass(TestRunnerKernel::class); + $instance_method = $class->getMethod('moduleData'); + $instance_method->setAccessible(TRUE); + /** @var \Drupal\Core\Extension\Extension $extension */ + $extension = $instance_method->invoke($kernel, 'simpletest'); + + if ($expected === FALSE) { + $this->assertFalse($extension); + } + else { + $this->assertInstanceOf(Extension::class, $extension); + $this->assertSame($expected, $extension->getPath()); + } + } + +} diff --git a/core/themes/stable/css/simpletest/simpletest.module.css b/core/themes/stable/css/simpletest/simpletest.module.css deleted file mode 100644 index f7a932e2864eaf7d71dd236efafe71079a19a9fc..0000000000000000000000000000000000000000 --- a/core/themes/stable/css/simpletest/simpletest.module.css +++ /dev/null @@ -1,93 +0,0 @@ - -/* Test Table */ -#simpletest-form-table th.select-all { - width: 1em; -} -th.simpletest-test-label { - width: 40%; -} - -.simpletest-image { - display: inline-block; - width: 1em; - cursor: pointer; -} -.simpletest-group-label label { - display: inline; - font-weight: bold; -} -.simpletest-test-label label { - margin-left: 1em; /* LTR */ -} -.simpletest-test-description .description { - margin: 0; -} -#simpletest-form-table tr td { - color: #494949; - background-color: white; -} -#simpletest-form-table tr.simpletest-group td { - color: #494949; - background-color: #edf5fa; -} - -table#simpletest-form-table tr.simpletest-group label { - display: inline; -} - -div.message > div.item-list { - font-weight: normal; -} - -div.simpletest-pass { - color: #33a333; -} -.simpletest-fail { - color: #981010; -} - -tr.simpletest-pass, -tr.simpletest-pass.odd { - background-color: #b6ffb6; -} -tr.simpletest-pass.even { - background-color: #9bff9b; -} -tr.simpletest-fail, -tr.simpletest-fail.odd { - background-color: #ffc9c9; -} -tr.simpletest-fail.even { - background-color: #ffacac; -} -tr.simpletest-exception, -tr.simpletest-exception.odd { - background-color: #f4ea71; -} -tr.simpletest-exception.even { - background-color: #f5e742; -} -tr.simpletest-debug, -tr.simpletest-debug.odd { - background-color: #eee; -} -tr.simpletest-debug.even { - background-color: #fff; -} - -a.simpletest-collapse { - position: absolute; - top: -99em; - width: 0; - height: 0; -} -a.simpletest-collapse:focus, -a.simpletest-collapse:hover { - position: relative; - z-index: 1000; - top: 0; - overflow: visible; - width: auto; - height: auto; - font-size: 80%; -} diff --git a/core/themes/stable/stable.info.yml b/core/themes/stable/stable.info.yml index 450b01da08da6e59d46fe6e50fd127117283a0c5..52e93789a099ff44396ed98c16ac93d2389d88b6 100644 --- a/core/themes/stable/stable.info.yml +++ b/core/themes/stable/stable.info.yml @@ -207,11 +207,6 @@ libraries-override: css/shortcut.theme.css: css/shortcut/shortcut.theme.css css/shortcut.icons.theme.css: css/shortcut/shortcut.icons.theme.css - simpletest/drupal.simpletest: - css: - component: - css/simpletest.module.css: css/simpletest/simpletest.module.css - system/base: css: component: