mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-18 18:46:17 +00:00
Adding tests for automatic addition of ids in hasMany
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@4828 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
dcf64033ed
commit
e9d7d60292
1 changed files with 57 additions and 0 deletions
|
@ -953,6 +953,63 @@ class DboSourceTest extends UnitTestCase {
|
|||
$this->assertPattern('/\s+FROM\s+`test_model5` AS `TestModel5`\s+WHERE\s+/', $result);
|
||||
$this->assertPattern('/\s+WHERE\s+(?:\()?`TestModel5`.`name`\s+!=\s+\'mariano\'(?:\))?\s*$/', $result);
|
||||
}
|
||||
|
||||
function testGenerateAssociationQueryHasManyWithFields() {
|
||||
$this->model = new TestModel5();
|
||||
$this->model->loadInfo();
|
||||
$this->_buildRelatedModels($this->model);
|
||||
|
||||
$binding = array('type' => 'hasMany', 'model' => 'TestModel6');
|
||||
$queryData = array('fields' => array('`TestModel5`.`name`'));
|
||||
$resultSet = null;
|
||||
$null = null;
|
||||
|
||||
$params = &$this->_prepareAssociationQuery($this->model, $queryData, $binding);
|
||||
|
||||
$result = $this->db->generateAssociationQuery($this->model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet);
|
||||
$this->assertPattern('/^SELECT\s+`TestModel6`\.`id`, `TestModel6`\.`test_model5_id`, `TestModel6`\.`name`, `TestModel6`\.`created`, `TestModel6`\.`updated`\s+/', $result);
|
||||
$this->assertPattern('/\s+FROM\s+`test_model6` AS `TestModel6`\s+WHERE\s+/', $result);
|
||||
$this->assertPattern('/WHERE\s+(?:\()?`TestModel6`\.`test_model5_id`\s+IN\s+\({\$__cakeID__\$}\)(?:\))?/', $result);
|
||||
|
||||
$result = $this->db->generateAssociationQuery($this->model, $null, null, null, null, $queryData, false, $null);
|
||||
$this->assertPattern('/^SELECT\s+`TestModel5`\.`id`, `TestModel5`\.`name`\s+/', $result);
|
||||
$this->assertPattern('/\s+FROM\s+`test_model5` AS `TestModel5`\s+WHERE\s+/', $result);
|
||||
$this->assertPattern('/\s+WHERE\s+(?:\()?1\s+=\s+1(?:\))?\s*$/', $result);
|
||||
|
||||
$binding = array('type' => 'hasMany', 'model' => 'TestModel6');
|
||||
$queryData = array('fields' => array('`TestModel5`.`id`, `TestModel5`.`name`'));
|
||||
$resultSet = null;
|
||||
$null = null;
|
||||
|
||||
$params = &$this->_prepareAssociationQuery($this->model, $queryData, $binding);
|
||||
|
||||
$result = $this->db->generateAssociationQuery($this->model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet);
|
||||
$this->assertPattern('/^SELECT\s+`TestModel6`\.`id`, `TestModel6`\.`test_model5_id`, `TestModel6`\.`name`, `TestModel6`\.`created`, `TestModel6`\.`updated`\s+/', $result);
|
||||
$this->assertPattern('/\s+FROM\s+`test_model6` AS `TestModel6`\s+WHERE\s+/', $result);
|
||||
$this->assertPattern('/WHERE\s+(?:\()?`TestModel6`\.`test_model5_id`\s+IN\s+\({\$__cakeID__\$}\)(?:\))?/', $result);
|
||||
|
||||
$result = $this->db->generateAssociationQuery($this->model, $null, null, null, null, $queryData, false, $null);
|
||||
$this->assertPattern('/^SELECT\s+`TestModel5`\.`id`, `TestModel5`\.`name`\s+/', $result);
|
||||
$this->assertPattern('/\s+FROM\s+`test_model5` AS `TestModel5`\s+WHERE\s+/', $result);
|
||||
$this->assertPattern('/\s+WHERE\s+(?:\()?1\s+=\s+1(?:\))?\s*$/', $result);
|
||||
|
||||
$binding = array('type' => 'hasMany', 'model' => 'TestModel6');
|
||||
$queryData = array('fields' => array('`TestModel5`.`name`', '`TestModel5`.`created`'));
|
||||
$resultSet = null;
|
||||
$null = null;
|
||||
|
||||
$params = &$this->_prepareAssociationQuery($this->model, $queryData, $binding);
|
||||
|
||||
$result = $this->db->generateAssociationQuery($this->model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet);
|
||||
$this->assertPattern('/^SELECT\s+`TestModel6`\.`id`, `TestModel6`\.`test_model5_id`, `TestModel6`\.`name`, `TestModel6`\.`created`, `TestModel6`\.`updated`\s+/', $result);
|
||||
$this->assertPattern('/\s+FROM\s+`test_model6` AS `TestModel6`\s+WHERE\s+/', $result);
|
||||
$this->assertPattern('/WHERE\s+(?:\()?`TestModel6`\.`test_model5_id`\s+IN\s+\({\$__cakeID__\$}\)(?:\))?/', $result);
|
||||
|
||||
$result = $this->db->generateAssociationQuery($this->model, $null, null, null, null, $queryData, false, $null);
|
||||
$this->assertPattern('/^SELECT\s+`TestModel5`\.`id`, `TestModel5`\.`name`, `TestModel5`\.`created`\s+/', $result);
|
||||
$this->assertPattern('/\s+FROM\s+`test_model5` AS `TestModel5`\s+WHERE\s+/', $result);
|
||||
$this->assertPattern('/\s+WHERE\s+(?:\()?1\s+=\s+1(?:\))?\s*$/', $result);
|
||||
}
|
||||
|
||||
function testGenerateAssociationQueryHasAndBelongsToMany() {
|
||||
$this->model = new TestModel4();
|
||||
|
|
Loading…
Add table
Reference in a new issue