/**
* test calculate to generate claculate statements on virtual fields
*
* @return void
*/
function testVirtualFieldsInCalculate()
{
$Article = ClassRegistry::init('Article');
$Article->virtualFields = array('this_moment' => 'NOW()', 'two' => '1 + 1', 'comment_count' => 'SELECT COUNT(*) FROM ' . $this->Dbo->fullTableName('comments') . ' WHERE Article.id = ' . $this->Dbo->fullTableName('comments') . '.article_id');
$result = $this->Dbo->calculate($Article, 'count', array('this_moment'));
$expected = 'COUNT(NOW()) AS `count`';
$this->assertEqual($expected, $result);
$result = $this->Dbo->calculate($Article, 'max', array('comment_count'));
$expected = 'MAX(SELECT COUNT(*) FROM comments WHERE `Article`.`id` = `comments`.`article_id`) AS `comment_count`';
$this->assertEqual($expected, $result);
}