Esempio n. 1
0
 public function testTranslation()
 {
     $mockTranslator = $this->getMockBuilder('\\AVCMS\\Core\\Translation\\Translator')->disableOriginalConstructor()->getMock();
     $expectedTranslation = array('Name Translated', 'Category Translated', 'One Translated', 'Submit Translated', 'Error Translated');
     $map = array(array('Name', array(), null, null, $expectedTranslation[0]), array('Category', array(), null, null, $expectedTranslation[1]), array("One", array(), null, null, $expectedTranslation[2]), array("Submit Original", array(), null, null, $expectedTranslation[3]), array("Example Error", array(), null, null, $expectedTranslation[4]));
     $mockTranslator->expects($this->any())->method('trans')->will($this->returnValueMap($map));
     $this->formView->setTranslator($mockTranslator);
     $fields = array('name' => $this->nameField, 'category' => $this->categoryField);
     $this->formView->setFields($fields);
     $this->formView->setSubmitButtonLabel('Submit Original');
     $fields = $this->formView->getFields();
     $this->assertEquals($expectedTranslation[0], $fields['name']['options']['label']);
     $this->assertEquals($expectedTranslation[1], $fields['category']['options']['label']);
     $this->assertEquals($expectedTranslation[2], $fields['category']['options']['choices'][1]);
     $this->assertEquals($expectedTranslation[3], $this->formView->getSubmitButtonLabel());
     $formErrors = array(new FormError('name', 'Example Error', true));
     $this->formView->setErrors($formErrors);
     $translatedErrors = $this->formView->getErrors();
     $this->assertEquals($expectedTranslation[4], $translatedErrors[0]->getMessage());
 }
Esempio n. 2
0
 /**
  * @param \AV\Form\FormBlueprint $form
  * @param null $request
  * @param mixed $entities
  * @param null $formView
  * @return \AV\Form\FormHandler
  */
 public function build(FormBlueprint $form, $request = null, $entities = array(), $formView = null)
 {
     if (!$formView) {
         $formView = new FormView();
         if (isset($this->translator)) {
             $formView->setTranslator($this->translator);
         }
     }
     $validatorExtension = new LaravelValidatorExtension();
     $formHandler = $this->formHandlerFactory->buildForm($form, $formView, $validatorExtension);
     if (!is_array($entities)) {
         $entities = array($entities);
     }
     foreach ($entities as $entity) {
         $formHandler->bindEntity($entity);
     }
     if ($request) {
         $formHandler->handleRequest($request);
     }
     return $formHandler;
 }