- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
<?php
2016-02-11 20:54:33 +00:00
/**
* @file
* Provides testing functionality.
*/
2019-10-01 12:37:28 +00:00
use Drupal\Component\Uuid\Php;
use Drupal\Core\Asset\AttachedAssets;
2015-01-21 15:21:06 +00:00
use Drupal\Core\Asset\AttachedAssetsInterface;
2019-10-01 12:37:28 +00:00
use Drupal\Core\Database\Database;
Issue #2244513 by kim.pepper, phenaproxima, 20th, andrei.dincu, beejeebus, Berdir, alexpott, jibran, andypost, larowlan, Chadwick Wood, acbramley, Wim Leers, sun, xjm, YesCT, chx, tim.plunkett: Move the unmanaged file APIs to the file_system service (file.inc)
2019-02-23 22:35:15 +00:00
use Drupal\Core\File\Exception\FileException;
2019-10-01 12:37:28 +00:00
use Drupal\Core\File\FileSystemInterface;
2014-03-31 17:37:55 +00:00
use Drupal\Core\Render\Element;
2014-06-30 03:33:08 +00:00
use Drupal\Core\Routing\RouteMatchInterface;
2019-10-01 12:37:28 +00:00
use Drupal\Core\StreamWrapper\PublicStream;
2019-08-23 03:56:22 +00:00
use Drupal\Core\Test\JUnitConverter;
use Drupal\Core\Test\PhpUnitTestRunner;
2016-05-11 20:12:24 +00:00
use Drupal\Core\Test\TestDatabase;
2019-08-23 03:56:22 +00:00
use Drupal\Core\Url;
2019-10-01 12:37:28 +00:00
use Drupal\simpletest\Form\SimpletestResultsForm;
2014-07-11 03:50:37 +00:00
use Drupal\simpletest\TestDiscovery;
2017-04-04 14:29:18 +00:00
use PHPUnit\Framework\TestCase;
2011-12-27 21:17:19 +00:00
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
/**
2009-12-04 16:49:48 +00:00
* Implements hook_help().
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
*/
2014-06-30 03:33:08 +00:00
function simpletest_help($route_name, RouteMatchInterface $route_match) {
2014-05-07 02:04:53 +00:00
switch ($route_name) {
case 'help.page.simpletest':
2009-12-01 13:43:11 +00:00
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
2017-03-04 01:20:24 +00:00
$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>';
2009-12-01 13:43:11 +00:00
$output .= '<h3>' . t('Uses') . '</h3>';
$output .= '<dl>';
$output .= '<dt>' . t('Running tests') . '</dt>';
2019-04-16 05:38:27 +00:00
$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>';
2014-02-13 00:51:47 +00:00
$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>';
2009-12-01 13:43:11 +00:00
$output .= '</dl>';
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
return $output;
2014-02-27 19:52:40 +00:00
2014-05-07 02:04:53 +00:00
case 'simpletest.test_form':
2014-02-27 19:52:40 +00:00
$output = t('Select the test(s) or test group(s) you would like to run, and click <em>Run tests</em>.');
return $output;
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
}
}
/**
2009-12-04 16:49:48 +00:00
* Implements hook_theme().
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
*/
function simpletest_theme() {
2017-03-04 01:20:24 +00:00
return [
'simpletest_result_summary' => [
'variables' => ['label' => NULL, 'items' => [], 'pass' => 0, 'fail' => 0, 'exception' => 0, 'debug' => 0],
],
];
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
}
2008-11-23 16:00:08 +00:00
/**
2009-12-04 16:49:48 +00:00
* Implements hook_js_alter().
2008-11-23 16:00:08 +00:00
*/
2015-01-21 15:21:06 +00:00
function simpletest_js_alter(&$javascript, AttachedAssetsInterface $assets) {
2008-11-23 16:00:08 +00:00
// 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';
2011-10-31 04:05:57 +00:00
if (array_key_exists($simpletest, $javascript) && array_key_exists('core/misc/tableselect.js', $javascript)) {
$javascript[$simpletest]['weight'] = $javascript['core/misc/tableselect.js']['weight'] - 1;
2008-11-23 16:00:08 +00:00
}
}
Issue #1898452 by joelpittet, amitgoyal, gnuget, steinmb, thedavidmeister, jenlampton, zaphoyd, Cottser, robmc, disasm, azinoman | c4rl: Simpletest.module - Convert theme_simpletest_result_summary functions to Twig.
2014-07-04 17:29:48 +00:00
/**
* 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');
2009-08-15 06:20:20 +00:00
}
Issue #1898452 by joelpittet, amitgoyal, gnuget, steinmb, thedavidmeister, jenlampton, zaphoyd, Cottser, robmc, disasm, azinoman | c4rl: Simpletest.module - Convert theme_simpletest_result_summary functions to Twig.
2014-07-04 17:29:48 +00:00
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);
2014-02-13 15:43:12 +00:00
return implode(', ', $parts);
2008-06-24 21:51:03 +00:00
}
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
/**
2014-02-27 21:21:47 +00:00
* Runs tests.
2008-11-01 18:32:22 +00:00
*
2019-08-23 03:56:22 +00:00
* @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.
2014-02-27 21:21:47 +00:00
*
* @return string
* The test ID.
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
*/
2014-07-11 03:50:37 +00:00
function simpletest_run_tests($test_list) {
2016-06-16 12:17:57 +00:00
// 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']);
2013-03-09 05:08:06 +00:00
}
2016-06-16 12:17:57 +00:00
if (isset($test_list['phpunit'])) {
$test_list = array_merge($test_list, $test_list['phpunit']);
unset($test_list['phpunit']);
2013-03-07 02:48:50 +00:00
}
Issue #2853118 by voleger, Jo Fitzgerald, Pavan B S, yogeshmpawar, hgunicamp, pk188, andypost, jeetendrakumar, longwave, gaurav.kapoor, RenatoG, daffie, mondrake, dhruveshdtripathi, catch, alexpott, xjm: Replace all calls to db_insert, which is deprecated
2018-09-18 12:15:20 +00:00
$test_id = \Drupal::database()->insert('simpletest_test_id')
2017-03-04 01:20:24 +00:00
->useDefaults(['test_id'])
2016-06-16 12:17:57 +00:00
->execute();
2013-03-07 02:48:50 +00:00
2009-08-15 17:52:53 +00:00
// Clear out the previous verbose files.
Issue #2244513 by kim.pepper, phenaproxima, 20th, andrei.dincu, beejeebus, Berdir, alexpott, jibran, andypost, larowlan, Chadwick Wood, acbramley, Wim Leers, sun, xjm, YesCT, chx, tim.plunkett: Move the unmanaged file APIs to the file_system service (file.inc)
2019-02-23 22:35:15 +00:00
try {
\Drupal::service('file_system')->deleteRecursive('public://simpletest/verbose');
}
catch (FileException $e) {
// Ignore failed deletes.
}
2008-06-24 21:51:03 +00:00
2008-11-01 18:32:22 +00:00
// Get the info for the first test being run.
2014-07-11 03:50:37 +00:00
$first_test = reset($test_list);
2015-02-09 10:30:16 +00:00
$info = TestDiscovery::getTestInfo($first_test);
2008-11-01 18:32:22 +00:00
2017-03-04 01:20:24 +00:00
$batch = [
2009-09-21 06:52:40 +00:00
'title' => t('Running tests'),
2017-03-04 01:20:24 +00:00
'operations' => [
['_simpletest_batch_operation', [$test_list, $test_id]],
],
2008-10-09 02:49:36 +00:00
'finished' => '_simpletest_batch_finished',
2008-11-01 18:32:22 +00:00
'progress_message' => '',
2017-03-04 01:20:24 +00:00
'library' => ['simpletest/drupal.simpletest'],
'init_message' => t('Processing test @num of @max - %test.', ['%test' => $info['name'], '@num' => '1', '@max' => count($test_list)]),
];
2008-10-09 02:49:36 +00:00
batch_set($batch);
2009-05-24 17:39:35 +00:00
2019-09-09 12:23:30 +00:00
\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');
2009-05-24 17:39:35 +00:00
2010-01-15 04:16:57 +00:00
return $test_id;
2008-06-24 21:51:03 +00:00
}
2013-03-07 02:48:50 +00:00
/**
2014-02-27 21:21:47 +00:00
* Executes PHPUnit tests and returns the results of the run.
2013-03-07 02:48:50 +00:00
*
* @param $test_id
* The current test ID.
* @param $unescaped_test_classnames
* An array of test class names, including full namespaces, to be passed as
2014-02-27 21:21:47 +00:00
* a regular expression to PHPUnit's --filter option.
2015-11-17 14:42:51 +00:00
* @param int $status
* (optional) The exit status code of the PHPUnit process will be assigned to
* this variable.
2013-03-07 02:48:50 +00:00
*
* @return array
2014-02-27 21:21:47 +00:00
* The parsed results of PHPUnit's JUnit XML output, in the format of
* {simpletest}'s schema.
2019-08-23 03:56:22 +00:00
*
* @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
2013-03-07 02:48:50 +00:00
*/
2015-11-17 14:42:51 +00:00
function simpletest_run_phpunit_tests($test_id, array $unescaped_test_classnames, &$status = NULL) {
2019-08-23 03:56:22 +00:00
$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);
2013-03-07 02:48:50 +00:00
}
/**
2014-02-27 21:21:47 +00:00
* Inserts the parsed PHPUnit results into {simpletest}.
2013-03-07 02:48:50 +00:00
*
2014-02-27 21:21:47 +00:00
* @param array[] $phpunit_results
* An array of test results returned from simpletest_phpunit_xml_to_rows().
2019-09-09 20:40:24 +00:00
*
* @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
2013-03-07 02:48:50 +00:00
*/
function simpletest_process_phpunit_results($phpunit_results) {
2019-09-09 20:40:24 +00:00
@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);
2013-03-07 02:48:50 +00:00
}
2016-06-16 12:17:57 +00:00
/**
* 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.
2019-08-23 03:56:22 +00:00
*
* @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
2016-06-16 12:17:57 +00:00
*/
function simpletest_summarize_phpunit_result($results) {
2019-08-23 03:56:22 +00:00
$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);
2016-06-16 12:17:57 +00:00
}
2013-03-07 02:48:50 +00:00
/**
2014-02-27 21:21:47 +00:00
* Returns the path to use for PHPUnit's --log-junit option.
2013-03-07 02:48:50 +00:00
*
* @param $test_id
* The current test ID.
2014-02-27 21:21:47 +00:00
*
2013-03-07 02:48:50 +00:00
* @return string
2014-02-27 21:21:47 +00:00
* Path to the PHPUnit XML file to use for the current $test_id.
2019-08-23 03:56:22 +00:00
*
* @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
2013-03-07 02:48:50 +00:00
*/
function simpletest_phpunit_xml_filepath($test_id) {
2019-08-23 03:56:22 +00:00
$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);
2013-03-07 02:48:50 +00:00
}
/**
* Returns the path to core's phpunit.xml.dist configuration file.
*
* @return string
2014-02-27 21:21:47 +00:00
* The path to core's phpunit.xml.dist configuration file.
2017-04-26 20:38:28 +00:00
*
* @deprecated in Drupal 8.4.x for removal before Drupal 9.0.0. PHPUnit test
* runners should change directory into core/ and then run the phpunit tool.
* See simpletest_phpunit_run_command() for an example.
*
* @see simpletest_phpunit_run_command()
2013-03-07 02:48:50 +00:00
*/
function simpletest_phpunit_configuration_filepath() {
2017-04-26 20:38:28 +00:00
@trigger_error('The ' . __FUNCTION__ . ' function is deprecated since version 8.4.x and will be removed in 9.0.0.', E_USER_DEPRECATED);
2014-11-17 12:20:57 +00:00
return \Drupal::root() . '/core/phpunit.xml.dist';
2013-03-07 02:48:50 +00:00
}
/**
2014-02-27 21:21:47 +00:00
* Executes the PHPUnit command.
2013-03-07 02:48:50 +00:00
*
* @param array $unescaped_test_classnames
* An array of test class names, including full namespaces, to be passed as
2014-02-27 21:21:47 +00:00
* a regular expression to PHPUnit's --filter option.
2013-03-07 02:48:50 +00:00
* @param string $phpunit_file
2014-02-27 21:21:47 +00:00
* A filepath to use for PHPUnit's --log-junit option.
2015-11-17 14:42:51 +00:00
* @param int $status
* (optional) The exit status code of the PHPUnit process will be assigned to
* this variable.
2016-09-15 11:12:44 +00:00
* @param string $output
* (optional) The output by running the phpunit command.
2014-02-27 21:21:47 +00:00
*
* @return string
2016-06-02 14:20:55 +00:00
* The results as returned by exec().
2019-08-23 03:56:22 +00:00
*
* @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
2013-03-07 02:48:50 +00:00
*/
2016-09-15 11:12:44 +00:00
function simpletest_phpunit_run_command(array $unescaped_test_classnames, $phpunit_file, &$status = NULL, &$output = NULL) {
2019-08-23 03:56:22 +00:00
$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);
2013-03-07 02:48:50 +00:00
}
2013-03-08 10:50:04 +00:00
/**
* Returns the command to run PHPUnit.
2014-02-27 21:21:47 +00:00
*
* @return string
* The command that can be run through exec().
2019-08-23 03:56:22 +00:00
*
* @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
2013-03-08 10:50:04 +00:00
*/
function simpletest_phpunit_command() {
2019-08-23 03:56:22 +00:00
$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();
2013-03-08 10:50:04 +00:00
}
2008-06-24 21:51:03 +00:00
/**
2015-02-13 19:51:15 +00:00
* Implements callback_batch_operation().
2008-06-24 21:51:03 +00:00
*/
function _simpletest_batch_operation($test_list_init, $test_id, &$context) {
2018-03-15 00:06:13 +00:00
\Drupal::service('test_discovery')->registerTestNamespaces();
2008-06-24 21:51:03 +00:00
// Get working values.
if (!isset($context['sandbox']['max'])) {
// First iteration: initialize working values.
$test_list = $test_list_init;
$context['sandbox']['max'] = count($test_list);
2017-03-04 01:20:24 +00:00
$test_results = ['#pass' => 0, '#fail' => 0, '#exception' => 0, '#debug' => 0];
2008-06-24 21:51:03 +00:00
}
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);
2017-04-04 14:29:18 +00:00
if (is_subclass_of($test_class, TestCase::class)) {
2019-08-23 03:56:22 +00:00
$runner = PhpUnitTestRunner::create(\Drupal::getContainer());
$phpunit_results = $runner->runTests($test_id, [$test_class]);
2019-09-09 20:40:24 +00:00
TestDatabase::processPhpUnitResults($phpunit_results);
2016-06-16 12:17:57 +00:00
$test_results[$test_class] = simpletest_summarize_phpunit_result($phpunit_results)[$test_class];
}
else {
$test = new $test_class($test_id);
$test->run();
2019-09-09 12:23:30 +00:00
\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]);
2016-06-16 12:17:57 +00:00
$test_results[$test_class] = $test->results;
}
2008-06-24 21:51:03 +00:00
$size = count($test_list);
2015-02-09 10:30:16 +00:00
$info = TestDiscovery::getTestInfo($test_class);
2008-06-24 21:51:03 +00:00
// 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'];
2017-03-04 01:20:24 +00:00
$items = [];
2014-03-31 17:37:55 +00:00
foreach (Element::children($test_results) as $class) {
2017-03-04 01:20:24 +00:00
$class_test_result = $test_results[$class] + [
Issue #1898452 by joelpittet, amitgoyal, gnuget, steinmb, thedavidmeister, jenlampton, zaphoyd, Cottser, robmc, disasm, azinoman | c4rl: Simpletest.module - Convert theme_simpletest_result_summary functions to Twig.
2014-07-04 17:29:48 +00:00
'#theme' => 'simpletest_result_summary',
'#label' => t($test_results[$class]['#name'] . ':'),
2017-03-04 01:20:24 +00:00
];
Issue #2704871 by pepegarciag, Mile23, Manuel Garcia, ieguskiza, snehi, gaurav.pahuja, dimaro, rajeshwari10, gargsuchi, pashupathi nath gajawada, penyaskito, xjm, ZeiP, Wim Leers, alexpott: Replace usages of deprecated method drupal_render()
2017-07-03 15:35:13 +00:00
array_unshift($items, \Drupal::service('renderer')->render($class_test_result));
2008-06-24 21:51:03 +00:00
}
2017-03-04 01:20:24 +00:00
$context['message'] = t('Processed test @num of @max - %test.', ['%test' => $info['name'], '@num' => $max - $size, '@max' => $max]);
$overall_results = $test_results + [
Issue #1898452 by joelpittet, amitgoyal, gnuget, steinmb, thedavidmeister, jenlampton, zaphoyd, Cottser, robmc, disasm, azinoman | c4rl: Simpletest.module - Convert theme_simpletest_result_summary functions to Twig.
2014-07-04 17:29:48 +00:00
'#theme' => 'simpletest_result_summary',
'#label' => t('Overall results:'),
2017-03-04 01:20:24 +00:00
];
Issue #2704871 by pepegarciag, Mile23, Manuel Garcia, ieguskiza, snehi, gaurav.pahuja, dimaro, rajeshwari10, gargsuchi, pashupathi nath gajawada, penyaskito, xjm, ZeiP, Wim Leers, alexpott: Replace usages of deprecated method drupal_render()
2017-07-03 15:35:13 +00:00
$context['message'] .= \Drupal::service('renderer')->render($overall_results);
Issue #1898452 by joelpittet, amitgoyal, gnuget, steinmb, thedavidmeister, jenlampton, zaphoyd, Cottser, robmc, disasm, azinoman | c4rl: Simpletest.module - Convert theme_simpletest_result_summary functions to Twig.
2014-07-04 17:29:48 +00:00
2017-03-04 01:20:24 +00:00
$item_list = [
2013-07-09 14:32:08 +00:00
'#theme' => 'item_list',
'#items' => $items,
2017-03-04 01:20:24 +00:00
];
Issue #2704871 by pepegarciag, Mile23, Manuel Garcia, ieguskiza, snehi, gaurav.pahuja, dimaro, rajeshwari10, gargsuchi, pashupathi nath gajawada, penyaskito, xjm, ZeiP, Wim Leers, alexpott: Replace usages of deprecated method drupal_render()
2017-07-03 15:35:13 +00:00
$context['message'] .= \Drupal::service('renderer')->render($item_list);
2008-06-24 21:51:03 +00:00
// 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;
}
2015-02-13 19:51:15 +00:00
/**
* Implements callback_batch_finished().
*/
2009-01-12 06:23:57 +00:00
function _simpletest_batch_finished($success, $results, $operations, $elapsed) {
2008-06-24 21:51:03 +00:00
if ($success) {
2018-05-01 09:15:07 +00:00
\Drupal::messenger()->addStatus(t('The test run finished in @elapsed.', ['@elapsed' => $elapsed]));
2008-06-24 21:51:03 +00:00
}
else {
2009-07-07 07:50:53 +00:00
// Use the test_id passed as a parameter to _simpletest_batch_operation().
2009-07-30 10:46:53 +00:00
$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.
2019-08-29 03:10:02 +00:00
$last_test = TestDatabase::lastTestGet($test_id);
(new TestDatabase($last_test['last_prefix']))->logRead($test_id, $last_test['test_class']);
2009-07-30 10:46:53 +00:00
2018-05-01 09:15:07 +00:00
\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.'));
2008-06-24 21:51:03 +00:00
}
2019-09-09 12:23:30 +00:00
\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');
2008-06-24 21:51:03 +00:00
}
2010-10-25 00:19:24 +00:00
/**
2009-07-30 10:46:53 +00:00
* Get information about the last test that ran given a test ID.
*
* @param $test_id
* The test ID to get the last test from.
2014-02-27 21:21:47 +00:00
* @return array
2009-07-30 10:46:53 +00:00
* Array containing the last database prefix used and the last test class
* that ran.
2019-08-22 04:02:01 +00:00
*
* @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
2009-07-30 10:46:53 +00:00
*/
function simpletest_last_test_get($test_id) {
2019-08-22 04:02:01 +00:00
@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);
2019-08-29 03:10:02 +00:00
return array_values(TestDatabase::lastTestGet($test_id));
2009-07-30 10:46:53 +00:00
}
2009-07-07 07:50:53 +00:00
/**
2014-02-27 21:21:47 +00:00
* Reads the error log and reports any errors as assertion failures.
2009-07-07 07:50:53 +00:00
*
* 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
2009-07-30 10:46:53 +00:00
* The test ID to which the log relates.
2014-02-10 17:31:31 +00:00
* @param $database_prefix
2009-07-30 10:46:53 +00:00
* The database prefix to which the log relates.
* @param $test_class
* The test class to which the log relates.
2014-02-10 17:31:31 +00:00
*
2014-02-27 21:21:47 +00:00
* @return bool
* Whether any fatal errors were found.
2019-08-22 04:02:01 +00:00
*
* @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
2009-07-07 07:50:53 +00:00
*/
2014-02-10 17:31:31 +00:00
function simpletest_log_read($test_id, $database_prefix, $test_class) {
2019-08-22 04:02:01 +00:00
@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);
2016-09-16 10:35:51 +00:00
$test_db = new TestDatabase($database_prefix);
2019-08-22 04:02:01 +00:00
return $test_db->logRead($test_id, $test_class);
2009-07-07 07:50:53 +00:00
}
2019-06-10 13:35:59 +00:00
/**
* 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.
2019-08-22 04:02:01 +00:00
*
* @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
2019-06-10 13:35:59 +00:00
*/
function simpletest_insert_assert($test_id, $test_class, $status, $message = '', $group = 'Other', array $caller = []) {
2019-08-22 04:02:01 +00:00
@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);
2019-06-10 13:35:59 +00:00
}
2008-06-24 21:51:03 +00:00
/**
2014-02-27 21:21:47 +00:00
* Gets a list of all of the tests provided by the system.
2009-06-08 09:23:55 +00:00
*
2012-08-31 10:03:05 +00:00
* The list of test classes is loaded by searching the designated directory for
2019-05-15 13:32:10 +00:00
* each module for files matching the PSR-4 standard. Once loaded the test list
2012-08-31 10:03:05 +00:00
* is cached and stored in a static variable.
2012-04-23 03:01:03 +00:00
*
2016-03-09 11:38:47 +00:00
* @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.
2013-11-22 23:59:11 +00:00
*
2014-02-27 21:21:47 +00:00
* @return array[]
2014-07-11 03:50:37 +00:00
* An array of tests keyed with the groups, and then keyed by test classes.
* For example:
2009-06-08 09:23:55 +00:00
* @code
2011-08-29 13:08:58 +00:00
* $groups['Block'] => array(
* 'BlockTestCase' => array(
* 'name' => 'Block functionality',
2015-06-08 22:40:25 +00:00
* 'description' => 'Add, edit and delete custom block.',
2011-08-29 13:08:58 +00:00
* 'group' => 'Block',
2009-06-08 09:23:55 +00:00
* ),
* );
* @endcode
2016-09-25 11:29:27 +00:00
*
* @deprecated in Drupal 8.3.x, for removal before 9.0.0 release. Use
* \Drupal::service('test_discovery')->getTestClasses($extension, $types)
* instead.
2008-06-24 21:51:03 +00:00
*/
2016-03-09 11:38:47 +00:00
function simpletest_test_get_all($extension = NULL, array $types = []) {
2018-03-15 00:06:13 +00:00
@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);
2016-03-09 11:38:47 +00:00
return \Drupal::service('test_discovery')->getTestClasses($extension, $types);
2008-06-24 21:51:03 +00:00
}
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
2012-04-23 03:01:03 +00:00
/**
2016-09-25 11:29:27 +00:00
* Registers test namespaces of all extensions and core test classes.
*
* @deprecated in Drupal 8.3.x for removal before 9.0.0 release. Use
* \Drupal::service('test_discovery')->registerTestNamespaces() instead.
2012-04-23 03:01:03 +00:00
*/
function simpletest_classloader_register() {
2018-03-15 00:06:13 +00:00
@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);
2014-07-11 03:50:37 +00:00
\Drupal::service('test_discovery')->registerTestNamespaces();
2012-04-23 03:01:03 +00:00
}
2009-12-28 12:06:49 +00:00
/**
2015-07-16 18:06:42 +00:00
* Generates a test file.
2014-02-27 21:21:47 +00:00
*
* @param string $filename
2015-07-16 18:06:42 +00:00
* 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.
2014-02-27 21:21:47 +00:00
* @param int $width
* The number of characters on one line.
* @param int $lines
* The number of lines in the file.
* @param string $type
2015-07-16 18:06:42 +00:00
* (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.
2014-02-27 21:21:47 +00:00
*
* @return string
* The name of the file, including the path.
2019-09-02 10:04:09 +00:00
*
* @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
2009-12-28 12:06:49 +00:00
*/
function simpletest_generate_file($filename, $width, $lines, $type = 'binary-text') {
2019-09-02 10:04:09 +00:00
@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);
2009-12-28 12:06:49 +00:00
$text = '';
2015-10-24 03:26:25 +00:00
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;
2015-07-06 15:07:27 +00:00
}
2009-12-28 12:06:49 +00:00
}
2015-10-24 03:26:25 +00:00
$text .= "\n";
}
2009-12-28 12:06:49 +00:00
// Create filename.
2010-09-01 20:08:17 +00:00
file_put_contents('public://' . $filename . '.txt', $text);
2009-12-28 12:06:49 +00:00
return $filename;
}
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
/**
2014-02-27 21:21:47 +00:00
* Removes all temporary database tables and directories.
2019-09-12 03:01:25 +00:00
*
* @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
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
*/
function simpletest_clean_environment() {
2019-09-12 03:01:25 +00:00
@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();
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
}
/**
2014-02-27 21:21:47 +00:00
* Removes prefixed tables from the database from crashed tests.
2019-09-12 03:01:25 +00:00
*
* @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
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
*/
function simpletest_clean_database() {
2019-09-12 03:01:25 +00:00
@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();
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
}
/**
2014-02-27 21:21:47 +00:00
* Finds all leftover temporary directories and removes them.
2019-09-12 03:01:25 +00:00
*
* @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
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
*/
function simpletest_clean_temporary_directories() {
2019-09-12 03:01:25 +00:00
@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();
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
}
2008-08-11 17:46:06 +00:00
/**
2014-02-27 21:21:47 +00:00
* Clears the test result tables.
2009-02-20 03:37:58 +00:00
*
* @param $test_id
* Test ID to remove results for, or NULL to remove all results.
2014-02-27 21:21:47 +00:00
*
* @return int
* The number of results that were removed.
2019-09-12 03:01:25 +00:00
*
* @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
2008-08-11 17:46:06 +00:00
*/
2009-02-20 03:37:58 +00:00
function simpletest_clean_results_table($test_id = NULL) {
2019-09-12 03:01:25 +00:00
@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;
2013-09-16 03:58:06 +00:00
if (\Drupal::config('simpletest.settings')->get('clear_results')) {
2019-09-12 03:01:25 +00:00
/* @var $cleaner \Drupal\simpletest\EnvironmentCleanerService */
$cleaner = \Drupal::service('environment_cleaner');
$count = $cleaner->cleanResultsTable($test_id);
2008-08-11 17:46:06 +00:00
}
2019-09-12 03:01:25 +00:00
return $count;
2008-08-11 17:46:06 +00:00
}
2011-11-30 03:13:51 +00:00
2013-03-07 02:48:50 +00:00
/**
2014-02-27 21:21:47 +00:00
* Converts PHPUnit's JUnit XML output to an array.
2013-03-07 02:48:50 +00:00
*
* @param $test_id
* The current test ID.
* @param $phpunit_xml_file
2014-02-27 21:21:47 +00:00
* Path to the PHPUnit XML file.
*
2017-09-12 09:50:56 +00:00
* @return array[]|null
2014-02-27 21:21:47 +00:00
* The results as array of rows in a format that can be inserted into
2017-09-12 09:50:56 +00:00
* {simpletest}. If the phpunit_xml_file does not have any contents then the
* function will return NULL.
2019-08-23 03:56:22 +00:00
*
* @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
2013-03-07 02:48:50 +00:00
*/
function simpletest_phpunit_xml_to_rows($test_id, $phpunit_xml_file) {
2019-08-23 03:56:22 +00:00
@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;
2013-03-07 02:48:50 +00:00
}
2013-04-23 18:50:13 +00:00
/**
2014-02-27 21:21:47 +00:00
* Finds all test cases recursively from a test suite list.
2013-04-23 18:50:13 +00:00
*
2014-03-26 19:42:03 +00:00
* @param \SimpleXMLElement $element
* The PHPUnit xml to search for test cases.
2017-09-04 17:30:59 +00:00
* @param \SimpleXMLElement $parent
2014-03-26 19:42:03 +00:00
* (Optional) The parent of the current element. Defaults to NULL.
2013-04-23 18:50:13 +00:00
*
* @return array
2014-02-27 21:21:47 +00:00
* A list of all test cases.
2019-08-23 03:56:22 +00:00
*
* @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
2013-04-23 18:50:13 +00:00
*/
2014-03-26 19:42:03 +00:00
function simpletest_phpunit_find_testcases(\SimpleXMLElement $element, \SimpleXMLElement $parent = NULL) {
2019-08-23 03:56:22 +00:00
@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);
2013-04-23 18:50:13 +00:00
}
/**
2014-02-27 21:21:47 +00:00
* Converts a PHPUnit test case result to a {simpletest} result row.
2013-04-23 18:50:13 +00:00
*
* @param int $test_id
* The current test ID.
2019-08-23 03:56:22 +00:00
* @param \SimpleXMLElement $test_case
2014-02-27 21:21:47 +00:00
* The PHPUnit test case represented as XML element.
2013-04-23 18:50:13 +00:00
*
* @return array
2014-02-27 21:21:47 +00:00
* An array containing the {simpletest} result row.
2019-08-23 03:56:22 +00:00
*
* @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
2013-04-23 18:50:13 +00:00
*/
2019-08-23 03:56:22 +00:00
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);
2013-04-23 18:50:13 +00:00
}
2019-10-01 12:37:28 +00:00
/**
* 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.';
}
}