Migrating DboSourceTest to PHPUnit

This commit is contained in:
José Lorenzo Rodríguez 2010-06-09 20:47:25 -04:30
parent fa1ae280ca
commit 9b3df1ea0e

View file

@ -1321,13 +1321,13 @@ class DboSourceTest extends CakeTestCase {
}"); }");
} }
$this->testDb =& new DboTest($this->__config); $this->testDb = new DboTest($this->__config);
$this->testDb->cacheSources = false; $this->testDb->cacheSources = false;
$this->testDb->startQuote = '`'; $this->testDb->startQuote = '`';
$this->testDb->endQuote = '`'; $this->testDb->endQuote = '`';
Configure::write('debug', 1); Configure::write('debug', 1);
$this->debug = Configure::read('debug'); $this->debug = Configure::read('debug');
$this->Model =& new TestModel(); $this->Model = new TestModel();
} }
/** /**
@ -1350,10 +1350,10 @@ class DboSourceTest extends CakeTestCase {
*/ */
function testFieldDoubleEscaping() { function testFieldDoubleEscaping() {
$config = array_merge($this->__config, array('driver' => 'test')); $config = array_merge($this->__config, array('driver' => 'test'));
$test =& ConnectionManager::create('quoteTest', $config); $test = ConnectionManager::create('quoteTest', $config);
$test->simulated = array(); $test->simulated = array();
$this->Model =& new Article2(array('alias' => 'Article', 'ds' => 'quoteTest')); $this->Model = new Article2(array('alias' => 'Article', 'ds' => 'quoteTest'));
$this->Model->setDataSource('quoteTest'); $this->Model->setDataSource('quoteTest');
$this->assertEqual($this->Model->escapeField(), '`Article`.`id`'); $this->assertEqual($this->Model->escapeField(), '`Article`.`id`');
@ -1392,26 +1392,26 @@ class DboSourceTest extends CakeTestCase {
*/ */
function testGenerateAssociationQuerySelfJoin() { function testGenerateAssociationQuerySelfJoin() {
$this->startTime = microtime(true); $this->startTime = microtime(true);
$this->Model =& new Article2(); $this->Model = new Article2();
$this->_buildRelatedModels($this->Model); $this->_buildRelatedModels($this->Model);
$this->_buildRelatedModels($this->Model->Category2); $this->_buildRelatedModels($this->Model->Category2);
$this->Model->Category2->ChildCat =& new Category2(); $this->Model->Category2->ChildCat = new Category2();
$this->Model->Category2->ParentCat =& new Category2(); $this->Model->Category2->ParentCat = new Category2();
$queryData = array(); $queryData = array();
foreach ($this->Model->Category2->associations() as $type) { foreach ($this->Model->Category2->associations() as $type) {
foreach ($this->Model->Category2->{$type} as $assoc => $assocData) { foreach ($this->Model->Category2->{$type} as $assoc => $assocData) {
$linkModel =& $this->Model->Category2->{$assoc}; $linkModel = $this->Model->Category2->{$assoc};
$external = isset($assocData['external']); $external = isset($assocData['external']);
if ($this->Model->Category2->alias == $linkModel->alias && $type != 'hasAndBelongsToMany' && $type != 'hasMany') { if ($this->Model->Category2->alias == $linkModel->alias && $type != 'hasAndBelongsToMany' && $type != 'hasMany') {
$result = $this->testDb->generateAssociationQuery($this->Model->Category2, $linkModel, $type, $assoc, $assocData, $queryData, $external, $null); $result = $this->testDb->generateAssociationQuery($this->Model->Category2, $linkModel, $type, $assoc, $assocData, $queryData, $external, $null);
$this->assertTrue($result); $this->assertFalse(empty($result));
} else { } else {
if ($this->Model->Category2->useDbConfig == $linkModel->useDbConfig) { if ($this->Model->Category2->useDbConfig == $linkModel->useDbConfig) {
$result = $this->testDb->generateAssociationQuery($this->Model->Category2, $linkModel, $type, $assoc, $assocData, $queryData, $external, $null); $result = $this->testDb->generateAssociationQuery($this->Model->Category2, $linkModel, $type, $assoc, $assocData, $queryData, $external, $null);
$this->assertTrue($result); $this->assertFalse(empty($result));
} }
} }
} }
@ -1420,7 +1420,7 @@ class DboSourceTest extends CakeTestCase {
$query = $this->testDb->generateAssociationQuery($this->Model->Category2, $null, null, null, null, $queryData, false, $null); $query = $this->testDb->generateAssociationQuery($this->Model->Category2, $null, null, null, null, $queryData, false, $null);
$this->assertPattern('/^SELECT\s+(.+)FROM(.+)`Category2`\.`group_id`\s+=\s+`Group`\.`id`\)\s+LEFT JOIN(.+)WHERE\s+1 = 1\s*$/', $query); $this->assertPattern('/^SELECT\s+(.+)FROM(.+)`Category2`\.`group_id`\s+=\s+`Group`\.`id`\)\s+LEFT JOIN(.+)WHERE\s+1 = 1\s*$/', $query);
$this->Model =& new TestModel4(); $this->Model = new TestModel4();
$this->Model->schema(); $this->Model->schema();
$this->_buildRelatedModels($this->Model); $this->_buildRelatedModels($this->Model);
@ -1436,6 +1436,7 @@ class DboSourceTest extends CakeTestCase {
$this->assertTrue($result); $this->assertTrue($result);
$expected = array( $expected = array(
'conditions' => array(),
'fields' => array( 'fields' => array(
'`TestModel4`.`id`', '`TestModel4`.`id`',
'`TestModel4`.`name`', '`TestModel4`.`name`',
@ -1454,11 +1455,10 @@ class DboSourceTest extends CakeTestCase {
'conditions' => '`TestModel4`.`parent_id` = `TestModel4Parent`.`id`' 'conditions' => '`TestModel4`.`parent_id` = `TestModel4Parent`.`id`'
) )
), ),
'order' => array(),
'limit' => array(), 'limit' => array(),
'offset' => array(), 'offset' => array(),
'conditions' => array(), 'group' => array()
'order' => array(),
'group' => null
); );
$this->assertEqual($queryData, $expected); $this->assertEqual($queryData, $expected);
@ -1482,10 +1482,10 @@ class DboSourceTest extends CakeTestCase {
* @return void * @return void
*/ */
function testGenerateInnerJoinAssociationQuery() { function testGenerateInnerJoinAssociationQuery() {
$this->Model =& new TestModel9(); $this->Model = new TestModel9();
$test =& ConnectionManager::create('test2', $this->__config); $test = ConnectionManager::create('test2', $this->__config);
$this->Model->setDataSource('test2'); $this->Model->setDataSource('test2');
$this->Model->TestModel8 =& new TestModel8(); $this->Model->TestModel8 = new TestModel8();
$this->Model->TestModel8->setDataSource('test2'); $this->Model->TestModel8->setDataSource('test2');
$this->testDb->read($this->Model, array('recursive' => 1)); $this->testDb->read($this->Model, array('recursive' => 1));
@ -1506,7 +1506,7 @@ class DboSourceTest extends CakeTestCase {
* @return void * @return void
*/ */
function testGenerateAssociationQuerySelfJoinWithConditionsInHasOneBinding() { function testGenerateAssociationQuerySelfJoinWithConditionsInHasOneBinding() {
$this->Model =& new TestModel8(); $this->Model = new TestModel8();
$this->Model->schema(); $this->Model->schema();
$this->_buildRelatedModels($this->Model); $this->_buildRelatedModels($this->Model);
@ -1534,7 +1534,7 @@ class DboSourceTest extends CakeTestCase {
* @return void * @return void
*/ */
function testGenerateAssociationQuerySelfJoinWithConditionsInBelongsToBinding() { function testGenerateAssociationQuerySelfJoinWithConditionsInBelongsToBinding() {
$this->Model =& new TestModel9(); $this->Model = new TestModel9();
$this->Model->schema(); $this->Model->schema();
$this->_buildRelatedModels($this->Model); $this->_buildRelatedModels($this->Model);
@ -1561,7 +1561,7 @@ class DboSourceTest extends CakeTestCase {
* @return void * @return void
*/ */
function testGenerateAssociationQuerySelfJoinWithConditions() { function testGenerateAssociationQuerySelfJoinWithConditions() {
$this->Model =& new TestModel4(); $this->Model = new TestModel4();
$this->Model->schema(); $this->Model->schema();
$this->_buildRelatedModels($this->Model); $this->_buildRelatedModels($this->Model);
@ -1581,7 +1581,7 @@ class DboSourceTest extends CakeTestCase {
$this->assertPattern('/\s+ON\s+\(`TestModel4`.`parent_id` = `TestModel4Parent`.`id`\)\s+WHERE/', $result); $this->assertPattern('/\s+ON\s+\(`TestModel4`.`parent_id` = `TestModel4Parent`.`id`\)\s+WHERE/', $result);
$this->assertPattern('/\s+WHERE\s+(?:\()?`TestModel4Parent`.`name`\s+!=\s+\'mariano\'(?:\))?\s*$/', $result); $this->assertPattern('/\s+WHERE\s+(?:\()?`TestModel4Parent`.`name`\s+!=\s+\'mariano\'(?:\))?\s*$/', $result);
$this->Featured2 =& new Featured2(); $this->Featured2 = new Featured2();
$this->Featured2->schema(); $this->Featured2->schema();
$this->Featured2->bindModel(array( $this->Featured2->bindModel(array(
@ -1623,7 +1623,7 @@ class DboSourceTest extends CakeTestCase {
* @return void * @return void
*/ */
function testGenerateAssociationQueryHasOne() { function testGenerateAssociationQueryHasOne() {
$this->Model =& new TestModel4(); $this->Model = new TestModel4();
$this->Model->schema(); $this->Model->schema();
$this->_buildRelatedModels($this->Model); $this->_buildRelatedModels($this->Model);
@ -1656,7 +1656,7 @@ class DboSourceTest extends CakeTestCase {
* @return void * @return void
*/ */
function testGenerateAssociationQueryHasOneWithConditions() { function testGenerateAssociationQueryHasOneWithConditions() {
$this->Model =& new TestModel4(); $this->Model = new TestModel4();
$this->Model->schema(); $this->Model->schema();
$this->_buildRelatedModels($this->Model); $this->_buildRelatedModels($this->Model);
@ -1686,7 +1686,7 @@ class DboSourceTest extends CakeTestCase {
* @return void * @return void
*/ */
function testGenerateAssociationQueryBelongsTo() { function testGenerateAssociationQueryBelongsTo() {
$this->Model =& new TestModel5(); $this->Model = new TestModel5();
$this->Model->schema(); $this->Model->schema();
$this->_buildRelatedModels($this->Model); $this->_buildRelatedModels($this->Model);
@ -1718,7 +1718,7 @@ class DboSourceTest extends CakeTestCase {
* @return void * @return void
*/ */
function testGenerateAssociationQueryBelongsToWithConditions() { function testGenerateAssociationQueryBelongsToWithConditions() {
$this->Model =& new TestModel5(); $this->Model = new TestModel5();
$this->Model->schema(); $this->Model->schema();
$this->_buildRelatedModels($this->Model); $this->_buildRelatedModels($this->Model);
@ -1750,7 +1750,7 @@ class DboSourceTest extends CakeTestCase {
* @return void * @return void
*/ */
function testGenerateAssociationQueryHasMany() { function testGenerateAssociationQueryHasMany() {
$this->Model =& new TestModel5(); $this->Model = new TestModel5();
$this->Model->schema(); $this->Model->schema();
$this->_buildRelatedModels($this->Model); $this->_buildRelatedModels($this->Model);
@ -1780,7 +1780,7 @@ class DboSourceTest extends CakeTestCase {
* @return void * @return void
*/ */
function testGenerateAssociationQueryHasManyWithLimit() { function testGenerateAssociationQueryHasManyWithLimit() {
$this->Model =& new TestModel5(); $this->Model = new TestModel5();
$this->Model->schema(); $this->Model->schema();
$this->_buildRelatedModels($this->Model); $this->_buildRelatedModels($this->Model);
@ -1820,7 +1820,7 @@ class DboSourceTest extends CakeTestCase {
* @return void * @return void
*/ */
function testGenerateAssociationQueryHasManyWithConditions() { function testGenerateAssociationQueryHasManyWithConditions() {
$this->Model =& new TestModel5(); $this->Model = new TestModel5();
$this->Model->schema(); $this->Model->schema();
$this->_buildRelatedModels($this->Model); $this->_buildRelatedModels($this->Model);
@ -1849,7 +1849,7 @@ class DboSourceTest extends CakeTestCase {
* @return void * @return void
*/ */
function testGenerateAssociationQueryHasManyWithOffsetAndLimit() { function testGenerateAssociationQueryHasManyWithOffsetAndLimit() {
$this->Model =& new TestModel5(); $this->Model = new TestModel5();
$this->Model->schema(); $this->Model->schema();
$this->_buildRelatedModels($this->Model); $this->_buildRelatedModels($this->Model);
@ -1887,7 +1887,7 @@ class DboSourceTest extends CakeTestCase {
* @return void * @return void
*/ */
function testGenerateAssociationQueryHasManyWithPageAndLimit() { function testGenerateAssociationQueryHasManyWithPageAndLimit() {
$this->Model =& new TestModel5(); $this->Model = new TestModel5();
$this->Model->schema(); $this->Model->schema();
$this->_buildRelatedModels($this->Model); $this->_buildRelatedModels($this->Model);
@ -1924,7 +1924,7 @@ class DboSourceTest extends CakeTestCase {
* @return void * @return void
*/ */
function testGenerateAssociationQueryHasManyWithFields() { function testGenerateAssociationQueryHasManyWithFields() {
$this->Model =& new TestModel5(); $this->Model = new TestModel5();
$this->Model->schema(); $this->Model->schema();
$this->_buildRelatedModels($this->Model); $this->_buildRelatedModels($this->Model);
@ -2050,7 +2050,7 @@ class DboSourceTest extends CakeTestCase {
* @return void * @return void
*/ */
function testGenerateAssociationQueryHasAndBelongsToMany() { function testGenerateAssociationQueryHasAndBelongsToMany() {
$this->Model =& new TestModel4(); $this->Model = new TestModel4();
$this->Model->schema(); $this->Model->schema();
$this->_buildRelatedModels($this->Model); $this->_buildRelatedModels($this->Model);
@ -2059,7 +2059,7 @@ class DboSourceTest extends CakeTestCase {
$resultSet = null; $resultSet = null;
$null = null; $null = null;
$params =& $this->_prepareAssociationQuery($this->Model, $queryData, $binding); $params = $this->_prepareAssociationQuery($this->Model, $queryData, $binding);
$result = $this->testDb->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet); $result = $this->testDb->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet);
$this->assertPattern('/^SELECT\s+`TestModel7`\.`id`, `TestModel7`\.`name`, `TestModel7`\.`created`, `TestModel7`\.`updated`, `TestModel4TestModel7`\.`test_model4_id`, `TestModel4TestModel7`\.`test_model7_id`\s+/', $result); $this->assertPattern('/^SELECT\s+`TestModel7`\.`id`, `TestModel7`\.`name`, `TestModel7`\.`created`, `TestModel7`\.`updated`, `TestModel4TestModel7`\.`test_model4_id`, `TestModel4TestModel7`\.`test_model7_id`\s+/', $result);
@ -2081,7 +2081,7 @@ class DboSourceTest extends CakeTestCase {
* @return void * @return void
*/ */
function testGenerateAssociationQueryHasAndBelongsToManyWithConditions() { function testGenerateAssociationQueryHasAndBelongsToManyWithConditions() {
$this->Model =& new TestModel4(); $this->Model = new TestModel4();
$this->Model->schema(); $this->Model->schema();
$this->_buildRelatedModels($this->Model); $this->_buildRelatedModels($this->Model);
@ -2090,7 +2090,7 @@ class DboSourceTest extends CakeTestCase {
$resultSet = null; $resultSet = null;
$null = null; $null = null;
$params =& $this->_prepareAssociationQuery($this->Model, $queryData, $binding); $params = $this->_prepareAssociationQuery($this->Model, $queryData, $binding);
$result = $this->testDb->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet); $result = $this->testDb->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet);
$this->assertPattern('/^SELECT\s+`TestModel7`\.`id`, `TestModel7`\.`name`, `TestModel7`\.`created`, `TestModel7`\.`updated`, `TestModel4TestModel7`\.`test_model4_id`, `TestModel4TestModel7`\.`test_model7_id`\s+/', $result); $this->assertPattern('/^SELECT\s+`TestModel7`\.`id`, `TestModel7`\.`name`, `TestModel7`\.`created`, `TestModel7`\.`updated`, `TestModel4TestModel7`\.`test_model4_id`, `TestModel4TestModel7`\.`test_model7_id`\s+/', $result);
@ -2110,7 +2110,7 @@ class DboSourceTest extends CakeTestCase {
* @return void * @return void
*/ */
function testGenerateAssociationQueryHasAndBelongsToManyWithOffsetAndLimit() { function testGenerateAssociationQueryHasAndBelongsToManyWithOffsetAndLimit() {
$this->Model =& new TestModel4(); $this->Model = new TestModel4();
$this->Model->schema(); $this->Model->schema();
$this->_buildRelatedModels($this->Model); $this->_buildRelatedModels($this->Model);
@ -2147,7 +2147,7 @@ class DboSourceTest extends CakeTestCase {
* @return void * @return void
*/ */
function testGenerateAssociationQueryHasAndBelongsToManyWithPageAndLimit() { function testGenerateAssociationQueryHasAndBelongsToManyWithPageAndLimit() {
$this->Model =& new TestModel4(); $this->Model = new TestModel4();
$this->Model->schema(); $this->Model->schema();
$this->_buildRelatedModels($this->Model); $this->_buildRelatedModels($this->Model);
@ -2192,7 +2192,7 @@ class DboSourceTest extends CakeTestCase {
} elseif (isset($assocData['className'])) { } elseif (isset($assocData['className'])) {
$className = $assocData['className']; $className = $assocData['className'];
} }
$model->$className =& new $className(); $model->$className = new $className();
$model->$className->schema(); $model->$className->schema();
} }
} }
@ -2213,7 +2213,7 @@ class DboSourceTest extends CakeTestCase {
$assocData = $model->{$type}[$assoc]; $assocData = $model->{$type}[$assoc];
$className = $assocData['className']; $className = $assocData['className'];
$linkModel =& $model->{$className}; $linkModel = $model->{$className};
$external = isset($assocData['external']); $external = isset($assocData['external']);
$queryData = $this->testDb->__scrubQueryData($queryData); $queryData = $this->testDb->__scrubQueryData($queryData);
@ -2506,6 +2506,7 @@ class DboSourceTest extends CakeTestCase {
* @return void * @return void
*/ */
function testArrayConditionsParsing() { function testArrayConditionsParsing() {
$this->loadFixtures('Post', 'Author');
$result = $this->testDb->conditions(array('Stereo.type' => 'in dash speakers')); $result = $this->testDb->conditions(array('Stereo.type' => 'in dash speakers'));
$this->assertPattern("/^\s+WHERE\s+`Stereo`.`type`\s+=\s+'in dash speakers'/", $result); $this->assertPattern("/^\s+WHERE\s+`Stereo`.`type`\s+=\s+'in dash speakers'/", $result);
@ -2800,7 +2801,7 @@ class DboSourceTest extends CakeTestCase {
* @return void * @return void
*/ */
function testConditionsWithModel() { function testConditionsWithModel() {
$this->Model =& new Article2(); $this->Model = new Article2();
$result = $this->testDb->conditions(array('Article2.viewed >=' => 0), true, true, $this->Model); $result = $this->testDb->conditions(array('Article2.viewed >=' => 0), true, true, $this->Model);
$expected = " WHERE `Article2`.`viewed` >= 0"; $expected = " WHERE `Article2`.`viewed` >= 0";
@ -3273,7 +3274,8 @@ class DboSourceTest extends CakeTestCase {
* @return void * @return void
*/ */
function testStatements() { function testStatements() {
$Article =& ClassRegistry::init('Article'); $this->loadFixtures('Article', 'User', 'Comment', 'Tag');
$Article = new Article();
$result = $this->testDb->update($Article, array('field1'), array('value1')); $result = $this->testDb->update($Article, array('field1'), array('value1'));
$this->assertFalse($result); $this->assertFalse($result);
@ -3304,7 +3306,7 @@ class DboSourceTest extends CakeTestCase {
$this->assertFalse($result); $this->assertFalse($result);
$result = $this->testDb->insertMulti('articles', array('field'), array('(1)', '(2)')); $result = $this->testDb->insertMulti('articles', array('field'), array('(1)', '(2)'));
$this->assertFalse($result); $this->assertNull($result);
$result = $this->testDb->getLastQuery(); $result = $this->testDb->getLastQuery();
$this->assertPattern('/^\s*INSERT INTO\s+' . $this->testDb->fullTableName('articles') . '\s+\(`field`\)\s+VALUES\s+\(1\),\s*\(2\)\s*$/', $result); $this->assertPattern('/^\s*INSERT INTO\s+' . $this->testDb->fullTableName('articles') . '\s+\(`field`\)\s+VALUES\s+\(1\),\s*\(2\)\s*$/', $result);
} }
@ -3316,7 +3318,7 @@ class DboSourceTest extends CakeTestCase {
* @return void * @return void
*/ */
function testSchema() { function testSchema() {
$Schema =& new CakeSchema(); $Schema = new CakeSchema();
$Schema->tables = array('table' => array(), 'anotherTable' => array()); $Schema->tables = array('table' => array(), 'anotherTable' => array());
$this->expectError(); $this->expectError();
@ -3802,7 +3804,7 @@ class DboSourceTest extends CakeTestCase {
// EMPTY STRING // EMPTY STRING
$result = $this->testDb->value('', 'boolean'); $result = $this->testDb->value('', 'boolean');
$this->assertEqual($result, "NULL"); $this->assertEqual($result, 0);
// BOOLEAN // BOOLEAN
@ -3927,10 +3929,10 @@ class DboSourceTest extends CakeTestCase {
* @return void * @return void
*/ */
function testRealQueries() { function testRealQueries() {
$this->loadFixtures('Apple', 'Article', 'User', 'Comment', 'Tag'); $this->loadFixtures('Apple', 'Article', 'User', 'Comment', 'Tag', 'Sample');
$Apple =& ClassRegistry::init('Apple'); $Apple = ClassRegistry::init('Apple');
$Article =& ClassRegistry::init('Article'); $Article = ClassRegistry::init('Article');
$result = $this->db->rawQuery('SELECT color, name FROM ' . $this->db->fullTableName('apples')); $result = $this->db->rawQuery('SELECT color, name FROM ' . $this->db->fullTableName('apples'));
$this->assertTrue(!empty($result)); $this->assertTrue(!empty($result));
@ -4159,8 +4161,6 @@ class DboSourceTest extends CakeTestCase {
*/ */
function testExecute() { function testExecute() {
$query = 'SELECT * FROM ' . $this->testDb->fullTableName('articles') . ' WHERE 1 = 1'; $query = 'SELECT * FROM ' . $this->testDb->fullTableName('articles') . ' WHERE 1 = 1';
$this->db->_result = null;
$this->db->took = null; $this->db->took = null;
$this->db->affected = null; $this->db->affected = null;
$result = $this->db->execute($query, array('stats' => false)); $result = $this->db->execute($query, array('stats' => false));
@ -4224,7 +4224,7 @@ class DboSourceTest extends CakeTestCase {
function testVirtualFields() { function testVirtualFields() {
$this->loadFixtures('Article'); $this->loadFixtures('Article');
$Article =& ClassRegistry::init('Article'); $Article = ClassRegistry::init('Article');
$Article->virtualFields = array( $Article->virtualFields = array(
'this_moment' => 'NOW()', 'this_moment' => 'NOW()',
'two' => '1 + 1', 'two' => '1 + 1',
@ -4294,7 +4294,7 @@ class DboSourceTest extends CakeTestCase {
function testVirtualFieldsInConditions() { function testVirtualFieldsInConditions() {
$this->loadFixtures('Article'); $this->loadFixtures('Article');
$Article =& ClassRegistry::init('Article'); $Article = ClassRegistry::init('Article');
$Article->virtualFields = array( $Article->virtualFields = array(
'this_moment' => 'NOW()', 'this_moment' => 'NOW()',
'two' => '1 + 1', 'two' => '1 + 1',
@ -4330,7 +4330,7 @@ class DboSourceTest extends CakeTestCase {
function testVirtualFieldsInOrder() { function testVirtualFieldsInOrder() {
$this->loadFixtures('Article'); $this->loadFixtures('Article');
$Article =& ClassRegistry::init('Article'); $Article = ClassRegistry::init('Article');
$Article->virtualFields = array( $Article->virtualFields = array(
'this_moment' => 'NOW()', 'this_moment' => 'NOW()',
'two' => '1 + 1', 'two' => '1 + 1',
@ -4349,7 +4349,7 @@ class DboSourceTest extends CakeTestCase {
function testVirtualFieldsInCalculate() { function testVirtualFieldsInCalculate() {
$this->loadFixtures('Article'); $this->loadFixtures('Article');
$Article =& ClassRegistry::init('Article'); $Article = ClassRegistry::init('Article');
$Article->virtualFields = array( $Article->virtualFields = array(
'this_moment' => 'NOW()', 'this_moment' => 'NOW()',
'two' => '1 + 1', 'two' => '1 + 1',
@ -4374,7 +4374,7 @@ class DboSourceTest extends CakeTestCase {
function testVirtualFieldsFetch() { function testVirtualFieldsFetch() {
$this->loadFixtures('Article', 'Comment'); $this->loadFixtures('Article', 'Comment');
$Article =& ClassRegistry::init('Article'); $Article = ClassRegistry::init('Article');
$Article->virtualFields = array( $Article->virtualFields = array(
'comment_count' => 'SELECT COUNT(*) FROM ' . $this->db->fullTableName('comments') . 'comment_count' => 'SELECT COUNT(*) FROM ' . $this->db->fullTableName('comments') .
' WHERE Article.id = ' . $this->db->fullTableName('comments') . '.article_id' ' WHERE Article.id = ' . $this->db->fullTableName('comments') . '.article_id'
@ -4397,13 +4397,13 @@ class DboSourceTest extends CakeTestCase {
*/ */
function testVirtualFieldsInGroup() { function testVirtualFieldsInGroup() {
$this->loadFixtures('Article'); $this->loadFixtures('Article');
$Article = new Article();
$Article =& ClassRegistry::init('Article');
$Article->virtualFields = array( $Article->virtualFields = array(
'this_year' => 'YEAR(Article.created)' 'this_year' => 'YEAR(Article.created)'
); );
$result = $this->db->group('this_year',$Article); $result = $this->db->group('this_year', $Article);
$expected = " GROUP BY (YEAR(`Article`.`created`))"; $expected = " GROUP BY (YEAR(`Article`.`created`))";
$this->assertEqual($expected, $result); $this->assertEqual($expected, $result);
} }