Пример #1
0
 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());
 }
Пример #2
0
 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());
 }
Пример #3
0
 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());
 }
Пример #4
0
 public function testGetValueReadsIssers()
 {
     $path = new PropertyPath('australian');
     $object = new Author();
     $object->setAustralian(false);
     $this->assertFalse($path->getValue($object));
 }
Пример #5
0
    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());
    }
Пример #6
0
 public function testGetValueReadHassers()
 {
     $path = new PropertyPath('read_permissions');
     $object = new Author();
     $object->setReadPermissions(true);
     $this->assertTrue($path->getValue($object));
 }