[Form] add tests for type_options in collectionType
This commit is contained in:
parent
0077963584
commit
fb0a37f9ba
87
tests/Symfony/Tests/Component/Form/Extension/Core/Type/CollectionTypeTest.php
Normal file → Executable file
87
tests/Symfony/Tests/Component/Form/Extension/Core/Type/CollectionTypeTest.php
Normal file → Executable file
@ -143,4 +143,91 @@ class CollectionFormTest extends TypeTestCase
|
||||
|
||||
$this->assertFalse($form->has('$$name$$'));
|
||||
}
|
||||
|
||||
public function testSetTypeOptions()
|
||||
{
|
||||
$form = $this->factory->create('collection', null, array(
|
||||
'type' => 'field',
|
||||
'type_options' => array(
|
||||
'required' => false,
|
||||
'max_length' => 20
|
||||
),
|
||||
));
|
||||
$form->setData(array('foo@foo.com', 'foo@bar.com'));
|
||||
|
||||
$this->assertEquals(false, $form[0]->isRequired());
|
||||
$this->assertEquals(false, $form[1]->isRequired());
|
||||
$this->assertEquals(20, $form[0]->getAttribute('max_length'));
|
||||
$this->assertEquals(20, $form[1]->getAttribute('max_length'));
|
||||
|
||||
$form->bind(array('foo@bar.com', 'bar@foo.com'));
|
||||
|
||||
$this->assertEquals(false, $form[0]->isRequired());
|
||||
$this->assertEquals(false, $form[1]->isRequired());
|
||||
$this->assertEquals(20, $form[0]->getAttribute('max_length'));
|
||||
$this->assertEquals(20, $form[1]->getAttribute('max_length'));
|
||||
|
||||
//Test with prototype and extra field
|
||||
$form = $this->factory->create('collection', null, array(
|
||||
'allow_add' => true,
|
||||
'prototype' => true,
|
||||
'type' => 'field',
|
||||
'type_options' => array(
|
||||
'required' => false,
|
||||
'max_length' => 20
|
||||
),
|
||||
));
|
||||
|
||||
$form->setData(array('foo@foo.com'));
|
||||
|
||||
$this->assertEquals(false, $form[0]->isRequired());
|
||||
$this->assertEquals(20, $form[0]->getAttribute('max_length'));
|
||||
|
||||
$form->bind(array('foo@bar.com', 'bar@foo.com'));
|
||||
|
||||
$this->assertEquals(false, $form[0]->isRequired());
|
||||
$this->assertEquals(false, $form[1]->isRequired());
|
||||
$this->assertEquals(20, $form[0]->getAttribute('max_length'));
|
||||
$this->assertEquals(20, $form[1]->getAttribute('max_length'));
|
||||
|
||||
}
|
||||
|
||||
public function testSetTypeOptionsWithoutOptions()
|
||||
{
|
||||
$form = $this->factory->create('collection', null, array(
|
||||
'type' => 'field',
|
||||
));
|
||||
$form->setData(array('foo@foo.com', 'foo@bar.com'));
|
||||
|
||||
$this->assertEquals(true, $form[0]->isRequired());
|
||||
$this->assertEquals(true, $form[1]->isRequired());
|
||||
$this->assertEquals(null, $form[0]->getAttribute('max_length'));
|
||||
$this->assertEquals(null, $form[1]->getAttribute('max_length'));
|
||||
|
||||
$form->bind(array('foo@bar.com', 'bar@foo.com'));
|
||||
|
||||
$this->assertEquals(true, $form[0]->isRequired());
|
||||
$this->assertEquals(true, $form[1]->isRequired());
|
||||
$this->assertEquals(null, $form[0]->getAttribute('max_length'));
|
||||
$this->assertEquals(null, $form[1]->getAttribute('max_length'));
|
||||
|
||||
//Test with prototype and extra field
|
||||
$form = $this->factory->create('collection', null, array(
|
||||
'allow_add' => true,
|
||||
'prototype' => true,
|
||||
'type' => 'field',
|
||||
));
|
||||
|
||||
$form->setData(array('foo@foo.com'));
|
||||
|
||||
$this->assertEquals(true, $form[0]->isRequired());
|
||||
$this->assertEquals(null, $form[0]->getAttribute('max_length'));
|
||||
|
||||
$form->bind(array('foo@bar.com', 'bar@foo.com'));
|
||||
|
||||
$this->assertEquals(true, $form[0]->isRequired());
|
||||
$this->assertEquals(true, $form[1]->isRequired());
|
||||
$this->assertEquals(null, $form[0]->getAttribute('max_length'));
|
||||
$this->assertEquals(null, $form[1]->getAttribute('max_length'));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user