Skip to content
This repository
Browse code

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

  • Loading branch information...
commit 373bebb12834a2c1515337867a2f342bc0aa9e4f 1 parent ac9721d
Mark Story authored July 29, 2010
71  cake/tests/cases/libs/model/behaviors/acl.test.php
@@ -90,14 +90,15 @@ function parentNode() {
90 90
 		if (!$this->id && empty($this->data)) {
91 91
 			return null;
92 92
 		}
93  
-		$data = $this->data;
94  
-		if (empty($this->data)) {
95  
-			$data = $this->read();
  93
+		if (isset($this->data['AclPerson']['mother_id'])) {
  94
+			$motherId = $this->data['AclPerson']['mother_id'];
  95
+		} else {
  96
+			$motherId = $this->field('mother_id');
96 97
 		}
97  
-		if (!$data['AclPerson']['mother_id']) {
  98
+		if (!$motherId) {
98 99
 			return null;
99 100
 		} else {
100  
-			return array('AclPerson' => array('id' => $data['AclPerson']['mother_id']));
  101
+			return array('AclPerson' => array('id' => $motherId));
101 102
 		}
102 103
 	}
103 104
 }
@@ -319,23 +320,60 @@ function testAfterSave() {
319 320
 				'foreign_key' => 1,
320 321
 				'parent_id' => null
321 322
 			)
322  
-		 );
323  
-		 $this->Aro->create();
324  
-		 $this->Aro->save($aroData);
  323
+		);
  324
+		$this->Aro->create();
  325
+		$this->Aro->save($aroData);
325 326
  
326  
-		 $Person->read(null, 8);
327  
-		 $Person->set('mother_id', 1);
328  
-		 $Person->save();
329  
-		 $result = $this->Aro->find('first', array(
  327
+		$Person->read(null, 8);
  328
+		$Person->set('mother_id', 1);
  329
+		$Person->save();
  330
+		$result = $this->Aro->find('first', array(
330 331
 			'conditions' => array('Aro.model' => 'AclPerson', 'Aro.foreign_key' => $Person->id)
331 332
 		));
332 333
 		 $this->assertTrue(is_array($result));
333 334
 		 $this->assertEqual($result['Aro']['parent_id'], 7);
334 335
  
335  
-		 $node = $Person->node(array('model' => 'AclPerson', 'foreign_key' => 8));
336  
-		 $this->assertEqual(sizeof($node), 2);
337  
-		 $this->assertEqual($node[0]['Aro']['parent_id'], 7);
338  
-		 $this->assertEqual($node[1]['Aro']['parent_id'], null);
  336
+		$node = $Person->node(array('model' => 'AclPerson', 'foreign_key' => 8));
  337
+		$this->assertEqual(sizeof($node), 2);
  338
+		$this->assertEqual($node[0]['Aro']['parent_id'], 7);
  339
+		$this->assertEqual($node[1]['Aro']['parent_id'], null);
  340
+	}
  341
+
  342
+/**
  343
+ * test that an afterSave on an update does not cause parent_id to become null.
  344
+ *
  345
+ * @return void
  346
+ */
  347
+	function testAfterSaveUpdateParentIdNotNull() {
  348
+		$aroData = array(
  349
+			'Aro' => array(
  350
+				'model' => 'AclPerson',
  351
+				'foreign_key' => 2,
  352
+				'parent_id' => null
  353
+			)
  354
+		);
  355
+		$this->Aro->save($aroData);
  356
+
  357
+		$Person =& new AclPerson();
  358
+		$data = array(
  359
+			'AclPerson' => array(
  360
+				'name' => 'Trent',
  361
+				'mother_id' => 2,
  362
+				'father_id' => 3,
  363
+			),
  364
+		);
  365
+		$Person->save($data);
  366
+		$result = $this->Aro->find('first', array(
  367
+			'conditions' => array('Aro.model' => 'AclPerson', 'Aro.foreign_key' => $Person->id)
  368
+		));
  369
+		$this->assertTrue(is_array($result));
  370
+		$this->assertEqual($result['Aro']['parent_id'], 5);
  371
+
  372
+		$Person->save(array('id' => $Person->id, 'name' => 'Bruce'));
  373
+		$result = $this->Aro->find('first', array(
  374
+			'conditions' => array('Aro.model' => 'AclPerson', 'Aro.foreign_key' => $Person->id)
  375
+		));
  376
+		$this->assertEqual($result['Aro']['parent_id'], 5);
339 377
 	}
340 378
 
341 379
 /**
@@ -397,7 +435,6 @@ function testAfterDelete() {
397 435
 			'conditions' => array('Aro.model' => 'AclPerson', 'Aro.foreign_key' => 2)
398 436
 		));
399 437
 		$this->assertTrue(empty($result));
400  
-
401 438
 	}
402 439
 
403 440
 /**

0 notes on commit 373bebb

Please sign in to comment.
Something went wrong with that request. Please try again.