I am on CH13 of the book specifically page: 326.
My SysMessageTest is failing:
My Code is as follows:
SysMessageTest.php
<?php
class SysMessageTest extends CDbTestCase
{
public $fixtures=array(
'messages'=>'SysMessage',
);
public function testGetLatest()
{
$message = SysMessage::getLatest();
$this->assertTrue($message instanceof SysMessage);
}
}
tbl_sys_message.php
<?php
return array(
'message1'=>array(
'message' => 'This is a test message',
'create_time' => new CDbExpression('NOW()'),
'create_user_id' => 1,
'update_time' => new CDbExpression('NOW()'),
'update_user_id' => 1,
),
);
GetLatest function in SysMessage AR Class
public static function getLatest()
{
//see if it is in the cache, if so, just return it
if( ($cache=Yii::app()->cache)!==null)
{
$key='TrackStar.ProjectListing.SystemMessage';
if(($sysMessage=$cache->get($key))!==false)
return $sysMessage;
}
//The system message was either not found in the cache, or
//there is no cache component defined for the application
//retrieve the system message from the database
$sysMessage = SysMessage::model()->find(array(
'order'=>'t.update_time DESC',
));
if($sysMessage != null)
{
//a valid message was found. Store it in cache for future retrievals
if(isset($key))
$cache->set($key,$sysMessage,300);
return $sysMessage;
}
else
return null;
}