Skip to content
Permalink
Browse files

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

  • Loading branch information...
markstory committed Jan 19, 2010
1 parent 7943f3d commit 080e34718d82ce64d16440e24ba0e922af76333d
@@ -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, '.')) {
@@ -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
@@ -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);
}
/**

0 comments on commit 080e347

Please sign in to comment.
You can’t perform that action at this time.