Select Git revision
database_test.test

#344575 by cdale: made the ANSI compatibility mode less strict to work...
Dries Buytaert authored
- Patch #344575 by cdale: made the ANSI compatibility mode less strict to work around a MySQL 5 bug.
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
database_test.test 70.47 KiB
<?php
// $Id$
/**
* Dummy class for fetching into a class.
*
* PDO supports using a new instance of an arbitrary class for records
* rather than just a stdClass or array. This class is for testing that
* functionality. (See testQueryFetchClass() below)
*/
class FakeRecord { }
/**
* Base test class for databases.
*
* Because all database tests share the same test data, we can centralize that
* here.
*/
class DatabaseTestCase extends DrupalWebTestCase {
function setUp() {
parent::setUp('database_test');
$schema['test'] = drupal_get_schema('test');
$schema['test_people'] = drupal_get_schema('test_people');
$schema['test_one_blob'] = drupal_get_schema('test_one_blob');
$schema['test_two_blobs'] = drupal_get_schema('test_two_blobs');
$schema['test_task'] = drupal_get_schema('test_task');
// This ends up being a test for table drop and create, too, which is nice.
$ret = array();
foreach ($schema as $name => $data) {
if (db_table_exists($name)) {
db_drop_table($ret, $name);
}
db_create_table($ret, $name, $data);
}
foreach ($schema as $name => $data) {
$this->assertTrue(db_table_exists($name), t('Table @name created successfully.', array('@name' => $name)));
}
$this->addSampleData();
}
/**
* Setup our sample data.
*
* These are added using db_query(), since we're not trying to test the
* INSERT operations here, just populate.
*/
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')