You are here

function DatabaseTestCase::addSampleData in SimpleTest 7

Setup our sample data.

These are added using db_query(), since we're not trying to test the INSERT operations here, just populate.

1 call to DatabaseTestCase::addSampleData()
DatabaseTestCase::setUp in tests/database_test.test
Generates a random database prefix, runs the install scripts on the prefixed database and enable the specified modules. After installation many caches are flushed and the internal browser is setup so that the page requests will run on the new prefix.…

File

tests/database_test.test, line 84

Class

DatabaseTestCase
Base test class for databases.

Code

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();
  $ringo = db_insert('test')
    ->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();
}