function DatabaseTestBase::addSampleData

Sets up our sample data.

3 calls to DatabaseTestBase::addSampleData()
DatabaseTestBase::setUp in core/modules/system/tests/src/Functional/Database/DatabaseTestBase.php
DatabaseTestBase::setUp in core/tests/Drupal/KernelTests/Core/Database/DatabaseTestBase.php
DatabaseWebTestBase::setUp in core/modules/system/src/Tests/Database/DatabaseWebTestBase.php
Sets up a Drupal site for running functional and integration tests.

File

core/tests/Drupal/KernelTests/Core/Database/DatabaseTestBase.php, line 69

Class

DatabaseTestBase
Base class for databases database tests.

Namespace

Drupal\KernelTests\Core\Database

Code

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('test_special_columns')
        ->fields([
        'id' => 1,
        'offset' => 'Offset value 1',
        'function' => 'Function value 1',
    ])
        ->execute();
    $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.