mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-09-09 04:52:42 +00:00
Fixing order of associated results on test that was making a test to fail. Fixing issue where HABTM conditions were not being taken into account when deleting links. Adding tests, fixes #5798
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7893 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
aa1abdda9a
commit
da39ce77b9
2 changed files with 49 additions and 9 deletions
|
@ -1699,7 +1699,7 @@ class Model extends Overloadable {
|
||||||
|
|
||||||
foreach ($this->hasAndBelongsToMany as $assoc => $data) {
|
foreach ($this->hasAndBelongsToMany as $assoc => $data) {
|
||||||
$records = $this->{$data['with']}->find('all', array(
|
$records = $this->{$data['with']}->find('all', array(
|
||||||
'conditions' => array($data['foreignKey'] => $id),
|
'conditions' => array_merge(array($data['foreignKey'] => $id), (array) $data['conditions']),
|
||||||
'fields' => $this->{$data['with']}->primaryKey,
|
'fields' => $this->{$data['with']}->primaryKey,
|
||||||
'recursive' => -1
|
'recursive' => -1
|
||||||
));
|
));
|
||||||
|
|
|
@ -100,13 +100,13 @@ class ModelTest extends CakeTestCase {
|
||||||
|
|
||||||
$result = $TestModel->hasAndBelongsToMany;
|
$result = $TestModel->hasAndBelongsToMany;
|
||||||
$expected = array('AssociationTest2' => array(
|
$expected = array('AssociationTest2' => array(
|
||||||
'unique' => false,
|
'unique' => false,
|
||||||
'joinTable' => 'join_as_join_bs',
|
'joinTable' => 'join_as_join_bs',
|
||||||
'foreignKey' => false,
|
'foreignKey' => false,
|
||||||
'className' => 'AssociationTest2',
|
'className' => 'AssociationTest2',
|
||||||
'with' => 'JoinAsJoinB',
|
'with' => 'JoinAsJoinB',
|
||||||
'associationForeignKey' => 'join_b_id',
|
'associationForeignKey' => 'join_b_id',
|
||||||
'conditions' => '', 'fields' => '', 'order' => '', 'limit' => '', 'offset' => '',
|
'conditions' => '', 'fields' => '', 'order' => '', 'limit' => '', 'offset' => '',
|
||||||
'finderQuery' => '', 'deleteQuery' => '', 'insertQuery' => ''
|
'finderQuery' => '', 'deleteQuery' => '', 'insertQuery' => ''
|
||||||
));
|
));
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
|
@ -183,12 +183,12 @@ class ModelTest extends CakeTestCase {
|
||||||
**/
|
**/
|
||||||
function testConstruct() {
|
function testConstruct() {
|
||||||
$this->loadFixtures('Post', 'Comment');
|
$this->loadFixtures('Post', 'Comment');
|
||||||
|
|
||||||
$TestModel =& ClassRegistry::init('MergeVarPluginPost');
|
$TestModel =& ClassRegistry::init('MergeVarPluginPost');
|
||||||
$this->assertEqual($TestModel->actsAs, array('Containable', 'Tree'));
|
$this->assertEqual($TestModel->actsAs, array('Containable', 'Tree'));
|
||||||
$this->assertTrue(isset($TestModel->Behaviors->Containable));
|
$this->assertTrue(isset($TestModel->Behaviors->Containable));
|
||||||
$this->assertTrue(isset($TestModel->Behaviors->Tree));
|
$this->assertTrue(isset($TestModel->Behaviors->Tree));
|
||||||
|
|
||||||
$TestModel =& ClassRegistry::init('MergeVarPluginComment');
|
$TestModel =& ClassRegistry::init('MergeVarPluginComment');
|
||||||
$this->assertEqual($TestModel->actsAs, array('Containable', 'Containable' => array('some_settings')));
|
$this->assertEqual($TestModel->actsAs, array('Containable', 'Containable' => array('some_settings')));
|
||||||
$this->assertTrue(isset($TestModel->Behaviors->Containable));
|
$this->assertTrue(isset($TestModel->Behaviors->Containable));
|
||||||
|
@ -2988,8 +2988,8 @@ class ModelTest extends CakeTestCase {
|
||||||
|
|
||||||
$result = $ThePaper->findById(2);
|
$result = $ThePaper->findById(2);
|
||||||
$expected = array(
|
$expected = array(
|
||||||
array('id' => '3', 'device_type_id' => '1', 'name' => 'Device 3', 'typ' => '2'),
|
|
||||||
array('id' => '1', 'device_type_id' => '1', 'name' => 'Device 1', 'typ' => '1'),
|
array('id' => '1', 'device_type_id' => '1', 'name' => 'Device 1', 'typ' => '1'),
|
||||||
|
array('id' => '3', 'device_type_id' => '1', 'name' => 'Device 3', 'typ' => '2')
|
||||||
);
|
);
|
||||||
$this->assertEqual($result['Monkey'], $expected);
|
$this->assertEqual($result['Monkey'], $expected);
|
||||||
|
|
||||||
|
@ -6159,6 +6159,46 @@ class ModelTest extends CakeTestCase {
|
||||||
$TestModel->setSource('join_as');
|
$TestModel->setSource('join_as');
|
||||||
$this->assertFalse($this->db->cacheSources);
|
$this->assertFalse($this->db->cacheSources);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* testDeleteHabtmReferenceWithConditions method
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function testDeleteHabtmReferenceWithConditions() {
|
||||||
|
$this->loadFixtures('Portfolio', 'Item', 'ItemsPortfolio');
|
||||||
|
|
||||||
|
$Portfolio =& new Portfolio();
|
||||||
|
$Portfolio->hasAndBelongsToMany['Item']['conditions'] = array('ItemsPortfolio.item_id >' => 1);
|
||||||
|
|
||||||
|
$result = $Portfolio->find('first', array('conditions' => array('Portfolio.id' => 1)));
|
||||||
|
$expected = array(
|
||||||
|
array('id' => 3, 'syfile_id' => 3, 'published' => 0, 'name' => 'Item 3', 'ItemsPortfolio' => array('id' => 3, 'item_id' => 3, 'portfolio_id' => 1)),
|
||||||
|
array('id' => 4, 'syfile_id' => 4, 'published' => 0, 'name' => 'Item 4', 'ItemsPortfolio' => array('id' => 4, 'item_id' => 4, 'portfolio_id' => 1)),
|
||||||
|
array('id' => 5, 'syfile_id' => 5, 'published' => 0, 'name' => 'Item 5', 'ItemsPortfolio' => array('id' => 5, 'item_id' => 5, 'portfolio_id' => 1)),
|
||||||
|
);
|
||||||
|
$this->assertEqual($result['Item'], $expected);
|
||||||
|
|
||||||
|
$result = $Portfolio->ItemsPortfolio->find('all', array('conditions' => array('ItemsPortfolio.portfolio_id' => 1)));
|
||||||
|
$expected = array(
|
||||||
|
array('ItemsPortfolio' => array('id' => 1, 'item_id' => 1, 'portfolio_id' => 1)),
|
||||||
|
array('ItemsPortfolio' => array('id' => 3, 'item_id' => 3, 'portfolio_id' => 1)),
|
||||||
|
array('ItemsPortfolio' => array('id' => 4, 'item_id' => 4, 'portfolio_id' => 1)),
|
||||||
|
array('ItemsPortfolio' => array('id' => 5, 'item_id' => 5, 'portfolio_id' => 1))
|
||||||
|
);
|
||||||
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
|
$Portfolio->delete(1);
|
||||||
|
|
||||||
|
$result = $Portfolio->find('first', array('conditions' => array('Portfolio.id' => 1)));
|
||||||
|
$this->assertFalse($result);
|
||||||
|
|
||||||
|
$result = $Portfolio->ItemsPortfolio->find('all', array('conditions' => array('ItemsPortfolio.portfolio_id' => 1)));
|
||||||
|
$expected = array(
|
||||||
|
array('ItemsPortfolio' => array('id' => 1, 'item_id' => 1, 'portfolio_id' => 1))
|
||||||
|
);
|
||||||
|
$this->assertEqual($result, $expected);
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* endTest method
|
* endTest method
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue