Révision 6ff32cea
Ajouté par Florent Torregrosa il y a environ 9 ans
drupal7/modules/simpletest/simpletest.module | ||
---|---|---|
328 | 328 |
// Also discover PSR-0 test classes, if the PHP version allows it. |
329 | 329 |
if (version_compare(PHP_VERSION, '5.3') > 0) { |
330 | 330 |
|
331 |
// Select all PSR-0 classes in the Tests namespace of all modules. |
|
331 |
// Select all PSR-0 and PSR-4 classes in the Tests namespace of all |
|
332 |
// modules. |
|
332 | 333 |
$system_list = db_query("SELECT name, filename FROM {system}")->fetchAllKeyed(); |
333 | 334 |
|
334 | 335 |
foreach ($system_list as $name => $filename) { |
335 |
// Build directory in which the test files would reside. |
|
336 |
$tests_dir = DRUPAL_ROOT . '/' . dirname($filename) . '/lib/Drupal/' . $name . '/Tests'; |
|
337 |
// Scan it for test files if it exists. |
|
338 |
if (is_dir($tests_dir)) { |
|
339 |
$files = file_scan_directory($tests_dir, '/.*\.php/'); |
|
340 |
if (!empty($files)) { |
|
341 |
$basedir = DRUPAL_ROOT . '/' . dirname($filename) . '/lib/'; |
|
342 |
foreach ($files as $file) { |
|
343 |
// Convert the file name into the namespaced class name. |
|
344 |
$replacements = array( |
|
345 |
'/' => '\\', |
|
346 |
$basedir => '', |
|
347 |
'.php' => '', |
|
348 |
); |
|
349 |
$classes[] = strtr($file->uri, $replacements); |
|
336 |
$module_dir = DRUPAL_ROOT . '/' . dirname($filename); |
|
337 |
// Search both the 'lib/Drupal/mymodule' directory (for PSR-0 classes) |
|
338 |
// and the 'src' directory (for PSR-4 classes). |
|
339 |
foreach(array('lib/Drupal/' . $name, 'src') as $subdir) { |
|
340 |
// Build directory in which the test files would reside. |
|
341 |
$tests_dir = $module_dir . '/' . $subdir . '/Tests'; |
|
342 |
// Scan it for test files if it exists. |
|
343 |
if (is_dir($tests_dir)) { |
|
344 |
$files = file_scan_directory($tests_dir, '/.*\.php/'); |
|
345 |
if (!empty($files)) { |
|
346 |
foreach ($files as $file) { |
|
347 |
// Convert the file name into the namespaced class name. |
|
348 |
$replacements = array( |
|
349 |
'/' => '\\', |
|
350 |
$module_dir . '/' => '', |
|
351 |
'lib/' => '', |
|
352 |
'src/' => 'Drupal\\' . $name . '\\', |
|
353 |
'.php' => '', |
|
354 |
); |
|
355 |
$classes[] = strtr($file->uri, $replacements); |
|
356 |
} |
|
350 | 357 |
} |
351 | 358 |
} |
352 | 359 |
} |
... | ... | |
406 | 413 |
|
407 | 414 |
// Only register PSR-0 class loading if we are on PHP 5.3 or higher. |
408 | 415 |
if (version_compare(PHP_VERSION, '5.3') > 0) { |
409 |
spl_autoload_register('_simpletest_autoload_psr0'); |
|
416 |
spl_autoload_register('_simpletest_autoload_psr4_psr0');
|
|
410 | 417 |
} |
411 | 418 |
} |
412 | 419 |
|
413 | 420 |
/** |
414 |
* Autoload callback to find PSR-0 test classes. |
|
421 |
* Autoload callback to find PSR-4 and PSR-0 test classes. |
|
422 |
* |
|
423 |
* Looks in the 'src/Tests' and in the 'lib/Drupal/mymodule/Tests' directory of |
|
424 |
* modules for the class. |
|
415 | 425 |
* |
416 | 426 |
* This will only work on classes where the namespace is of the pattern |
417 | 427 |
* "Drupal\$extension\Tests\.." |
418 | 428 |
*/ |
419 |
function _simpletest_autoload_psr0($class) { |
|
429 |
function _simpletest_autoload_psr4_psr0($class) {
|
|
420 | 430 |
|
421 | 431 |
// Static cache for extension paths. |
422 | 432 |
// This cache is lazily filled as soon as it is needed. |
... | ... | |
446 | 456 |
$namespace = substr($class, 0, $nspos); |
447 | 457 |
$classname = substr($class, $nspos + 1); |
448 | 458 |
|
449 |
// Build the filepath where we expect the class to be defined. |
|
450 |
$path = dirname($extensions[$extension]) . '/lib/' . |
|
451 |
str_replace('\\', '/', $namespace) . '/' . |
|
459 |
// Try the PSR-4 location first, and the PSR-0 location as a fallback. |
|
460 |
// Build the PSR-4 filepath where we expect the class to be defined. |
|
461 |
$psr4_path = dirname($extensions[$extension]) . '/src/' . |
|
462 |
str_replace('\\', '/', substr($namespace, strlen('Drupal\\' . $extension . '\\'))) . '/' . |
|
452 | 463 |
str_replace('_', '/', $classname) . '.php'; |
453 | 464 |
|
454 | 465 |
// Include the file, if it does exist. |
455 |
if (file_exists($path)) { |
|
456 |
include $path; |
|
466 |
if (file_exists($psr4_path)) { |
|
467 |
include $psr4_path; |
|
468 |
} |
|
469 |
else { |
|
470 |
// Build the PSR-0 filepath where we expect the class to be defined. |
|
471 |
$psr0_path = dirname($extensions[$extension]) . '/lib/' . |
|
472 |
str_replace('\\', '/', $namespace) . '/' . |
|
473 |
str_replace('_', '/', $classname) . '.php'; |
|
474 |
|
|
475 |
// Include the file, if it does exist. |
|
476 |
if (file_exists($psr0_path)) { |
|
477 |
include $psr0_path; |
|
478 |
} |
|
457 | 479 |
} |
458 | 480 |
} |
459 | 481 |
} |
Formats disponibles : Unified diff
Update core to 7.36