/**
  * Validates the form data using the provided input filter.
  *
  * If validation errors are found, the form is populated with the corresponding error messages.
  * Form values are updated with the clean values provided by the filter.
  *
  * @param  Form $form
  * @return boolean
  */
 public function validate(Form $form)
 {
     $this->inputFilter->setData($form->values());
     if (!($isValid = $this->inputFilter->isValid())) {
         $form->setErrorMessages($this->inputFilter->getMessages());
         return $isValid;
     }
     $form->submit($this->inputFilter->getValues());
     return $isValid;
 }
 function it_should_not_add_messages_to_form_when_validation_succeeds(Form $form, InputFilter $filter)
 {
     $submittedValues = ['username' => 'john.doe', 'password' => 'changeme'];
     $this->beConstructedWith($filter);
     $filter->setData($submittedValues)->shouldBeCalled();
     $filter->isValid()->willReturn(true);
     $filter->getValues()->willReturn($submittedValues);
     $form->values()->willReturn($submittedValues);
     $form->submit($submittedValues)->shouldBeCalled();
     $form->setErrorMessages(Argument::type('array'))->shouldNotBeCalled();
     $this->validate($form);
 }
 /** @test */
 public function it_should_render_all_the_form_elements_that_were_not_already_rendered_individually()
 {
     $form = new Form();
     $form->add(new Text('username'))->add(new Hidden('user_id'))->add(new Hidden('user_role_id'));
     $form->submit(['user_id' => 1, 'user_role_id' => 2]);
     $view = $form->buildView();
     $this->renderer->renderRow($view->username, ['label' => 'Username']);
     $html = $this->renderer->renderRest($view);
     $this->assertEquals('<input type="hidden" name="user_id" value="1"><input type="hidden" name="user_role_id" value="2">', $html);
 }