protected function ExampleFixtureManagementTest::setUp in Examples for Developers 8
Same name and namespace in other branches
- 3.x modules/testing_example/tests/src/Kernel/ExampleFixtureManagementTest.php \Drupal\Tests\testing_example\Kernel\ExampleFixtureManagementTest::setUp()
Use setUp() to do anything that is common to all the tests in this class.
Group tests in a class so they can take advantage of setUp() activities as much as possible.
In a Kernel test, setUp() can be responsible for creating any schema or database configuration which must exist for the test.
Overrides KernelTestBase::setUp
File
- testing_example/
tests/ src/ Kernel/ ExampleFixtureManagementTest.php, line 61
Class
- ExampleFixtureManagementTest
- Demonstrate manipulating fixture data in a kernel test.
Namespace
Drupal\Tests\testing_example\KernelCode
protected function setUp() {
parent::setUp();
// Since kernel tests do not install modules, we have to install whatever
// schema and config we expect to be present in those modules.
//
// Figuring out what schema and EntitySchema and config to install is not
// always easy. Use core kernel tests for examples. The baseline is that you
// have to install everything in the database that is needed.
//
// Sequences table is prerequisite of the 'node' schema.
$this
->installSchema('system', [
'sequences',
]);
// Install *module* schema for node/user modules.
$this
->installSchema('node', [
'node_access',
]);
$this
->installSchema('user', [
'users_data',
]);
// Install *entity* schema for the node entity.
$this
->installEntitySchema('node');
$this
->installEntitySchema('user');
// Install any config provided by the enabled.
$this
->installConfig([
'field',
'node',
'text',
'filter',
'user',
]);
// Finally, create an 'owner' account.
$this->owner = $this
->createUser([], 'testuser');
}