|
@@ -214,6 +214,18 @@ class FormTest extends \PHPUnit_Framework_TestCase
|
|
|
$form->bind(array()); // irrelevant
|
|
|
}
|
|
|
|
|
|
+ public function testBindThrowsExceptionIfNoValidatorIsSet()
|
|
|
+ {
|
|
|
+ $field = $this->createMockField('firstName');
|
|
|
+ $form = new Form('author', new Author());
|
|
|
+ $form->add($field);
|
|
|
+ $form->setValidationGroups('group');
|
|
|
+
|
|
|
+ $this->setExpectedException('Symfony\Component\Form\Exception\FormException');
|
|
|
+
|
|
|
+ $form->bind(array()); // irrelevant
|
|
|
+ }
|
|
|
+
|
|
|
public function testMultipartFormsWithoutParentsRequireFiles()
|
|
|
{
|
|
|
$form = new Form('author', new Author(), $this->validator);
|
|
@@ -236,6 +248,57 @@ class FormTest extends \PHPUnit_Framework_TestCase
|
|
|
$form->bind(array('file' => 'test.txt'));
|
|
|
}
|
|
|
|
|
|
+ public function testUpdateFromPropertyIsIgnoredIfFormHasObject()
|
|
|
+ {
|
|
|
+ $author = new Author();
|
|
|
+ $author->child = new Author();
|
|
|
+ $standaloneChild = new Author();
|
|
|
+
|
|
|
+ $form = new Form('child', $standaloneChild);
|
|
|
+ $form->updateFromProperty($author);
|
|
|
+
|
|
|
+ // should not be $author->child!!
|
|
|
+ $this->assertSame($standaloneChild, $form->getData());
|
|
|
+ }
|
|
|
+
|
|
|
+ public function testUpdateFromPropertyIsNotIgnoredIfFormHasNoObject()
|
|
|
+ {
|
|
|
+ $author = new Author();
|
|
|
+ $author->child = new Author();
|
|
|
+
|
|
|
+ $form = new Form('child');
|
|
|
+ $form->updateFromProperty($author);
|
|
|
+
|
|
|
+ // should not be $author->child!!
|
|
|
+ $this->assertSame($author->child, $form->getData());
|
|
|
+ }
|
|
|
+
|
|
|
+ public function testUpdatePropertyIsIgnoredIfFormHasObject()
|
|
|
+ {
|
|
|
+ $author = new Author();
|
|
|
+ $author->child = $child = new Author();
|
|
|
+ $standaloneChild = new Author();
|
|
|
+
|
|
|
+ $form = new Form('child', $standaloneChild);
|
|
|
+ $form->updateProperty($author);
|
|
|
+
|
|
|
+ // $author->child was not modified
|
|
|
+ $this->assertSame($child, $author->child);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function testUpdatePropertyIsNotIgnoredIfFormHasNoObject()
|
|
|
+ {
|
|
|
+ $author = new Author();
|
|
|
+ $child = new Author();
|
|
|
+
|
|
|
+ $form = new Form('child');
|
|
|
+ $form->setData($child);
|
|
|
+ $form->updateProperty($author);
|
|
|
+
|
|
|
+ // $author->child was set
|
|
|
+ $this->assertSame($child, $author->child);
|
|
|
+ }
|
|
|
+
|
|
|
protected function createMockField($key)
|
|
|
{
|
|
|
$field = $this->getMock(
|