@@ 1452-1474 (lines=23) @@ | ||
1449 | * |
|
1450 | * @return void |
|
1451 | */ |
|
1452 | public function testGenerateAssociationQueryHasOneWithConditions() { |
|
1453 | $this->Model = new TestModel4(); |
|
1454 | $this->Model->schema(); |
|
1455 | $this->_buildRelatedModels($this->Model); |
|
1456 | ||
1457 | $binding = array('type' => 'hasOne', 'model' => 'TestModel5'); |
|
1458 | ||
1459 | $queryData = array('conditions' => array('TestModel5.name !=' => 'mariano')); |
|
1460 | $resultSet = null; |
|
1461 | $null = null; |
|
1462 | ||
1463 | $params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding); |
|
1464 | ||
1465 | $result = $this->Dbo->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet); |
|
1466 | $this->assertTrue($result); |
|
1467 | ||
1468 | $result = $this->Dbo->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null); |
|
1469 | ||
1470 | $this->assertRegExp('/^SELECT\s+`TestModel4`\.`id`, `TestModel4`\.`name`, `TestModel4`\.`created`, `TestModel4`\.`updated`, `TestModel5`\.`id`, `TestModel5`\.`test_model4_id`, `TestModel5`\.`name`, `TestModel5`\.`created`, `TestModel5`\.`updated`\s+/', $result); |
|
1471 | $this->assertRegExp('/\s+FROM\s+\S+`test_model4` AS `TestModel4`\s+LEFT JOIN\s+\S+`test_model5` AS `TestModel5`/', $result); |
|
1472 | $this->assertRegExp('/\s+ON\s+\(`TestModel5`.`test_model4_id`\s+=\s+`TestModel4`.`id`\)\s+WHERE/', $result); |
|
1473 | $this->assertRegExp('/\s+WHERE\s+(?:\()?\s*`TestModel5`.`name`\s+!=\s+\'mariano\'\s*(?:\))?\s*$/', $result); |
|
1474 | } |
|
1475 | ||
1476 | /** |
|
1477 | * testGenerateAssociationQueryBelongsTo method |
|
@@ 1545-1567 (lines=23) @@ | ||
1542 | * |
|
1543 | * @return void |
|
1544 | */ |
|
1545 | public function testGenerateAssociationQueryHasMany() { |
|
1546 | $this->Model = new TestModel5(); |
|
1547 | $this->Model->schema(); |
|
1548 | $this->_buildRelatedModels($this->Model); |
|
1549 | ||
1550 | $binding = array('type' => 'hasMany', 'model' => 'TestModel6'); |
|
1551 | $queryData = array(); |
|
1552 | $resultSet = null; |
|
1553 | $null = null; |
|
1554 | ||
1555 | $params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding); |
|
1556 | ||
1557 | $result = $this->Dbo->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet); |
|
1558 | ||
1559 | $this->assertRegExp('/^SELECT\s+`TestModel6`\.`id`, `TestModel6`\.`test_model5_id`, `TestModel6`\.`name`, `TestModel6`\.`created`, `TestModel6`\.`updated`\s+/', $result); |
|
1560 | $this->assertRegExp('/\s+FROM\s+\S+`test_model6` AS `TestModel6`\s+WHERE/', $result); |
|
1561 | $this->assertRegExp('/\s+WHERE\s+`TestModel6`.`test_model5_id`\s+=\s+\({\$__cakeID__\$}\)/', $result); |
|
1562 | ||
1563 | $result = $this->Dbo->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null); |
|
1564 | $this->assertRegExp('/^SELECT\s+`TestModel5`\.`id`, `TestModel5`\.`test_model4_id`, `TestModel5`\.`name`, `TestModel5`\.`created`, `TestModel5`\.`updated`\s+/', $result); |
|
1565 | $this->assertRegExp('/\s+FROM\s+\S+`test_model5` AS `TestModel5`\s+WHERE\s+/', $result); |
|
1566 | $this->assertRegExp('/\s+WHERE\s+(?:\()?\s*1 = 1\s*(?:\))?\s*$/', $result); |
|
1567 | } |
|
1568 | ||
1569 | /** |
|
1570 | * testGenerateAssociationQueryHasManyWithLimit method |
|
@@ 1613-1634 (lines=22) @@ | ||
1610 | * |
|
1611 | * @return void |
|
1612 | */ |
|
1613 | public function testGenerateAssociationQueryHasManyWithConditions() { |
|
1614 | $this->Model = new TestModel5(); |
|
1615 | $this->Model->schema(); |
|
1616 | $this->_buildRelatedModels($this->Model); |
|
1617 | ||
1618 | $binding = array('type' => 'hasMany', 'model' => 'TestModel6'); |
|
1619 | $queryData = array('conditions' => array('TestModel5.name !=' => 'mariano')); |
|
1620 | $resultSet = null; |
|
1621 | $null = null; |
|
1622 | ||
1623 | $params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding); |
|
1624 | ||
1625 | $result = $this->Dbo->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet); |
|
1626 | $this->assertRegExp('/^SELECT\s+`TestModel6`\.`id`, `TestModel6`\.`test_model5_id`, `TestModel6`\.`name`, `TestModel6`\.`created`, `TestModel6`\.`updated`\s+/', $result); |
|
1627 | $this->assertRegExp('/\s+FROM\s+\S+`test_model6` AS `TestModel6`\s+WHERE\s+/', $result); |
|
1628 | $this->assertRegExp('/WHERE\s+(?:\()?`TestModel6`\.`test_model5_id`\s+=\s+\({\$__cakeID__\$}\)(?:\))?/', $result); |
|
1629 | ||
1630 | $result = $this->Dbo->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null); |
|
1631 | $this->assertRegExp('/^SELECT\s+`TestModel5`\.`id`, `TestModel5`\.`test_model4_id`, `TestModel5`\.`name`, `TestModel5`\.`created`, `TestModel5`\.`updated`\s+/', $result); |
|
1632 | $this->assertRegExp('/\s+FROM\s+\S+`test_model5` AS `TestModel5`\s+WHERE\s+/', $result); |
|
1633 | $this->assertRegExp('/\s+WHERE\s+(?:\()?`TestModel5`.`name`\s+!=\s+\'mariano\'(?:\))?\s*$/', $result); |
|
1634 | } |
|
1635 | ||
1636 | /** |
|
1637 | * testGenerateAssociationQueryHasManyWithOffsetAndLimit method |
|
@@ 1892-1913 (lines=22) @@ | ||
1889 | * |
|
1890 | * @return void |
|
1891 | */ |
|
1892 | public function testGenerateAssociationQueryHasAndBelongsToManyWithConditions() { |
|
1893 | $this->Model = new TestModel4(); |
|
1894 | $this->Model->schema(); |
|
1895 | $this->_buildRelatedModels($this->Model); |
|
1896 | ||
1897 | $binding = array('type' => 'hasAndBelongsToMany', 'model' => 'TestModel7'); |
|
1898 | $queryData = array('conditions' => array('TestModel4.name !=' => 'mariano')); |
|
1899 | $resultSet = null; |
|
1900 | $null = null; |
|
1901 | ||
1902 | $params = $this->_prepareAssociationQuery($this->Model, $queryData, $binding); |
|
1903 | ||
1904 | $result = $this->Dbo->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet); |
|
1905 | $this->assertRegExp('/^SELECT\s+`TestModel7`\.`id`, `TestModel7`\.`name`, `TestModel7`\.`created`, `TestModel7`\.`updated`, `TestModel4TestModel7`\.`test_model4_id`, `TestModel4TestModel7`\.`test_model7_id`\s+/', $result); |
|
1906 | $this->assertRegExp('/\s+FROM\s+\S+`test_model7`\s+AS\s+`TestModel7`\s+JOIN\s+\S+`test_model4_test_model7`\s+AS\s+`TestModel4TestModel7`/', $result); |
|
1907 | $this->assertRegExp('/\s+ON\s+\(`TestModel4TestModel7`\.`test_model4_id`\s+=\s+{\$__cakeID__\$}/', $result); |
|
1908 | $this->assertRegExp('/\s+AND\s+`TestModel4TestModel7`\.`test_model7_id`\s+=\s+`TestModel7`\.`id`\)\s+WHERE\s+/', $result); |
|
1909 | ||
1910 | $result = $this->Dbo->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null); |
|
1911 | $this->assertRegExp('/^SELECT\s+`TestModel4`\.`id`, `TestModel4`\.`name`, `TestModel4`\.`created`, `TestModel4`\.`updated`\s+/', $result); |
|
1912 | $this->assertRegExp('/\s+FROM\s+\S+`test_model4` AS `TestModel4`\s+WHERE\s+(?:\()?`TestModel4`.`name`\s+!=\s+\'mariano\'(?:\))?\s*$/', $result); |
|
1913 | } |
|
1914 | ||
1915 | /** |
|
1916 | * testGenerateAssociationQueryHasAndBelongsToManyWithOffsetAndLimit method |