public function testToArray() { $nested_options_list = Schema\OptionDefinitionList::create(); $nested_options_list->add(Schema\OptionDefinition::create(array('value' => 'Nested Foobar One'))); $list = Schema\OptionDefinitionList::create(); $list->add(Schema\OptionDefinition::create(array('name' => 'Parent Foobar', 'value' => $nested_options_list))); $expected_list_array = array('Parent Foobar' => array('Nested Foobar One')); $this->assertSame($expected_list_array, $list->toArray()); }
protected function parseOption(\DOMXPath $xpath, \DOMElement $element) { $name = null; $value = null; $default = null; if ($element->hasAttribute('name')) { $name = $element->getAttribute('name'); } $nested_options = $xpath->query('./option', $element); if ($nested_options->length > 0) { $value = Schema\OptionDefinitionList::create(); foreach ($nested_options as $option_element) { $value->add($this->parseOption($xpath, $option_element)); } } else { $value = trim($element->nodeValue); } return Schema\OptionDefinition::create(array('name' => $name, 'value' => $this->literalize($value), 'default' => $this->literalize($default))); }