mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Minor refactor, and adding tests from previous commit. Fixes #208
This commit is contained in:
parent
7943f3d168
commit
080e34718d
2 changed files with 14 additions and 4 deletions
|
@ -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, '.')) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue