From ff8f9e7e6ded99b240e12dec8efc358e2a42df27 Mon Sep 17 00:00:00 2001 From: Magomogo Date: Fri, 27 Sep 2013 14:23:53 +0700 Subject: [PATCH] editing aggregated properties test --- test/ModelPersonEditorWorkflowTest.php | 31 ++++++++++++++++++++------ 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/test/ModelPersonEditorWorkflowTest.php b/test/ModelPersonEditorWorkflowTest.php index dfdd2e1..363045f 100644 --- a/test/ModelPersonEditorWorkflowTest.php +++ b/test/ModelPersonEditorWorkflowTest.php @@ -48,14 +48,17 @@ public function testCanBeEditWithSomeEditor() 'firstName' => 'John', 'lastName' => 'Doe', 'email' => 'John.Doe@example.com', + 'creditCard' => array( + 'system' => 'VISA', + 'pan' => '9512456785213698', + ) )); $editor->saveTo($this->dbContainer()); - $this->assertEquals( - 'Mr. John Doe', - Person\Model::load($this->dbContainer(), $this->propertiesId)->politeTitle() - ); + $updatedModel = Person\Model::load($this->dbContainer(), $this->propertiesId); + $this->assertEquals('Mr. John Doe', $updatedModel->politeTitle()); + $this->assertEquals('VISA, 9512 **** **** 3698', $updatedModel->paymentInfo()); } //---------------------------------------------------------------------------------------------------------------------- @@ -83,9 +86,7 @@ public function __construct($person = null) public function edit($data) { - foreach ($data as $name => $value) { - $this->properties->$name = $value; - } + $this->editProperties($data, $this->properties); } /** @@ -101,4 +102,20 @@ private static function newPerson() { return new Person\Model(new Person\Properties(array('title' => 'Mr.'))); } + + /** + * @param $data + * @param AbstractProperties $properties + */ + private function editProperties($data, $properties) + { + foreach ($data as $name => $value) { + if (is_array($value)) { + $this->editProperties($value, $this->exposeProperties($properties->$name)); + } else { + $properties->$name = $value; + } + } + } + } \ No newline at end of file