Add databox_descriptionStructure::toArray method

This commit is contained in:
Romain Neutron
2013-04-17 15:08:07 +02:00
parent a137bc7cf7
commit 196b566a83
2 changed files with 34 additions and 0 deletions

View File

@@ -118,4 +118,11 @@ class databox_descriptionStructure implements IteratorAggregate
{ {
return isset($this->elements[$id]); return isset($this->elements[$id]);
} }
public function toArray()
{
return array_map(function ($element) {
return $element->toArray();
}, array_values($this->elements));
}
} }

View File

@@ -0,0 +1,27 @@
<?php
class databox_descriptionStructureTest extends PhraseanetPHPUnitAbstract
{
public function testToArray()
{
$structure = new \databox_descriptionStructure();
$array = array('name1' => 'value1', 'name2' => 'value2');
$element = $this->provideDataboxFieldMock();
$element->expects($this->once())
->method('toArray')
->will($this->returnValue($array));
$structure->add_element($element);
$this->assertEquals(array($array), $structure->toArray());
}
private function provideDataboxFieldMock()
{
return $this->getMockBuilder('databox_field')
->disableOriginalConstructor()
->getMock();
}
}