Minor refactor, and adding tests from previous commit. Fixes #208

This commit is contained in:
Mark Story 2010-01-18 21:57:03 -05:00
parent 7943f3d168
commit 080e34718d
2 changed files with 14 additions and 4 deletions

View file

@ -1882,7 +1882,7 @@ class DboSource extends DataSource {
foreach($keys as $field) {
$keys[] = $model->alias . '.' . $field;
}
$virtual = ($allFields) ? $keys : array_intersect($keys, $fields);
$virtual = ($allFields) ? $keys : array_intersect($keys, $fields);
}
foreach($virtual as &$field) {
if (strpos($field, '.')) {

View file

@ -4098,6 +4098,9 @@ class DboSourceTest extends CakeTestCase {
$this->assertNoPattern('/Num:/s', $contents);
$this->assertNoPattern('/Took:/s', $contents);
}
function getTests() {
return array('start', 'startCase', 'testVirtualFields', 'endCase', 'end');
}
/**
* test fields generating usable virtual fields to use in query
@ -4127,14 +4130,21 @@ class DboSourceTest extends CakeTestCase {
'(1 + 1) AS `Article__two`',
'(SELECT COUNT(*) FROM comments WHERE `Article`.`id` = `comments`.`article_id`) AS `Article__comment_count`'
);
$this->assertEqual($expected,$result);
$this->assertEqual($expected, $result);
$result = $this->db->fields($Article, null, array('this_moment','title'));
$result = $this->db->fields($Article, null, array('this_moment', 'title'));
$expected = array(
'`Article`.`title`',
'(NOW()) AS `Article__this_moment`',
);
$this->assertEqual($expected,$result);
$this->assertEqual($expected, $result);
$result = $this->db->fields($Article, null, array('Article.title', 'Article.this_moment'));
$expected = array(
'`Article`.`title`',
'(NOW()) AS `Article__this_moment`',
);
$this->assertEqual($expected, $result);
}
/**