private function createForm($name)
 {
     $builder = new FormBuilder($name, null, $this->dispatcher, $this->factory);
     $builder->setCompound(true);
     $builder->setDataMapper($this->dataMapper);
     return $builder->getForm();
 }
 /**
  * Ensure that the form is correctly considered valid.
  *
  * @dataProvider dataIsValid
  *
  * @param string $httpMethod The HTTP method.
  * @param array $parameters Parameters for the query/request.
  * @param boolean $expectedValid If the form is expected to be valid.
  */
 public function testIsValid($httpMethod, $parameters, $expectedValid)
 {
     $flow = $this->getFlowWithMockedMethods(array('getName', 'getRequest'));
     $flow->setRevalidatePreviousSteps(false);
     $flow->expects($this->any())->method('getName')->will($this->returnValue('createTopic'));
     $flow->expects($this->any())->method('getRequest')->will($this->returnValue(Request::create('', $httpMethod, $parameters)));
     $dispatcher = $this->getMock('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface');
     $factory = Forms::createFormFactoryBuilder()->getFormFactory();
     $formBuilder = new FormBuilder(null, 'stdClass', $dispatcher, $factory);
     $useFqcn = method_exists('Symfony\\Component\\Form\\AbstractType', 'getBlockPrefix');
     $form = $formBuilder->setCompound(true)->setDataMapper($this->getMock('Symfony\\Component\\Form\\DataMapperInterface'))->add('aField', $useFqcn ? 'Symfony\\Component\\Form\\Extension\\Core\\Type\\TextType' : 'text')->setMethod($httpMethod)->setRequestHandler(new HttpFoundationRequestHandler())->getForm();
     $this->assertSame($expectedValid, $flow->isValid($form));
 }
 /**
  * tests only so far that actual value/object is retrieved.
  *
  * @expectedException        Exception
  * @expectedExceptionCode    0
  * @expectedExceptionMessage unknown collection class
  */
 public function testAppendFormFieldElementNested()
 {
     $container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerInterface');
     $pool = new Pool($container, 'title', 'logo.png');
     $helper = new AdminHelper($pool);
     $admin = $this->getMock('Sonata\\AdminBundle\\Admin\\AdminInterface');
     $object = $this->getMock('stdClass', array('getSubObject'));
     $simpleObject = $this->getMock('stdClass', array('getSubObject'));
     $subObject = $this->getMock('stdClass', array('getAnd'));
     $sub2Object = $this->getMock('stdClass', array('getMore'));
     $sub3Object = $this->getMock('stdClass', array('getFinalData'));
     $dataMapper = $this->getMock('Symfony\\Component\\Form\\DataMapperInterface');
     $formFactory = $this->getMock('Symfony\\Component\\Form\\FormFactoryInterface');
     $eventDispatcher = $this->getMock('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface');
     $formBuilder = new FormBuilder('test', get_class($simpleObject), $eventDispatcher, $formFactory);
     $childFormBuilder = new FormBuilder('subObject', get_class($subObject), $eventDispatcher, $formFactory);
     $object->expects($this->atLeastOnce())->method('getSubObject')->will($this->returnValue(array($subObject)));
     $subObject->expects($this->atLeastOnce())->method('getAnd')->will($this->returnValue($sub2Object));
     $sub2Object->expects($this->atLeastOnce())->method('getMore')->will($this->returnValue(array($sub3Object)));
     $sub3Object->expects($this->atLeastOnce())->method('getFinalData')->will($this->returnValue('value'));
     $formBuilder->setCompound(true);
     $formBuilder->setDataMapper($dataMapper);
     $formBuilder->add($childFormBuilder);
     $admin->expects($this->once())->method('getFormBuilder')->will($this->returnValue($formBuilder));
     $admin->expects($this->once())->method('getSubject')->will($this->returnValue($object));
     $helper->appendFormFieldElement($admin, $simpleObject, 'uniquePartOfId_sub_object_0_and_more_0_final_data');
 }