public function testSubmitWithEmptyDataCreatesObjectIfInitiallySubmittedWithObject() { $builder = $this->factory->createBuilder('form', null, array('data' => new Author(), 'required' => false)); $builder->add('firstName', 'text'); $builder->add('lastName', 'text'); $form = $builder->getForm(); $form->setData(null); // partially empty, still an object is created $form->submit(array('firstName' => 'Bernhard', 'lastName' => '')); $author = new Author(); $author->firstName = 'Bernhard'; $author->setLastName(''); $this->assertEquals($author, $form->getData()); }
public function testBindWithEmptyDataCreatesObjectIfInitiallyBoundWithObject() { $form = $this->factory->create('form', null, array('data' => new Author(), 'required' => false)); $form->add($this->factory->createNamed('form', 'firstName')); $form->add($this->factory->createNamed('form', 'lastName')); $form->setData(null); // partially empty, still an object is created $form->bind(array('firstName' => 'Bernhard', 'lastName' => '')); $author = new Author(); $author->firstName = 'Bernhard'; $author->setLastName(''); $this->assertEquals($author, $form->getData()); }
public function testGetValueCamelizesGetterNames() { $path = new PropertyPath('last_name'); $object = new Author(); $object->setLastName('Schussek'); $this->assertEquals('Schussek', $path->getValue($object)); }
public function testFormTypeCreatesDefaultValueForEmptyDataOption() { $factory = new FormFactory(array(new \Symfony\Component\Form\Extension\Core\CoreExtension())); $form = $factory->createNamedBuilder('author', new AuthorType())->getForm(); $form->bind(array('firstName' => 'John', 'lastName' => 'Smith')); $author = new Author(); $author->firstName = 'John'; $author->setLastName('Smith'); $this->assertEquals($author, $form->getData()); }
public function testSubmitWithEmptyDataCreatesObjectIfInitiallySubmittedWithObject() { $builder = $this->factory->createBuilder('Symfony\Component\Form\Extension\Core\Type\FormType', null, array( // data class is inferred from the passed object 'data' => new Author(), 'required' => false, )); $builder->add('firstName', 'Symfony\Component\Form\Extension\Core\Type\TextType'); $builder->add('lastName', 'Symfony\Component\Form\Extension\Core\Type\TextType'); $form = $builder->getForm(); $form->setData(null); // partially empty, still an object is created $form->submit(array('firstName' => 'Bernhard', 'lastName' => '')); $author = new Author(); $author->firstName = 'Bernhard'; $author->setLastName(''); $this->assertEquals($author, $form->getData()); }