Browse Source

Add test for merging associative properties.

Associated/hash properties should be merged like
dictionaries/array_merge.

Refs #2914
Mark Story 12 years ago
parent
commit
d2cde87777
1 changed files with 44 additions and 1 deletions
  1. 44 1
      tests/TestCase/Utility/MergeVariablesTraitTest.php

+ 44 - 1
tests/TestCase/Utility/MergeVariablesTraitTest.php

@@ -44,6 +44,15 @@ class Child extends Base {
 		'Orange'
 	];
 
+	public $nestedProperty = [
+		'Red' => [
+			'apple' => 'gala',
+		],
+		'Green' => [
+			'citrus' => 'lime'
+		],
+	];
+
 }
 
 class Grandchild extends Child {
@@ -54,6 +63,16 @@ class Grandchild extends Child {
 		'Green' => ['apple'],
 		'Yellow' => ['banana']
 	];
+
+	public $nestedProperty = [
+		'Red' => [
+			'apple' => 'mcintosh',
+			'citrus' => 'blood orange',
+		],
+		'Green' => [
+			'citrus' => 'key lime'
+		],
+	];
 }
 
 /**
@@ -76,7 +95,7 @@ class MergeVariablesTraitTest extends TestCase {
 	}
 
 /**
- * Test merging vars as an assoc list.
+ * Test merging vars as an associative list.
  *
  * @return void
  */
@@ -93,7 +112,31 @@ class MergeVariablesTraitTest extends TestCase {
 	}
 
 /**
+ * Test merging variable in associated properties that contain
+ * additional keys.
+ *
+ * @return void
+ */
+	public function testMergeVarsAsAssocWithKeyValues() {
+		$object = new Grandchild();
+		$object->mergeVars(['nestedProperty'], ['associative' => ['nestedProperty']]);
+
+		$expected = [
+			'Red' => [
+				'apple' => 'mcintosh',
+				'citrus' => 'blood orange',
+			],
+			'Green' => [
+				'citrus' => 'key lime',
+			],
+		];
+		$this->assertEquals($expected, $object->nestedProperty);
+	}
+
+/**
  * Test merging vars with mixed modes.
+ *
+ * @return void
  */
 	public function testMergeVarsMixedModes() {
 		$object = new Grandchild();