public static function DatabaseTestBase::addSampleData in Drupal 9
Same name and namespace in other branches
- 8 core/tests/Drupal/KernelTests/Core/Database/DatabaseTestBase.php \Drupal\KernelTests\Core\Database\DatabaseTestBase::addSampleData()
Sets up our sample data.
2 calls to DatabaseTestBase::addSampleData()
- DatabaseTestBase::setUp in core/
tests/ Drupal/ KernelTests/ Core/ Database/ DatabaseTestBase.php - DatabaseTestBase::setUp in core/
modules/ system/ tests/ src/ Functional/ Database/ DatabaseTestBase.php
File
- core/
tests/ Drupal/ KernelTests/ Core/ Database/ DatabaseTestBase.php, line 69
Class
- DatabaseTestBase
- Base class for databases database tests.
Namespace
Drupal\KernelTests\Core\DatabaseCode
public static function addSampleData() {
$connection = Database::getConnection();
// We need the IDs, so we can't use a multi-insert here.
$john = $connection
->insert('test')
->fields([
'name' => 'John',
'age' => 25,
'job' => 'Singer',
])
->execute();
$george = $connection
->insert('test')
->fields([
'name' => 'George',
'age' => 27,
'job' => 'Singer',
])
->execute();
$connection
->insert('test')
->fields([
'name' => 'Ringo',
'age' => 28,
'job' => 'Drummer',
])
->execute();
$paul = $connection
->insert('test')
->fields([
'name' => 'Paul',
'age' => 26,
'job' => 'Songwriter',
])
->execute();
$connection
->insert('test_classtype')
->fields([
'classname' => 'Drupal\\Tests\\system\\Functional\\Database\\FakeRecord',
'name' => 'Kay',
'age' => 26,
'job' => 'Web Developer',
])
->execute();
$connection
->insert('test_people')
->fields([
'name' => 'Meredith',
'age' => 30,
'job' => 'Speaker',
])
->execute();
$connection
->insert('test_task')
->fields([
'pid',
'task',
'priority',
])
->values([
'pid' => $john,
'task' => 'eat',
'priority' => 3,
])
->values([
'pid' => $john,
'task' => 'sleep',
'priority' => 4,
])
->values([
'pid' => $john,
'task' => 'code',
'priority' => 1,
])
->values([
'pid' => $george,
'task' => 'sing',
'priority' => 2,
])
->values([
'pid' => $george,
'task' => 'sleep',
'priority' => 2,
])
->values([
'pid' => $paul,
'task' => 'found new band',
'priority' => 1,
])
->values([
'pid' => $paul,
'task' => 'perform at superbowl',
'priority' => 3,
])
->execute();
$connection
->insert('select')
->fields([
'id' => 1,
'update' => 'Update value 1',
])
->execute();
$connection
->insert('virtual')
->fields([
'id' => 1,
'function' => 'Function value 1',
])
->execute();
}