By tim.plunkett on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
8.x
Description:
In Drupal 7, a list of modules could be passed to the setUp() method of a simpletest automated test to enable those modules in the test methods. Instead in Drupal 8, a public static class property is used.
Sometimes the setUp method was only used to enable modules. In those cases, it can be removed entirely.
Drupal 7
class NodeLoadHooksTestCase extends DrupalWebTestCase {
function setUp() {
parent::setUp('node_test');
}
// ...
}
Drupal 8
class NodeLoadHooksTest extends NodeTestBase {
public static $modules = array('node_test');
// ...
}
In other cases, setUp() was used for other things as well. In these cases, continue to call parent::setUp(), but pass no arguments.
Drupal 7
class NodeCreationTestCase extends DrupalWebTestCase {
function setUp() {
parent::setUp('node_test_exception');
$web_user = $this->drupalCreateUser(array('create page content', 'edit own page content'));
$this->drupalLogin($web_user);
}
// ...
}
Drupal 8
class NodeCreationTest extends NodeTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('node_test_exception');
function setUp() {
parent::setUp();
$web_user = $this->drupalCreateUser(array('create page content', 'edit own page content'));
$this->drupalLogin($web_user);
}
// ...
}
Impacts:
Module developers