function it_binds_validator(Request $request, Validator $validator, ElementInterface $textElement) { $request->get(DeForm::DEFORM_ID)->willReturn('testform'); $request->get('foo')->willReturn('test'); $textElement->getValidationRules()->willReturn('required'); $textElement->isReadonly()->willReturn(false); $textElement->setValue('test')->willReturn(false); $textElement->getValue()->willReturn('test'); $validator->validate(['foo' => 'required'], Argument::any())->shouldBeCalled(); $validator->updateValidationStatus(Argument::any())->shouldBeCalled(); $this->make($this->html)->isValid(); }
/** * Registers a new form element. * * @param \DeForm\Element\ElementInterface $element * @return self */ public function addElement(ElementInterface $element) { $name = $element->getName(); if (true === array_key_exists($name, $this->elements)) { throw new \LogicException(sprintf('Cannot set the element "%s" more than once (same name)', $name)); } $request_value = $this->request->get($name); $this->elements[$name] = $element; if (true === $this->canSetElementValue($element, $request_value)) { $element->setValue($request_value); } return $this; }
function it_should_return_element_value_from_request(NodeInterface $node, RequestInterface $request) { $node->getAttribute('name')->willReturn('foo')->shouldBeCalled(); $request->file('foo')->willReturn('bar')->shouldBeCalled(); $this->getValue()->shouldBe('bar'); }
/** * Get the value of a form element. * * @return mixed */ public function getValue() { return $this->request->file($this->getName()); }
function it_should_fill_the_form(Request $request, Element $el1, Element $el2) { $request->get(DeForm::DEFORM_ID)->willReturn('foo'); $request->get('field_1')->willReturn('bar'); $request->get('field_2')->willReturn(42); $el1->getName()->willReturn($field_1 = 'field_1'); $el1->isReadonly()->willReturn(false); $el1->setValue('bar')->shouldBeCalled(); $el2->getName()->willReturn($field_2 = 'field_2'); $el2->isReadonly()->willReturn(false); $el2->setValue(42)->shouldBeCalled(); $this->addElement($el1); $this->addElement($el2); $el1->setValue($new_value_field_1 = 'first')->shouldBeCalled(); $el2->setValue($new_value_field_2 = 'second')->shouldBeCalled(); $this->fill([$field_1 => $new_value_field_1, $field_2 => $new_value_field_2]); }