Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding more tests for virtualFields and complex expressions. Closes #…

  • Loading branch information...
commit aad72871a09b8b1bf750cde84d42e6a4f4fd7d2e 1 parent e150697
@markstory markstory authored
View
44 cake/tests/cases/libs/model/datasources/dbo_source.test.php
@@ -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 @@ function testVirtualFields() {
* @return void
*/
function testVirtualFieldsInConditions() {
- $this->loadFixtures('Article');
-
$Article =& ClassRegistry::init('Article');
$Article->virtualFields = array(
'this_moment' => 'NOW()',
@@ -4374,7 +4372,6 @@ function testConditionsWithComplexVirtualFields() {
* 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 @@ function testConditionsWithComplexVirtualFields() {
* @return void
*/
function testVirtualFieldsInOrder() {
- $this->loadFixtures('Article');
-
$Article =& ClassRegistry::init('Article');
$Article->virtualFields = array(
'this_moment' => 'NOW()',
@@ -4413,8 +4408,6 @@ function testVirtualFieldsInOrder() {
* @return void
*/
function testVirtualFieldsInCalculate() {
- $this->loadFixtures('Article');
-
$Article =& ClassRegistry::init('Article');
$Article->virtualFields = array(
'this_moment' => 'NOW()',
@@ -4455,6 +4448,39 @@ function testVirtualFieldsFetch() {
));
$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 @@ function testFieldsWithComplexVirtualFields() {
* @return void
*/
function testVirtualFieldsInGroup() {
- $this->loadFixtures('Article');
-
$Article =& ClassRegistry::init('Article');
$Article->virtualFields = array(
'this_year' => 'YEAR(Article.created)'
View
9 cake/tests/fixtures/data_test_fixture.php
@@ -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'
+ )
+ );
}
Please sign in to comment.
Something went wrong with that request. Please try again.