Skip to content

Commit

Permalink
editing aggregated properties test
Browse files Browse the repository at this point in the history
  • Loading branch information
Magomogo committed Sep 27, 2013
1 parent dc93b81 commit ff8f9e7
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions test/ModelPersonEditorWorkflowTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,17 @@ public function testCanBeEditWithSomeEditor()
'firstName' => 'John',
'lastName' => 'Doe',
'email' => '[email protected]',
'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());
}

//----------------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -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);
}

/**
Expand All @@ -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;
}
}
}

}

0 comments on commit ff8f9e7

Please sign in to comment.