Skip to content

Commit

Permalink
Updating test suite to properly handle parent_id situations. Fixes #881
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Jul 30, 2010
1 parent ac9721d commit 373bebb
Showing 1 changed file with 54 additions and 17 deletions.
71 changes: 54 additions & 17 deletions cake/tests/cases/libs/model/behaviors/acl.test.php
Expand Up @@ -90,14 +90,15 @@ function parentNode() {
if (!$this->id && empty($this->data)) { if (!$this->id && empty($this->data)) {
return null; return null;
} }
$data = $this->data; if (isset($this->data['AclPerson']['mother_id'])) {
if (empty($this->data)) { $motherId = $this->data['AclPerson']['mother_id'];
$data = $this->read(); } else {
$motherId = $this->field('mother_id');
} }
if (!$data['AclPerson']['mother_id']) { if (!$motherId) {
return null; return null;
} else { } else {
return array('AclPerson' => array('id' => $data['AclPerson']['mother_id'])); return array('AclPerson' => array('id' => $motherId));
} }
} }
} }
Expand Down Expand Up @@ -319,23 +320,60 @@ function testAfterSave() {
'foreign_key' => 1, 'foreign_key' => 1,
'parent_id' => null 'parent_id' => null
) )
); );
$this->Aro->create(); $this->Aro->create();
$this->Aro->save($aroData); $this->Aro->save($aroData);


$Person->read(null, 8); $Person->read(null, 8);
$Person->set('mother_id', 1); $Person->set('mother_id', 1);
$Person->save(); $Person->save();
$result = $this->Aro->find('first', array( $result = $this->Aro->find('first', array(
'conditions' => array('Aro.model' => 'AclPerson', 'Aro.foreign_key' => $Person->id) 'conditions' => array('Aro.model' => 'AclPerson', 'Aro.foreign_key' => $Person->id)
)); ));
$this->assertTrue(is_array($result)); $this->assertTrue(is_array($result));
$this->assertEqual($result['Aro']['parent_id'], 7); $this->assertEqual($result['Aro']['parent_id'], 7);


$node = $Person->node(array('model' => 'AclPerson', 'foreign_key' => 8)); $node = $Person->node(array('model' => 'AclPerson', 'foreign_key' => 8));
$this->assertEqual(sizeof($node), 2); $this->assertEqual(sizeof($node), 2);
$this->assertEqual($node[0]['Aro']['parent_id'], 7); $this->assertEqual($node[0]['Aro']['parent_id'], 7);
$this->assertEqual($node[1]['Aro']['parent_id'], null); $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);
} }


/** /**
Expand Down Expand Up @@ -397,7 +435,6 @@ function testAfterDelete() {
'conditions' => array('Aro.model' => 'AclPerson', 'Aro.foreign_key' => 2) 'conditions' => array('Aro.model' => 'AclPerson', 'Aro.foreign_key' => 2)
)); ));
$this->assertTrue(empty($result)); $this->assertTrue(empty($result));

} }


/** /**
Expand Down

0 comments on commit 373bebb

Please sign in to comment.