mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
Updating test suite to properly handle parent_id situations. Fixes #881
This commit is contained in:
parent
ac9721d582
commit
373bebb128
1 changed files with 54 additions and 17 deletions
|
@ -90,14 +90,15 @@ class AclPerson extends CakeTestModel {
|
|||
if (!$this->id && empty($this->data)) {
|
||||
return null;
|
||||
}
|
||||
$data = $this->data;
|
||||
if (empty($this->data)) {
|
||||
$data = $this->read();
|
||||
if (isset($this->data['AclPerson']['mother_id'])) {
|
||||
$motherId = $this->data['AclPerson']['mother_id'];
|
||||
} else {
|
||||
$motherId = $this->field('mother_id');
|
||||
}
|
||||
if (!$data['AclPerson']['mother_id']) {
|
||||
if (!$motherId) {
|
||||
return null;
|
||||
} else {
|
||||
return array('AclPerson' => array('id' => $data['AclPerson']['mother_id']));
|
||||
return array('AclPerson' => array('id' => $motherId));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -319,23 +320,60 @@ class AclBehaviorTestCase extends CakeTestCase {
|
|||
'foreign_key' => 1,
|
||||
'parent_id' => null
|
||||
)
|
||||
);
|
||||
$this->Aro->create();
|
||||
$this->Aro->save($aroData);
|
||||
);
|
||||
$this->Aro->create();
|
||||
$this->Aro->save($aroData);
|
||||
|
||||
$Person->read(null, 8);
|
||||
$Person->set('mother_id', 1);
|
||||
$Person->save();
|
||||
$result = $this->Aro->find('first', array(
|
||||
$Person->read(null, 8);
|
||||
$Person->set('mother_id', 1);
|
||||
$Person->save();
|
||||
$result = $this->Aro->find('first', array(
|
||||
'conditions' => array('Aro.model' => 'AclPerson', 'Aro.foreign_key' => $Person->id)
|
||||
));
|
||||
$this->assertTrue(is_array($result));
|
||||
$this->assertEqual($result['Aro']['parent_id'], 7);
|
||||
|
||||
$node = $Person->node(array('model' => 'AclPerson', 'foreign_key' => 8));
|
||||
$this->assertEqual(sizeof($node), 2);
|
||||
$this->assertEqual($node[0]['Aro']['parent_id'], 7);
|
||||
$this->assertEqual($node[1]['Aro']['parent_id'], null);
|
||||
$node = $Person->node(array('model' => 'AclPerson', 'foreign_key' => 8));
|
||||
$this->assertEqual(sizeof($node), 2);
|
||||
$this->assertEqual($node[0]['Aro']['parent_id'], 7);
|
||||
$this->assertEqual($node[1]['Aro']['parent_id'], null);
|
||||
}
|
||||
|
||||
/**
|
||||
* test that an afterSave on an update does not cause parent_id to become null.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testAfterSaveUpdateParentIdNotNull() {
|
||||
$aroData = array(
|
||||
'Aro' => array(
|
||||
'model' => 'AclPerson',
|
||||
'foreign_key' => 2,
|
||||
'parent_id' => null
|
||||
)
|
||||
);
|
||||
$this->Aro->save($aroData);
|
||||
|
||||
$Person =& new AclPerson();
|
||||
$data = array(
|
||||
'AclPerson' => array(
|
||||
'name' => 'Trent',
|
||||
'mother_id' => 2,
|
||||
'father_id' => 3,
|
||||
),
|
||||
);
|
||||
$Person->save($data);
|
||||
$result = $this->Aro->find('first', array(
|
||||
'conditions' => array('Aro.model' => 'AclPerson', 'Aro.foreign_key' => $Person->id)
|
||||
));
|
||||
$this->assertTrue(is_array($result));
|
||||
$this->assertEqual($result['Aro']['parent_id'], 5);
|
||||
|
||||
$Person->save(array('id' => $Person->id, 'name' => 'Bruce'));
|
||||
$result = $this->Aro->find('first', array(
|
||||
'conditions' => array('Aro.model' => 'AclPerson', 'Aro.foreign_key' => $Person->id)
|
||||
));
|
||||
$this->assertEqual($result['Aro']['parent_id'], 5);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -397,7 +435,6 @@ class AclBehaviorTestCase extends CakeTestCase {
|
|||
'conditions' => array('Aro.model' => 'AclPerson', 'Aro.foreign_key' => 2)
|
||||
));
|
||||
$this->assertTrue(empty($result));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue