/** * Add element to the form. * * @param string $name * @param \Rapid\Form\Element $element * * @return Form */ public function addElement($name, \Rapid\Form\Element $element) { $element->setAttribute('name', $this->elementName($name)); $element->setAttribute('id', $this->elementId($name)); if ($this->model && $this->model->property($name)) { $element->setValue($this->model->property($name)); } $this->elements[$name] = $element; return $this; }
public function testSetValidators() { $validator = $this->getMockBuilder('Rapid\\Form\\Validator\\Required')->getMock(); $this->assertEquals(array(), $this->element->validators()); $validators = array(); $this->element->setValidators($validators); $this->assertEquals($validators, $this->element->validators()); $validators[] = clone $validator; $this->element->setValidators($validators); $this->assertEquals($validators, $this->element->validators()); $validator2 = clone $validator; $this->element->addValidator($validator2); $validators[] = $validator2; $this->assertEquals($validators, $this->element->validators()); }