Issue #2132441 by chx, eliza411: Run-tests.sh --module is broken.
parent
402a3cae63
commit
08eeef15db
|
@ -419,6 +419,10 @@ function simpletest_log_read($test_id, $prefix, $test_class, $during_test = FALS
|
||||||
* each module for files matching the PSR-0 standard. Once loaded the test list
|
* each module for files matching the PSR-0 standard. Once loaded the test list
|
||||||
* is cached and stored in a static variable.
|
* is cached and stored in a static variable.
|
||||||
*
|
*
|
||||||
|
* @param string $module
|
||||||
|
* Name of a module. If set then only tests belonging to this module are
|
||||||
|
* returned.
|
||||||
|
*
|
||||||
* @return
|
* @return
|
||||||
* An array of tests keyed with the groups specified in each of the tests
|
* An array of tests keyed with the groups specified in each of the tests
|
||||||
* getInfo() method and then keyed by the test class. An example of the array
|
* getInfo() method and then keyed by the test class. An example of the array
|
||||||
|
@ -434,17 +438,20 @@ function simpletest_log_read($test_id, $prefix, $test_class, $during_test = FALS
|
||||||
* );
|
* );
|
||||||
* @endcode
|
* @endcode
|
||||||
*/
|
*/
|
||||||
function simpletest_test_get_all() {
|
function simpletest_test_get_all($module = NULL) {
|
||||||
$groups = &drupal_static(__FUNCTION__);
|
$all_groups = &drupal_static(__FUNCTION__);
|
||||||
|
$cid = "simpletest:$module";
|
||||||
|
|
||||||
if (!$groups) {
|
if (!isset($all_groups[$cid])) {
|
||||||
|
$all_groups[$cid] = array();
|
||||||
|
$groups = &$all_groups[$cid];
|
||||||
// Make sure that namespaces for disabled modules are registered so that the
|
// Make sure that namespaces for disabled modules are registered so that the
|
||||||
// checks below will find them.
|
// checks below will find them.
|
||||||
simpletest_classloader_register();
|
simpletest_classloader_register();
|
||||||
|
|
||||||
// Load test information from cache if available, otherwise retrieve the
|
// Load test information from cache if available, otherwise retrieve the
|
||||||
// information from each tests getInfo() method.
|
// information from each tests getInfo() method.
|
||||||
if ($cache = cache()->get('simpletest')) {
|
if ($cache = cache()->get($cid)) {
|
||||||
$groups = $cache->data;
|
$groups = $cache->data;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -453,6 +460,12 @@ function simpletest_test_get_all() {
|
||||||
$module_data = system_rebuild_module_data();
|
$module_data = system_rebuild_module_data();
|
||||||
$all_data = $module_data + system_rebuild_theme_data();
|
$all_data = $module_data + system_rebuild_theme_data();
|
||||||
$all_data += drupal_system_listing('/\.profile$/', 'profiles', 'name');
|
$all_data += drupal_system_listing('/\.profile$/', 'profiles', 'name');
|
||||||
|
// If module is set then we keep only that one module.
|
||||||
|
if (isset($module)) {
|
||||||
|
$all_data = array(
|
||||||
|
$module => $all_data[$module],
|
||||||
|
);
|
||||||
|
}
|
||||||
foreach ($all_data as $name => $data) {
|
foreach ($all_data as $name => $data) {
|
||||||
// Build directory in which the test files would reside.
|
// Build directory in which the test files would reside.
|
||||||
$tests_dir = DRUPAL_ROOT . '/' . dirname($data->uri) . '/lib/Drupal/' . $name . '/Tests';
|
$tests_dir = DRUPAL_ROOT . '/' . dirname($data->uri) . '/lib/Drupal/' . $name . '/Tests';
|
||||||
|
@ -499,8 +512,8 @@ function simpletest_test_get_all() {
|
||||||
}
|
}
|
||||||
// If this test class requires a non-existing module, skip it.
|
// If this test class requires a non-existing module, skip it.
|
||||||
if (!empty($info['dependencies'])) {
|
if (!empty($info['dependencies'])) {
|
||||||
foreach ($info['dependencies'] as $module) {
|
foreach ($info['dependencies'] as $dependency) {
|
||||||
if (!isset($module_data[$module])) {
|
if (!isset($dependency_data[$dependency])) {
|
||||||
continue 2;
|
continue 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -518,10 +531,10 @@ function simpletest_test_get_all() {
|
||||||
|
|
||||||
// Allow modules extending core tests to disable originals.
|
// Allow modules extending core tests to disable originals.
|
||||||
drupal_alter('simpletest', $groups);
|
drupal_alter('simpletest', $groups);
|
||||||
cache()->set('simpletest', $groups);
|
cache()->set($cid, $groups);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $groups;
|
return $all_groups[$cid];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -722,17 +735,26 @@ function simpletest_library_info() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get PHPUnit Classes
|
* Gets PHPUnit Classes.
|
||||||
*
|
*
|
||||||
* @param bool $name_only
|
* @param string $module
|
||||||
* If TRUE, returns a flat array of class names only.
|
* Name of a module. If set then only tests belonging to this module is
|
||||||
|
* returned.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
* Returns an array of test classes.
|
||||||
*/
|
*/
|
||||||
function simpletest_phpunit_get_available_tests() {
|
function simpletest_phpunit_get_available_tests($module = NULL) {
|
||||||
// Try to load the class names array from cache.
|
// Try to load the class names array from cache.
|
||||||
if ($cache = \Drupal::cache()->get('simpletest_phpunit')) {
|
$cid = 'simpletest_phpunit:' . $module;
|
||||||
|
if ($cache = \Drupal::cache()->get($cid)) {
|
||||||
$test_classes = $cache->data;
|
$test_classes = $cache->data;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
if ($module) {
|
||||||
|
$prefix = 'Drupal\\' . $module . '\\';
|
||||||
|
$n = strlen($prefix);
|
||||||
|
}
|
||||||
// If there was no cached data available we have to find the tests.
|
// If there was no cached data available we have to find the tests.
|
||||||
// Load the PHPUnit configuration file, which tells us where to find the
|
// Load the PHPUnit configuration file, which tells us where to find the
|
||||||
// tests.
|
// tests.
|
||||||
|
@ -750,13 +772,13 @@ function simpletest_phpunit_get_available_tests() {
|
||||||
}
|
}
|
||||||
|
|
||||||
$name = get_class($test);
|
$name = get_class($test);
|
||||||
if (!array_key_exists($name, $test_classes)) {
|
if (!array_key_exists($name, $test_classes) && (!$module || substr($name, 0, $n) == $prefix)) {
|
||||||
$test_classes[$name] = $test->getInfo();
|
$test_classes[$name] = $test->getInfo();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Since we have recalculated, we now need to store the new data into cache.
|
// Since we have recalculated, we now need to store the new data into cache.
|
||||||
\Drupal::cache()->set('simpletest_phpunit', $test_classes);
|
\Drupal::cache()->set($cid, $test_classes);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $test_classes;
|
return $test_classes;
|
||||||
|
|
|
@ -205,7 +205,7 @@ function simpletest_script_parse_args() {
|
||||||
'php' => '',
|
'php' => '',
|
||||||
'concurrency' => 1,
|
'concurrency' => 1,
|
||||||
'all' => FALSE,
|
'all' => FALSE,
|
||||||
'module' => FALSE,
|
'module' => NULL,
|
||||||
'class' => FALSE,
|
'class' => FALSE,
|
||||||
'file' => FALSE,
|
'file' => FALSE,
|
||||||
'color' => FALSE,
|
'color' => FALSE,
|
||||||
|
@ -330,6 +330,10 @@ function simpletest_script_init($server_software) {
|
||||||
/**
|
/**
|
||||||
* Get all available tests from simpletest and PHPUnit.
|
* Get all available tests from simpletest and PHPUnit.
|
||||||
*
|
*
|
||||||
|
* @param string $module
|
||||||
|
* Name of a module. If set then only tests belonging to this module are
|
||||||
|
* returned.
|
||||||
|
*
|
||||||
* @return
|
* @return
|
||||||
* An array of tests keyed with the groups specified in each of the tests
|
* An array of tests keyed with the groups specified in each of the tests
|
||||||
* getInfo() method and then keyed by the test class. An example of the array
|
* getInfo() method and then keyed by the test class. An example of the array
|
||||||
|
@ -345,9 +349,9 @@ function simpletest_script_init($server_software) {
|
||||||
* );
|
* );
|
||||||
* @endcode
|
* @endcode
|
||||||
*/
|
*/
|
||||||
function simpletest_script_get_all_tests() {
|
function simpletest_script_get_all_tests($module = NULL) {
|
||||||
$tests = simpletest_test_get_all();
|
$tests = simpletest_test_get_all($module);
|
||||||
$tests['PHPUnit'] = simpletest_phpunit_get_available_tests();
|
$tests['PHPUnit'] = simpletest_phpunit_get_available_tests($module);
|
||||||
return $tests;
|
return $tests;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -626,8 +630,8 @@ function simpletest_script_get_test_list() {
|
||||||
global $args;
|
global $args;
|
||||||
|
|
||||||
$test_list = array();
|
$test_list = array();
|
||||||
if ($args['all']) {
|
if ($args['all'] || $args['module']) {
|
||||||
$groups = simpletest_script_get_all_tests();
|
$groups = simpletest_script_get_all_tests($args['module']);
|
||||||
$all_tests = array();
|
$all_tests = array();
|
||||||
foreach ($groups as $group => $tests) {
|
foreach ($groups as $group => $tests) {
|
||||||
$all_tests = array_merge($all_tests, array_keys($tests));
|
$all_tests = array_merge($all_tests, array_keys($tests));
|
||||||
|
@ -640,20 +644,6 @@ function simpletest_script_get_test_list() {
|
||||||
$test_list[] = $class_name;
|
$test_list[] = $class_name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
elseif ($args['module']) {
|
|
||||||
$modules = drupal_system_listing('/^' . DRUPAL_PHP_FUNCTION_PATTERN . '\.module$/', 'modules', 'name', 0);
|
|
||||||
foreach ($args['test_names'] as $module) {
|
|
||||||
// PSR-0 only.
|
|
||||||
$dir = dirname($modules[$module]->uri) . "/lib/Drupal/$module/Tests";
|
|
||||||
$files = file_scan_directory($dir, '@\.php$@', array(
|
|
||||||
'key' => 'name',
|
|
||||||
'recurse' => TRUE,
|
|
||||||
));
|
|
||||||
foreach ($files as $test => $file) {
|
|
||||||
$test_list[] = "Drupal\\$module\\Tests\\$test";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
elseif ($args['file']) {
|
elseif ($args['file']) {
|
||||||
// Extract test case class names from specified files.
|
// Extract test case class names from specified files.
|
||||||
foreach ($args['test_names'] as $file) {
|
foreach ($args['test_names'] as $file) {
|
||||||
|
|
Loading…
Reference in New Issue