@@ -118,6 +119,15 @@ class DatabaseTestCase extends DrupalWebTestCase {
))
->execute();
db_insert('test_classtype')
->fields(array(
'classname'=>'FakeRecord',
'name'=>'Kay',
'age'=>26,
'job'=>'Web Developer',
))
->execute();
db_insert('test_people')
->fields(array(
'name'=>'Meredith',
@@ -407,6 +417,27 @@ class DatabaseFetchTestCase extends DatabaseTestCase {
$this->assertIdentical(count($records),1,'There is only one record.');
}
/**
* Confirms that we can fetch a record into a new instance of a custom class.
* The name of the class is determined from a value of the first column.
*
* @see FakeRecord
*/
functiontestQueryFetchClasstype(){
$records=array();
$result=db_query('SELECT classname, name, job FROM {test_classtype} WHERE age = :age',array(':age'=>26),array('fetch'=>PDO::FETCH_CLASS|PDO::FETCH_CLASSTYPE));
foreach($resultas$record){
$records[]=$record;
if($this->assertTrue($recordinstanceofFakeRecord,'Record is an object of class FakeRecord.')){
$this->assertIdentical($record->name,'Kay','Kay is found.');
$this->assertIdentical($record->job,'Web Developer','A 26 year old Web Developer.');
}
$this->assertFalse(isset($record->classname),'Classname field not found, as intended.');
}
$this->assertIdentical(count($records),1,'There is only one record.');