Skip to content

Commit

Permalink
Adding test for DboSource::group() and virtual fields
Browse files Browse the repository at this point in the history
Closes #184
  • Loading branch information
lorenzo committed Jan 11, 2010
1 parent 3fe4b46 commit aa9258c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
1 change: 0 additions & 1 deletion cake/libs/model/datasources/dbo_source.php
Expand Up @@ -2333,7 +2333,6 @@ function group($group, $model = null) {
if (!is_array($group)) {
$group = array($group);
}

foreach($group as $index => $key) {
if ($model->isVirtualField($key)) {
$group[$index] = '(' . $model->getVirtualField($key) . ')';
Expand Down
18 changes: 18 additions & 0 deletions cake/tests/cases/libs/model/datasources/dbo_source.test.php
Expand Up @@ -4240,5 +4240,23 @@ function testVirtualFieldsFetch() {
));
$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);
}
}
?>

0 comments on commit aa9258c

Please sign in to comment.