Commit 03fba965 authored by alexpott's avatar alexpott

Issue #2801817 by Mile23: Inject services inot SimpletestTestForm and...

Issue #2801817 by Mile23: Inject services inot SimpletestTestForm and functional cleanup for the test_discovery service
parent f8f39839
......@@ -70,7 +70,7 @@ public function boot() {
$this->getContainer()->get('module_handler')->loadAll();
simpletest_classloader_register();
$this->getContainer()->get('test_discovery')->registerTestNamespaces();
// Register stream wrappers.
$this->getContainer()->get('stream_wrapper_manager')->register();
......
......@@ -583,13 +583,20 @@ function simpletest_log_read($test_id, $database_prefix, $test_class) {
* ),
* );
* @endcode
*
* @deprecated in Drupal 8.3.x, for removal before 9.0.0 release. Use
* \Drupal::service('test_discovery')->getTestClasses($extension, $types)
* instead.
*/
function simpletest_test_get_all($extension = NULL, array $types = []) {
return \Drupal::service('test_discovery')->getTestClasses($extension, $types);
}
/**
* Registers namespaces for disabled modules.
* 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.
*/
function simpletest_classloader_register() {
\Drupal::service('test_discovery')->registerTestNamespaces();
......
......@@ -5,6 +5,7 @@
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\RendererInterface;
use Drupal\simpletest\TestDiscovery;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
......@@ -19,12 +20,20 @@ class SimpletestTestForm extends FormBase {
*/
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('renderer'),
$container->get('test_discovery')
);
}
......@@ -33,9 +42,12 @@ public static function create(ContainerInterface $container) {
*
* @param \Drupal\Core\Render\RendererInterface $renderer
* The renderer.
* @param \Drupal\simpletest\TestDiscovery $test_discovery
* The test discovery service.
*/
public function __construct(RendererInterface $renderer) {
public function __construct(RendererInterface $renderer, TestDiscovery $test_discovery) {
$this->renderer = $renderer;
$this->testDiscovery = $test_discovery;
}
/**
......@@ -136,7 +148,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
];
// Generate the list of tests arranged by group.
$groups = simpletest_test_get_all();
$groups = $this->testDiscovery->getTestClasses();
foreach ($groups as $group => $tests) {
$form['tests'][$group] = array(
'#attributes' => array('class' => array('simpletest-group')),
......@@ -200,7 +212,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
// Test discovery does not run upon form submission.
simpletest_classloader_register();
$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
......
......@@ -81,7 +81,7 @@ public function __construct($root, $class_loader, ModuleHandlerInterface $module
}
/**
* Registers test namespaces of all available extensions.
* Registers test namespaces of all extensions and core test classes.
*
* @return array
* An associative array whose keys are PSR-4 namespace prefixes and whose
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment