function DatabaseTestSchemaDataTrait::addSampleData

Same name in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Database/DatabaseTestSchemaDataTrait.php \Drupal\KernelTests\Core\Database\DatabaseTestSchemaDataTrait::addSampleData()
  2. 11.x core/tests/Drupal/KernelTests/Core/Database/DatabaseTestSchemaDataTrait.php \Drupal\KernelTests\Core\Database\DatabaseTestSchemaDataTrait::addSampleData()

Sets up our sample data.

3 calls to DatabaseTestSchemaDataTrait::addSampleData()
DatabaseTestBase::setUp in core/modules/system/tests/src/Functional/Database/DatabaseTestBase.php
DatabaseTestBase::setUp in core/tests/Drupal/KernelTests/Core/Database/DatabaseTestBase.php
DriverSpecificDatabaseTestBase::setUp in core/tests/Drupal/KernelTests/Core/Database/DriverSpecificDatabaseTestBase.php

File

core/tests/Drupal/KernelTests/Core/Database/DatabaseTestSchemaDataTrait.php, line 17

Class

DatabaseTestSchemaDataTrait
Trait to manage data samples for test tables.

Namespace

Drupal\KernelTests\Core\Database

Code

protected function addSampleData() : void {
    // We need the IDs, so we can't use a multi-insert here.
    $john = $this->connection
        ->insert('test')
        ->fields([
        'name' => 'John',
        'age' => 25,
        'job' => 'Singer',
    ])
        ->execute();
    $george = $this->connection
        ->insert('test')
        ->fields([
        'name' => 'George',
        'age' => 27,
        'job' => 'Singer',
    ])
        ->execute();
    $this->connection
        ->insert('test')
        ->fields([
        'name' => 'Ringo',
        'age' => 28,
        'job' => 'Drummer',
    ])
        ->execute();
    $paul = $this->connection
        ->insert('test')
        ->fields([
        'name' => 'Paul',
        'age' => 26,
        'job' => 'Songwriter',
    ])
        ->execute();
    $this->connection
        ->insert('test_classtype')
        ->fields([
        'classname' => FakeRecord::class,
        'name' => 'Kay',
        'age' => 26,
        'job' => 'Web Developer',
    ])
        ->execute();
    $this->connection
        ->insert('test_people')
        ->fields([
        'name' => 'Meredith',
        'age' => 30,
        'job' => 'Speaker',
    ])
        ->execute();
    $this->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();
    $this->connection
        ->insert('select')
        ->fields([
        'id' => 1,
        'update' => 'Update value 1',
    ])
        ->execute();
    $this->connection
        ->insert('virtual')
        ->fields([
        'id' => 1,
        'function' => 'Function value 1',
    ])
        ->execute();
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.