Adding test for DboSource::group() and virtual fields

Closes #184
This commit is contained in:
José Lorenzo Rodríguez 2010-01-11 12:08:46 -04:30
parent 3fe4b46614
commit aa9258cbd1
2 changed files with 18 additions and 1 deletions

View file

@ -2333,7 +2333,6 @@ class DboSource extends DataSource {
if (!is_array($group)) {
$group = array($group);
}
foreach($group as $index => $key) {
if ($model->isVirtualField($key)) {
$group[$index] = '(' . $model->getVirtualField($key) . ')';

View file

@ -4240,5 +4240,23 @@ class DboSourceTest extends CakeTestCase {
));
$this->assertEqual($expected, $result);
}
/**
* test calculate to generate claculate statements on virtual fields
*
* @return void
*/
function testVirtualFieldsInGroup() {
$this->loadFixtures('Article');
$Article =& ClassRegistry::init('Article');
$Article->virtualFields = array(
'this_year' => 'YEAR(Article.created)'
);
$result = $this->db->group('this_year',$Article);
$expected = " GROUP BY (YEAR(`Article`.`created`))";
$this->assertEqual($expected, $result);
}
}
?>