Permalink
Browse files

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

Closes #184
  • Loading branch information...
1 parent 3fe4b46 commit aa9258cbd162bfb317a0915647e7b85c9e50987d @lorenzo lorenzo committed Jan 11, 2010
View
1 cake/libs/model/datasources/dbo_source.php
@@ -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) . ')';
View
18 cake/tests/cases/libs/model/datasources/dbo_source.test.php
@@ -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.