mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 02:56:15 +00:00
Adding more tests for virtualFields and complex expressions. Closes #1079
This commit is contained in:
parent
e15069769d
commit
aad72871a0
2 changed files with 42 additions and 11 deletions
|
@ -1279,7 +1279,7 @@ class DboSourceTest extends CakeTestCase {
|
|||
*/
|
||||
var $fixtures = array(
|
||||
'core.apple', 'core.article', 'core.articles_tag', 'core.attachment', 'core.comment',
|
||||
'core.sample', 'core.tag', 'core.user', 'core.post', 'core.author'
|
||||
'core.sample', 'core.tag', 'core.user', 'core.post', 'core.author', 'core.data_test'
|
||||
);
|
||||
|
||||
/**
|
||||
|
@ -4329,8 +4329,6 @@ class DboSourceTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
function testVirtualFieldsInConditions() {
|
||||
$this->loadFixtures('Article');
|
||||
|
||||
$Article =& ClassRegistry::init('Article');
|
||||
$Article->virtualFields = array(
|
||||
'this_moment' => 'NOW()',
|
||||
|
@ -4374,7 +4372,6 @@ class DboSourceTest extends CakeTestCase {
|
|||
* COS((50 - Article.longitude) * PI() / 180)
|
||||
) * 180 / PI() * 60 * 1.1515 * 1.609344'
|
||||
);
|
||||
|
||||
$conditions = array('distance >=' => 20);
|
||||
$result = $this->db->conditions($conditions, true, true, $Article);
|
||||
|
||||
|
@ -4389,8 +4386,6 @@ class DboSourceTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
function testVirtualFieldsInOrder() {
|
||||
$this->loadFixtures('Article');
|
||||
|
||||
$Article =& ClassRegistry::init('Article');
|
||||
$Article->virtualFields = array(
|
||||
'this_moment' => 'NOW()',
|
||||
|
@ -4413,8 +4408,6 @@ class DboSourceTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
function testVirtualFieldsInCalculate() {
|
||||
$this->loadFixtures('Article');
|
||||
|
||||
$Article =& ClassRegistry::init('Article');
|
||||
$Article->virtualFields = array(
|
||||
'this_moment' => 'NOW()',
|
||||
|
@ -4455,6 +4448,39 @@ class DboSourceTest extends CakeTestCase {
|
|||
));
|
||||
$this->assertEqual($expected, $result);
|
||||
}
|
||||
˝
|
||||
/**
|
||||
* test reading complex virtualFields with subqueries.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testVirtualFieldsComplexRead() {
|
||||
$this->loadFixtures('DataTest', 'Article', 'Comment');
|
||||
|
||||
$Article =& ClassRegistry::init('Article');
|
||||
$commentTable = $this->db->fullTableName('comments');
|
||||
$Article =& ClassRegistry::init('Article');
|
||||
$Article->virtualFields = array(
|
||||
'comment_count' => 'SELECT COUNT(*) FROM ' . $commentTable .
|
||||
' AS Comment WHERE Article.id = Comment.article_id'
|
||||
);
|
||||
$result = $Article->find('all');
|
||||
$this->assertTrue(count($result) > 0);
|
||||
$this->assertTrue($result[0]['Article']['comment_count'] > 0);
|
||||
|
||||
$DataTest =& ClassRegistry::init('DataTest');
|
||||
$DataTest->virtualFields = array(
|
||||
'complicated' => 'ACOS(SIN(20 * PI() / 180)
|
||||
* SIN(DataTest.float * PI() / 180)
|
||||
+ COS(20 * PI() / 180)
|
||||
* COS(DataTest.count * PI() / 180)
|
||||
* COS((50 - DataTest.float) * PI() / 180)
|
||||
) * 180 / PI() * 60 * 1.1515 * 1.609344'
|
||||
);
|
||||
$result = $DataTest->find('all');
|
||||
$this->assertTrue(count($result) > 0);
|
||||
$this->assertTrue($result[0]['DataTest']['complicated'] > 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* test that virtualFields with complex functions and aliases work.
|
||||
|
@ -4489,8 +4515,6 @@ class DboSourceTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
function testVirtualFieldsInGroup() {
|
||||
$this->loadFixtures('Article');
|
||||
|
||||
$Article =& ClassRegistry::init('Article');
|
||||
$Article->virtualFields = array(
|
||||
'this_year' => 'YEAR(Article.created)'
|
||||
|
|
9
cake/tests/fixtures/data_test_fixture.php
vendored
9
cake/tests/fixtures/data_test_fixture.php
vendored
|
@ -55,5 +55,12 @@ class DataTestFixture extends CakeTestFixture {
|
|||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $records = array();
|
||||
var $records = array(
|
||||
array(
|
||||
'count' => 2,
|
||||
'float' => 2.4,
|
||||
'created' => '2010-09-06 12:28:00',
|
||||
'updated' => '2010-09-06 12:28:00'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue