Skip to content

Commit

Permalink
Minor refactor, and adding tests from previous commit. Fixes #208
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Jan 19, 2010
1 parent 7943f3d commit 080e347
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cake/libs/model/datasources/dbo_source.php
Expand Up @@ -1882,7 +1882,7 @@ function fields(&$model, $alias = null, $fields = array(), $quote = true) {
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, '.')) {
Expand Down
16 changes: 13 additions & 3 deletions cake/tests/cases/libs/model/datasources/dbo_source.test.php
Expand Up @@ -4098,6 +4098,9 @@ function testShowQuery() {
$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
Expand Down Expand Up @@ -4127,14 +4130,21 @@ function testVirtualFields() {
'(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);
}

/**
Expand Down

0 comments on commit 080e347

Please sign in to comment.