Newer
Older
<?php
/**
* @file
* Contains \Drupal\system\Tests\Database\DatabaseTestBase.
*/
namespace Drupal\system\Tests\Database;
Alex Pott
committed
use Drupal\simpletest\KernelTestBase;
/**
Dries Buytaert
committed
* Base class for databases database tests.
*
* Because all database tests share the same test data, we can centralize that
* here.
*/
Alex Pott
committed
abstract class DatabaseTestBase extends KernelTestBase {
public static $modules = array('database_test');
Alex Pott
committed
protected function setUp() {
parent::setUp();
$this->installSchema('database_test', array(
'test',
'test_people',
Dries Buytaert
committed
'test_people_copy',
'test_one_blob',
'test_two_blobs',
'test_task',
'test_null',
'test_serialized',
Alex Pott
committed
'test_special_columns',
Dries Buytaert
committed
self::addSampleData();
}
/**
Jennifer Hodgdon
committed
* Sets up tables for NULL handling.
*/
function ensureSampleDataNull() {
db_insert('test_null')
->fields(array('name', 'age'))
->values(array(
'name' => 'Kermit',
'age' => 25,
))
->values(array(
'name' => 'Fozzie',
'age' => NULL,
))
->values(array(
'name' => 'Gonzo',
'age' => 27,
))
->execute();
}
/**
Jennifer Hodgdon
committed
* Sets up our sample data.
*/
Dries Buytaert
committed
static function addSampleData() {
// We need the IDs, so we can't use a multi-insert here.
$john = db_insert('test')
->fields(array(
'name' => 'John',
'age' => 25,
'job' => 'Singer',
))
->execute();
$george = db_insert('test')
->fields(array(
'name' => 'George',
'age' => 27,
'job' => 'Singer',
))
->execute();
Angie Byron
committed
db_insert('test')
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
->fields(array(
'name' => 'Ringo',
'age' => 28,
'job' => 'Drummer',
))
->execute();
$paul = db_insert('test')
->fields(array(
'name' => 'Paul',
'age' => 26,
'job' => 'Songwriter',
))
->execute();
db_insert('test_people')
->fields(array(
'name' => 'Meredith',
'age' => 30,
'job' => 'Speaker',
))
->execute();
db_insert('test_task')
->fields(array('pid', 'task', 'priority'))
->values(array(
'pid' => $john,
'task' => 'eat',
'priority' => 3,
))
->values(array(
'pid' => $john,
'task' => 'sleep',
'priority' => 4,
))
->values(array(
'pid' => $john,
'task' => 'code',
'priority' => 1,
))
->values(array(
'pid' => $george,
'task' => 'sing',
'priority' => 2,
))
->values(array(
'pid' => $george,
'task' => 'sleep',
'priority' => 2,
))
->values(array(
'pid' => $paul,
'task' => 'found new band',
'priority' => 1,
))
->values(array(
'pid' => $paul,
'task' => 'perform at superbowl',
'priority' => 3,
))
->execute();
Alex Pott
committed
db_insert('test_special_columns')
->fields(array(
'id' => 1,
'offset' => 'Offset value 1',
))
->execute();