mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 02:56:15 +00:00
Migrating DboSourceTest to PHPUnit
This commit is contained in:
parent
fa1ae280ca
commit
9b3df1ea0e
1 changed files with 57 additions and 57 deletions
|
@ -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->startQuote = '`';
|
||||
$this->testDb->endQuote = '`';
|
||||
Configure::write('debug', 1);
|
||||
$this->debug = Configure::read('debug');
|
||||
$this->Model =& new TestModel();
|
||||
$this->Model = new TestModel();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1350,10 +1350,10 @@ class DboSourceTest extends CakeTestCase {
|
|||
*/
|
||||
function testFieldDoubleEscaping() {
|
||||
$config = array_merge($this->__config, array('driver' => 'test'));
|
||||
$test =& ConnectionManager::create('quoteTest', $config);
|
||||
$test = ConnectionManager::create('quoteTest', $config);
|
||||
$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->assertEqual($this->Model->escapeField(), '`Article`.`id`');
|
||||
|
@ -1392,26 +1392,26 @@ class DboSourceTest extends CakeTestCase {
|
|||
*/
|
||||
function testGenerateAssociationQuerySelfJoin() {
|
||||
$this->startTime = microtime(true);
|
||||
$this->Model =& new Article2();
|
||||
$this->Model = new Article2();
|
||||
$this->_buildRelatedModels($this->Model);
|
||||
$this->_buildRelatedModels($this->Model->Category2);
|
||||
$this->Model->Category2->ChildCat =& new Category2();
|
||||
$this->Model->Category2->ParentCat =& new Category2();
|
||||
$this->Model->Category2->ChildCat = new Category2();
|
||||
$this->Model->Category2->ParentCat = new Category2();
|
||||
|
||||
$queryData = array();
|
||||
|
||||
foreach ($this->Model->Category2->associations() as $type) {
|
||||
foreach ($this->Model->Category2->{$type} as $assoc => $assocData) {
|
||||
$linkModel =& $this->Model->Category2->{$assoc};
|
||||
$linkModel = $this->Model->Category2->{$assoc};
|
||||
$external = isset($assocData['external']);
|
||||
|
||||
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);
|
||||
$this->assertTrue($result);
|
||||
$this->assertFalse(empty($result));
|
||||
} else {
|
||||
if ($this->Model->Category2->useDbConfig == $linkModel->useDbConfig) {
|
||||
$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);
|
||||
$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->_buildRelatedModels($this->Model);
|
||||
|
||||
|
@ -1436,6 +1436,7 @@ class DboSourceTest extends CakeTestCase {
|
|||
$this->assertTrue($result);
|
||||
|
||||
$expected = array(
|
||||
'conditions' => array(),
|
||||
'fields' => array(
|
||||
'`TestModel4`.`id`',
|
||||
'`TestModel4`.`name`',
|
||||
|
@ -1454,11 +1455,10 @@ class DboSourceTest extends CakeTestCase {
|
|||
'conditions' => '`TestModel4`.`parent_id` = `TestModel4Parent`.`id`'
|
||||
)
|
||||
),
|
||||
'order' => array(),
|
||||
'limit' => array(),
|
||||
'offset' => array(),
|
||||
'conditions' => array(),
|
||||
'order' => array(),
|
||||
'group' => null
|
||||
'group' => array()
|
||||
);
|
||||
$this->assertEqual($queryData, $expected);
|
||||
|
||||
|
@ -1482,10 +1482,10 @@ class DboSourceTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
function testGenerateInnerJoinAssociationQuery() {
|
||||
$this->Model =& new TestModel9();
|
||||
$test =& ConnectionManager::create('test2', $this->__config);
|
||||
$this->Model = new TestModel9();
|
||||
$test = ConnectionManager::create('test2', $this->__config);
|
||||
$this->Model->setDataSource('test2');
|
||||
$this->Model->TestModel8 =& new TestModel8();
|
||||
$this->Model->TestModel8 = new TestModel8();
|
||||
$this->Model->TestModel8->setDataSource('test2');
|
||||
|
||||
$this->testDb->read($this->Model, array('recursive' => 1));
|
||||
|
@ -1506,7 +1506,7 @@ class DboSourceTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
function testGenerateAssociationQuerySelfJoinWithConditionsInHasOneBinding() {
|
||||
$this->Model =& new TestModel8();
|
||||
$this->Model = new TestModel8();
|
||||
$this->Model->schema();
|
||||
$this->_buildRelatedModels($this->Model);
|
||||
|
||||
|
@ -1534,7 +1534,7 @@ class DboSourceTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
function testGenerateAssociationQuerySelfJoinWithConditionsInBelongsToBinding() {
|
||||
$this->Model =& new TestModel9();
|
||||
$this->Model = new TestModel9();
|
||||
$this->Model->schema();
|
||||
$this->_buildRelatedModels($this->Model);
|
||||
|
||||
|
@ -1561,7 +1561,7 @@ class DboSourceTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
function testGenerateAssociationQuerySelfJoinWithConditions() {
|
||||
$this->Model =& new TestModel4();
|
||||
$this->Model = new TestModel4();
|
||||
$this->Model->schema();
|
||||
$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+WHERE\s+(?:\()?`TestModel4Parent`.`name`\s+!=\s+\'mariano\'(?:\))?\s*$/', $result);
|
||||
|
||||
$this->Featured2 =& new Featured2();
|
||||
$this->Featured2 = new Featured2();
|
||||
$this->Featured2->schema();
|
||||
|
||||
$this->Featured2->bindModel(array(
|
||||
|
@ -1623,7 +1623,7 @@ class DboSourceTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
function testGenerateAssociationQueryHasOne() {
|
||||
$this->Model =& new TestModel4();
|
||||
$this->Model = new TestModel4();
|
||||
$this->Model->schema();
|
||||
$this->_buildRelatedModels($this->Model);
|
||||
|
||||
|
@ -1656,7 +1656,7 @@ class DboSourceTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
function testGenerateAssociationQueryHasOneWithConditions() {
|
||||
$this->Model =& new TestModel4();
|
||||
$this->Model = new TestModel4();
|
||||
$this->Model->schema();
|
||||
$this->_buildRelatedModels($this->Model);
|
||||
|
||||
|
@ -1686,7 +1686,7 @@ class DboSourceTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
function testGenerateAssociationQueryBelongsTo() {
|
||||
$this->Model =& new TestModel5();
|
||||
$this->Model = new TestModel5();
|
||||
$this->Model->schema();
|
||||
$this->_buildRelatedModels($this->Model);
|
||||
|
||||
|
@ -1718,7 +1718,7 @@ class DboSourceTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
function testGenerateAssociationQueryBelongsToWithConditions() {
|
||||
$this->Model =& new TestModel5();
|
||||
$this->Model = new TestModel5();
|
||||
$this->Model->schema();
|
||||
$this->_buildRelatedModels($this->Model);
|
||||
|
||||
|
@ -1750,7 +1750,7 @@ class DboSourceTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
function testGenerateAssociationQueryHasMany() {
|
||||
$this->Model =& new TestModel5();
|
||||
$this->Model = new TestModel5();
|
||||
$this->Model->schema();
|
||||
$this->_buildRelatedModels($this->Model);
|
||||
|
||||
|
@ -1780,7 +1780,7 @@ class DboSourceTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
function testGenerateAssociationQueryHasManyWithLimit() {
|
||||
$this->Model =& new TestModel5();
|
||||
$this->Model = new TestModel5();
|
||||
$this->Model->schema();
|
||||
$this->_buildRelatedModels($this->Model);
|
||||
|
||||
|
@ -1820,7 +1820,7 @@ class DboSourceTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
function testGenerateAssociationQueryHasManyWithConditions() {
|
||||
$this->Model =& new TestModel5();
|
||||
$this->Model = new TestModel5();
|
||||
$this->Model->schema();
|
||||
$this->_buildRelatedModels($this->Model);
|
||||
|
||||
|
@ -1849,7 +1849,7 @@ class DboSourceTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
function testGenerateAssociationQueryHasManyWithOffsetAndLimit() {
|
||||
$this->Model =& new TestModel5();
|
||||
$this->Model = new TestModel5();
|
||||
$this->Model->schema();
|
||||
$this->_buildRelatedModels($this->Model);
|
||||
|
||||
|
@ -1887,7 +1887,7 @@ class DboSourceTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
function testGenerateAssociationQueryHasManyWithPageAndLimit() {
|
||||
$this->Model =& new TestModel5();
|
||||
$this->Model = new TestModel5();
|
||||
$this->Model->schema();
|
||||
$this->_buildRelatedModels($this->Model);
|
||||
|
||||
|
@ -1924,7 +1924,7 @@ class DboSourceTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
function testGenerateAssociationQueryHasManyWithFields() {
|
||||
$this->Model =& new TestModel5();
|
||||
$this->Model = new TestModel5();
|
||||
$this->Model->schema();
|
||||
$this->_buildRelatedModels($this->Model);
|
||||
|
||||
|
@ -2050,7 +2050,7 @@ class DboSourceTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
function testGenerateAssociationQueryHasAndBelongsToMany() {
|
||||
$this->Model =& new TestModel4();
|
||||
$this->Model = new TestModel4();
|
||||
$this->Model->schema();
|
||||
$this->_buildRelatedModels($this->Model);
|
||||
|
||||
|
@ -2059,7 +2059,7 @@ class DboSourceTest extends CakeTestCase {
|
|||
$resultSet = 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);
|
||||
$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
|
||||
*/
|
||||
function testGenerateAssociationQueryHasAndBelongsToManyWithConditions() {
|
||||
$this->Model =& new TestModel4();
|
||||
$this->Model = new TestModel4();
|
||||
$this->Model->schema();
|
||||
$this->_buildRelatedModels($this->Model);
|
||||
|
||||
|
@ -2090,7 +2090,7 @@ class DboSourceTest extends CakeTestCase {
|
|||
$resultSet = 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);
|
||||
$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
|
||||
*/
|
||||
function testGenerateAssociationQueryHasAndBelongsToManyWithOffsetAndLimit() {
|
||||
$this->Model =& new TestModel4();
|
||||
$this->Model = new TestModel4();
|
||||
$this->Model->schema();
|
||||
$this->_buildRelatedModels($this->Model);
|
||||
|
||||
|
@ -2147,7 +2147,7 @@ class DboSourceTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
function testGenerateAssociationQueryHasAndBelongsToManyWithPageAndLimit() {
|
||||
$this->Model =& new TestModel4();
|
||||
$this->Model = new TestModel4();
|
||||
$this->Model->schema();
|
||||
$this->_buildRelatedModels($this->Model);
|
||||
|
||||
|
@ -2192,7 +2192,7 @@ class DboSourceTest extends CakeTestCase {
|
|||
} elseif (isset($assocData['className'])) {
|
||||
$className = $assocData['className'];
|
||||
}
|
||||
$model->$className =& new $className();
|
||||
$model->$className = new $className();
|
||||
$model->$className->schema();
|
||||
}
|
||||
}
|
||||
|
@ -2213,7 +2213,7 @@ class DboSourceTest extends CakeTestCase {
|
|||
$assocData = $model->{$type}[$assoc];
|
||||
$className = $assocData['className'];
|
||||
|
||||
$linkModel =& $model->{$className};
|
||||
$linkModel = $model->{$className};
|
||||
$external = isset($assocData['external']);
|
||||
$queryData = $this->testDb->__scrubQueryData($queryData);
|
||||
|
||||
|
@ -2506,6 +2506,7 @@ class DboSourceTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
function testArrayConditionsParsing() {
|
||||
$this->loadFixtures('Post', 'Author');
|
||||
$result = $this->testDb->conditions(array('Stereo.type' => 'in dash speakers'));
|
||||
$this->assertPattern("/^\s+WHERE\s+`Stereo`.`type`\s+=\s+'in dash speakers'/", $result);
|
||||
|
||||
|
@ -2800,7 +2801,7 @@ class DboSourceTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
function testConditionsWithModel() {
|
||||
$this->Model =& new Article2();
|
||||
$this->Model = new Article2();
|
||||
|
||||
$result = $this->testDb->conditions(array('Article2.viewed >=' => 0), true, true, $this->Model);
|
||||
$expected = " WHERE `Article2`.`viewed` >= 0";
|
||||
|
@ -3273,7 +3274,8 @@ class DboSourceTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
function testStatements() {
|
||||
$Article =& ClassRegistry::init('Article');
|
||||
$this->loadFixtures('Article', 'User', 'Comment', 'Tag');
|
||||
$Article = new Article();
|
||||
|
||||
$result = $this->testDb->update($Article, array('field1'), array('value1'));
|
||||
$this->assertFalse($result);
|
||||
|
@ -3304,7 +3306,7 @@ class DboSourceTest extends CakeTestCase {
|
|||
$this->assertFalse($result);
|
||||
|
||||
$result = $this->testDb->insertMulti('articles', array('field'), array('(1)', '(2)'));
|
||||
$this->assertFalse($result);
|
||||
$this->assertNull($result);
|
||||
$result = $this->testDb->getLastQuery();
|
||||
$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
|
||||
*/
|
||||
function testSchema() {
|
||||
$Schema =& new CakeSchema();
|
||||
$Schema = new CakeSchema();
|
||||
$Schema->tables = array('table' => array(), 'anotherTable' => array());
|
||||
|
||||
$this->expectError();
|
||||
|
@ -3802,7 +3804,7 @@ class DboSourceTest extends CakeTestCase {
|
|||
|
||||
// EMPTY STRING
|
||||
$result = $this->testDb->value('', 'boolean');
|
||||
$this->assertEqual($result, "NULL");
|
||||
$this->assertEqual($result, 0);
|
||||
|
||||
|
||||
// BOOLEAN
|
||||
|
@ -3927,10 +3929,10 @@ class DboSourceTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
function testRealQueries() {
|
||||
$this->loadFixtures('Apple', 'Article', 'User', 'Comment', 'Tag');
|
||||
$this->loadFixtures('Apple', 'Article', 'User', 'Comment', 'Tag', 'Sample');
|
||||
|
||||
$Apple =& ClassRegistry::init('Apple');
|
||||
$Article =& ClassRegistry::init('Article');
|
||||
$Apple = ClassRegistry::init('Apple');
|
||||
$Article = ClassRegistry::init('Article');
|
||||
|
||||
$result = $this->db->rawQuery('SELECT color, name FROM ' . $this->db->fullTableName('apples'));
|
||||
$this->assertTrue(!empty($result));
|
||||
|
@ -4159,8 +4161,6 @@ class DboSourceTest extends CakeTestCase {
|
|||
*/
|
||||
function testExecute() {
|
||||
$query = 'SELECT * FROM ' . $this->testDb->fullTableName('articles') . ' WHERE 1 = 1';
|
||||
|
||||
$this->db->_result = null;
|
||||
$this->db->took = null;
|
||||
$this->db->affected = null;
|
||||
$result = $this->db->execute($query, array('stats' => false));
|
||||
|
@ -4224,7 +4224,7 @@ class DboSourceTest extends CakeTestCase {
|
|||
function testVirtualFields() {
|
||||
$this->loadFixtures('Article');
|
||||
|
||||
$Article =& ClassRegistry::init('Article');
|
||||
$Article = ClassRegistry::init('Article');
|
||||
$Article->virtualFields = array(
|
||||
'this_moment' => 'NOW()',
|
||||
'two' => '1 + 1',
|
||||
|
@ -4294,7 +4294,7 @@ class DboSourceTest extends CakeTestCase {
|
|||
function testVirtualFieldsInConditions() {
|
||||
$this->loadFixtures('Article');
|
||||
|
||||
$Article =& ClassRegistry::init('Article');
|
||||
$Article = ClassRegistry::init('Article');
|
||||
$Article->virtualFields = array(
|
||||
'this_moment' => 'NOW()',
|
||||
'two' => '1 + 1',
|
||||
|
@ -4330,7 +4330,7 @@ class DboSourceTest extends CakeTestCase {
|
|||
function testVirtualFieldsInOrder() {
|
||||
$this->loadFixtures('Article');
|
||||
|
||||
$Article =& ClassRegistry::init('Article');
|
||||
$Article = ClassRegistry::init('Article');
|
||||
$Article->virtualFields = array(
|
||||
'this_moment' => 'NOW()',
|
||||
'two' => '1 + 1',
|
||||
|
@ -4349,7 +4349,7 @@ class DboSourceTest extends CakeTestCase {
|
|||
function testVirtualFieldsInCalculate() {
|
||||
$this->loadFixtures('Article');
|
||||
|
||||
$Article =& ClassRegistry::init('Article');
|
||||
$Article = ClassRegistry::init('Article');
|
||||
$Article->virtualFields = array(
|
||||
'this_moment' => 'NOW()',
|
||||
'two' => '1 + 1',
|
||||
|
@ -4374,7 +4374,7 @@ class DboSourceTest extends CakeTestCase {
|
|||
function testVirtualFieldsFetch() {
|
||||
$this->loadFixtures('Article', 'Comment');
|
||||
|
||||
$Article =& ClassRegistry::init('Article');
|
||||
$Article = ClassRegistry::init('Article');
|
||||
$Article->virtualFields = array(
|
||||
'comment_count' => 'SELECT COUNT(*) FROM ' . $this->db->fullTableName('comments') .
|
||||
' WHERE Article.id = ' . $this->db->fullTableName('comments') . '.article_id'
|
||||
|
@ -4397,13 +4397,13 @@ class DboSourceTest extends CakeTestCase {
|
|||
*/
|
||||
function testVirtualFieldsInGroup() {
|
||||
$this->loadFixtures('Article');
|
||||
|
||||
$Article =& ClassRegistry::init('Article');
|
||||
$Article = new Article();
|
||||
$Article->virtualFields = array(
|
||||
'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`))";
|
||||
$this->assertEqual($expected, $result);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue