public function testChild() { $c = new Child('p', 'This is a paragraph', new Child('p', 'This is another paragraph')); $c->setAttributes('class', 'some-class'); $this->assertEquals('p', $c->getNodeName()); $this->assertEquals('This is a paragraph', $c->getNodeValue()); $this->assertEquals('some-class', $c->getAttribute('class')); }
/** * Method to render the form using a basic 1:1 DT/DD layout * * @return void */ protected function renderWithoutTemplate() { // Initialize properties. $this->output = null; $children = $this->form->getChildren(); $this->form->removeChildren(); $id = null !== $this->form->getAttribute('id') ? $this->form->getAttribute('id') . '-field-group-' : 'pop-form-field-group-'; // Create DL element. $i = 1; $dl = new Child('dl', null, null, false, $this->form->getIndent()); $dl->setAttributes('id', $id . $i); // Loop through the children and create and attach the appropriate DT and DT elements, with labels where applicable. foreach ($children as $child) { if ($child->getNodeName() == 'fieldset') { $chdrn = $child->getChildren(); if (isset($chdrn[0])) { $attribs = $chdrn[0]->getAttributes(); } } else { $attribs = $child->getAttributes(); } $name = isset($attribs['name']) ? $attribs['name'] : ''; $name = str_replace('[]', '', $name); if (count($this->groups) > 0) { if (isset($this->groups[$i]) && $this->groups[$i] == $name) { $this->form->addChild($dl); $i++; $dl = new Child('dl', null, null, false, $this->form->getIndent()); $dl->setAttributes('id', $id . $i); } } // Clear the password field from display. if ($child->getAttribute('type') == 'password') { $child->setValue(null); $child->setAttributes('value', null); } // If the element label is set, render the appropriate DT and DD elements. if (null !== $child->getLabel()) { // Create the DT and DD elements. $dt = new Child('dt', null, null, false, $this->form->getIndent() . ' '); $dd = new Child('dd', null, null, false, $this->form->getIndent() . ' '); // Format the label name. $lblName = $child->getNodeName() == 'fieldset' ? '1' : ''; $label = new Child('label', $child->getLabel(), null, false, $this->form->getIndent() . ' '); $label->setAttributes('for', $name . $lblName); $labelAttributes = $child->getLabelAttributes(); if (null !== $labelAttributes) { foreach ($labelAttributes as $a => $v) { $label->setAttributes($a, $v); } } else { if ($child->isRequired()) { $label->setAttributes('class', 'required'); } } // Add the appropriate children to the appropriate elements. $dt->addChild($label); $child->setIndent($this->form->getIndent() . ' '); $childChildren = $child->getChildren(); $child->removeChildren(); foreach ($childChildren as $cChild) { $cChild->setIndent($this->form->getIndent() . ' '); $child->addChild($cChild); } $dd->addChild($child); $dl->addChildren(array($dt, $dd)); // Else, render only a DD element. } else { $dd = new Child('dd', null, null, false, $this->form->getIndent() . ' '); $child->setIndent($this->form->getIndent() . ' '); $dd->addChild($child); $dl->addChild($dd); } } // Add the DL element and its children to the form element. $this->form->addChild($dl); $this->output = $this->form->render(true); }