Skip to content
Permalink
Browse files

Add test for merging associative properties.

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

Refs #2914
  • Loading branch information...
markstory committed Mar 1, 2014
1 parent 148fd51 commit d2cde877778e2058d61b6c9e215330f0c49fadfe
Showing with 44 additions and 1 deletion.
  1. +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 @@ public function testMergeVarsAsList() {
}
/**
* Test merging vars as an assoc list.
* Test merging vars as an associative list.
*
* @return void
*/
@@ -92,8 +111,32 @@ public function testMergeVarsAsAssoc() {
$this->assertEquals($expected, $object->assocProperty);
}
/**
* 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();

0 comments on commit d2cde87

Please sign in to comment.
You can’t perform that action at this time.