Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Updating test suite to properly handle parent_id situations. Fixes #881

  • Loading branch information...
commit 373bebb12834a2c1515337867a2f342bc0aa9e4f 1 parent ac9721d
Mark Story markstory authored
Showing with 54 additions and 17 deletions.
  1. +54 −17 cake/tests/cases/libs/model/behaviors/acl.test.php
71 cake/tests/cases/libs/model/behaviors/acl.test.php
View
@@ -90,14 +90,15 @@ function parentNode() {
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 @@ function testAfterSave() {
'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 @@ function testAfterDelete() {
'conditions' => array('Aro.model' => 'AclPerson', 'Aro.foreign_key' => 2)
));
$this->assertTrue(empty($result));
-
}
/**
Please sign in to comment.
Something went wrong with that request. Please try again.