Exemplo n.º 1
0
 /**
  * Returns true if the form was submitted, false otherwise.
  *
  * @return boolean
  */
 public function isSubmitted()
 {
     if ($this->formNode->getAttribute('name') === $this->request->get(static::DEFORM_ID)) {
         return true;
     }
     return false;
 }
Exemplo n.º 2
0
 function it_should_parse_mixed_checkbox_elements(Node $node1, Node $node2, Node $node3, Node $node4, Node $node5, Node $node6)
 {
     foreach (func_get_args() as $node) {
         $node->getElementType()->shouldBeCalled()->willReturn('input_checkbox');
     }
     $node1->getAttribute('name')->willReturn('foo');
     $node2->getAttribute('name')->willReturn('foo');
     $node3->getAttribute('name')->willReturn('foo');
     $node4->getAttribute('name')->willReturn('bar');
     $node5->getAttribute('name')->willReturn('bar');
     $node6->getAttribute('name')->willReturn('foobar');
     $this->createFromNodes(func_get_args())->shouldReturnMixedNodes(['foo' => ['className' => 'DeForm\\Element\\CheckboxGroupElement', 'length' => 3], 'bar' => ['className' => 'DeForm\\Element\\CheckboxGroupElement', 'length' => 2], 'foobar' => 'DeForm\\Element\\CheckboxElement']);
 }
Exemplo n.º 3
0
 function let(Request $request, Validator $validator, ElementFactory $elementFactory, ParserFactoryInterface $parserFactory, NodeInterface $formNode, NodeInterface $textInput, NodeInterface $hiddenInput, ElementInterface $textElement, DocumentInterface $document, ParserInterface $parser)
 {
     $this->beConstructedWith($request, $validator, $elementFactory, $parserFactory);
     $parserFactory->createDocument($this->html)->willReturn($document);
     $parserFactory->createParser($document)->willReturn($parser);
     $parser->getFormNode()->willReturn($formNode);
     $parser->getElementsNodes()->willReturn($nodes = [$textInput]);
     $formNode->getAttribute('name')->willReturn($form_name = 'testform');
     $formNode->createElement('input')->shouldBeCalled()->willReturn($hiddenInput);
     $hiddenInput->setAttribute('type', 'hidden')->shouldBeCalled();
     $hiddenInput->setAttribute('value', $form_name)->shouldBeCalled();
     $hiddenInput->setAttribute('name', DeForm::DEFORM_ID)->shouldBeCalled();
     $formNode->appendChild($hiddenInput)->shouldBeCalled();
     $textInput->getElementType()->willReturn('input_text');
     $textElement->getName()->willReturn('foo');
     $elementFactory->createFromNodes($nodes)->willReturn([$textElement]);
 }
Exemplo n.º 4
0
 function it_throws_exception_when_try_to_set_multiple_values_on_single_select_element(NodeInterface $nodeInterface)
 {
     $value = [2, 3];
     $nodeInterface->hasAttribute('multi')->willReturn(false);
     $this->shouldThrow('\\InvalidArgumentException')->during('setValue', [$value]);
 }
Exemplo n.º 5
0
 /**
  * Return the validation rules for element.
  *
  * @return string|null
  */
 public function getValidationRules()
 {
     return $this->node->getAttribute('data-validate');
 }
Exemplo n.º 6
0
 function it_should_be_invalid_element(NodeInterface $node)
 {
     $node->hasAttribute('data-invalid')->shouldBeCalled()->willReturn(true);
     $this->shouldNotBeValid();
 }
Exemplo n.º 7
0
 function it_should_mark_as_unchecked_element(NodeInterface $node)
 {
     $node->removeAttribute('checked')->shouldBeCalled();
     $this->setUnchecked()->shouldBe($this);
 }
Exemplo n.º 8
0
 /**
  * @param NodeInterface $node
  * @return \DeForm\Element\ElementInterface|null
  */
 protected function createElement(NodeInterface $node)
 {
     $element_type = $node->getElementType();
     if (false === isset($this->mapTypes[$element_type])) {
         return null;
     }
     $class_name = '\\DeForm\\Element\\' . $this->mapTypes[$element_type];
     if ('input_file' === $element_type) {
         return new $class_name($node, $this->request);
     }
     return new $class_name($node);
 }
Exemplo n.º 9
0
 function it_should_mark_as_unchecked_element(NodeInterface $node)
 {
     $node->removeAttribute('checked')->shouldBeCalled();
     $this->setUnchecked()->shouldHaveType('DeForm\\Element\\CheckboxElement');
 }
Exemplo n.º 10
0
 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');
 }
Exemplo n.º 11
0
 function let(Node $formNode, Document $document, Request $request, ValidationHelper $validationHelper)
 {
     $formNode->getAttribute('name')->willReturn('foo');
     $this->beConstructedWith($formNode, $document, $request, $validationHelper);
 }