Exemplo n.º 1
0
 /**
  * @dataProvider testData
  *
  * @param string $class  class name
  * @param string $name   form name
  * @param array  $fields fields for builder
  *
  * @return void
  */
 public function testBuildForm($class, $name, $fields)
 {
     $builderDouble = $this->getMock('Symfony\\Component\\Form\\FormBuilderInterface');
     $i = 0;
     foreach ($fields as $field) {
         $builderDouble->expects($this->at($i++))->method('add')->with($field['name'], $field['type'], $field['options']);
     }
     $sut = new DocumentType($this->classMap, $this->fieldMap);
     $sut->initialize($class);
     $sut->buildForm($builderDouble, []);
     $this->assertEquals($name, $sut->getName());
 }
Exemplo n.º 2
0
 /**
  * @param Request $request request
  *
  * @return \Symfony\Component\Form\Form
  */
 private function getForm(Request $request)
 {
     list($service) = explode(':', $request->attributes->get('_controller'));
     $this->formType->initialize($service);
     return $this->formFactory->create($this->formType, null, array('method' => $request->getMethod()));
 }
Exemplo n.º 3
0
 /**
  * @param Request       $request request
  * @param DocumentModel $model   model
  *
  * @return \Symfony\Component\Form\Form
  */
 public function getForm(Request $request, DocumentModel $model)
 {
     $this->formType->initialize($model->getEntityClass());
     return $this->formFactory->create($this->formType, null, ['method' => $request->getMethod()]);
 }
Exemplo n.º 4
0
 /**
  * Test DocumentType::handlePreSubmitEvent()
  *
  * @return void
  */
 public function testHandlePreSubmitEvent()
 {
     $class = __CLASS__;
     $fields = [['name1', 'type1', ['options1']], ['name2', 'type2', ['options2']]];
     $submittedData = ['name1' => 'data1', 'name2' => 'data2'];
     $formDouble = $this->getMockBuilder('Symfony\\Component\\Form\\FormInterface')->disableOriginalConstructor()->getMock();
     $formDouble->expects($this->once())->method('isRequired')->willReturn(true);
     $sut = new DocumentType($this->fieldBuilderDouble, [$class => $fields]);
     $sut->initialize($class);
     $this->fieldBuilderDouble->expects($this->exactly(2))->method('supportsField')->withConsecutive(['type1', ['options1']], ['type2', ['options2']])->willReturn(true);
     $this->fieldBuilderDouble->expects($this->exactly(2))->method('buildField')->withConsecutive([$sut, $formDouble, 'name1', 'type1', ['options1'], 'data1'], [$sut, $formDouble, 'name2', 'type2', ['options2'], 'data2']);
     $sut->handlePreSubmitEvent(new FormEvent($formDouble, $submittedData));
 }