Merge branch '3.2'
* 3.2: [Serializer] Xml encoder throws exception for valid data [Form] Hardened form type tests fixed CS Added setInputStream deprecation to UPGRADE guides fixed CS
This commit is contained in:
commit
93810bcddf
@ -12,6 +12,52 @@ Console
|
|||||||
* Setting unknown style options is deprecated and will throw an exception in
|
* Setting unknown style options is deprecated and will throw an exception in
|
||||||
Symfony 4.0.
|
Symfony 4.0.
|
||||||
|
|
||||||
|
* The `QuestionHelper::setInputStream()` method is deprecated and will be
|
||||||
|
removed in Symfony 4.0. Use `StreamableInputInterface::setStream()` or
|
||||||
|
`CommandTester::setInputs()` instead.
|
||||||
|
|
||||||
|
Before:
|
||||||
|
|
||||||
|
```php
|
||||||
|
$input = new ArrayInput();
|
||||||
|
|
||||||
|
$questionHelper->setInputStream($stream);
|
||||||
|
$questionHelper->ask($input, $output, $question);
|
||||||
|
```
|
||||||
|
|
||||||
|
After:
|
||||||
|
|
||||||
|
```php
|
||||||
|
$input = new ArrayInput();
|
||||||
|
$input->setStream($stream);
|
||||||
|
|
||||||
|
$questionHelper->ask($input, $output, $question);
|
||||||
|
```
|
||||||
|
|
||||||
|
Before:
|
||||||
|
|
||||||
|
```php
|
||||||
|
$commandTester = new CommandTester($command);
|
||||||
|
|
||||||
|
$stream = fopen('php://memory', 'r+', false);
|
||||||
|
fputs($stream, "AppBundle\nYes");
|
||||||
|
rewind($stream);
|
||||||
|
|
||||||
|
$command->getHelper('question')->setInputStream($stream);
|
||||||
|
|
||||||
|
$commandTester->execute();
|
||||||
|
```
|
||||||
|
|
||||||
|
After:
|
||||||
|
|
||||||
|
```php
|
||||||
|
$commandTester = new CommandTester($command);
|
||||||
|
|
||||||
|
$commandTester->setInputs(array('AppBundle', 'Yes'));
|
||||||
|
|
||||||
|
$commandTester->execute();
|
||||||
|
```
|
||||||
|
|
||||||
DependencyInjection
|
DependencyInjection
|
||||||
-------------------
|
-------------------
|
||||||
|
|
||||||
@ -21,7 +67,7 @@ DependencyInjection
|
|||||||
ExpressionLanguage
|
ExpressionLanguage
|
||||||
-------------------
|
-------------------
|
||||||
|
|
||||||
* Passing a `ParserCacheInterface` instance to the `ExpressionLanguage` has been
|
* Passing a `ParserCacheInterface` instance to the `ExpressionLanguage` has been
|
||||||
deprecated and will not be supported in Symfony 4.0. You should use the
|
deprecated and will not be supported in Symfony 4.0. You should use the
|
||||||
`CacheItemPoolInterface` interface instead.
|
`CacheItemPoolInterface` interface instead.
|
||||||
|
|
||||||
|
@ -12,6 +12,52 @@ Console
|
|||||||
* Setting unknown style options is not supported anymore and throws an
|
* Setting unknown style options is not supported anymore and throws an
|
||||||
exception.
|
exception.
|
||||||
|
|
||||||
|
* The `QuestionHelper::setInputStream()` method is removed. Use
|
||||||
|
`StreamableInputInterface::setStream()` or `CommandTester::setInputs()`
|
||||||
|
instead.
|
||||||
|
|
||||||
|
Before:
|
||||||
|
|
||||||
|
```php
|
||||||
|
$input = new ArrayInput();
|
||||||
|
|
||||||
|
$questionHelper->setInputStream($stream);
|
||||||
|
$questionHelper->ask($input, $output, $question);
|
||||||
|
```
|
||||||
|
|
||||||
|
After:
|
||||||
|
|
||||||
|
```php
|
||||||
|
$input = new ArrayInput();
|
||||||
|
$input->setStream($stream);
|
||||||
|
|
||||||
|
$questionHelper->ask($input, $output, $question);
|
||||||
|
```
|
||||||
|
|
||||||
|
Before:
|
||||||
|
|
||||||
|
```php
|
||||||
|
$commandTester = new CommandTester($command);
|
||||||
|
|
||||||
|
$stream = fopen('php://memory', 'r+', false);
|
||||||
|
fputs($stream, "AppBundle\nYes");
|
||||||
|
rewind($stream);
|
||||||
|
|
||||||
|
$command->getHelper('question')->setInputStream($stream);
|
||||||
|
|
||||||
|
$commandTester->execute();
|
||||||
|
```
|
||||||
|
|
||||||
|
After:
|
||||||
|
|
||||||
|
```php
|
||||||
|
$commandTester = new CommandTester($command);
|
||||||
|
|
||||||
|
$commandTester->setInputs(array('AppBundle', 'Yes'));
|
||||||
|
|
||||||
|
$commandTester->execute();
|
||||||
|
```
|
||||||
|
|
||||||
Debug
|
Debug
|
||||||
-----
|
-----
|
||||||
|
|
||||||
|
@ -29,13 +29,16 @@ use Symfony\Bridge\Doctrine\Tests\Fixtures\SingleStringIdEntity;
|
|||||||
use Symfony\Component\Form\ChoiceList\View\ChoiceGroupView;
|
use Symfony\Component\Form\ChoiceList\View\ChoiceGroupView;
|
||||||
use Symfony\Component\Form\ChoiceList\View\ChoiceView;
|
use Symfony\Component\Form\ChoiceList\View\ChoiceView;
|
||||||
use Symfony\Component\Form\Forms;
|
use Symfony\Component\Form\Forms;
|
||||||
use Symfony\Component\Form\Test\TypeTestCase;
|
use Symfony\Component\Form\Tests\Extension\Core\Type\BaseTypeTest;
|
||||||
|
use Symfony\Component\Form\Tests\Extension\Core\Type\FormTypeTest;
|
||||||
use Symfony\Component\PropertyAccess\PropertyAccess;
|
use Symfony\Component\PropertyAccess\PropertyAccess;
|
||||||
use Symfony\Bridge\Doctrine\Tests\Fixtures\SingleAssociationToIntIdEntity;
|
use Symfony\Bridge\Doctrine\Tests\Fixtures\SingleAssociationToIntIdEntity;
|
||||||
use Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdNoToStringEntity;
|
use Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdNoToStringEntity;
|
||||||
|
|
||||||
class EntityTypeTest extends TypeTestCase
|
class EntityTypeTest extends BaseTypeTest
|
||||||
{
|
{
|
||||||
|
const TESTED_TYPE = 'Symfony\Bridge\Doctrine\Form\Type\EntityType';
|
||||||
|
|
||||||
const ITEM_GROUP_CLASS = 'Symfony\Bridge\Doctrine\Tests\Fixtures\GroupableEntity';
|
const ITEM_GROUP_CLASS = 'Symfony\Bridge\Doctrine\Tests\Fixtures\GroupableEntity';
|
||||||
const SINGLE_IDENT_CLASS = 'Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdEntity';
|
const SINGLE_IDENT_CLASS = 'Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdEntity';
|
||||||
const SINGLE_IDENT_NO_TO_STRING_CLASS = 'Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdNoToStringEntity';
|
const SINGLE_IDENT_NO_TO_STRING_CLASS = 'Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdNoToStringEntity';
|
||||||
@ -116,7 +119,7 @@ class EntityTypeTest extends TypeTestCase
|
|||||||
*/
|
*/
|
||||||
public function testClassOptionIsRequired()
|
public function testClassOptionIsRequired()
|
||||||
{
|
{
|
||||||
$this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType');
|
$this->factory->createNamed('name', static::TESTED_TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -124,7 +127,7 @@ class EntityTypeTest extends TypeTestCase
|
|||||||
*/
|
*/
|
||||||
public function testInvalidClassOption()
|
public function testInvalidClassOption()
|
||||||
{
|
{
|
||||||
$this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
$this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||||
'class' => 'foo',
|
'class' => 'foo',
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
@ -136,7 +139,7 @@ class EntityTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
$this->persist(array($entity1, $entity2));
|
$this->persist(array($entity1, $entity2));
|
||||||
|
|
||||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||||
'em' => 'default',
|
'em' => 'default',
|
||||||
'class' => self::SINGLE_IDENT_CLASS,
|
'class' => self::SINGLE_IDENT_CLASS,
|
||||||
'required' => false,
|
'required' => false,
|
||||||
@ -153,13 +156,14 @@ class EntityTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
$this->persist(array($entity1, $entity2));
|
$this->persist(array($entity1, $entity2));
|
||||||
|
|
||||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
$view = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||||
'em' => 'default',
|
'em' => 'default',
|
||||||
'class' => self::SINGLE_IDENT_CLASS,
|
'class' => self::SINGLE_IDENT_CLASS,
|
||||||
'required' => false,
|
'required' => false,
|
||||||
));
|
))
|
||||||
|
->createView();
|
||||||
|
|
||||||
$this->assertEquals(array(1 => new ChoiceView($entity1, '1', 'Foo'), 2 => new ChoiceView($entity2, '2', 'Bar')), $field->createView()->vars['choices']);
|
$this->assertEquals(array(1 => new ChoiceView($entity1, '1', 'Foo'), 2 => new ChoiceView($entity2, '2', 'Bar')), $view->vars['choices']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSetDataToUninitializedEntityWithNonRequiredQueryBuilder()
|
public function testSetDataToUninitializedEntityWithNonRequiredQueryBuilder()
|
||||||
@ -170,15 +174,16 @@ class EntityTypeTest extends TypeTestCase
|
|||||||
$this->persist(array($entity1, $entity2));
|
$this->persist(array($entity1, $entity2));
|
||||||
$qb = $this->em->createQueryBuilder()->select('e')->from(self::SINGLE_IDENT_CLASS, 'e');
|
$qb = $this->em->createQueryBuilder()->select('e')->from(self::SINGLE_IDENT_CLASS, 'e');
|
||||||
|
|
||||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
$view = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||||
'em' => 'default',
|
'em' => 'default',
|
||||||
'class' => self::SINGLE_IDENT_CLASS,
|
'class' => self::SINGLE_IDENT_CLASS,
|
||||||
'required' => false,
|
'required' => false,
|
||||||
'choice_label' => 'name',
|
'choice_label' => 'name',
|
||||||
'query_builder' => $qb,
|
'query_builder' => $qb,
|
||||||
));
|
))
|
||||||
|
->createView();
|
||||||
|
|
||||||
$this->assertEquals(array(1 => new ChoiceView($entity1, '1', 'Foo'), 2 => new ChoiceView($entity2, '2', 'Bar')), $field->createView()->vars['choices']);
|
$this->assertEquals(array(1 => new ChoiceView($entity1, '1', 'Foo'), 2 => new ChoiceView($entity2, '2', 'Bar')), $view->vars['choices']);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -186,7 +191,7 @@ class EntityTypeTest extends TypeTestCase
|
|||||||
*/
|
*/
|
||||||
public function testConfigureQueryBuilderWithNonQueryBuilderAndNonClosure()
|
public function testConfigureQueryBuilderWithNonQueryBuilderAndNonClosure()
|
||||||
{
|
{
|
||||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||||
'em' => 'default',
|
'em' => 'default',
|
||||||
'class' => self::SINGLE_IDENT_CLASS,
|
'class' => self::SINGLE_IDENT_CLASS,
|
||||||
'query_builder' => new \stdClass(),
|
'query_builder' => new \stdClass(),
|
||||||
@ -198,7 +203,7 @@ class EntityTypeTest extends TypeTestCase
|
|||||||
*/
|
*/
|
||||||
public function testConfigureQueryBuilderWithClosureReturningNonQueryBuilder()
|
public function testConfigureQueryBuilderWithClosureReturningNonQueryBuilder()
|
||||||
{
|
{
|
||||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||||
'em' => 'default',
|
'em' => 'default',
|
||||||
'class' => self::SINGLE_IDENT_CLASS,
|
'class' => self::SINGLE_IDENT_CLASS,
|
||||||
'query_builder' => function () {
|
'query_builder' => function () {
|
||||||
@ -216,7 +221,7 @@ class EntityTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
$this->persist(array($entity1, $entity2));
|
$this->persist(array($entity1, $entity2));
|
||||||
|
|
||||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||||
'em' => 'default',
|
'em' => 'default',
|
||||||
'class' => self::SINGLE_IDENT_CLASS,
|
'class' => self::SINGLE_IDENT_CLASS,
|
||||||
'query_builder' => function () {
|
'query_builder' => function () {
|
||||||
@ -229,7 +234,7 @@ class EntityTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testSetDataSingleNull()
|
public function testSetDataSingleNull()
|
||||||
{
|
{
|
||||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||||
'multiple' => false,
|
'multiple' => false,
|
||||||
'em' => 'default',
|
'em' => 'default',
|
||||||
'class' => self::SINGLE_IDENT_CLASS,
|
'class' => self::SINGLE_IDENT_CLASS,
|
||||||
@ -242,7 +247,7 @@ class EntityTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testSetDataMultipleExpandedNull()
|
public function testSetDataMultipleExpandedNull()
|
||||||
{
|
{
|
||||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||||
'multiple' => true,
|
'multiple' => true,
|
||||||
'expanded' => true,
|
'expanded' => true,
|
||||||
'em' => 'default',
|
'em' => 'default',
|
||||||
@ -256,7 +261,7 @@ class EntityTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testSetDataMultipleNonExpandedNull()
|
public function testSetDataMultipleNonExpandedNull()
|
||||||
{
|
{
|
||||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||||
'multiple' => true,
|
'multiple' => true,
|
||||||
'expanded' => false,
|
'expanded' => false,
|
||||||
'em' => 'default',
|
'em' => 'default',
|
||||||
@ -268,47 +273,6 @@ class EntityTypeTest extends TypeTestCase
|
|||||||
$this->assertSame(array(), $field->getViewData());
|
$this->assertSame(array(), $field->getViewData());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSubmitSingleExpandedNull()
|
|
||||||
{
|
|
||||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
|
||||||
'multiple' => false,
|
|
||||||
'expanded' => true,
|
|
||||||
'em' => 'default',
|
|
||||||
'class' => self::SINGLE_IDENT_CLASS,
|
|
||||||
));
|
|
||||||
$field->submit(null);
|
|
||||||
|
|
||||||
$this->assertNull($field->getData());
|
|
||||||
$this->assertSame('', $field->getViewData(), 'View data is always a string');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testSubmitSingleNonExpandedNull()
|
|
||||||
{
|
|
||||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
|
||||||
'multiple' => false,
|
|
||||||
'expanded' => false,
|
|
||||||
'em' => 'default',
|
|
||||||
'class' => self::SINGLE_IDENT_CLASS,
|
|
||||||
));
|
|
||||||
$field->submit(null);
|
|
||||||
|
|
||||||
$this->assertNull($field->getData());
|
|
||||||
$this->assertSame('', $field->getViewData());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testSubmitMultipleNull()
|
|
||||||
{
|
|
||||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
|
||||||
'multiple' => true,
|
|
||||||
'em' => 'default',
|
|
||||||
'class' => self::SINGLE_IDENT_CLASS,
|
|
||||||
));
|
|
||||||
$field->submit(null);
|
|
||||||
|
|
||||||
$this->assertEquals(new ArrayCollection(), $field->getData());
|
|
||||||
$this->assertSame(array(), $field->getViewData());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testSubmitSingleNonExpandedSingleIdentifier()
|
public function testSubmitSingleNonExpandedSingleIdentifier()
|
||||||
{
|
{
|
||||||
$entity1 = new SingleIntIdEntity(1, 'Foo');
|
$entity1 = new SingleIntIdEntity(1, 'Foo');
|
||||||
@ -316,7 +280,7 @@ class EntityTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
$this->persist(array($entity1, $entity2));
|
$this->persist(array($entity1, $entity2));
|
||||||
|
|
||||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||||
'multiple' => false,
|
'multiple' => false,
|
||||||
'expanded' => false,
|
'expanded' => false,
|
||||||
'em' => 'default',
|
'em' => 'default',
|
||||||
@ -341,7 +305,7 @@ class EntityTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
$this->persist(array($innerEntity1, $innerEntity2, $entity1, $entity2));
|
$this->persist(array($innerEntity1, $innerEntity2, $entity1, $entity2));
|
||||||
|
|
||||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||||
'multiple' => false,
|
'multiple' => false,
|
||||||
'expanded' => false,
|
'expanded' => false,
|
||||||
'em' => 'default',
|
'em' => 'default',
|
||||||
@ -363,7 +327,7 @@ class EntityTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
$this->persist(array($entity1, $entity2));
|
$this->persist(array($entity1, $entity2));
|
||||||
|
|
||||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||||
'multiple' => false,
|
'multiple' => false,
|
||||||
'expanded' => false,
|
'expanded' => false,
|
||||||
'em' => 'default',
|
'em' => 'default',
|
||||||
@ -387,7 +351,7 @@ class EntityTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
$this->persist(array($entity1, $entity2, $entity3));
|
$this->persist(array($entity1, $entity2, $entity3));
|
||||||
|
|
||||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||||
'multiple' => true,
|
'multiple' => true,
|
||||||
'expanded' => false,
|
'expanded' => false,
|
||||||
'em' => 'default',
|
'em' => 'default',
|
||||||
@ -416,7 +380,7 @@ class EntityTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
$this->persist(array($innerEntity1, $innerEntity2, $innerEntity3, $entity1, $entity2, $entity3));
|
$this->persist(array($innerEntity1, $innerEntity2, $innerEntity3, $entity1, $entity2, $entity3));
|
||||||
|
|
||||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||||
'multiple' => true,
|
'multiple' => true,
|
||||||
'expanded' => false,
|
'expanded' => false,
|
||||||
'em' => 'default',
|
'em' => 'default',
|
||||||
@ -441,7 +405,7 @@ class EntityTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
$this->persist(array($entity1, $entity2, $entity3));
|
$this->persist(array($entity1, $entity2, $entity3));
|
||||||
|
|
||||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||||
'multiple' => true,
|
'multiple' => true,
|
||||||
'expanded' => false,
|
'expanded' => false,
|
||||||
'em' => 'default',
|
'em' => 'default',
|
||||||
@ -472,7 +436,7 @@ class EntityTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
$this->persist(array($entity1, $entity2, $entity3));
|
$this->persist(array($entity1, $entity2, $entity3));
|
||||||
|
|
||||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||||
'multiple' => true,
|
'multiple' => true,
|
||||||
'expanded' => false,
|
'expanded' => false,
|
||||||
'em' => 'default',
|
'em' => 'default',
|
||||||
@ -498,7 +462,7 @@ class EntityTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
$this->persist(array($entity1, $entity2, $entity3));
|
$this->persist(array($entity1, $entity2, $entity3));
|
||||||
|
|
||||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||||
'multiple' => true,
|
'multiple' => true,
|
||||||
'expanded' => false,
|
'expanded' => false,
|
||||||
'em' => 'default',
|
'em' => 'default',
|
||||||
@ -528,7 +492,7 @@ class EntityTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
$this->persist(array($entity1, $entity2));
|
$this->persist(array($entity1, $entity2));
|
||||||
|
|
||||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||||
'multiple' => false,
|
'multiple' => false,
|
||||||
'expanded' => true,
|
'expanded' => true,
|
||||||
'em' => 'default',
|
'em' => 'default',
|
||||||
@ -554,7 +518,7 @@ class EntityTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
$this->persist(array($entity1, $entity2, $entity3));
|
$this->persist(array($entity1, $entity2, $entity3));
|
||||||
|
|
||||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||||
'multiple' => true,
|
'multiple' => true,
|
||||||
'expanded' => true,
|
'expanded' => true,
|
||||||
'em' => 'default',
|
'em' => 'default',
|
||||||
@ -583,7 +547,7 @@ class EntityTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
$this->persist(array($entity1, $entity2));
|
$this->persist(array($entity1, $entity2));
|
||||||
|
|
||||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||||
'multiple' => true,
|
'multiple' => true,
|
||||||
'expanded' => true,
|
'expanded' => true,
|
||||||
'em' => 'default',
|
'em' => 'default',
|
||||||
@ -608,7 +572,7 @@ class EntityTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
$this->persist(array($entity1, $entity2));
|
$this->persist(array($entity1, $entity2));
|
||||||
|
|
||||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||||
'multiple' => false,
|
'multiple' => false,
|
||||||
'expanded' => false,
|
'expanded' => false,
|
||||||
'em' => 'default',
|
'em' => 'default',
|
||||||
@ -630,7 +594,7 @@ class EntityTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
$this->persist(array($entity1, $entity2));
|
$this->persist(array($entity1, $entity2));
|
||||||
|
|
||||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||||
'multiple' => false,
|
'multiple' => false,
|
||||||
'expanded' => true,
|
'expanded' => true,
|
||||||
'em' => 'default',
|
'em' => 'default',
|
||||||
@ -656,7 +620,7 @@ class EntityTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
$this->persist(array($entity1, $entity2, $entity3));
|
$this->persist(array($entity1, $entity2, $entity3));
|
||||||
|
|
||||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||||
'multiple' => true,
|
'multiple' => true,
|
||||||
'expanded' => false,
|
'expanded' => false,
|
||||||
'em' => 'default',
|
'em' => 'default',
|
||||||
@ -687,7 +651,7 @@ class EntityTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
$this->persist(array($entity1, $entity2, $entity3));
|
$this->persist(array($entity1, $entity2, $entity3));
|
||||||
|
|
||||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||||
'multiple' => true,
|
'multiple' => true,
|
||||||
'expanded' => false,
|
'expanded' => false,
|
||||||
'em' => 'default',
|
'em' => 'default',
|
||||||
@ -712,7 +676,7 @@ class EntityTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
$this->persist(array($entity1, $entity2, $entity3));
|
$this->persist(array($entity1, $entity2, $entity3));
|
||||||
|
|
||||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||||
'multiple' => true,
|
'multiple' => true,
|
||||||
'expanded' => true,
|
'expanded' => true,
|
||||||
'em' => 'default',
|
'em' => 'default',
|
||||||
@ -742,7 +706,7 @@ class EntityTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
$this->persist(array($entity1, $entity2, $entity3));
|
$this->persist(array($entity1, $entity2, $entity3));
|
||||||
|
|
||||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||||
'em' => 'default',
|
'em' => 'default',
|
||||||
'class' => self::SINGLE_IDENT_CLASS,
|
'class' => self::SINGLE_IDENT_CLASS,
|
||||||
// not all persisted entities should be displayed
|
// not all persisted entities should be displayed
|
||||||
@ -765,7 +729,7 @@ class EntityTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
$this->persist(array($entity1, $entity2));
|
$this->persist(array($entity1, $entity2));
|
||||||
|
|
||||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||||
'em' => 'default',
|
'em' => 'default',
|
||||||
'class' => self::SINGLE_IDENT_CLASS,
|
'class' => self::SINGLE_IDENT_CLASS,
|
||||||
'choice_label' => 'name',
|
'choice_label' => 'name',
|
||||||
@ -787,7 +751,7 @@ class EntityTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
$this->persist(array($entity1, $entity2));
|
$this->persist(array($entity1, $entity2));
|
||||||
|
|
||||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||||
'em' => 'default',
|
'em' => 'default',
|
||||||
'class' => self::ITEM_GROUP_CLASS,
|
'class' => self::ITEM_GROUP_CLASS,
|
||||||
'choice_label' => 'name',
|
'choice_label' => 'name',
|
||||||
@ -818,7 +782,7 @@ class EntityTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
$this->persist(array($entity1, $entity2));
|
$this->persist(array($entity1, $entity2));
|
||||||
|
|
||||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||||
'em' => 'default',
|
'em' => 'default',
|
||||||
'class' => self::SINGLE_IDENT_CLASS,
|
'class' => self::SINGLE_IDENT_CLASS,
|
||||||
'choice_label' => 'name',
|
'choice_label' => 'name',
|
||||||
@ -844,7 +808,7 @@ class EntityTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
$this->persist(array($item1, $item2, $item3, $item4));
|
$this->persist(array($item1, $item2, $item3, $item4));
|
||||||
|
|
||||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||||
'em' => 'default',
|
'em' => 'default',
|
||||||
'class' => self::ITEM_GROUP_CLASS,
|
'class' => self::ITEM_GROUP_CLASS,
|
||||||
'choices' => array($item1, $item2, $item3, $item4),
|
'choices' => array($item1, $item2, $item3, $item4),
|
||||||
@ -875,7 +839,7 @@ class EntityTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
$this->persist(array($entity1, $entity2, $entity3));
|
$this->persist(array($entity1, $entity2, $entity3));
|
||||||
|
|
||||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||||
'em' => 'default',
|
'em' => 'default',
|
||||||
'class' => self::SINGLE_IDENT_CLASS,
|
'class' => self::SINGLE_IDENT_CLASS,
|
||||||
'preferred_choices' => array($entity3, $entity2),
|
'preferred_choices' => array($entity3, $entity2),
|
||||||
@ -894,7 +858,7 @@ class EntityTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
$this->persist(array($entity1, $entity2, $entity3));
|
$this->persist(array($entity1, $entity2, $entity3));
|
||||||
|
|
||||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||||
'em' => 'default',
|
'em' => 'default',
|
||||||
'class' => self::SINGLE_IDENT_CLASS,
|
'class' => self::SINGLE_IDENT_CLASS,
|
||||||
'choices' => array($entity2, $entity3),
|
'choices' => array($entity2, $entity3),
|
||||||
@ -914,7 +878,7 @@ class EntityTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
$this->persist(array($entity1, $entity2, $entity3));
|
$this->persist(array($entity1, $entity2, $entity3));
|
||||||
|
|
||||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||||
'em' => 'default',
|
'em' => 'default',
|
||||||
'class' => self::SINGLE_IDENT_CLASS,
|
'class' => self::SINGLE_IDENT_CLASS,
|
||||||
'choices' => array($entity1, $entity2),
|
'choices' => array($entity1, $entity2),
|
||||||
@ -937,7 +901,7 @@ class EntityTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
$this->persist(array($innerEntity1, $innerEntity2, $entity1, $entity2));
|
$this->persist(array($innerEntity1, $innerEntity2, $entity1, $entity2));
|
||||||
|
|
||||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||||
'em' => 'default',
|
'em' => 'default',
|
||||||
'class' => self::SINGLE_ASSOC_IDENT_CLASS,
|
'class' => self::SINGLE_ASSOC_IDENT_CLASS,
|
||||||
'choices' => array($entity1, $entity2),
|
'choices' => array($entity1, $entity2),
|
||||||
@ -958,7 +922,7 @@ class EntityTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
$this->persist(array($entity1, $entity2, $entity3));
|
$this->persist(array($entity1, $entity2, $entity3));
|
||||||
|
|
||||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||||
'em' => 'default',
|
'em' => 'default',
|
||||||
'class' => self::COMPOSITE_IDENT_CLASS,
|
'class' => self::COMPOSITE_IDENT_CLASS,
|
||||||
'choices' => array($entity1, $entity2),
|
'choices' => array($entity1, $entity2),
|
||||||
@ -981,7 +945,7 @@ class EntityTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
$repository = $this->em->getRepository(self::SINGLE_IDENT_CLASS);
|
$repository = $this->em->getRepository(self::SINGLE_IDENT_CLASS);
|
||||||
|
|
||||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||||
'em' => 'default',
|
'em' => 'default',
|
||||||
'class' => self::SINGLE_IDENT_CLASS,
|
'class' => self::SINGLE_IDENT_CLASS,
|
||||||
'query_builder' => $repository->createQueryBuilder('e')
|
'query_builder' => $repository->createQueryBuilder('e')
|
||||||
@ -1009,7 +973,7 @@ class EntityTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
$repository = $this->em->getRepository(self::SINGLE_ASSOC_IDENT_CLASS);
|
$repository = $this->em->getRepository(self::SINGLE_ASSOC_IDENT_CLASS);
|
||||||
|
|
||||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||||
'em' => 'default',
|
'em' => 'default',
|
||||||
'class' => self::SINGLE_ASSOC_IDENT_CLASS,
|
'class' => self::SINGLE_ASSOC_IDENT_CLASS,
|
||||||
'query_builder' => $repository->createQueryBuilder('e')
|
'query_builder' => $repository->createQueryBuilder('e')
|
||||||
@ -1031,10 +995,10 @@ class EntityTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
$this->persist(array($entity1, $entity2, $entity3));
|
$this->persist(array($entity1, $entity2, $entity3));
|
||||||
|
|
||||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||||
'em' => 'default',
|
'em' => 'default',
|
||||||
'class' => self::SINGLE_IDENT_CLASS,
|
'class' => self::SINGLE_IDENT_CLASS,
|
||||||
'query_builder' => function ($repository) {
|
'query_builder' => function (EntityRepository $repository) {
|
||||||
return $repository->createQueryBuilder('e')
|
return $repository->createQueryBuilder('e')
|
||||||
->where('e.id IN (1, 2)');
|
->where('e.id IN (1, 2)');
|
||||||
},
|
},
|
||||||
@ -1055,10 +1019,10 @@ class EntityTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
$this->persist(array($entity1, $entity2, $entity3));
|
$this->persist(array($entity1, $entity2, $entity3));
|
||||||
|
|
||||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||||
'em' => 'default',
|
'em' => 'default',
|
||||||
'class' => self::COMPOSITE_IDENT_CLASS,
|
'class' => self::COMPOSITE_IDENT_CLASS,
|
||||||
'query_builder' => function ($repository) {
|
'query_builder' => function (EntityRepository $repository) {
|
||||||
return $repository->createQueryBuilder('e')
|
return $repository->createQueryBuilder('e')
|
||||||
->where('e.id1 IN (10, 50)');
|
->where('e.id1 IN (10, 50)');
|
||||||
},
|
},
|
||||||
@ -1077,7 +1041,7 @@ class EntityTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
$this->persist(array($entity1));
|
$this->persist(array($entity1));
|
||||||
|
|
||||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||||
'multiple' => false,
|
'multiple' => false,
|
||||||
'expanded' => false,
|
'expanded' => false,
|
||||||
'em' => 'default',
|
'em' => 'default',
|
||||||
@ -1098,7 +1062,7 @@ class EntityTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
$this->persist(array($entity1));
|
$this->persist(array($entity1));
|
||||||
|
|
||||||
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||||
'multiple' => false,
|
'multiple' => false,
|
||||||
'expanded' => false,
|
'expanded' => false,
|
||||||
'em' => 'default',
|
'em' => 'default',
|
||||||
@ -1124,7 +1088,7 @@ class EntityTypeTest extends TypeTestCase
|
|||||||
->with(self::SINGLE_IDENT_CLASS)
|
->with(self::SINGLE_IDENT_CLASS)
|
||||||
->will($this->returnValue($this->em));
|
->will($this->returnValue($this->em));
|
||||||
|
|
||||||
$this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
$this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||||
'class' => self::SINGLE_IDENT_CLASS,
|
'class' => self::SINGLE_IDENT_CLASS,
|
||||||
'required' => false,
|
'required' => false,
|
||||||
'choice_label' => 'name',
|
'choice_label' => 'name',
|
||||||
@ -1139,7 +1103,7 @@ class EntityTypeTest extends TypeTestCase
|
|||||||
$this->emRegistry->expects($this->never())
|
$this->emRegistry->expects($this->never())
|
||||||
->method('getManagerForClass');
|
->method('getManagerForClass');
|
||||||
|
|
||||||
$this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
|
$this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||||
'em' => $this->em,
|
'em' => $this->em,
|
||||||
'class' => self::SINGLE_IDENT_CLASS,
|
'class' => self::SINGLE_IDENT_CLASS,
|
||||||
'choice_label' => 'name',
|
'choice_label' => 'name',
|
||||||
@ -1168,15 +1132,15 @@ class EntityTypeTest extends TypeTestCase
|
|||||||
->addTypeGuesser($entityTypeGuesser)
|
->addTypeGuesser($entityTypeGuesser)
|
||||||
->getFormFactory();
|
->getFormFactory();
|
||||||
|
|
||||||
$formBuilder = $factory->createNamedBuilder('form', 'Symfony\Component\Form\Extension\Core\Type\FormType');
|
$formBuilder = $factory->createNamedBuilder('form', FormTypeTest::TESTED_TYPE);
|
||||||
|
|
||||||
$formBuilder->add('property1', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', array(
|
$formBuilder->add('property1', static::TESTED_TYPE, array(
|
||||||
'em' => 'default',
|
'em' => 'default',
|
||||||
'class' => self::SINGLE_IDENT_CLASS,
|
'class' => self::SINGLE_IDENT_CLASS,
|
||||||
'query_builder' => $repo->createQueryBuilder('e')->where('e.id IN (1, 2)'),
|
'query_builder' => $repo->createQueryBuilder('e')->where('e.id IN (1, 2)'),
|
||||||
));
|
));
|
||||||
|
|
||||||
$formBuilder->add('property2', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', array(
|
$formBuilder->add('property2', static::TESTED_TYPE, array(
|
||||||
'em' => 'default',
|
'em' => 'default',
|
||||||
'class' => self::SINGLE_IDENT_CLASS,
|
'class' => self::SINGLE_IDENT_CLASS,
|
||||||
'query_builder' => function (EntityRepository $repo) {
|
'query_builder' => function (EntityRepository $repo) {
|
||||||
@ -1184,7 +1148,7 @@ class EntityTypeTest extends TypeTestCase
|
|||||||
},
|
},
|
||||||
));
|
));
|
||||||
|
|
||||||
$formBuilder->add('property3', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', array(
|
$formBuilder->add('property3', static::TESTED_TYPE, array(
|
||||||
'em' => 'default',
|
'em' => 'default',
|
||||||
'class' => self::SINGLE_IDENT_CLASS,
|
'class' => self::SINGLE_IDENT_CLASS,
|
||||||
'query_builder' => function (EntityRepository $repo) {
|
'query_builder' => function (EntityRepository $repo) {
|
||||||
@ -1231,15 +1195,15 @@ class EntityTypeTest extends TypeTestCase
|
|||||||
->addTypeGuesser($entityTypeGuesser)
|
->addTypeGuesser($entityTypeGuesser)
|
||||||
->getFormFactory();
|
->getFormFactory();
|
||||||
|
|
||||||
$formBuilder = $factory->createNamedBuilder('form', 'Symfony\Component\Form\Extension\Core\Type\FormType');
|
$formBuilder = $factory->createNamedBuilder('form', FormTypeTest::TESTED_TYPE);
|
||||||
|
|
||||||
$formBuilder->add('property1', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', array(
|
$formBuilder->add('property1', static::TESTED_TYPE, array(
|
||||||
'em' => 'default',
|
'em' => 'default',
|
||||||
'class' => self::SINGLE_IDENT_CLASS,
|
'class' => self::SINGLE_IDENT_CLASS,
|
||||||
'query_builder' => $repo->createQueryBuilder('e')->where('e.id = :id')->setParameter('id', 1),
|
'query_builder' => $repo->createQueryBuilder('e')->where('e.id = :id')->setParameter('id', 1),
|
||||||
));
|
));
|
||||||
|
|
||||||
$formBuilder->add('property2', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', array(
|
$formBuilder->add('property2', static::TESTED_TYPE, array(
|
||||||
'em' => 'default',
|
'em' => 'default',
|
||||||
'class' => self::SINGLE_IDENT_CLASS,
|
'class' => self::SINGLE_IDENT_CLASS,
|
||||||
'query_builder' => function (EntityRepository $repo) {
|
'query_builder' => function (EntityRepository $repo) {
|
||||||
@ -1247,7 +1211,7 @@ class EntityTypeTest extends TypeTestCase
|
|||||||
},
|
},
|
||||||
));
|
));
|
||||||
|
|
||||||
$formBuilder->add('property3', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', array(
|
$formBuilder->add('property3', static::TESTED_TYPE, array(
|
||||||
'em' => 'default',
|
'em' => 'default',
|
||||||
'class' => self::SINGLE_IDENT_CLASS,
|
'class' => self::SINGLE_IDENT_CLASS,
|
||||||
'query_builder' => function (EntityRepository $repo) {
|
'query_builder' => function (EntityRepository $repo) {
|
||||||
@ -1282,4 +1246,213 @@ class EntityTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
return $registry;
|
return $registry;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testPassDisabledAsOption()
|
||||||
|
{
|
||||||
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
|
'em' => 'default',
|
||||||
|
'disabled' => true,
|
||||||
|
'class' => self::SINGLE_IDENT_CLASS,
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->assertTrue($form->isDisabled());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPassIdAndNameToView()
|
||||||
|
{
|
||||||
|
$view = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||||
|
'em' => 'default',
|
||||||
|
'class' => self::SINGLE_IDENT_CLASS,
|
||||||
|
))
|
||||||
|
->createView();
|
||||||
|
|
||||||
|
$this->assertEquals('name', $view->vars['id']);
|
||||||
|
$this->assertEquals('name', $view->vars['name']);
|
||||||
|
$this->assertEquals('name', $view->vars['full_name']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testStripLeadingUnderscoresAndDigitsFromId()
|
||||||
|
{
|
||||||
|
$view = $this->factory->createNamed('_09name', static::TESTED_TYPE, null, array(
|
||||||
|
'em' => 'default',
|
||||||
|
'class' => self::SINGLE_IDENT_CLASS,
|
||||||
|
))
|
||||||
|
->createView();
|
||||||
|
|
||||||
|
$this->assertEquals('name', $view->vars['id']);
|
||||||
|
$this->assertEquals('_09name', $view->vars['name']);
|
||||||
|
$this->assertEquals('_09name', $view->vars['full_name']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPassIdAndNameToViewWithParent()
|
||||||
|
{
|
||||||
|
$view = $this->factory->createNamedBuilder('parent', FormTypeTest::TESTED_TYPE)
|
||||||
|
->add('child', static::TESTED_TYPE, array(
|
||||||
|
'em' => 'default',
|
||||||
|
'class' => self::SINGLE_IDENT_CLASS,
|
||||||
|
))
|
||||||
|
->getForm()
|
||||||
|
->createView();
|
||||||
|
|
||||||
|
$this->assertEquals('parent_child', $view['child']->vars['id']);
|
||||||
|
$this->assertEquals('child', $view['child']->vars['name']);
|
||||||
|
$this->assertEquals('parent[child]', $view['child']->vars['full_name']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPassIdAndNameToViewWithGrandParent()
|
||||||
|
{
|
||||||
|
$builder = $this->factory->createNamedBuilder('parent', FormTypeTest::TESTED_TYPE)
|
||||||
|
->add('child', FormTypeTest::TESTED_TYPE);
|
||||||
|
$builder->get('child')->add('grand_child', static::TESTED_TYPE, array(
|
||||||
|
'em' => 'default',
|
||||||
|
'class' => self::SINGLE_IDENT_CLASS,
|
||||||
|
));
|
||||||
|
$view = $builder->getForm()->createView();
|
||||||
|
|
||||||
|
$this->assertEquals('parent_child_grand_child', $view['child']['grand_child']->vars['id']);
|
||||||
|
$this->assertEquals('grand_child', $view['child']['grand_child']->vars['name']);
|
||||||
|
$this->assertEquals('parent[child][grand_child]', $view['child']['grand_child']->vars['full_name']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPassTranslationDomainToView()
|
||||||
|
{
|
||||||
|
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
|
'em' => 'default',
|
||||||
|
'class' => self::SINGLE_IDENT_CLASS,
|
||||||
|
'translation_domain' => 'domain',
|
||||||
|
))
|
||||||
|
->createView();
|
||||||
|
|
||||||
|
$this->assertSame('domain', $view->vars['translation_domain']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testInheritTranslationDomainFromParent()
|
||||||
|
{
|
||||||
|
$view = $this->factory
|
||||||
|
->createNamedBuilder('parent', FormTypeTest::TESTED_TYPE, null, array(
|
||||||
|
'translation_domain' => 'domain',
|
||||||
|
))
|
||||||
|
->add('child', static::TESTED_TYPE, array(
|
||||||
|
'em' => 'default',
|
||||||
|
'class' => self::SINGLE_IDENT_CLASS,
|
||||||
|
))
|
||||||
|
->getForm()
|
||||||
|
->createView();
|
||||||
|
|
||||||
|
$this->assertEquals('domain', $view['child']->vars['translation_domain']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPreferOwnTranslationDomain()
|
||||||
|
{
|
||||||
|
$view = $this->factory
|
||||||
|
->createNamedBuilder('parent', FormTypeTest::TESTED_TYPE, null, array(
|
||||||
|
'translation_domain' => 'parent_domain',
|
||||||
|
))
|
||||||
|
->add('child', static::TESTED_TYPE, array(
|
||||||
|
'em' => 'default',
|
||||||
|
'class' => self::SINGLE_IDENT_CLASS,
|
||||||
|
'translation_domain' => 'domain',
|
||||||
|
))
|
||||||
|
->getForm()
|
||||||
|
->createView();
|
||||||
|
|
||||||
|
$this->assertEquals('domain', $view['child']->vars['translation_domain']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testDefaultTranslationDomain()
|
||||||
|
{
|
||||||
|
$view = $this->factory
|
||||||
|
->createNamedBuilder('parent', FormTypeTest::TESTED_TYPE)
|
||||||
|
->add('child', static::TESTED_TYPE, array(
|
||||||
|
'em' => 'default',
|
||||||
|
'class' => self::SINGLE_IDENT_CLASS,
|
||||||
|
))
|
||||||
|
->getForm()
|
||||||
|
->createView();
|
||||||
|
|
||||||
|
$this->assertNull($view['child']->vars['translation_domain']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPassLabelToView()
|
||||||
|
{
|
||||||
|
$view = $this->factory->createNamed('__test___field', static::TESTED_TYPE, null, array(
|
||||||
|
'label' => 'My label',
|
||||||
|
'em' => 'default',
|
||||||
|
'class' => self::SINGLE_IDENT_CLASS,
|
||||||
|
))
|
||||||
|
->createView();
|
||||||
|
|
||||||
|
$this->assertSame('My label', $view->vars['label']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPassMultipartFalseToView()
|
||||||
|
{
|
||||||
|
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
|
'em' => 'default',
|
||||||
|
'class' => self::SINGLE_IDENT_CLASS,
|
||||||
|
))
|
||||||
|
->createView();
|
||||||
|
|
||||||
|
$this->assertFalse($view->vars['multipart']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSubmitNull($expected = null, $norm = null, $view = null)
|
||||||
|
{
|
||||||
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
|
'em' => 'default',
|
||||||
|
'class' => self::SINGLE_IDENT_CLASS,
|
||||||
|
));
|
||||||
|
$form->submit(null);
|
||||||
|
|
||||||
|
$this->assertNull($form->getData());
|
||||||
|
$this->assertNull($form->getNormData());
|
||||||
|
$this->assertSame('', $form->getViewData(), 'View data is always a string');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSubmitNullExpanded()
|
||||||
|
{
|
||||||
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
|
'em' => 'default',
|
||||||
|
'class' => self::SINGLE_IDENT_CLASS,
|
||||||
|
'expanded' => true,
|
||||||
|
));
|
||||||
|
$form->submit(null);
|
||||||
|
|
||||||
|
$this->assertNull($form->getData());
|
||||||
|
$this->assertNull($form->getNormData());
|
||||||
|
$this->assertSame('', $form->getViewData(), 'View data is always a string');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSubmitNullMultiple()
|
||||||
|
{
|
||||||
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
|
'em' => 'default',
|
||||||
|
'class' => self::SINGLE_IDENT_CLASS,
|
||||||
|
'multiple' => true,
|
||||||
|
));
|
||||||
|
$form->submit(null);
|
||||||
|
|
||||||
|
$collection = new ArrayCollection();
|
||||||
|
|
||||||
|
$this->assertEquals($collection, $form->getData());
|
||||||
|
$this->assertEquals($collection, $form->getNormData());
|
||||||
|
$this->assertSame(array(), $form->getViewData(), 'View data is always an array');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSubmitNullExpandedMultiple()
|
||||||
|
{
|
||||||
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
|
'em' => 'default',
|
||||||
|
'class' => self::SINGLE_IDENT_CLASS,
|
||||||
|
'expanded' => true,
|
||||||
|
'multiple' => true,
|
||||||
|
));
|
||||||
|
$form->submit(null);
|
||||||
|
|
||||||
|
$collection = new ArrayCollection();
|
||||||
|
|
||||||
|
$this->assertEquals($collection, $form->getData());
|
||||||
|
$this->assertEquals($collection, $form->getNormData());
|
||||||
|
$this->assertSame(array(), $form->getViewData(), 'View data is always an array');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,8 @@ use Symfony\Component\Form\Test\TypeTestCase;
|
|||||||
*/
|
*/
|
||||||
abstract class BaseTypeTest extends TypeTestCase
|
abstract class BaseTypeTest extends TypeTestCase
|
||||||
{
|
{
|
||||||
|
const TESTED_TYPE = '';
|
||||||
|
|
||||||
public function testPassDisabledAsOption()
|
public function testPassDisabledAsOption()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create($this->getTestedType(), null, array('disabled' => true));
|
$form = $this->factory->create($this->getTestedType(), null, array('disabled' => true));
|
||||||
@ -47,7 +49,7 @@ abstract class BaseTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testPassIdAndNameToViewWithParent()
|
public function testPassIdAndNameToViewWithParent()
|
||||||
{
|
{
|
||||||
$view = $this->factory->createNamedBuilder('parent', 'Symfony\Component\Form\Extension\Core\Type\FormType')
|
$view = $this->factory->createNamedBuilder('parent', FormTypeTest::TESTED_TYPE)
|
||||||
->add('child', $this->getTestedType())
|
->add('child', $this->getTestedType())
|
||||||
->getForm()
|
->getForm()
|
||||||
->createView();
|
->createView();
|
||||||
@ -59,8 +61,8 @@ abstract class BaseTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testPassIdAndNameToViewWithGrandParent()
|
public function testPassIdAndNameToViewWithGrandParent()
|
||||||
{
|
{
|
||||||
$builder = $this->factory->createNamedBuilder('parent', 'Symfony\Component\Form\Extension\Core\Type\FormType')
|
$builder = $this->factory->createNamedBuilder('parent', FormTypeTest::TESTED_TYPE)
|
||||||
->add('child', 'Symfony\Component\Form\Extension\Core\Type\FormType');
|
->add('child', FormTypeTest::TESTED_TYPE);
|
||||||
$builder->get('child')->add('grand_child', $this->getTestedType());
|
$builder->get('child')->add('grand_child', $this->getTestedType());
|
||||||
$view = $builder->getForm()->createView();
|
$view = $builder->getForm()->createView();
|
||||||
|
|
||||||
@ -71,10 +73,10 @@ abstract class BaseTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testPassTranslationDomainToView()
|
public function testPassTranslationDomainToView()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create($this->getTestedType(), null, array(
|
$view = $this->factory->create($this->getTestedType(), null, array(
|
||||||
'translation_domain' => 'domain',
|
'translation_domain' => 'domain',
|
||||||
));
|
))
|
||||||
$view = $form->createView();
|
->createView();
|
||||||
|
|
||||||
$this->assertSame('domain', $view->vars['translation_domain']);
|
$this->assertSame('domain', $view->vars['translation_domain']);
|
||||||
}
|
}
|
||||||
@ -82,7 +84,7 @@ abstract class BaseTypeTest extends TypeTestCase
|
|||||||
public function testInheritTranslationDomainFromParent()
|
public function testInheritTranslationDomainFromParent()
|
||||||
{
|
{
|
||||||
$view = $this->factory
|
$view = $this->factory
|
||||||
->createNamedBuilder('parent', 'Symfony\Component\Form\Extension\Core\Type\FormType', null, array(
|
->createNamedBuilder('parent', FormTypeTest::TESTED_TYPE, null, array(
|
||||||
'translation_domain' => 'domain',
|
'translation_domain' => 'domain',
|
||||||
))
|
))
|
||||||
->add('child', $this->getTestedType())
|
->add('child', $this->getTestedType())
|
||||||
@ -95,7 +97,7 @@ abstract class BaseTypeTest extends TypeTestCase
|
|||||||
public function testPreferOwnTranslationDomain()
|
public function testPreferOwnTranslationDomain()
|
||||||
{
|
{
|
||||||
$view = $this->factory
|
$view = $this->factory
|
||||||
->createNamedBuilder('parent', 'Symfony\Component\Form\Extension\Core\Type\FormType', null, array(
|
->createNamedBuilder('parent', FormTypeTest::TESTED_TYPE, null, array(
|
||||||
'translation_domain' => 'parent_domain',
|
'translation_domain' => 'parent_domain',
|
||||||
))
|
))
|
||||||
->add('child', $this->getTestedType(), array(
|
->add('child', $this->getTestedType(), array(
|
||||||
@ -109,7 +111,7 @@ abstract class BaseTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testDefaultTranslationDomain()
|
public function testDefaultTranslationDomain()
|
||||||
{
|
{
|
||||||
$view = $this->factory->createNamedBuilder('parent', 'Symfony\Component\Form\Extension\Core\Type\FormType')
|
$view = $this->factory->createNamedBuilder('parent', FormTypeTest::TESTED_TYPE)
|
||||||
->add('child', $this->getTestedType())
|
->add('child', $this->getTestedType())
|
||||||
->getForm()
|
->getForm()
|
||||||
->createView();
|
->createView();
|
||||||
@ -119,19 +121,32 @@ abstract class BaseTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testPassLabelToView()
|
public function testPassLabelToView()
|
||||||
{
|
{
|
||||||
$form = $this->factory->createNamed('__test___field', $this->getTestedType(), null, array('label' => 'My label'));
|
$view = $this->factory->createNamed('__test___field', $this->getTestedType(), null, array('label' => 'My label'))
|
||||||
$view = $form->createView();
|
->createView();
|
||||||
|
|
||||||
$this->assertSame('My label', $view->vars['label']);
|
$this->assertSame('My label', $view->vars['label']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testPassMultipartFalseToView()
|
public function testPassMultipartFalseToView()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create($this->getTestedType());
|
$view = $this->factory->create($this->getTestedType())
|
||||||
$view = $form->createView();
|
->createView();
|
||||||
|
|
||||||
$this->assertFalse($view->vars['multipart']);
|
$this->assertFalse($view->vars['multipart']);
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract protected function getTestedType();
|
public function testSubmitNull($expected = null, $norm = null, $view = null)
|
||||||
|
{
|
||||||
|
$form = $this->factory->create($this->getTestedType());
|
||||||
|
$form->submit(null);
|
||||||
|
|
||||||
|
$this->assertSame($expected, $form->getData());
|
||||||
|
$this->assertSame($norm, $form->getNormData());
|
||||||
|
$this->assertSame($view, $form->getViewData());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getTestedType()
|
||||||
|
{
|
||||||
|
return static::TESTED_TYPE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,20 +14,17 @@ namespace Symfony\Component\Form\Tests\Extension\Core\Type;
|
|||||||
/**
|
/**
|
||||||
* @author Stepan Anchugov <kixxx1@gmail.com>
|
* @author Stepan Anchugov <kixxx1@gmail.com>
|
||||||
*/
|
*/
|
||||||
class BirthdayTypeTest extends BaseTypeTest
|
class BirthdayTypeTest extends DateTypeTest
|
||||||
{
|
{
|
||||||
|
const TESTED_TYPE = 'Symfony\Component\Form\Extension\Core\Type\BirthdayType';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
|
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
|
||||||
*/
|
*/
|
||||||
public function testSetInvalidYearsOption()
|
public function testSetInvalidYearsOption()
|
||||||
{
|
{
|
||||||
$this->factory->create('Symfony\Component\Form\Extension\Core\Type\BirthdayType', null, array(
|
$this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'years' => 'bad value',
|
'years' => 'bad value',
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getTestedType()
|
|
||||||
{
|
|
||||||
return 'Symfony\Component\Form\Extension\Core\Type\BirthdayType';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -16,13 +16,10 @@ namespace Symfony\Component\Form\Tests\Extension\Core\Type;
|
|||||||
*/
|
*/
|
||||||
class ButtonTypeTest extends BaseTypeTest
|
class ButtonTypeTest extends BaseTypeTest
|
||||||
{
|
{
|
||||||
|
const TESTED_TYPE = 'Symfony\Component\Form\Extension\Core\Type\ButtonType';
|
||||||
|
|
||||||
public function testCreateButtonInstances()
|
public function testCreateButtonInstances()
|
||||||
{
|
{
|
||||||
$this->assertInstanceOf('Symfony\Component\Form\Button', $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ButtonType'));
|
$this->assertInstanceOf('Symfony\Component\Form\Button', $this->factory->create(static::TESTED_TYPE));
|
||||||
}
|
|
||||||
|
|
||||||
protected function getTestedType()
|
|
||||||
{
|
|
||||||
return 'Symfony\Component\Form\Extension\Core\Type\ButtonType';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,13 +12,14 @@
|
|||||||
namespace Symfony\Component\Form\Tests\Extension\Core\Type;
|
namespace Symfony\Component\Form\Tests\Extension\Core\Type;
|
||||||
|
|
||||||
use Symfony\Component\Form\CallbackTransformer;
|
use Symfony\Component\Form\CallbackTransformer;
|
||||||
use Symfony\Component\Form\Test\TypeTestCase;
|
|
||||||
|
|
||||||
class CheckboxTypeTest extends TypeTestCase
|
class CheckboxTypeTest extends BaseTypeTest
|
||||||
{
|
{
|
||||||
|
const TESTED_TYPE = 'Symfony\Component\Form\Extension\Core\Type\CheckboxType';
|
||||||
|
|
||||||
public function testDataIsFalseByDefault()
|
public function testDataIsFalseByDefault()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CheckboxType');
|
$form = $this->factory->create(static::TESTED_TYPE);
|
||||||
|
|
||||||
$this->assertFalse($form->getData());
|
$this->assertFalse($form->getData());
|
||||||
$this->assertFalse($form->getNormData());
|
$this->assertFalse($form->getNormData());
|
||||||
@ -27,42 +28,42 @@ class CheckboxTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testPassValueToView()
|
public function testPassValueToView()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CheckboxType', null, array('value' => 'foobar'));
|
$view = $this->factory->create(static::TESTED_TYPE, null, array('value' => 'foobar'))
|
||||||
$view = $form->createView();
|
->createView();
|
||||||
|
|
||||||
$this->assertEquals('foobar', $view->vars['value']);
|
$this->assertEquals('foobar', $view->vars['value']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCheckedIfDataTrue()
|
public function testCheckedIfDataTrue()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CheckboxType');
|
$view = $this->factory->create(static::TESTED_TYPE)
|
||||||
$form->setData(true);
|
->setData(true)
|
||||||
$view = $form->createView();
|
->createView();
|
||||||
|
|
||||||
$this->assertTrue($view->vars['checked']);
|
$this->assertTrue($view->vars['checked']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCheckedIfDataTrueWithEmptyValue()
|
public function testCheckedIfDataTrueWithEmptyValue()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CheckboxType', null, array('value' => ''));
|
$view = $this->factory->create(static::TESTED_TYPE, null, array('value' => ''))
|
||||||
$form->setData(true);
|
->setData(true)
|
||||||
$view = $form->createView();
|
->createView();
|
||||||
|
|
||||||
$this->assertTrue($view->vars['checked']);
|
$this->assertTrue($view->vars['checked']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testNotCheckedIfDataFalse()
|
public function testNotCheckedIfDataFalse()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CheckboxType');
|
$view = $this->factory->create(static::TESTED_TYPE)
|
||||||
$form->setData(false);
|
->setData(false)
|
||||||
$view = $form->createView();
|
->createView();
|
||||||
|
|
||||||
$this->assertFalse($view->vars['checked']);
|
$this->assertFalse($view->vars['checked']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSubmitWithValueChecked()
|
public function testSubmitWithValueChecked()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CheckboxType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'value' => 'foobar',
|
'value' => 'foobar',
|
||||||
));
|
));
|
||||||
$form->submit('foobar');
|
$form->submit('foobar');
|
||||||
@ -73,7 +74,7 @@ class CheckboxTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testSubmitWithRandomValueChecked()
|
public function testSubmitWithRandomValueChecked()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CheckboxType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'value' => 'foobar',
|
'value' => 'foobar',
|
||||||
));
|
));
|
||||||
$form->submit('krixikraxi');
|
$form->submit('krixikraxi');
|
||||||
@ -84,7 +85,7 @@ class CheckboxTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testSubmitWithValueUnchecked()
|
public function testSubmitWithValueUnchecked()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CheckboxType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'value' => 'foobar',
|
'value' => 'foobar',
|
||||||
));
|
));
|
||||||
$form->submit(null);
|
$form->submit(null);
|
||||||
@ -95,7 +96,7 @@ class CheckboxTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testSubmitWithEmptyValueChecked()
|
public function testSubmitWithEmptyValueChecked()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CheckboxType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'value' => '',
|
'value' => '',
|
||||||
));
|
));
|
||||||
$form->submit('');
|
$form->submit('');
|
||||||
@ -106,7 +107,7 @@ class CheckboxTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testSubmitWithEmptyValueUnchecked()
|
public function testSubmitWithEmptyValueUnchecked()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CheckboxType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'value' => '',
|
'value' => '',
|
||||||
));
|
));
|
||||||
$form->submit(null);
|
$form->submit(null);
|
||||||
@ -117,7 +118,7 @@ class CheckboxTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testSubmitWithEmptyValueAndFalseUnchecked()
|
public function testSubmitWithEmptyValueAndFalseUnchecked()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CheckboxType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'value' => '',
|
'value' => '',
|
||||||
));
|
));
|
||||||
$form->submit(false);
|
$form->submit(false);
|
||||||
@ -128,7 +129,7 @@ class CheckboxTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testSubmitWithEmptyValueAndTrueChecked()
|
public function testSubmitWithEmptyValueAndTrueChecked()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CheckboxType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'value' => '',
|
'value' => '',
|
||||||
));
|
));
|
||||||
$form->submit(true);
|
$form->submit(true);
|
||||||
@ -152,7 +153,7 @@ class CheckboxTypeTest extends TypeTestCase
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
$form = $this->factory->createBuilder('Symfony\Component\Form\Extension\Core\Type\CheckboxType')
|
$form = $this->factory->createBuilder(static::TESTED_TYPE)
|
||||||
->addModelTransformer($transformer)
|
->addModelTransformer($transformer)
|
||||||
->getForm();
|
->getForm();
|
||||||
|
|
||||||
@ -171,4 +172,9 @@ class CheckboxTypeTest extends TypeTestCase
|
|||||||
array('unchecked', false),
|
array('unchecked', false),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testSubmitNull($expected = null, $norm = null, $view = null)
|
||||||
|
{
|
||||||
|
parent::testSubmitNull(false, false, null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,11 +13,11 @@ namespace Symfony\Component\Form\Tests\Extension\Core\Type;
|
|||||||
|
|
||||||
use Symfony\Component\Form\ChoiceList\View\ChoiceGroupView;
|
use Symfony\Component\Form\ChoiceList\View\ChoiceGroupView;
|
||||||
use Symfony\Component\Form\ChoiceList\View\ChoiceView;
|
use Symfony\Component\Form\ChoiceList\View\ChoiceView;
|
||||||
use Symfony\Component\Form\Extension\Core\ChoiceList\ObjectChoiceList;
|
|
||||||
use Symfony\Component\Form\Test\TypeTestCase;
|
|
||||||
|
|
||||||
class ChoiceTypeTest extends TypeTestCase
|
class ChoiceTypeTest extends BaseTypeTest
|
||||||
{
|
{
|
||||||
|
const TESTED_TYPE = 'Symfony\Component\Form\Extension\Core\Type\ChoiceType';
|
||||||
|
|
||||||
private $choices = array(
|
private $choices = array(
|
||||||
'Bernhard' => 'a',
|
'Bernhard' => 'a',
|
||||||
'Fabien' => 'b',
|
'Fabien' => 'b',
|
||||||
@ -85,7 +85,7 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
*/
|
*/
|
||||||
public function testChoicesOptionExpectsArrayOrTraversable()
|
public function testChoicesOptionExpectsArrayOrTraversable()
|
||||||
{
|
{
|
||||||
$this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
$this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'choices' => new \stdClass(),
|
'choices' => new \stdClass(),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
@ -95,20 +95,19 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
*/
|
*/
|
||||||
public function testChoiceLoaderOptionExpectsChoiceLoaderInterface()
|
public function testChoiceLoaderOptionExpectsChoiceLoaderInterface()
|
||||||
{
|
{
|
||||||
$this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
$this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'choice_loader' => new \stdClass(),
|
'choice_loader' => new \stdClass(),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testChoiceListAndChoicesCanBeEmpty()
|
public function testChoiceListAndChoicesCanBeEmpty()
|
||||||
{
|
{
|
||||||
$this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
$this->factory->create(static::TESTED_TYPE);
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testExpandedChoicesOptionsTurnIntoChildren()
|
public function testExpandedChoicesOptionsTurnIntoChildren()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'expanded' => true,
|
'expanded' => true,
|
||||||
'choices' => $this->choices,
|
'choices' => $this->choices,
|
||||||
));
|
));
|
||||||
@ -118,7 +117,7 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testChoiceListWithScalarValues()
|
public function testChoiceListWithScalarValues()
|
||||||
{
|
{
|
||||||
$view = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'choices' => $this->scalarChoices,
|
'choices' => $this->scalarChoices,
|
||||||
))->createView();
|
))->createView();
|
||||||
|
|
||||||
@ -132,7 +131,7 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testChoiceListWithScalarValuesAndFalseAsPreSetData()
|
public function testChoiceListWithScalarValuesAndFalseAsPreSetData()
|
||||||
{
|
{
|
||||||
$view = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', false, array(
|
$view = $this->factory->create(static::TESTED_TYPE, false, array(
|
||||||
'choices' => $this->scalarChoices,
|
'choices' => $this->scalarChoices,
|
||||||
))->createView();
|
))->createView();
|
||||||
|
|
||||||
@ -141,7 +140,7 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testExpandedChoiceListWithScalarValues()
|
public function testExpandedChoiceListWithScalarValues()
|
||||||
{
|
{
|
||||||
$view = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'choices' => $this->scalarChoices,
|
'choices' => $this->scalarChoices,
|
||||||
'expanded' => true,
|
'expanded' => true,
|
||||||
))->createView();
|
))->createView();
|
||||||
@ -153,7 +152,7 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testExpandedChoiceListWithBooleanAndNullValues()
|
public function testExpandedChoiceListWithBooleanAndNullValues()
|
||||||
{
|
{
|
||||||
$view = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'choices' => $this->booleanChoicesWithNull,
|
'choices' => $this->booleanChoicesWithNull,
|
||||||
'expanded' => true,
|
'expanded' => true,
|
||||||
))->createView();
|
))->createView();
|
||||||
@ -165,7 +164,7 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testExpandedChoiceListWithScalarValuesAndFalseAsPreSetData()
|
public function testExpandedChoiceListWithScalarValuesAndFalseAsPreSetData()
|
||||||
{
|
{
|
||||||
$view = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', false, array(
|
$view = $this->factory->create(static::TESTED_TYPE, false, array(
|
||||||
'choices' => $this->scalarChoices,
|
'choices' => $this->scalarChoices,
|
||||||
'expanded' => true,
|
'expanded' => true,
|
||||||
))->createView();
|
))->createView();
|
||||||
@ -178,7 +177,7 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testExpandedChoiceListWithBooleanAndNullValuesAndFalseAsPreSetData()
|
public function testExpandedChoiceListWithBooleanAndNullValuesAndFalseAsPreSetData()
|
||||||
{
|
{
|
||||||
$view = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', false, array(
|
$view = $this->factory->create(static::TESTED_TYPE, false, array(
|
||||||
'choices' => $this->booleanChoicesWithNull,
|
'choices' => $this->booleanChoicesWithNull,
|
||||||
'expanded' => true,
|
'expanded' => true,
|
||||||
))->createView();
|
))->createView();
|
||||||
@ -190,7 +189,7 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testPlaceholderPresentOnNonRequiredExpandedSingleChoice()
|
public function testPlaceholderPresentOnNonRequiredExpandedSingleChoice()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'multiple' => false,
|
'multiple' => false,
|
||||||
'expanded' => true,
|
'expanded' => true,
|
||||||
'required' => false,
|
'required' => false,
|
||||||
@ -203,7 +202,7 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testPlaceholderNotPresentIfRequired()
|
public function testPlaceholderNotPresentIfRequired()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'multiple' => false,
|
'multiple' => false,
|
||||||
'expanded' => true,
|
'expanded' => true,
|
||||||
'required' => true,
|
'required' => true,
|
||||||
@ -216,7 +215,7 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testPlaceholderNotPresentIfMultiple()
|
public function testPlaceholderNotPresentIfMultiple()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'multiple' => true,
|
'multiple' => true,
|
||||||
'expanded' => true,
|
'expanded' => true,
|
||||||
'required' => false,
|
'required' => false,
|
||||||
@ -229,7 +228,7 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testPlaceholderNotPresentIfEmptyChoice()
|
public function testPlaceholderNotPresentIfEmptyChoice()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'multiple' => false,
|
'multiple' => false,
|
||||||
'expanded' => true,
|
'expanded' => true,
|
||||||
'required' => false,
|
'required' => false,
|
||||||
@ -245,7 +244,7 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testPlaceholderWithBooleanChoices()
|
public function testPlaceholderWithBooleanChoices()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'multiple' => false,
|
'multiple' => false,
|
||||||
'expanded' => false,
|
'expanded' => false,
|
||||||
'required' => false,
|
'required' => false,
|
||||||
@ -254,9 +253,8 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
'No' => false,
|
'No' => false,
|
||||||
),
|
),
|
||||||
'placeholder' => 'Select an option',
|
'placeholder' => 'Select an option',
|
||||||
));
|
))
|
||||||
|
->createView();
|
||||||
$view = $form->createView();
|
|
||||||
|
|
||||||
$this->assertSame('', $view->vars['value'], 'Value should be empty');
|
$this->assertSame('', $view->vars['value'], 'Value should be empty');
|
||||||
$this->assertSame('1', $view->vars['choices'][0]->value);
|
$this->assertSame('1', $view->vars['choices'][0]->value);
|
||||||
@ -266,7 +264,7 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testPlaceholderWithBooleanChoicesWithFalseAsPreSetData()
|
public function testPlaceholderWithBooleanChoicesWithFalseAsPreSetData()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', false, array(
|
$view = $this->factory->create(static::TESTED_TYPE, false, array(
|
||||||
'multiple' => false,
|
'multiple' => false,
|
||||||
'expanded' => false,
|
'expanded' => false,
|
||||||
'required' => false,
|
'required' => false,
|
||||||
@ -275,9 +273,8 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
'No' => false,
|
'No' => false,
|
||||||
),
|
),
|
||||||
'placeholder' => 'Select an option',
|
'placeholder' => 'Select an option',
|
||||||
));
|
))
|
||||||
|
->createView();
|
||||||
$view = $form->createView();
|
|
||||||
|
|
||||||
$this->assertSame('0', $view->vars['value'], 'Value should be "0"');
|
$this->assertSame('0', $view->vars['value'], 'Value should be "0"');
|
||||||
$this->assertSame('1', $view->vars['choices'][0]->value);
|
$this->assertSame('1', $view->vars['choices'][0]->value);
|
||||||
@ -287,7 +284,7 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testPlaceholderWithExpandedBooleanChoices()
|
public function testPlaceholderWithExpandedBooleanChoices()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'multiple' => false,
|
'multiple' => false,
|
||||||
'expanded' => true,
|
'expanded' => true,
|
||||||
'required' => false,
|
'required' => false,
|
||||||
@ -311,7 +308,7 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testPlaceholderWithExpandedBooleanChoicesAndWithFalseAsPreSetData()
|
public function testPlaceholderWithExpandedBooleanChoicesAndWithFalseAsPreSetData()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', false, array(
|
$form = $this->factory->create(static::TESTED_TYPE, false, array(
|
||||||
'multiple' => false,
|
'multiple' => false,
|
||||||
'expanded' => true,
|
'expanded' => true,
|
||||||
'required' => false,
|
'required' => false,
|
||||||
@ -335,7 +332,7 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testExpandedChoicesOptionsAreFlattened()
|
public function testExpandedChoicesOptionsAreFlattened()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'expanded' => true,
|
'expanded' => true,
|
||||||
'choices' => $this->groupedChoices,
|
'choices' => $this->groupedChoices,
|
||||||
));
|
));
|
||||||
@ -360,7 +357,7 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
$obj4 = (object) array('id' => 4, 'name' => 'Jon');
|
$obj4 = (object) array('id' => 4, 'name' => 'Jon');
|
||||||
$obj5 = (object) array('id' => 5, 'name' => 'Roman');
|
$obj5 = (object) array('id' => 5, 'name' => 'Roman');
|
||||||
|
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'expanded' => true,
|
'expanded' => true,
|
||||||
'choices' => array(
|
'choices' => array(
|
||||||
'Symfony' => array($obj1, $obj2, $obj3),
|
'Symfony' => array($obj1, $obj2, $obj3),
|
||||||
@ -379,7 +376,7 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testExpandedCheckboxesAreNeverRequired()
|
public function testExpandedCheckboxesAreNeverRequired()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'multiple' => true,
|
'multiple' => true,
|
||||||
'expanded' => true,
|
'expanded' => true,
|
||||||
'required' => true,
|
'required' => true,
|
||||||
@ -393,7 +390,7 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testExpandedRadiosAreRequiredIfChoiceChildIsRequired()
|
public function testExpandedRadiosAreRequiredIfChoiceChildIsRequired()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'multiple' => false,
|
'multiple' => false,
|
||||||
'expanded' => true,
|
'expanded' => true,
|
||||||
'required' => true,
|
'required' => true,
|
||||||
@ -407,7 +404,7 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testExpandedRadiosAreNotRequiredIfChoiceChildIsNotRequired()
|
public function testExpandedRadiosAreNotRequiredIfChoiceChildIsNotRequired()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'multiple' => false,
|
'multiple' => false,
|
||||||
'expanded' => true,
|
'expanded' => true,
|
||||||
'required' => false,
|
'required' => false,
|
||||||
@ -421,7 +418,7 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testSubmitSingleNonExpanded()
|
public function testSubmitSingleNonExpanded()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'multiple' => false,
|
'multiple' => false,
|
||||||
'expanded' => false,
|
'expanded' => false,
|
||||||
'choices' => $this->choices,
|
'choices' => $this->choices,
|
||||||
@ -436,7 +433,7 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testSubmitSingleNonExpandedInvalidChoice()
|
public function testSubmitSingleNonExpandedInvalidChoice()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'multiple' => false,
|
'multiple' => false,
|
||||||
'expanded' => false,
|
'expanded' => false,
|
||||||
'choices' => $this->choices,
|
'choices' => $this->choices,
|
||||||
@ -451,7 +448,7 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testSubmitSingleNonExpandedNull()
|
public function testSubmitSingleNonExpandedNull()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'multiple' => false,
|
'multiple' => false,
|
||||||
'expanded' => false,
|
'expanded' => false,
|
||||||
'choices' => $this->choices,
|
'choices' => $this->choices,
|
||||||
@ -467,9 +464,9 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
// In edge cases (for example, when choices are loaded dynamically by a
|
// In edge cases (for example, when choices are loaded dynamically by a
|
||||||
// loader), the choices may be empty. Make sure to behave the same as when
|
// loader), the choices may be empty. Make sure to behave the same as when
|
||||||
// choices are available.
|
// choices are available.
|
||||||
public function testSubmitSingleNonExpandedNullNoChoices()
|
public function testSubmitNull($expected = null, $norm = null, $view = null)
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'multiple' => false,
|
'multiple' => false,
|
||||||
'expanded' => false,
|
'expanded' => false,
|
||||||
'choices' => array(),
|
'choices' => array(),
|
||||||
@ -478,13 +475,14 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
$form->submit(null);
|
$form->submit(null);
|
||||||
|
|
||||||
$this->assertNull($form->getData());
|
$this->assertNull($form->getData());
|
||||||
|
$this->assertNull($form->getNormData());
|
||||||
$this->assertSame('', $form->getViewData());
|
$this->assertSame('', $form->getViewData());
|
||||||
$this->assertTrue($form->isSynchronized());
|
$this->assertTrue($form->isSynchronized());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSubmitSingleNonExpandedEmpty()
|
public function testSubmitSingleNonExpandedEmpty()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'multiple' => false,
|
'multiple' => false,
|
||||||
'expanded' => false,
|
'expanded' => false,
|
||||||
'choices' => $this->choices,
|
'choices' => $this->choices,
|
||||||
@ -499,7 +497,7 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testSubmitSingleNonExpandedEmptyExplicitEmptyChoice()
|
public function testSubmitSingleNonExpandedEmptyExplicitEmptyChoice()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'multiple' => false,
|
'multiple' => false,
|
||||||
'expanded' => false,
|
'expanded' => false,
|
||||||
'choices' => array(
|
'choices' => array(
|
||||||
@ -522,7 +520,7 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
// choices are available.
|
// choices are available.
|
||||||
public function testSubmitSingleNonExpandedEmptyNoChoices()
|
public function testSubmitSingleNonExpandedEmptyNoChoices()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'multiple' => false,
|
'multiple' => false,
|
||||||
'expanded' => false,
|
'expanded' => false,
|
||||||
'choices' => array(),
|
'choices' => array(),
|
||||||
@ -537,7 +535,7 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testSubmitSingleNonExpandedFalse()
|
public function testSubmitSingleNonExpandedFalse()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'multiple' => false,
|
'multiple' => false,
|
||||||
'expanded' => false,
|
'expanded' => false,
|
||||||
'choices' => $this->choices,
|
'choices' => $this->choices,
|
||||||
@ -555,7 +553,7 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
// choices are available.
|
// choices are available.
|
||||||
public function testSubmitSingleNonExpandedFalseNoChoices()
|
public function testSubmitSingleNonExpandedFalseNoChoices()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'multiple' => false,
|
'multiple' => false,
|
||||||
'expanded' => false,
|
'expanded' => false,
|
||||||
'choices' => array(),
|
'choices' => array(),
|
||||||
@ -570,7 +568,7 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testSubmitSingleNonExpandedObjectChoices()
|
public function testSubmitSingleNonExpandedObjectChoices()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'multiple' => false,
|
'multiple' => false,
|
||||||
'expanded' => false,
|
'expanded' => false,
|
||||||
'choices' => $this->objectChoices,
|
'choices' => $this->objectChoices,
|
||||||
@ -588,7 +586,7 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testSubmitSingleChoiceWithEmptyData()
|
public function testSubmitSingleChoiceWithEmptyData()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'multiple' => false,
|
'multiple' => false,
|
||||||
'expanded' => false,
|
'expanded' => false,
|
||||||
'choices' => array('test'),
|
'choices' => array('test'),
|
||||||
@ -602,7 +600,7 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testSubmitMultipleChoiceWithEmptyData()
|
public function testSubmitMultipleChoiceWithEmptyData()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'multiple' => true,
|
'multiple' => true,
|
||||||
'expanded' => false,
|
'expanded' => false,
|
||||||
'choices' => array('test'),
|
'choices' => array('test'),
|
||||||
@ -616,7 +614,7 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testSubmitSingleChoiceExpandedWithEmptyData()
|
public function testSubmitSingleChoiceExpandedWithEmptyData()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'multiple' => false,
|
'multiple' => false,
|
||||||
'expanded' => true,
|
'expanded' => true,
|
||||||
'choices' => array('test'),
|
'choices' => array('test'),
|
||||||
@ -630,7 +628,7 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testSubmitMultipleChoiceExpandedWithEmptyData()
|
public function testSubmitMultipleChoiceExpandedWithEmptyData()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'multiple' => true,
|
'multiple' => true,
|
||||||
'expanded' => true,
|
'expanded' => true,
|
||||||
'choices' => array('test'),
|
'choices' => array('test'),
|
||||||
@ -644,7 +642,7 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testSubmitMultipleNonExpanded()
|
public function testSubmitMultipleNonExpanded()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'multiple' => true,
|
'multiple' => true,
|
||||||
'expanded' => false,
|
'expanded' => false,
|
||||||
'choices' => $this->choices,
|
'choices' => $this->choices,
|
||||||
@ -659,7 +657,7 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testSubmitMultipleNonExpandedEmpty()
|
public function testSubmitMultipleNonExpandedEmpty()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'multiple' => true,
|
'multiple' => true,
|
||||||
'expanded' => false,
|
'expanded' => false,
|
||||||
'choices' => $this->choices,
|
'choices' => $this->choices,
|
||||||
@ -677,7 +675,7 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
// choices are available.
|
// choices are available.
|
||||||
public function testSubmitMultipleNonExpandedEmptyNoChoices()
|
public function testSubmitMultipleNonExpandedEmptyNoChoices()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'multiple' => true,
|
'multiple' => true,
|
||||||
'expanded' => false,
|
'expanded' => false,
|
||||||
'choices' => array(),
|
'choices' => array(),
|
||||||
@ -692,7 +690,7 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testSubmitMultipleNonExpandedInvalidScalarChoice()
|
public function testSubmitMultipleNonExpandedInvalidScalarChoice()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'multiple' => true,
|
'multiple' => true,
|
||||||
'expanded' => false,
|
'expanded' => false,
|
||||||
'choices' => $this->choices,
|
'choices' => $this->choices,
|
||||||
@ -707,7 +705,7 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testSubmitMultipleNonExpandedInvalidArrayChoice()
|
public function testSubmitMultipleNonExpandedInvalidArrayChoice()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'multiple' => true,
|
'multiple' => true,
|
||||||
'expanded' => false,
|
'expanded' => false,
|
||||||
'choices' => $this->choices,
|
'choices' => $this->choices,
|
||||||
@ -722,7 +720,7 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testSubmitMultipleNonExpandedObjectChoices()
|
public function testSubmitMultipleNonExpandedObjectChoices()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'multiple' => true,
|
'multiple' => true,
|
||||||
'expanded' => false,
|
'expanded' => false,
|
||||||
'choices' => $this->objectChoices,
|
'choices' => $this->objectChoices,
|
||||||
@ -739,7 +737,7 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testSubmitSingleExpandedRequired()
|
public function testSubmitSingleExpandedRequired()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'multiple' => false,
|
'multiple' => false,
|
||||||
'expanded' => true,
|
'expanded' => true,
|
||||||
'required' => true,
|
'required' => true,
|
||||||
@ -767,7 +765,7 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testSubmitSingleExpandedRequiredInvalidChoice()
|
public function testSubmitSingleExpandedRequiredInvalidChoice()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'multiple' => false,
|
'multiple' => false,
|
||||||
'expanded' => true,
|
'expanded' => true,
|
||||||
'required' => true,
|
'required' => true,
|
||||||
@ -795,7 +793,7 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testSubmitSingleExpandedNonRequired()
|
public function testSubmitSingleExpandedNonRequired()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'multiple' => false,
|
'multiple' => false,
|
||||||
'expanded' => true,
|
'expanded' => true,
|
||||||
'required' => false,
|
'required' => false,
|
||||||
@ -825,7 +823,7 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testSubmitSingleExpandedNonRequiredInvalidChoice()
|
public function testSubmitSingleExpandedNonRequiredInvalidChoice()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'multiple' => false,
|
'multiple' => false,
|
||||||
'expanded' => true,
|
'expanded' => true,
|
||||||
'required' => false,
|
'required' => false,
|
||||||
@ -853,7 +851,7 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testSubmitSingleExpandedRequiredNull()
|
public function testSubmitSingleExpandedRequiredNull()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'multiple' => false,
|
'multiple' => false,
|
||||||
'expanded' => true,
|
'expanded' => true,
|
||||||
'required' => true,
|
'required' => true,
|
||||||
@ -884,7 +882,7 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
// choices are available.
|
// choices are available.
|
||||||
public function testSubmitSingleExpandedRequiredNullNoChoices()
|
public function testSubmitSingleExpandedRequiredNullNoChoices()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'multiple' => false,
|
'multiple' => false,
|
||||||
'expanded' => true,
|
'expanded' => true,
|
||||||
'required' => true,
|
'required' => true,
|
||||||
@ -901,7 +899,7 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testSubmitSingleExpandedRequiredEmpty()
|
public function testSubmitSingleExpandedRequiredEmpty()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'multiple' => false,
|
'multiple' => false,
|
||||||
'expanded' => true,
|
'expanded' => true,
|
||||||
'required' => true,
|
'required' => true,
|
||||||
@ -932,7 +930,7 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
// choices are available.
|
// choices are available.
|
||||||
public function testSubmitSingleExpandedRequiredEmptyNoChoices()
|
public function testSubmitSingleExpandedRequiredEmptyNoChoices()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'multiple' => false,
|
'multiple' => false,
|
||||||
'expanded' => true,
|
'expanded' => true,
|
||||||
'required' => true,
|
'required' => true,
|
||||||
@ -949,7 +947,7 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testSubmitSingleExpandedRequiredFalse()
|
public function testSubmitSingleExpandedRequiredFalse()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'multiple' => false,
|
'multiple' => false,
|
||||||
'expanded' => true,
|
'expanded' => true,
|
||||||
'required' => true,
|
'required' => true,
|
||||||
@ -980,7 +978,7 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
// choices are available.
|
// choices are available.
|
||||||
public function testSubmitSingleExpandedRequiredFalseNoChoices()
|
public function testSubmitSingleExpandedRequiredFalseNoChoices()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'multiple' => false,
|
'multiple' => false,
|
||||||
'expanded' => true,
|
'expanded' => true,
|
||||||
'required' => true,
|
'required' => true,
|
||||||
@ -997,7 +995,7 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testSubmitSingleExpandedNonRequiredNull()
|
public function testSubmitSingleExpandedNonRequiredNull()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'multiple' => false,
|
'multiple' => false,
|
||||||
'expanded' => true,
|
'expanded' => true,
|
||||||
'required' => false,
|
'required' => false,
|
||||||
@ -1030,7 +1028,7 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
// choices are available.
|
// choices are available.
|
||||||
public function testSubmitSingleExpandedNonRequiredNullNoChoices()
|
public function testSubmitSingleExpandedNonRequiredNullNoChoices()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'multiple' => false,
|
'multiple' => false,
|
||||||
'expanded' => true,
|
'expanded' => true,
|
||||||
'required' => false,
|
'required' => false,
|
||||||
@ -1047,7 +1045,7 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testSubmitSingleExpandedNonRequiredEmpty()
|
public function testSubmitSingleExpandedNonRequiredEmpty()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'multiple' => false,
|
'multiple' => false,
|
||||||
'expanded' => true,
|
'expanded' => true,
|
||||||
'required' => false,
|
'required' => false,
|
||||||
@ -1080,7 +1078,7 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
// choices are available.
|
// choices are available.
|
||||||
public function testSubmitSingleExpandedNonRequiredEmptyNoChoices()
|
public function testSubmitSingleExpandedNonRequiredEmptyNoChoices()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'multiple' => false,
|
'multiple' => false,
|
||||||
'expanded' => true,
|
'expanded' => true,
|
||||||
'required' => false,
|
'required' => false,
|
||||||
@ -1097,7 +1095,7 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testSubmitSingleExpandedNonRequiredFalse()
|
public function testSubmitSingleExpandedNonRequiredFalse()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'multiple' => false,
|
'multiple' => false,
|
||||||
'expanded' => true,
|
'expanded' => true,
|
||||||
'required' => false,
|
'required' => false,
|
||||||
@ -1130,7 +1128,7 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
// choices are available.
|
// choices are available.
|
||||||
public function testSubmitSingleExpandedNonRequiredFalseNoChoices()
|
public function testSubmitSingleExpandedNonRequiredFalseNoChoices()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'multiple' => false,
|
'multiple' => false,
|
||||||
'expanded' => true,
|
'expanded' => true,
|
||||||
'required' => false,
|
'required' => false,
|
||||||
@ -1147,7 +1145,7 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testSubmitSingleExpandedWithEmptyChild()
|
public function testSubmitSingleExpandedWithEmptyChild()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'multiple' => false,
|
'multiple' => false,
|
||||||
'expanded' => true,
|
'expanded' => true,
|
||||||
'choices' => array(
|
'choices' => array(
|
||||||
@ -1169,7 +1167,7 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testSubmitSingleExpandedObjectChoices()
|
public function testSubmitSingleExpandedObjectChoices()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'multiple' => false,
|
'multiple' => false,
|
||||||
'expanded' => true,
|
'expanded' => true,
|
||||||
'choices' => $this->objectChoices,
|
'choices' => $this->objectChoices,
|
||||||
@ -1196,7 +1194,7 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testSubmitMultipleExpanded()
|
public function testSubmitMultipleExpanded()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'multiple' => true,
|
'multiple' => true,
|
||||||
'expanded' => true,
|
'expanded' => true,
|
||||||
'choices' => $this->choices,
|
'choices' => $this->choices,
|
||||||
@ -1223,7 +1221,7 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testSubmitMultipleExpandedInvalidScalarChoice()
|
public function testSubmitMultipleExpandedInvalidScalarChoice()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'multiple' => true,
|
'multiple' => true,
|
||||||
'expanded' => true,
|
'expanded' => true,
|
||||||
'choices' => $this->choices,
|
'choices' => $this->choices,
|
||||||
@ -1250,7 +1248,7 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testSubmitMultipleExpandedInvalidArrayChoice()
|
public function testSubmitMultipleExpandedInvalidArrayChoice()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'multiple' => true,
|
'multiple' => true,
|
||||||
'expanded' => true,
|
'expanded' => true,
|
||||||
'choices' => $this->choices,
|
'choices' => $this->choices,
|
||||||
@ -1277,7 +1275,7 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testSubmitMultipleExpandedEmpty()
|
public function testSubmitMultipleExpandedEmpty()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'multiple' => true,
|
'multiple' => true,
|
||||||
'expanded' => true,
|
'expanded' => true,
|
||||||
'choices' => $this->choices,
|
'choices' => $this->choices,
|
||||||
@ -1305,7 +1303,7 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
// choices are available.
|
// choices are available.
|
||||||
public function testSubmitMultipleExpandedEmptyNoChoices()
|
public function testSubmitMultipleExpandedEmptyNoChoices()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'multiple' => true,
|
'multiple' => true,
|
||||||
'expanded' => true,
|
'expanded' => true,
|
||||||
'choices' => array(),
|
'choices' => array(),
|
||||||
@ -1319,7 +1317,7 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testSubmitMultipleExpandedWithEmptyChild()
|
public function testSubmitMultipleExpandedWithEmptyChild()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'multiple' => true,
|
'multiple' => true,
|
||||||
'expanded' => true,
|
'expanded' => true,
|
||||||
'choices' => array(
|
'choices' => array(
|
||||||
@ -1344,7 +1342,7 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testSubmitMultipleExpandedObjectChoices()
|
public function testSubmitMultipleExpandedObjectChoices()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'multiple' => true,
|
'multiple' => true,
|
||||||
'expanded' => true,
|
'expanded' => true,
|
||||||
'choices' => $this->objectChoices,
|
'choices' => $this->objectChoices,
|
||||||
@ -1371,15 +1369,16 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testSingleSelectedObjectChoices()
|
public function testSingleSelectedObjectChoices()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', $this->objectChoices[3], array(
|
$view = $this->factory->create(static::TESTED_TYPE, $this->objectChoices[3], array(
|
||||||
'multiple' => false,
|
'multiple' => false,
|
||||||
'expanded' => false,
|
'expanded' => false,
|
||||||
'choices' => $this->objectChoices,
|
'choices' => $this->objectChoices,
|
||||||
'choice_label' => 'name',
|
'choice_label' => 'name',
|
||||||
'choice_value' => 'id',
|
'choice_value' => 'id',
|
||||||
));
|
))
|
||||||
|
->createView();
|
||||||
|
|
||||||
$view = $form->createView();
|
/** @var callable $selectedChecker */
|
||||||
$selectedChecker = $view->vars['is_selected'];
|
$selectedChecker = $view->vars['is_selected'];
|
||||||
|
|
||||||
$this->assertTrue($selectedChecker($view->vars['choices'][3]->value, $view->vars['value']));
|
$this->assertTrue($selectedChecker($view->vars['choices'][3]->value, $view->vars['value']));
|
||||||
@ -1388,15 +1387,16 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testMultipleSelectedObjectChoices()
|
public function testMultipleSelectedObjectChoices()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', array($this->objectChoices[3]), array(
|
$view = $this->factory->create(static::TESTED_TYPE, array($this->objectChoices[3]), array(
|
||||||
'multiple' => true,
|
'multiple' => true,
|
||||||
'expanded' => false,
|
'expanded' => false,
|
||||||
'choices' => $this->objectChoices,
|
'choices' => $this->objectChoices,
|
||||||
'choice_label' => 'name',
|
'choice_label' => 'name',
|
||||||
'choice_value' => 'id',
|
'choice_value' => 'id',
|
||||||
));
|
))
|
||||||
|
->createView();
|
||||||
|
|
||||||
$view = $form->createView();
|
/** @var callable $selectedChecker */
|
||||||
$selectedChecker = $view->vars['is_selected'];
|
$selectedChecker = $view->vars['is_selected'];
|
||||||
|
|
||||||
$this->assertTrue($selectedChecker($view->vars['choices'][3]->value, $view->vars['value']));
|
$this->assertTrue($selectedChecker($view->vars['choices'][3]->value, $view->vars['value']));
|
||||||
@ -1405,75 +1405,75 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testPassRequiredToView()
|
public function testPassRequiredToView()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'choices' => $this->choices,
|
'choices' => $this->choices,
|
||||||
));
|
))
|
||||||
$view = $form->createView();
|
->createView();
|
||||||
|
|
||||||
$this->assertTrue($view->vars['required']);
|
$this->assertTrue($view->vars['required']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testPassNonRequiredToView()
|
public function testPassNonRequiredToView()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'required' => false,
|
'required' => false,
|
||||||
'choices' => $this->choices,
|
'choices' => $this->choices,
|
||||||
));
|
))
|
||||||
$view = $form->createView();
|
->createView();
|
||||||
|
|
||||||
$this->assertFalse($view->vars['required']);
|
$this->assertFalse($view->vars['required']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testPassMultipleToView()
|
public function testPassMultipleToView()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'multiple' => true,
|
'multiple' => true,
|
||||||
'choices' => $this->choices,
|
'choices' => $this->choices,
|
||||||
));
|
))
|
||||||
$view = $form->createView();
|
->createView();
|
||||||
|
|
||||||
$this->assertTrue($view->vars['multiple']);
|
$this->assertTrue($view->vars['multiple']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testPassExpandedToView()
|
public function testPassExpandedToView()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'expanded' => true,
|
'expanded' => true,
|
||||||
'choices' => $this->choices,
|
'choices' => $this->choices,
|
||||||
));
|
))
|
||||||
$view = $form->createView();
|
->createView();
|
||||||
|
|
||||||
$this->assertTrue($view->vars['expanded']);
|
$this->assertTrue($view->vars['expanded']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testPassChoiceTranslationDomainToView()
|
public function testPassChoiceTranslationDomainToView()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'choices' => $this->choices,
|
'choices' => $this->choices,
|
||||||
));
|
))
|
||||||
$view = $form->createView();
|
->createView();
|
||||||
|
|
||||||
$this->assertNull($view->vars['choice_translation_domain']);
|
$this->assertNull($view->vars['choice_translation_domain']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testChoiceTranslationDomainWithTrueValueToView()
|
public function testChoiceTranslationDomainWithTrueValueToView()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'choices' => $this->choices,
|
'choices' => $this->choices,
|
||||||
'choice_translation_domain' => true,
|
'choice_translation_domain' => true,
|
||||||
));
|
))
|
||||||
$view = $form->createView();
|
->createView();
|
||||||
|
|
||||||
$this->assertNull($view->vars['choice_translation_domain']);
|
$this->assertNull($view->vars['choice_translation_domain']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDefaultChoiceTranslationDomainIsSameAsTranslationDomainToView()
|
public function testDefaultChoiceTranslationDomainIsSameAsTranslationDomainToView()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'choices' => $this->choices,
|
'choices' => $this->choices,
|
||||||
'translation_domain' => 'foo',
|
'translation_domain' => 'foo',
|
||||||
));
|
))
|
||||||
$view = $form->createView();
|
->createView();
|
||||||
|
|
||||||
$this->assertEquals('foo', $view->vars['choice_translation_domain']);
|
$this->assertEquals('foo', $view->vars['choice_translation_domain']);
|
||||||
}
|
}
|
||||||
@ -1481,12 +1481,10 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
public function testInheritChoiceTranslationDomainFromParent()
|
public function testInheritChoiceTranslationDomainFromParent()
|
||||||
{
|
{
|
||||||
$view = $this->factory
|
$view = $this->factory
|
||||||
->createNamedBuilder('parent', 'Symfony\Component\Form\Extension\Core\Type\FormType', null, array(
|
->createNamedBuilder('parent', FormTypeTest::TESTED_TYPE, null, array(
|
||||||
'translation_domain' => 'domain',
|
'translation_domain' => 'domain',
|
||||||
))
|
))
|
||||||
->add('child', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', array(
|
->add('child', static::TESTED_TYPE)
|
||||||
'choices' => array(),
|
|
||||||
))
|
|
||||||
->getForm()
|
->getForm()
|
||||||
->createView();
|
->createView();
|
||||||
|
|
||||||
@ -1495,24 +1493,24 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testPlaceholderIsNullByDefaultIfRequired()
|
public function testPlaceholderIsNullByDefaultIfRequired()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'multiple' => false,
|
'multiple' => false,
|
||||||
'required' => true,
|
'required' => true,
|
||||||
'choices' => $this->choices,
|
'choices' => $this->choices,
|
||||||
));
|
))
|
||||||
$view = $form->createView();
|
->createView();
|
||||||
|
|
||||||
$this->assertNull($view->vars['placeholder']);
|
$this->assertNull($view->vars['placeholder']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testPlaceholderIsEmptyStringByDefaultIfNotRequired()
|
public function testPlaceholderIsEmptyStringByDefaultIfNotRequired()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'multiple' => false,
|
'multiple' => false,
|
||||||
'required' => false,
|
'required' => false,
|
||||||
'choices' => $this->choices,
|
'choices' => $this->choices,
|
||||||
));
|
))
|
||||||
$view = $form->createView();
|
->createView();
|
||||||
|
|
||||||
$this->assertSame('', $view->vars['placeholder']);
|
$this->assertSame('', $view->vars['placeholder']);
|
||||||
}
|
}
|
||||||
@ -1522,14 +1520,14 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
*/
|
*/
|
||||||
public function testPassPlaceholderToView($multiple, $expanded, $required, $placeholder, $viewValue)
|
public function testPassPlaceholderToView($multiple, $expanded, $required, $placeholder, $viewValue)
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'multiple' => $multiple,
|
'multiple' => $multiple,
|
||||||
'expanded' => $expanded,
|
'expanded' => $expanded,
|
||||||
'required' => $required,
|
'required' => $required,
|
||||||
'placeholder' => $placeholder,
|
'placeholder' => $placeholder,
|
||||||
'choices' => $this->choices,
|
'choices' => $this->choices,
|
||||||
));
|
))
|
||||||
$view = $form->createView();
|
->createView();
|
||||||
|
|
||||||
$this->assertSame($viewValue, $view->vars['placeholder']);
|
$this->assertSame($viewValue, $view->vars['placeholder']);
|
||||||
$this->assertFalse($view->vars['placeholder_in_choices']);
|
$this->assertFalse($view->vars['placeholder_in_choices']);
|
||||||
@ -1540,14 +1538,14 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
*/
|
*/
|
||||||
public function testDontPassPlaceholderIfContainedInChoices($multiple, $expanded, $required, $placeholder, $viewValue)
|
public function testDontPassPlaceholderIfContainedInChoices($multiple, $expanded, $required, $placeholder, $viewValue)
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'multiple' => $multiple,
|
'multiple' => $multiple,
|
||||||
'expanded' => $expanded,
|
'expanded' => $expanded,
|
||||||
'required' => $required,
|
'required' => $required,
|
||||||
'placeholder' => $placeholder,
|
'placeholder' => $placeholder,
|
||||||
'choices' => array('Empty' => '', 'A' => 'a'),
|
'choices' => array('Empty' => '', 'A' => 'a'),
|
||||||
));
|
))
|
||||||
$view = $form->createView();
|
->createView();
|
||||||
|
|
||||||
$this->assertNull($view->vars['placeholder']);
|
$this->assertNull($view->vars['placeholder']);
|
||||||
$this->assertTrue($view->vars['placeholder_in_choices']);
|
$this->assertTrue($view->vars['placeholder_in_choices']);
|
||||||
@ -1600,10 +1598,10 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
public function testPassChoicesToView()
|
public function testPassChoicesToView()
|
||||||
{
|
{
|
||||||
$choices = array('A' => 'a', 'B' => 'b', 'C' => 'c', 'D' => 'd');
|
$choices = array('A' => 'a', 'B' => 'b', 'C' => 'c', 'D' => 'd');
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'choices' => $choices,
|
'choices' => $choices,
|
||||||
));
|
))
|
||||||
$view = $form->createView();
|
->createView();
|
||||||
|
|
||||||
$this->assertEquals(array(
|
$this->assertEquals(array(
|
||||||
new ChoiceView('a', 'a', 'A'),
|
new ChoiceView('a', 'a', 'A'),
|
||||||
@ -1616,11 +1614,11 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
public function testPassPreferredChoicesToView()
|
public function testPassPreferredChoicesToView()
|
||||||
{
|
{
|
||||||
$choices = array('A' => 'a', 'B' => 'b', 'C' => 'c', 'D' => 'd');
|
$choices = array('A' => 'a', 'B' => 'b', 'C' => 'c', 'D' => 'd');
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'choices' => $choices,
|
'choices' => $choices,
|
||||||
'preferred_choices' => array('b', 'd'),
|
'preferred_choices' => array('b', 'd'),
|
||||||
));
|
))
|
||||||
$view = $form->createView();
|
->createView();
|
||||||
|
|
||||||
$this->assertEquals(array(
|
$this->assertEquals(array(
|
||||||
0 => new ChoiceView('a', 'a', 'A'),
|
0 => new ChoiceView('a', 'a', 'A'),
|
||||||
@ -1634,11 +1632,11 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testPassHierarchicalChoicesToView()
|
public function testPassHierarchicalChoicesToView()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'choices' => $this->groupedChoices,
|
'choices' => $this->groupedChoices,
|
||||||
'preferred_choices' => array('b', 'd'),
|
'preferred_choices' => array('b', 'd'),
|
||||||
));
|
))
|
||||||
$view = $form->createView();
|
->createView();
|
||||||
|
|
||||||
$this->assertEquals(array(
|
$this->assertEquals(array(
|
||||||
'Symfony' => new ChoiceGroupView('Symfony', array(
|
'Symfony' => new ChoiceGroupView('Symfony', array(
|
||||||
@ -1665,12 +1663,12 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
$obj2 = (object) array('value' => 'b', 'label' => 'B');
|
$obj2 = (object) array('value' => 'b', 'label' => 'B');
|
||||||
$obj3 = (object) array('value' => 'c', 'label' => 'C');
|
$obj3 = (object) array('value' => 'c', 'label' => 'C');
|
||||||
$obj4 = (object) array('value' => 'd', 'label' => 'D');
|
$obj4 = (object) array('value' => 'd', 'label' => 'D');
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'choices' => array($obj1, $obj2, $obj3, $obj4),
|
'choices' => array($obj1, $obj2, $obj3, $obj4),
|
||||||
'choice_label' => 'label',
|
'choice_label' => 'label',
|
||||||
'choice_value' => 'value',
|
'choice_value' => 'value',
|
||||||
));
|
))
|
||||||
$view = $form->createView();
|
->createView();
|
||||||
|
|
||||||
$this->assertEquals(array(
|
$this->assertEquals(array(
|
||||||
new ChoiceView($obj1, 'a', 'A'),
|
new ChoiceView($obj1, 'a', 'A'),
|
||||||
@ -1682,12 +1680,12 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testAdjustFullNameForMultipleNonExpanded()
|
public function testAdjustFullNameForMultipleNonExpanded()
|
||||||
{
|
{
|
||||||
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
$view = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||||
'multiple' => true,
|
'multiple' => true,
|
||||||
'expanded' => false,
|
'expanded' => false,
|
||||||
'choices' => $this->choices,
|
'choices' => $this->choices,
|
||||||
));
|
))
|
||||||
$view = $form->createView();
|
->createView();
|
||||||
|
|
||||||
$this->assertSame('name[]', $view->vars['full_name']);
|
$this->assertSame('name[]', $view->vars['full_name']);
|
||||||
}
|
}
|
||||||
@ -1695,7 +1693,7 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
// https://github.com/symfony/symfony/issues/3298
|
// https://github.com/symfony/symfony/issues/3298
|
||||||
public function testInitializeWithEmptyChoices()
|
public function testInitializeWithEmptyChoices()
|
||||||
{
|
{
|
||||||
$this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
$this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||||
'choices' => array(),
|
'choices' => array(),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
@ -1707,7 +1705,7 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
$obj3 = (object) array('value' => 'c', 'label' => 'C');
|
$obj3 = (object) array('value' => 'c', 'label' => 'C');
|
||||||
$obj4 = (object) array('value' => 'd', 'label' => 'D');
|
$obj4 = (object) array('value' => 'd', 'label' => 'D');
|
||||||
|
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'choices' => array($obj1, $obj2, $obj3, $obj4),
|
'choices' => array($obj1, $obj2, $obj3, $obj4),
|
||||||
'choice_label' => 'label',
|
'choice_label' => 'label',
|
||||||
'choice_value' => 'value',
|
'choice_value' => 'value',
|
||||||
@ -1717,7 +1715,7 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
));
|
));
|
||||||
|
|
||||||
// Trigger data initialization
|
// Trigger data initialization
|
||||||
$form->getViewData();
|
$this->assertSame('c', $form->getViewData());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1730,7 +1728,7 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
public function testCustomChoiceTypeDoesNotInheritChoiceLabels()
|
public function testCustomChoiceTypeDoesNotInheritChoiceLabels()
|
||||||
{
|
{
|
||||||
$builder = $this->factory->createBuilder();
|
$builder = $this->factory->createBuilder();
|
||||||
$builder->add('choice', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', array(
|
$builder->add('choice', static::TESTED_TYPE, array(
|
||||||
'choices' => array(
|
'choices' => array(
|
||||||
'1' => '1',
|
'1' => '1',
|
||||||
'2' => '2',
|
'2' => '2',
|
||||||
@ -1751,7 +1749,7 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
*/
|
*/
|
||||||
public function testSubmitInvalidNestedValue($multiple, $expanded, $submissionData)
|
public function testSubmitInvalidNestedValue($multiple, $expanded, $submissionData)
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'choices' => $this->choices,
|
'choices' => $this->choices,
|
||||||
'multiple' => $multiple,
|
'multiple' => $multiple,
|
||||||
'expanded' => $expanded,
|
'expanded' => $expanded,
|
||||||
|
@ -11,15 +11,16 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\Form\Tests\Extension\Core\Type;
|
namespace Symfony\Component\Form\Tests\Extension\Core\Type;
|
||||||
|
|
||||||
use Symfony\Component\Form\Test\TypeTestCase;
|
|
||||||
use Symfony\Component\Form\Tests\Fixtures\Author;
|
use Symfony\Component\Form\Tests\Fixtures\Author;
|
||||||
|
|
||||||
class CollectionTypeTest extends TypeTestCase
|
class CollectionTypeTest extends BaseTypeTest
|
||||||
{
|
{
|
||||||
|
const TESTED_TYPE = 'Symfony\Component\Form\Extension\Core\Type\CollectionType';
|
||||||
|
|
||||||
public function testContainsNoChildByDefault()
|
public function testContainsNoChildByDefault()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CollectionType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'entry_type' => 'Symfony\Component\Form\Extension\Core\Type\TextType',
|
'entry_type' => TextTypeTest::TESTED_TYPE,
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->assertCount(0, $form);
|
$this->assertCount(0, $form);
|
||||||
@ -27,8 +28,8 @@ class CollectionTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testSetDataAdjustsSize()
|
public function testSetDataAdjustsSize()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CollectionType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'entry_type' => 'Symfony\Component\Form\Extension\Core\Type\TextType',
|
'entry_type' => TextTypeTest::TESTED_TYPE,
|
||||||
'entry_options' => array(
|
'entry_options' => array(
|
||||||
'attr' => array('maxlength' => 20),
|
'attr' => array('maxlength' => 20),
|
||||||
),
|
),
|
||||||
@ -56,8 +57,8 @@ class CollectionTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testThrowsExceptionIfObjectIsNotTraversable()
|
public function testThrowsExceptionIfObjectIsNotTraversable()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CollectionType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'entry_type' => 'Symfony\Component\Form\Extension\Core\Type\TextType',
|
'entry_type' => TextTypeTest::TESTED_TYPE,
|
||||||
));
|
));
|
||||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Form\Exception\UnexpectedTypeException');
|
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Form\Exception\UnexpectedTypeException');
|
||||||
$form->setData(new \stdClass());
|
$form->setData(new \stdClass());
|
||||||
@ -65,8 +66,8 @@ class CollectionTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testNotResizedIfSubmittedWithMissingData()
|
public function testNotResizedIfSubmittedWithMissingData()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CollectionType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'entry_type' => 'Symfony\Component\Form\Extension\Core\Type\TextType',
|
'entry_type' => TextTypeTest::TESTED_TYPE,
|
||||||
));
|
));
|
||||||
$form->setData(array('foo@foo.com', 'bar@bar.com'));
|
$form->setData(array('foo@foo.com', 'bar@bar.com'));
|
||||||
$form->submit(array('foo@bar.com'));
|
$form->submit(array('foo@bar.com'));
|
||||||
@ -79,8 +80,8 @@ class CollectionTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testResizedDownIfSubmittedWithMissingDataAndAllowDelete()
|
public function testResizedDownIfSubmittedWithMissingDataAndAllowDelete()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CollectionType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'entry_type' => 'Symfony\Component\Form\Extension\Core\Type\TextType',
|
'entry_type' => TextTypeTest::TESTED_TYPE,
|
||||||
'allow_delete' => true,
|
'allow_delete' => true,
|
||||||
));
|
));
|
||||||
$form->setData(array('foo@foo.com', 'bar@bar.com'));
|
$form->setData(array('foo@foo.com', 'bar@bar.com'));
|
||||||
@ -94,8 +95,8 @@ class CollectionTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testResizedDownIfSubmittedWithEmptyDataAndDeleteEmpty()
|
public function testResizedDownIfSubmittedWithEmptyDataAndDeleteEmpty()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CollectionType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'entry_type' => 'Symfony\Component\Form\Extension\Core\Type\TextType',
|
'entry_type' => TextTypeTest::TESTED_TYPE,
|
||||||
'allow_delete' => true,
|
'allow_delete' => true,
|
||||||
'delete_empty' => true,
|
'delete_empty' => true,
|
||||||
));
|
));
|
||||||
@ -111,8 +112,8 @@ class CollectionTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testDontAddEmptyDataIfDeleteEmpty()
|
public function testDontAddEmptyDataIfDeleteEmpty()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CollectionType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'entry_type' => 'Symfony\Component\Form\Extension\Core\Type\TextType',
|
'entry_type' => TextTypeTest::TESTED_TYPE,
|
||||||
'allow_add' => true,
|
'allow_add' => true,
|
||||||
'delete_empty' => true,
|
'delete_empty' => true,
|
||||||
));
|
));
|
||||||
@ -128,8 +129,8 @@ class CollectionTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testNoDeleteEmptyIfDeleteNotAllowed()
|
public function testNoDeleteEmptyIfDeleteNotAllowed()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CollectionType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'entry_type' => 'Symfony\Component\Form\Extension\Core\Type\TextType',
|
'entry_type' => TextTypeTest::TESTED_TYPE,
|
||||||
'allow_delete' => false,
|
'allow_delete' => false,
|
||||||
'delete_empty' => true,
|
'delete_empty' => true,
|
||||||
));
|
));
|
||||||
@ -143,7 +144,7 @@ class CollectionTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testResizedDownIfSubmittedWithCompoundEmptyDataAndDeleteEmpty()
|
public function testResizedDownIfSubmittedWithCompoundEmptyDataAndDeleteEmpty()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CollectionType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'entry_type' => 'Symfony\Component\Form\Tests\Fixtures\AuthorType',
|
'entry_type' => 'Symfony\Component\Form\Tests\Fixtures\AuthorType',
|
||||||
// If the field is not required, no new Author will be created if the
|
// If the field is not required, no new Author will be created if the
|
||||||
// form is completely empty
|
// form is completely empty
|
||||||
@ -166,8 +167,8 @@ class CollectionTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testNotResizedIfSubmittedWithExtraData()
|
public function testNotResizedIfSubmittedWithExtraData()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CollectionType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'entry_type' => 'Symfony\Component\Form\Extension\Core\Type\TextType',
|
'entry_type' => TextTypeTest::TESTED_TYPE,
|
||||||
));
|
));
|
||||||
$form->setData(array('foo@bar.com'));
|
$form->setData(array('foo@bar.com'));
|
||||||
$form->submit(array('foo@foo.com', 'bar@bar.com'));
|
$form->submit(array('foo@foo.com', 'bar@bar.com'));
|
||||||
@ -179,8 +180,8 @@ class CollectionTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testResizedUpIfSubmittedWithExtraDataAndAllowAdd()
|
public function testResizedUpIfSubmittedWithExtraDataAndAllowAdd()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CollectionType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'entry_type' => 'Symfony\Component\Form\Extension\Core\Type\TextType',
|
'entry_type' => TextTypeTest::TESTED_TYPE,
|
||||||
'allow_add' => true,
|
'allow_add' => true,
|
||||||
));
|
));
|
||||||
$form->setData(array('foo@bar.com'));
|
$form->setData(array('foo@bar.com'));
|
||||||
@ -195,8 +196,8 @@ class CollectionTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testAllowAddButNoPrototype()
|
public function testAllowAddButNoPrototype()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CollectionType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'entry_type' => 'Symfony\Component\Form\Extension\Core\Type\FormType',
|
'entry_type' => FormTypeTest::TESTED_TYPE,
|
||||||
'allow_add' => true,
|
'allow_add' => true,
|
||||||
'prototype' => false,
|
'prototype' => false,
|
||||||
));
|
));
|
||||||
@ -207,8 +208,8 @@ class CollectionTypeTest extends TypeTestCase
|
|||||||
public function testPrototypeMultipartPropagation()
|
public function testPrototypeMultipartPropagation()
|
||||||
{
|
{
|
||||||
$form = $this->factory
|
$form = $this->factory
|
||||||
->create('Symfony\Component\Form\Extension\Core\Type\CollectionType', null, array(
|
->create(static::TESTED_TYPE, null, array(
|
||||||
'entry_type' => 'Symfony\Component\Form\Extension\Core\Type\FileType',
|
'entry_type' => FileTypeTest::TESTED_TYPE,
|
||||||
'allow_add' => true,
|
'allow_add' => true,
|
||||||
'prototype' => true,
|
'prototype' => true,
|
||||||
))
|
))
|
||||||
@ -219,8 +220,8 @@ class CollectionTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testGetDataDoesNotContainsPrototypeNameBeforeDataAreSet()
|
public function testGetDataDoesNotContainsPrototypeNameBeforeDataAreSet()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CollectionType', array(), array(
|
$form = $this->factory->create(static::TESTED_TYPE, array(), array(
|
||||||
'entry_type' => 'Symfony\Component\Form\Extension\Core\Type\FileType',
|
'entry_type' => FileTypeTest::TESTED_TYPE,
|
||||||
'prototype' => true,
|
'prototype' => true,
|
||||||
'allow_add' => true,
|
'allow_add' => true,
|
||||||
));
|
));
|
||||||
@ -231,8 +232,8 @@ class CollectionTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testGetDataDoesNotContainsPrototypeNameAfterDataAreSet()
|
public function testGetDataDoesNotContainsPrototypeNameAfterDataAreSet()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CollectionType', array(), array(
|
$form = $this->factory->create(static::TESTED_TYPE, array(), array(
|
||||||
'entry_type' => 'Symfony\Component\Form\Extension\Core\Type\FileType',
|
'entry_type' => FileTypeTest::TESTED_TYPE,
|
||||||
'allow_add' => true,
|
'allow_add' => true,
|
||||||
'prototype' => true,
|
'prototype' => true,
|
||||||
));
|
));
|
||||||
@ -244,16 +245,16 @@ class CollectionTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testPrototypeNameOption()
|
public function testPrototypeNameOption()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CollectionType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'entry_type' => 'Symfony\Component\Form\Extension\Core\Type\FormType',
|
'entry_type' => FormTypeTest::TESTED_TYPE,
|
||||||
'prototype' => true,
|
'prototype' => true,
|
||||||
'allow_add' => true,
|
'allow_add' => true,
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->assertSame('__name__', $form->getConfig()->getAttribute('prototype')->getName(), '__name__ is the default');
|
$this->assertSame('__name__', $form->getConfig()->getAttribute('prototype')->getName(), '__name__ is the default');
|
||||||
|
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CollectionType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'entry_type' => 'Symfony\Component\Form\Extension\Core\Type\FormType',
|
'entry_type' => FormTypeTest::TESTED_TYPE,
|
||||||
'prototype' => true,
|
'prototype' => true,
|
||||||
'allow_add' => true,
|
'allow_add' => true,
|
||||||
'prototype_name' => '__test__',
|
'prototype_name' => '__test__',
|
||||||
@ -264,8 +265,8 @@ class CollectionTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testPrototypeDefaultLabel()
|
public function testPrototypeDefaultLabel()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CollectionType', array(), array(
|
$form = $this->factory->create(static::TESTED_TYPE, array(), array(
|
||||||
'entry_type' => 'Symfony\Component\Form\Extension\Core\Type\FileType',
|
'entry_type' => FileTypeTest::TESTED_TYPE,
|
||||||
'allow_add' => true,
|
'allow_add' => true,
|
||||||
'prototype' => true,
|
'prototype' => true,
|
||||||
'prototype_name' => '__test__',
|
'prototype_name' => '__test__',
|
||||||
@ -276,11 +277,11 @@ class CollectionTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testPrototypeData()
|
public function testPrototypeData()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CollectionType', array(), array(
|
$form = $this->factory->create(static::TESTED_TYPE, array(), array(
|
||||||
'allow_add' => true,
|
'allow_add' => true,
|
||||||
'prototype' => true,
|
'prototype' => true,
|
||||||
'prototype_data' => 'foo',
|
'prototype_data' => 'foo',
|
||||||
'entry_type' => 'Symfony\Component\Form\Extension\Core\Type\TextType',
|
'entry_type' => TextTypeTest::TESTED_TYPE,
|
||||||
'entry_options' => array(
|
'entry_options' => array(
|
||||||
'data' => 'bar',
|
'data' => 'bar',
|
||||||
'label' => false,
|
'label' => false,
|
||||||
@ -293,8 +294,8 @@ class CollectionTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testPrototypeDefaultRequired()
|
public function testPrototypeDefaultRequired()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CollectionType', array(), array(
|
$form = $this->factory->create(static::TESTED_TYPE, array(), array(
|
||||||
'entry_type' => 'Symfony\Component\Form\Extension\Core\Type\FileType',
|
'entry_type' => FileTypeTest::TESTED_TYPE,
|
||||||
'allow_add' => true,
|
'allow_add' => true,
|
||||||
'prototype' => true,
|
'prototype' => true,
|
||||||
'prototype_name' => '__test__',
|
'prototype_name' => '__test__',
|
||||||
@ -305,8 +306,8 @@ class CollectionTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testPrototypeSetNotRequired()
|
public function testPrototypeSetNotRequired()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CollectionType', array(), array(
|
$form = $this->factory->create(static::TESTED_TYPE, array(), array(
|
||||||
'entry_type' => 'Symfony\Component\Form\Extension\Core\Type\FileType',
|
'entry_type' => FileTypeTest::TESTED_TYPE,
|
||||||
'allow_add' => true,
|
'allow_add' => true,
|
||||||
'prototype' => true,
|
'prototype' => true,
|
||||||
'prototype_name' => '__test__',
|
'prototype_name' => '__test__',
|
||||||
@ -319,14 +320,14 @@ class CollectionTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testPrototypeSetNotRequiredIfParentNotRequired()
|
public function testPrototypeSetNotRequiredIfParentNotRequired()
|
||||||
{
|
{
|
||||||
$child = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CollectionType', array(), array(
|
$child = $this->factory->create(static::TESTED_TYPE, array(), array(
|
||||||
'entry_type' => 'Symfony\Component\Form\Extension\Core\Type\FileType',
|
'entry_type' => FileTypeTest::TESTED_TYPE,
|
||||||
'allow_add' => true,
|
'allow_add' => true,
|
||||||
'prototype' => true,
|
'prototype' => true,
|
||||||
'prototype_name' => '__test__',
|
'prototype_name' => '__test__',
|
||||||
));
|
));
|
||||||
|
|
||||||
$parent = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\FormType', array(), array(
|
$parent = $this->factory->create(FormTypeTest::TESTED_TYPE, array(), array(
|
||||||
'required' => false,
|
'required' => false,
|
||||||
));
|
));
|
||||||
|
|
||||||
@ -338,8 +339,8 @@ class CollectionTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testPrototypeNotOverrideRequiredByEntryOptionsInFavorOfParent()
|
public function testPrototypeNotOverrideRequiredByEntryOptionsInFavorOfParent()
|
||||||
{
|
{
|
||||||
$child = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CollectionType', array(), array(
|
$child = $this->factory->create(static::TESTED_TYPE, array(), array(
|
||||||
'entry_type' => 'Symfony\Component\Form\Extension\Core\Type\FileType',
|
'entry_type' => FileTypeTest::TESTED_TYPE,
|
||||||
'allow_add' => true,
|
'allow_add' => true,
|
||||||
'prototype' => true,
|
'prototype' => true,
|
||||||
'prototype_name' => '__test__',
|
'prototype_name' => '__test__',
|
||||||
@ -348,7 +349,7 @@ class CollectionTypeTest extends TypeTestCase
|
|||||||
),
|
),
|
||||||
));
|
));
|
||||||
|
|
||||||
$parent = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\FormType', array(), array(
|
$parent = $this->factory->create(FormTypeTest::TESTED_TYPE, array(), array(
|
||||||
'required' => false,
|
'required' => false,
|
||||||
));
|
));
|
||||||
|
|
||||||
@ -358,4 +359,9 @@ class CollectionTypeTest extends TypeTestCase
|
|||||||
$this->assertFalse($child->createView()->vars['required'], 'Child is not required');
|
$this->assertFalse($child->createView()->vars['required'], 'Child is not required');
|
||||||
$this->assertFalse($child->createView()->vars['prototype']->vars['required'], '"Prototype" should not be required');
|
$this->assertFalse($child->createView()->vars['prototype']->vars['required'], '"Prototype" should not be required');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testSubmitNull($expected = null, $norm = null, $view = null)
|
||||||
|
{
|
||||||
|
parent::testSubmitNull(array(), array(), array());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,12 +11,13 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\Form\Tests\Extension\Core\Type;
|
namespace Symfony\Component\Form\Tests\Extension\Core\Type;
|
||||||
|
|
||||||
use Symfony\Component\Form\Test\TypeTestCase as TestCase;
|
|
||||||
use Symfony\Component\Form\ChoiceList\View\ChoiceView;
|
use Symfony\Component\Form\ChoiceList\View\ChoiceView;
|
||||||
use Symfony\Component\Intl\Util\IntlTestHelper;
|
use Symfony\Component\Intl\Util\IntlTestHelper;
|
||||||
|
|
||||||
class CountryTypeTest extends TestCase
|
class CountryTypeTest extends BaseTypeTest
|
||||||
{
|
{
|
||||||
|
const TESTED_TYPE = 'Symfony\Component\Form\Extension\Core\Type\CountryType';
|
||||||
|
|
||||||
protected function setUp()
|
protected function setUp()
|
||||||
{
|
{
|
||||||
IntlTestHelper::requireIntl($this, false);
|
IntlTestHelper::requireIntl($this, false);
|
||||||
@ -26,9 +27,8 @@ class CountryTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testCountriesAreSelectable()
|
public function testCountriesAreSelectable()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CountryType');
|
$choices = $this->factory->create(static::TESTED_TYPE)
|
||||||
$view = $form->createView();
|
->createView()->vars['choices'];
|
||||||
$choices = $view->vars['choices'];
|
|
||||||
|
|
||||||
// Don't check objects for identity
|
// Don't check objects for identity
|
||||||
$this->assertContains(new ChoiceView('DE', 'DE', 'Germany'), $choices, '', false, false);
|
$this->assertContains(new ChoiceView('DE', 'DE', 'Germany'), $choices, '', false, false);
|
||||||
@ -40,9 +40,8 @@ class CountryTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testUnknownCountryIsNotIncluded()
|
public function testUnknownCountryIsNotIncluded()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CountryType', 'Symfony\Component\Form\Extension\Core\Type\CountryType');
|
$choices = $this->factory->create(static::TESTED_TYPE, 'country')
|
||||||
$view = $form->createView();
|
->createView()->vars['choices'];
|
||||||
$choices = $view->vars['choices'];
|
|
||||||
|
|
||||||
foreach ($choices as $choice) {
|
foreach ($choices as $choice) {
|
||||||
if ('ZZ' === $choice->value) {
|
if ('ZZ' === $choice->value) {
|
||||||
@ -50,4 +49,9 @@ class CountryTypeTest extends TestCase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testSubmitNull($expected = null, $norm = null, $view = null)
|
||||||
|
{
|
||||||
|
parent::testSubmitNull($expected, $norm, '');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,12 +11,13 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\Form\Tests\Extension\Core\Type;
|
namespace Symfony\Component\Form\Tests\Extension\Core\Type;
|
||||||
|
|
||||||
use Symfony\Component\Form\Test\TypeTestCase as TestCase;
|
|
||||||
use Symfony\Component\Form\ChoiceList\View\ChoiceView;
|
use Symfony\Component\Form\ChoiceList\View\ChoiceView;
|
||||||
use Symfony\Component\Intl\Util\IntlTestHelper;
|
use Symfony\Component\Intl\Util\IntlTestHelper;
|
||||||
|
|
||||||
class CurrencyTypeTest extends TestCase
|
class CurrencyTypeTest extends BaseTypeTest
|
||||||
{
|
{
|
||||||
|
const TESTED_TYPE = 'Symfony\Component\Form\Extension\Core\Type\CurrencyType';
|
||||||
|
|
||||||
protected function setUp()
|
protected function setUp()
|
||||||
{
|
{
|
||||||
IntlTestHelper::requireIntl($this, false);
|
IntlTestHelper::requireIntl($this, false);
|
||||||
@ -26,12 +27,16 @@ class CurrencyTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testCurrenciesAreSelectable()
|
public function testCurrenciesAreSelectable()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CurrencyType');
|
$choices = $this->factory->create(static::TESTED_TYPE)
|
||||||
$view = $form->createView();
|
->createView()->vars['choices'];
|
||||||
$choices = $view->vars['choices'];
|
|
||||||
|
|
||||||
$this->assertContains(new ChoiceView('EUR', 'EUR', 'Euro'), $choices, '', false, false);
|
$this->assertContains(new ChoiceView('EUR', 'EUR', 'Euro'), $choices, '', false, false);
|
||||||
$this->assertContains(new ChoiceView('USD', 'USD', 'US Dollar'), $choices, '', false, false);
|
$this->assertContains(new ChoiceView('USD', 'USD', 'US Dollar'), $choices, '', false, false);
|
||||||
$this->assertContains(new ChoiceView('SIT', 'SIT', 'Slovenian Tolar'), $choices, '', false, false);
|
$this->assertContains(new ChoiceView('SIT', 'SIT', 'Slovenian Tolar'), $choices, '', false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testSubmitNull($expected = null, $norm = null, $view = null)
|
||||||
|
{
|
||||||
|
parent::testSubmitNull($expected, $norm, '');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,228 +13,199 @@ namespace Symfony\Component\Form\Tests\Extension\Core\Type;
|
|||||||
|
|
||||||
use Symfony\Component\Form\Extension\Core\Type\DateIntervalType;
|
use Symfony\Component\Form\Extension\Core\Type\DateIntervalType;
|
||||||
use Symfony\Component\Form\FormError;
|
use Symfony\Component\Form\FormError;
|
||||||
use Symfony\Component\Form\Test\TypeTestCase as TestCase;
|
|
||||||
|
|
||||||
class DateIntervalTypeTest extends TestCase
|
class DateIntervalTypeTest extends BaseTypeTest
|
||||||
{
|
{
|
||||||
|
const TESTED_TYPE = DateIntervalType::class;
|
||||||
|
|
||||||
public function testSubmitDateInterval()
|
public function testSubmitDateInterval()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array('input' => 'dateinterval'));
|
||||||
'Symfony\Component\Form\Extension\Core\Type\DateIntervalType',
|
|
||||||
null,
|
$form->submit(array(
|
||||||
array(
|
|
||||||
'input' => 'dateinterval',
|
|
||||||
)
|
|
||||||
);
|
|
||||||
$form->submit(
|
|
||||||
array(
|
|
||||||
'years' => '7',
|
'years' => '7',
|
||||||
'months' => '6',
|
'months' => '6',
|
||||||
'days' => '5',
|
'days' => '5',
|
||||||
)
|
));
|
||||||
);
|
|
||||||
$dateInterval = new \DateInterval('P7Y6M5D');
|
$this->assertDateIntervalEquals(new \DateInterval('P7Y6M5D'), $form->getData());
|
||||||
$this->assertDateIntervalEquals($dateInterval, $form->getData());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSubmitString()
|
public function testSubmitString()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array('input' => 'string'));
|
||||||
'Symfony\Component\Form\Extension\Core\Type\DateIntervalType',
|
|
||||||
null,
|
$form->submit(array(
|
||||||
array(
|
|
||||||
'input' => 'string',
|
|
||||||
)
|
|
||||||
);
|
|
||||||
$form->submit(
|
|
||||||
array(
|
|
||||||
'years' => '7',
|
'years' => '7',
|
||||||
'months' => '6',
|
'months' => '6',
|
||||||
'days' => '5',
|
'days' => '5',
|
||||||
)
|
));
|
||||||
);
|
|
||||||
$this->assertEquals('P7Y6M5D', $form->getData());
|
$this->assertSame('P7Y6M5D', $form->getData());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSubmitArray()
|
public function testSubmitArray()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array('input' => 'array'));
|
||||||
'Symfony\Component\Form\Extension\Core\Type\DateIntervalType',
|
|
||||||
null,
|
$input = array(
|
||||||
array(
|
|
||||||
'input' => 'array',
|
|
||||||
)
|
|
||||||
);
|
|
||||||
$form->submit(
|
|
||||||
array(
|
|
||||||
'years' => '7',
|
'years' => '7',
|
||||||
'months' => '6',
|
'months' => '6',
|
||||||
'days' => '5',
|
'days' => '5',
|
||||||
)
|
|
||||||
);
|
);
|
||||||
$this->assertEquals(array('years' => '7', 'months' => '6', 'days' => '5'), $form->getData());
|
|
||||||
|
$form->submit($input);
|
||||||
|
|
||||||
|
$this->assertSame($input, $form->getData());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSubmitWithoutMonths()
|
public function testSubmitWithoutMonths()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create(
|
$interval = new \DateInterval('P7Y5D');
|
||||||
'Symfony\Component\Form\Extension\Core\Type\DateIntervalType',
|
|
||||||
null,
|
$form = $this->factory->create(static::TESTED_TYPE, $interval, array(
|
||||||
array(
|
|
||||||
'input' => 'dateinterval',
|
'input' => 'dateinterval',
|
||||||
'with_months' => false,
|
'with_months' => false,
|
||||||
)
|
));
|
||||||
);
|
|
||||||
$form->setData(new \DateInterval('P7Y5D'));
|
$form->submit(array(
|
||||||
$input = array(
|
|
||||||
'years' => '7',
|
'years' => '7',
|
||||||
'months' => '6',
|
'months' => '6',
|
||||||
'days' => '5',
|
'days' => '5',
|
||||||
);
|
));
|
||||||
$form->submit($input);
|
|
||||||
$this->assertDateIntervalEquals(new \DateInterval('P7Y5D'), $form->getData());
|
$this->assertDateIntervalEquals($interval, $form->getData());
|
||||||
|
$this->assertTrue($form->isSynchronized());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSubmitWithTime()
|
public function testSubmitWithTime()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create(
|
$interval = new \DateInterval('P7Y6M5DT4H3M2S');
|
||||||
'Symfony\Component\Form\Extension\Core\Type\DateIntervalType',
|
$form = $this->factory->create(static::TESTED_TYPE, $interval, array(
|
||||||
null,
|
|
||||||
array(
|
|
||||||
'input' => 'dateinterval',
|
'input' => 'dateinterval',
|
||||||
'with_hours' => true,
|
'with_hours' => true,
|
||||||
'with_minutes' => true,
|
'with_minutes' => true,
|
||||||
'with_seconds' => true,
|
'with_seconds' => true,
|
||||||
)
|
));
|
||||||
);
|
|
||||||
$form->setData(new \DateInterval('P7Y6M5DT4H3M2S'));
|
$form->submit(array(
|
||||||
$input = array(
|
|
||||||
'years' => '7',
|
'years' => '7',
|
||||||
'months' => '6',
|
'months' => '6',
|
||||||
'days' => '5',
|
'days' => '5',
|
||||||
'hours' => '4',
|
'hours' => '4',
|
||||||
'minutes' => '3',
|
'minutes' => '3',
|
||||||
'seconds' => '2',
|
'seconds' => '2',
|
||||||
);
|
));
|
||||||
$form->submit($input);
|
|
||||||
$this->assertDateIntervalEquals(new \DateInterval('P7Y6M5DT4H3M2S'), $form->getData());
|
$this->assertDateIntervalEquals($interval, $form->getData());
|
||||||
|
$this->assertTrue($form->isSynchronized());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSubmitWithWeeks()
|
public function testSubmitWithWeeks()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create(
|
$form = $this->factory->create(static::TESTED_TYPE, new \DateInterval('P0Y'), array(
|
||||||
'Symfony\Component\Form\Extension\Core\Type\DateIntervalType',
|
|
||||||
null,
|
|
||||||
array(
|
|
||||||
'input' => 'dateinterval',
|
'input' => 'dateinterval',
|
||||||
'with_years' => false,
|
'with_years' => false,
|
||||||
'with_months' => false,
|
'with_months' => false,
|
||||||
'with_weeks' => true,
|
'with_weeks' => true,
|
||||||
'with_days' => false,
|
'with_days' => false,
|
||||||
)
|
));
|
||||||
);
|
|
||||||
$form->setData(new \DateInterval('P0Y'));
|
$form->submit(array(
|
||||||
$input = array(
|
|
||||||
'weeks' => '30',
|
'weeks' => '30',
|
||||||
);
|
));
|
||||||
$form->submit($input);
|
|
||||||
$this->assertDateIntervalEquals(new \DateInterval('P30W'), $form->getData());
|
$this->assertDateIntervalEquals(new \DateInterval('P30W'), $form->getData());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSubmitWithInvert()
|
public function testSubmitWithInvert()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'Symfony\Component\Form\Extension\Core\Type\DateIntervalType',
|
|
||||||
null,
|
|
||||||
array(
|
|
||||||
'input' => 'dateinterval',
|
'input' => 'dateinterval',
|
||||||
'with_invert' => true,
|
'with_invert' => true,
|
||||||
)
|
));
|
||||||
);
|
|
||||||
$input = array(
|
$form->submit(array(
|
||||||
'years' => '7',
|
'years' => '7',
|
||||||
'months' => '6',
|
'months' => '6',
|
||||||
'days' => '5',
|
'days' => '5',
|
||||||
'invert' => true,
|
'invert' => true,
|
||||||
);
|
));
|
||||||
$form->submit($input);
|
|
||||||
$interval = new \DateInterval('P7Y6M5D');
|
$interval = new \DateInterval('P7Y6M5D');
|
||||||
$interval->invert = 1;
|
$interval->invert = 1;
|
||||||
|
|
||||||
$this->assertDateIntervalEquals($interval, $form->getData());
|
$this->assertDateIntervalEquals($interval, $form->getData());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSubmitStringSingleText()
|
public function testSubmitStringSingleText()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'Symfony\Component\Form\Extension\Core\Type\DateIntervalType',
|
|
||||||
null,
|
|
||||||
array(
|
|
||||||
'input' => 'string',
|
'input' => 'string',
|
||||||
'widget' => 'single_text',
|
'widget' => 'single_text',
|
||||||
)
|
));
|
||||||
);
|
|
||||||
$form->submit('P7Y6M5D');
|
$interval = 'P7Y6M5D';
|
||||||
$this->assertEquals('P7Y6M5D', $form->getData());
|
|
||||||
$this->assertEquals('P7Y6M5D', $form->getViewData());
|
$form->submit($interval);
|
||||||
|
|
||||||
|
$this->assertSame($interval, $form->getData());
|
||||||
|
$this->assertSame($interval, $form->getViewData());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSubmitStringSingleTextWithSeconds()
|
public function testSubmitStringSingleTextWithSeconds()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'Symfony\Component\Form\Extension\Core\Type\DateIntervalType',
|
|
||||||
null,
|
|
||||||
array(
|
|
||||||
'input' => 'string',
|
'input' => 'string',
|
||||||
'widget' => 'single_text',
|
'widget' => 'single_text',
|
||||||
'with_hours' => true,
|
'with_hours' => true,
|
||||||
'with_minutes' => true,
|
'with_minutes' => true,
|
||||||
'with_seconds' => true,
|
'with_seconds' => true,
|
||||||
)
|
));
|
||||||
);
|
|
||||||
$form->submit('P7Y6M5DT4H3M2S');
|
$interval = 'P7Y6M5DT4H3M2S';
|
||||||
$this->assertEquals('P7Y6M5DT4H3M2S', $form->getData());
|
|
||||||
$this->assertEquals('P7Y6M5DT4H3M2S', $form->getViewData());
|
$form->submit($interval);
|
||||||
|
|
||||||
|
$this->assertSame($interval, $form->getData());
|
||||||
|
$this->assertSame($interval, $form->getViewData());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSubmitArrayInteger()
|
public function testSubmitArrayInteger()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'Symfony\Component\Form\Extension\Core\Type\DateIntervalType',
|
|
||||||
null,
|
|
||||||
array(
|
|
||||||
'widget' => 'integer',
|
'widget' => 'integer',
|
||||||
'with_invert' => true,
|
'with_invert' => true,
|
||||||
)
|
));
|
||||||
);
|
|
||||||
$input = array(
|
$years = '7';
|
||||||
|
|
||||||
|
$form->submit(array(
|
||||||
'years' => '7',
|
'years' => '7',
|
||||||
'months' => '6',
|
'months' => '6',
|
||||||
'days' => '5',
|
'days' => '5',
|
||||||
'invert' => true,
|
'invert' => true,
|
||||||
);
|
));
|
||||||
$form->submit($input);
|
|
||||||
$this->assertSame('7', $form['years']->getData());
|
$this->assertSame($years, $form['years']->getData());
|
||||||
$this->assertSame('7', $form['years']->getViewData());
|
$this->assertSame($years, $form['years']->getViewData());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testInitializeWithDateInterval()
|
public function testInitializeWithDateInterval()
|
||||||
{
|
{
|
||||||
// Throws an exception if "data_class" option is not explicitly set
|
// Throws an exception if "data_class" option is not explicitly set
|
||||||
// to null in the type
|
// to null in the type
|
||||||
$this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateIntervalType', new \DateInterval('P0Y'));
|
$this->factory->create(static::TESTED_TYPE, new \DateInterval('P0Y'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testPassDefaultPlaceholderToViewIfNotRequired()
|
public function testPassDefaultPlaceholderToViewIfNotRequired()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create(
|
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'Symfony\Component\Form\Extension\Core\Type\DateIntervalType',
|
|
||||||
null,
|
|
||||||
array(
|
|
||||||
'required' => false,
|
'required' => false,
|
||||||
'with_seconds' => true,
|
'with_seconds' => true,
|
||||||
)
|
))
|
||||||
);
|
->createView();
|
||||||
$view = $form->createView();
|
|
||||||
$this->assertSame('', $view['years']->vars['placeholder']);
|
$this->assertSame('', $view['years']->vars['placeholder']);
|
||||||
$this->assertSame('', $view['months']->vars['placeholder']);
|
$this->assertSame('', $view['months']->vars['placeholder']);
|
||||||
$this->assertSame('', $view['days']->vars['placeholder']);
|
$this->assertSame('', $view['days']->vars['placeholder']);
|
||||||
@ -243,15 +214,12 @@ class DateIntervalTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testPassNoPlaceholderToViewIfRequired()
|
public function testPassNoPlaceholderToViewIfRequired()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create(
|
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'Symfony\Component\Form\Extension\Core\Type\DateIntervalType',
|
|
||||||
null,
|
|
||||||
array(
|
|
||||||
'required' => true,
|
'required' => true,
|
||||||
'with_seconds' => true,
|
'with_seconds' => true,
|
||||||
)
|
))
|
||||||
);
|
->createView();
|
||||||
$view = $form->createView();
|
|
||||||
$this->assertNull($view['years']->vars['placeholder']);
|
$this->assertNull($view['years']->vars['placeholder']);
|
||||||
$this->assertNull($view['months']->vars['placeholder']);
|
$this->assertNull($view['months']->vars['placeholder']);
|
||||||
$this->assertNull($view['days']->vars['placeholder']);
|
$this->assertNull($view['days']->vars['placeholder']);
|
||||||
@ -260,15 +228,12 @@ class DateIntervalTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testPassPlaceholderAsString()
|
public function testPassPlaceholderAsString()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create(
|
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'Symfony\Component\Form\Extension\Core\Type\DateIntervalType',
|
|
||||||
null,
|
|
||||||
array(
|
|
||||||
'placeholder' => 'Empty',
|
'placeholder' => 'Empty',
|
||||||
'with_seconds' => true,
|
'with_seconds' => true,
|
||||||
)
|
))
|
||||||
);
|
->createView();
|
||||||
$view = $form->createView();
|
|
||||||
$this->assertSame('Empty', $view['years']->vars['placeholder']);
|
$this->assertSame('Empty', $view['years']->vars['placeholder']);
|
||||||
$this->assertSame('Empty', $view['months']->vars['placeholder']);
|
$this->assertSame('Empty', $view['months']->vars['placeholder']);
|
||||||
$this->assertSame('Empty', $view['days']->vars['placeholder']);
|
$this->assertSame('Empty', $view['days']->vars['placeholder']);
|
||||||
@ -277,10 +242,7 @@ class DateIntervalTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testPassPlaceholderAsArray()
|
public function testPassPlaceholderAsArray()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create(
|
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'Symfony\Component\Form\Extension\Core\Type\DateIntervalType',
|
|
||||||
null,
|
|
||||||
array(
|
|
||||||
'placeholder' => array(
|
'placeholder' => array(
|
||||||
'years' => 'Empty years',
|
'years' => 'Empty years',
|
||||||
'months' => 'Empty months',
|
'months' => 'Empty months',
|
||||||
@ -292,9 +254,9 @@ class DateIntervalTypeTest extends TestCase
|
|||||||
'with_hours' => true,
|
'with_hours' => true,
|
||||||
'with_minutes' => true,
|
'with_minutes' => true,
|
||||||
'with_seconds' => true,
|
'with_seconds' => true,
|
||||||
)
|
))
|
||||||
);
|
->createView();
|
||||||
$view = $form->createView();
|
|
||||||
$this->assertSame('Empty years', $view['years']->vars['placeholder']);
|
$this->assertSame('Empty years', $view['years']->vars['placeholder']);
|
||||||
$this->assertSame('Empty months', $view['months']->vars['placeholder']);
|
$this->assertSame('Empty months', $view['months']->vars['placeholder']);
|
||||||
$this->assertSame('Empty days', $view['days']->vars['placeholder']);
|
$this->assertSame('Empty days', $view['days']->vars['placeholder']);
|
||||||
@ -305,10 +267,7 @@ class DateIntervalTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testPassPlaceholderAsPartialArrayAddEmptyIfNotRequired()
|
public function testPassPlaceholderAsPartialArrayAddEmptyIfNotRequired()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create(
|
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'Symfony\Component\Form\Extension\Core\Type\DateIntervalType',
|
|
||||||
null,
|
|
||||||
array(
|
|
||||||
'required' => false,
|
'required' => false,
|
||||||
'placeholder' => array(
|
'placeholder' => array(
|
||||||
'years' => 'Empty years',
|
'years' => 'Empty years',
|
||||||
@ -319,9 +278,9 @@ class DateIntervalTypeTest extends TestCase
|
|||||||
'with_hours' => true,
|
'with_hours' => true,
|
||||||
'with_minutes' => true,
|
'with_minutes' => true,
|
||||||
'with_seconds' => true,
|
'with_seconds' => true,
|
||||||
)
|
))
|
||||||
);
|
->createView();
|
||||||
$view = $form->createView();
|
|
||||||
$this->assertSame('Empty years', $view['years']->vars['placeholder']);
|
$this->assertSame('Empty years', $view['years']->vars['placeholder']);
|
||||||
$this->assertSame('', $view['months']->vars['placeholder']);
|
$this->assertSame('', $view['months']->vars['placeholder']);
|
||||||
$this->assertSame('Empty days', $view['days']->vars['placeholder']);
|
$this->assertSame('Empty days', $view['days']->vars['placeholder']);
|
||||||
@ -332,10 +291,7 @@ class DateIntervalTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testPassPlaceholderAsPartialArrayAddNullIfRequired()
|
public function testPassPlaceholderAsPartialArrayAddNullIfRequired()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create(
|
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'Symfony\Component\Form\Extension\Core\Type\DateIntervalType',
|
|
||||||
null,
|
|
||||||
array(
|
|
||||||
'required' => true,
|
'required' => true,
|
||||||
'placeholder' => array(
|
'placeholder' => array(
|
||||||
'years' => 'Empty years',
|
'years' => 'Empty years',
|
||||||
@ -346,9 +302,9 @@ class DateIntervalTypeTest extends TestCase
|
|||||||
'with_hours' => true,
|
'with_hours' => true,
|
||||||
'with_minutes' => true,
|
'with_minutes' => true,
|
||||||
'with_seconds' => true,
|
'with_seconds' => true,
|
||||||
)
|
))
|
||||||
);
|
->createView();
|
||||||
$view = $form->createView();
|
|
||||||
$this->assertSame('Empty years', $view['years']->vars['placeholder']);
|
$this->assertSame('Empty years', $view['years']->vars['placeholder']);
|
||||||
$this->assertNull($view['months']->vars['placeholder']);
|
$this->assertNull($view['months']->vars['placeholder']);
|
||||||
$this->assertSame('Empty days', $view['days']->vars['placeholder']);
|
$this->assertSame('Empty days', $view['days']->vars['placeholder']);
|
||||||
@ -360,24 +316,23 @@ class DateIntervalTypeTest extends TestCase
|
|||||||
public function testDateTypeChoiceErrorsBubbleUp()
|
public function testDateTypeChoiceErrorsBubbleUp()
|
||||||
{
|
{
|
||||||
$error = new FormError('Invalid!');
|
$error = new FormError('Invalid!');
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateIntervalType', null);
|
$form = $this->factory->create(static::TESTED_TYPE, null);
|
||||||
|
|
||||||
$form['years']->addError($error);
|
$form['years']->addError($error);
|
||||||
|
|
||||||
$this->assertSame(array(), iterator_to_array($form['years']->getErrors()));
|
$this->assertSame(array(), iterator_to_array($form['years']->getErrors()));
|
||||||
$this->assertSame(array($error), iterator_to_array($form->getErrors()));
|
$this->assertSame(array($error), iterator_to_array($form->getErrors()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testTranslationsAreDisabledForChoiceWidget()
|
public function testTranslationsAreDisabledForChoiceWidget()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
DateIntervalType::class,
|
|
||||||
null,
|
|
||||||
array(
|
|
||||||
'widget' => 'choice',
|
'widget' => 'choice',
|
||||||
'with_hours' => true,
|
'with_hours' => true,
|
||||||
'with_minutes' => true,
|
'with_minutes' => true,
|
||||||
'with_seconds' => true,
|
'with_seconds' => true,
|
||||||
)
|
));
|
||||||
);
|
|
||||||
$this->assertFalse($form->get('years')->getConfig()->getOption('choice_translation_domain'));
|
$this->assertFalse($form->get('years')->getConfig()->getOption('choice_translation_domain'));
|
||||||
$this->assertFalse($form->get('months')->getConfig()->getOption('choice_translation_domain'));
|
$this->assertFalse($form->get('months')->getConfig()->getOption('choice_translation_domain'));
|
||||||
$this->assertFalse($form->get('days')->getConfig()->getOption('choice_translation_domain'));
|
$this->assertFalse($form->get('days')->getConfig()->getOption('choice_translation_domain'));
|
||||||
@ -388,22 +343,19 @@ class DateIntervalTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testInvertDoesNotInheritRequiredOption()
|
public function testInvertDoesNotInheritRequiredOption()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'Symfony\Component\Form\Extension\Core\Type\DateIntervalType',
|
|
||||||
null,
|
|
||||||
array(
|
|
||||||
'input' => 'dateinterval',
|
'input' => 'dateinterval',
|
||||||
'with_invert' => true,
|
'with_invert' => true,
|
||||||
'required' => true,
|
'required' => true,
|
||||||
)
|
));
|
||||||
);
|
|
||||||
$this->assertFalse($form->get('invert')->getConfig()->getOption('required'));
|
$this->assertFalse($form->get('invert')->getConfig()->getOption('required'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCanChangeTimeFieldsLabels()
|
public function testCanChangeTimeFieldsLabels()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create(
|
$form = $this->factory->create(
|
||||||
DateIntervalType::class,
|
static::TESTED_TYPE,
|
||||||
null,
|
null,
|
||||||
array(
|
array(
|
||||||
'required' => true,
|
'required' => true,
|
||||||
@ -435,12 +387,12 @@ class DateIntervalTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testInvertDefaultLabel()
|
public function testInvertDefaultLabel()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create(DateIntervalType::class, null, array('with_invert' => true));
|
$form = $this->factory->create(static::TESTED_TYPE, null, array('with_invert' => true));
|
||||||
|
|
||||||
$view = $form->createView();
|
$view = $form->createView();
|
||||||
$this->assertSame('Negative interval', $view['invert']->vars['label']);
|
$this->assertSame('Negative interval', $view['invert']->vars['label']);
|
||||||
|
|
||||||
$form = $this->factory->create(DateIntervalType::class, null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'with_invert' => true,
|
'with_invert' => true,
|
||||||
'labels' => array('invert' => null),
|
'labels' => array('invert' => null),
|
||||||
));
|
));
|
||||||
@ -448,4 +400,13 @@ class DateIntervalTypeTest extends TestCase
|
|||||||
$view = $form->createView();
|
$view = $form->createView();
|
||||||
$this->assertSame('Negative interval', $view['invert']->vars['label']);
|
$this->assertSame('Negative interval', $view['invert']->vars['label']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testSubmitNull($expected = null, $norm = null, $view = null)
|
||||||
|
{
|
||||||
|
parent::testSubmitNull($expected, $norm, array(
|
||||||
|
'years' => '',
|
||||||
|
'months' => '',
|
||||||
|
'days' => '',
|
||||||
|
));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,10 +12,11 @@
|
|||||||
namespace Symfony\Component\Form\Tests\Extension\Core\Type;
|
namespace Symfony\Component\Form\Tests\Extension\Core\Type;
|
||||||
|
|
||||||
use Symfony\Component\Form\FormError;
|
use Symfony\Component\Form\FormError;
|
||||||
use Symfony\Component\Form\Test\TypeTestCase as TestCase;
|
|
||||||
|
|
||||||
class DateTimeTypeTest extends TestCase
|
class DateTimeTypeTest extends BaseTypeTest
|
||||||
{
|
{
|
||||||
|
const TESTED_TYPE = 'Symfony\Component\Form\Extension\Core\Type\DateTimeType';
|
||||||
|
|
||||||
protected function setUp()
|
protected function setUp()
|
||||||
{
|
{
|
||||||
\Locale::setDefault('en');
|
\Locale::setDefault('en');
|
||||||
@ -25,7 +26,7 @@ class DateTimeTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testSubmitDateTime()
|
public function testSubmitDateTime()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateTimeType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'model_timezone' => 'UTC',
|
'model_timezone' => 'UTC',
|
||||||
'view_timezone' => 'UTC',
|
'view_timezone' => 'UTC',
|
||||||
'date_widget' => 'choice',
|
'date_widget' => 'choice',
|
||||||
@ -53,7 +54,7 @@ class DateTimeTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testSubmitString()
|
public function testSubmitString()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateTimeType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'model_timezone' => 'UTC',
|
'model_timezone' => 'UTC',
|
||||||
'view_timezone' => 'UTC',
|
'view_timezone' => 'UTC',
|
||||||
'input' => 'string',
|
'input' => 'string',
|
||||||
@ -79,7 +80,7 @@ class DateTimeTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testSubmitTimestamp()
|
public function testSubmitTimestamp()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateTimeType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'model_timezone' => 'UTC',
|
'model_timezone' => 'UTC',
|
||||||
'view_timezone' => 'UTC',
|
'view_timezone' => 'UTC',
|
||||||
'input' => 'timestamp',
|
'input' => 'timestamp',
|
||||||
@ -107,7 +108,7 @@ class DateTimeTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testSubmitWithoutMinutes()
|
public function testSubmitWithoutMinutes()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateTimeType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'model_timezone' => 'UTC',
|
'model_timezone' => 'UTC',
|
||||||
'view_timezone' => 'UTC',
|
'view_timezone' => 'UTC',
|
||||||
'date_widget' => 'choice',
|
'date_widget' => 'choice',
|
||||||
@ -137,7 +138,7 @@ class DateTimeTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testSubmitWithSeconds()
|
public function testSubmitWithSeconds()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateTimeType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'model_timezone' => 'UTC',
|
'model_timezone' => 'UTC',
|
||||||
'view_timezone' => 'UTC',
|
'view_timezone' => 'UTC',
|
||||||
'date_widget' => 'choice',
|
'date_widget' => 'choice',
|
||||||
@ -169,7 +170,7 @@ class DateTimeTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testSubmitDifferentTimezones()
|
public function testSubmitDifferentTimezones()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateTimeType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'model_timezone' => 'America/New_York',
|
'model_timezone' => 'America/New_York',
|
||||||
'view_timezone' => 'Pacific/Tahiti',
|
'view_timezone' => 'Pacific/Tahiti',
|
||||||
'date_widget' => 'choice',
|
'date_widget' => 'choice',
|
||||||
@ -201,7 +202,7 @@ class DateTimeTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testSubmitDifferentTimezonesDateTime()
|
public function testSubmitDifferentTimezonesDateTime()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateTimeType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'model_timezone' => 'America/New_York',
|
'model_timezone' => 'America/New_York',
|
||||||
'view_timezone' => 'Pacific/Tahiti',
|
'view_timezone' => 'Pacific/Tahiti',
|
||||||
'widget' => 'single_text',
|
'widget' => 'single_text',
|
||||||
@ -220,7 +221,7 @@ class DateTimeTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testSubmitStringSingleText()
|
public function testSubmitStringSingleText()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateTimeType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'model_timezone' => 'UTC',
|
'model_timezone' => 'UTC',
|
||||||
'view_timezone' => 'UTC',
|
'view_timezone' => 'UTC',
|
||||||
'input' => 'string',
|
'input' => 'string',
|
||||||
@ -235,7 +236,7 @@ class DateTimeTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testSubmitStringSingleTextWithSeconds()
|
public function testSubmitStringSingleTextWithSeconds()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateTimeType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'model_timezone' => 'UTC',
|
'model_timezone' => 'UTC',
|
||||||
'view_timezone' => 'UTC',
|
'view_timezone' => 'UTC',
|
||||||
'input' => 'string',
|
'input' => 'string',
|
||||||
@ -251,7 +252,7 @@ class DateTimeTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testSubmitDifferentPattern()
|
public function testSubmitDifferentPattern()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateTimeType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'date_format' => 'MM*yyyy*dd',
|
'date_format' => 'MM*yyyy*dd',
|
||||||
'date_widget' => 'single_text',
|
'date_widget' => 'single_text',
|
||||||
'time_widget' => 'single_text',
|
'time_widget' => 'single_text',
|
||||||
@ -272,27 +273,27 @@ class DateTimeTypeTest extends TestCase
|
|||||||
{
|
{
|
||||||
// Throws an exception if "data_class" option is not explicitly set
|
// Throws an exception if "data_class" option is not explicitly set
|
||||||
// to null in the type
|
// to null in the type
|
||||||
$this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateTimeType', new \DateTime());
|
$this->factory->create(static::TESTED_TYPE, new \DateTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSingleTextWidgetShouldUseTheRightInputType()
|
public function testSingleTextWidgetShouldUseTheRightInputType()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateTimeType', null, array(
|
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'widget' => 'single_text',
|
'widget' => 'single_text',
|
||||||
));
|
))
|
||||||
|
->createView();
|
||||||
|
|
||||||
$view = $form->createView();
|
|
||||||
$this->assertEquals('datetime', $view->vars['type']);
|
$this->assertEquals('datetime', $view->vars['type']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testPassDefaultPlaceholderToViewIfNotRequired()
|
public function testPassDefaultPlaceholderToViewIfNotRequired()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateTimeType', null, array(
|
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'required' => false,
|
'required' => false,
|
||||||
'with_seconds' => true,
|
'with_seconds' => true,
|
||||||
));
|
))
|
||||||
|
->createView();
|
||||||
|
|
||||||
$view = $form->createView();
|
|
||||||
$this->assertSame('', $view['date']['year']->vars['placeholder']);
|
$this->assertSame('', $view['date']['year']->vars['placeholder']);
|
||||||
$this->assertSame('', $view['date']['month']->vars['placeholder']);
|
$this->assertSame('', $view['date']['month']->vars['placeholder']);
|
||||||
$this->assertSame('', $view['date']['day']->vars['placeholder']);
|
$this->assertSame('', $view['date']['day']->vars['placeholder']);
|
||||||
@ -303,12 +304,12 @@ class DateTimeTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testPassNoPlaceholderToViewIfRequired()
|
public function testPassNoPlaceholderToViewIfRequired()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateTimeType', null, array(
|
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'required' => true,
|
'required' => true,
|
||||||
'with_seconds' => true,
|
'with_seconds' => true,
|
||||||
));
|
))
|
||||||
|
->createView();
|
||||||
|
|
||||||
$view = $form->createView();
|
|
||||||
$this->assertNull($view['date']['year']->vars['placeholder']);
|
$this->assertNull($view['date']['year']->vars['placeholder']);
|
||||||
$this->assertNull($view['date']['month']->vars['placeholder']);
|
$this->assertNull($view['date']['month']->vars['placeholder']);
|
||||||
$this->assertNull($view['date']['day']->vars['placeholder']);
|
$this->assertNull($view['date']['day']->vars['placeholder']);
|
||||||
@ -319,12 +320,12 @@ class DateTimeTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testPassPlaceholderAsString()
|
public function testPassPlaceholderAsString()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateTimeType', null, array(
|
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'placeholder' => 'Empty',
|
'placeholder' => 'Empty',
|
||||||
'with_seconds' => true,
|
'with_seconds' => true,
|
||||||
));
|
))
|
||||||
|
->createView();
|
||||||
|
|
||||||
$view = $form->createView();
|
|
||||||
$this->assertSame('Empty', $view['date']['year']->vars['placeholder']);
|
$this->assertSame('Empty', $view['date']['year']->vars['placeholder']);
|
||||||
$this->assertSame('Empty', $view['date']['month']->vars['placeholder']);
|
$this->assertSame('Empty', $view['date']['month']->vars['placeholder']);
|
||||||
$this->assertSame('Empty', $view['date']['day']->vars['placeholder']);
|
$this->assertSame('Empty', $view['date']['day']->vars['placeholder']);
|
||||||
@ -335,7 +336,7 @@ class DateTimeTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testPassPlaceholderAsArray()
|
public function testPassPlaceholderAsArray()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateTimeType', null, array(
|
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'placeholder' => array(
|
'placeholder' => array(
|
||||||
'year' => 'Empty year',
|
'year' => 'Empty year',
|
||||||
'month' => 'Empty month',
|
'month' => 'Empty month',
|
||||||
@ -345,9 +346,9 @@ class DateTimeTypeTest extends TestCase
|
|||||||
'second' => 'Empty second',
|
'second' => 'Empty second',
|
||||||
),
|
),
|
||||||
'with_seconds' => true,
|
'with_seconds' => true,
|
||||||
));
|
))
|
||||||
|
->createView();
|
||||||
|
|
||||||
$view = $form->createView();
|
|
||||||
$this->assertSame('Empty year', $view['date']['year']->vars['placeholder']);
|
$this->assertSame('Empty year', $view['date']['year']->vars['placeholder']);
|
||||||
$this->assertSame('Empty month', $view['date']['month']->vars['placeholder']);
|
$this->assertSame('Empty month', $view['date']['month']->vars['placeholder']);
|
||||||
$this->assertSame('Empty day', $view['date']['day']->vars['placeholder']);
|
$this->assertSame('Empty day', $view['date']['day']->vars['placeholder']);
|
||||||
@ -358,7 +359,7 @@ class DateTimeTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testPassPlaceholderAsPartialArrayAddEmptyIfNotRequired()
|
public function testPassPlaceholderAsPartialArrayAddEmptyIfNotRequired()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateTimeType', null, array(
|
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'required' => false,
|
'required' => false,
|
||||||
'placeholder' => array(
|
'placeholder' => array(
|
||||||
'year' => 'Empty year',
|
'year' => 'Empty year',
|
||||||
@ -367,9 +368,9 @@ class DateTimeTypeTest extends TestCase
|
|||||||
'second' => 'Empty second',
|
'second' => 'Empty second',
|
||||||
),
|
),
|
||||||
'with_seconds' => true,
|
'with_seconds' => true,
|
||||||
));
|
))
|
||||||
|
->createView();
|
||||||
|
|
||||||
$view = $form->createView();
|
|
||||||
$this->assertSame('Empty year', $view['date']['year']->vars['placeholder']);
|
$this->assertSame('Empty year', $view['date']['year']->vars['placeholder']);
|
||||||
$this->assertSame('', $view['date']['month']->vars['placeholder']);
|
$this->assertSame('', $view['date']['month']->vars['placeholder']);
|
||||||
$this->assertSame('Empty day', $view['date']['day']->vars['placeholder']);
|
$this->assertSame('Empty day', $view['date']['day']->vars['placeholder']);
|
||||||
@ -380,7 +381,7 @@ class DateTimeTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testPassPlaceholderAsPartialArrayAddNullIfRequired()
|
public function testPassPlaceholderAsPartialArrayAddNullIfRequired()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateTimeType', null, array(
|
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'required' => true,
|
'required' => true,
|
||||||
'placeholder' => array(
|
'placeholder' => array(
|
||||||
'year' => 'Empty year',
|
'year' => 'Empty year',
|
||||||
@ -389,9 +390,9 @@ class DateTimeTypeTest extends TestCase
|
|||||||
'second' => 'Empty second',
|
'second' => 'Empty second',
|
||||||
),
|
),
|
||||||
'with_seconds' => true,
|
'with_seconds' => true,
|
||||||
));
|
))
|
||||||
|
->createView();
|
||||||
|
|
||||||
$view = $form->createView();
|
|
||||||
$this->assertSame('Empty year', $view['date']['year']->vars['placeholder']);
|
$this->assertSame('Empty year', $view['date']['year']->vars['placeholder']);
|
||||||
$this->assertNull($view['date']['month']->vars['placeholder']);
|
$this->assertNull($view['date']['month']->vars['placeholder']);
|
||||||
$this->assertSame('Empty day', $view['date']['day']->vars['placeholder']);
|
$this->assertSame('Empty day', $view['date']['day']->vars['placeholder']);
|
||||||
@ -402,50 +403,50 @@ class DateTimeTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testPassHtml5TypeIfSingleTextAndHtml5Format()
|
public function testPassHtml5TypeIfSingleTextAndHtml5Format()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateTimeType', null, array(
|
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'widget' => 'single_text',
|
'widget' => 'single_text',
|
||||||
));
|
))
|
||||||
|
->createView();
|
||||||
|
|
||||||
$view = $form->createView();
|
|
||||||
$this->assertSame('datetime', $view->vars['type']);
|
$this->assertSame('datetime', $view->vars['type']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDontPassHtml5TypeIfHtml5NotAllowed()
|
public function testDontPassHtml5TypeIfHtml5NotAllowed()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateTimeType', null, array(
|
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'widget' => 'single_text',
|
'widget' => 'single_text',
|
||||||
'html5' => false,
|
'html5' => false,
|
||||||
));
|
))
|
||||||
|
->createView();
|
||||||
|
|
||||||
$view = $form->createView();
|
|
||||||
$this->assertFalse(isset($view->vars['type']));
|
$this->assertFalse(isset($view->vars['type']));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDontPassHtml5TypeIfNotHtml5Format()
|
public function testDontPassHtml5TypeIfNotHtml5Format()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateTimeType', null, array(
|
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'widget' => 'single_text',
|
'widget' => 'single_text',
|
||||||
'format' => 'yyyy-MM-dd HH:mm',
|
'format' => 'yyyy-MM-dd HH:mm',
|
||||||
));
|
))
|
||||||
|
->createView();
|
||||||
|
|
||||||
$view = $form->createView();
|
|
||||||
$this->assertFalse(isset($view->vars['type']));
|
$this->assertFalse(isset($view->vars['type']));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDontPassHtml5TypeIfNotSingleText()
|
public function testDontPassHtml5TypeIfNotSingleText()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateTimeType', null, array(
|
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'widget' => 'text',
|
'widget' => 'text',
|
||||||
));
|
))
|
||||||
|
->createView();
|
||||||
|
|
||||||
$view = $form->createView();
|
|
||||||
$this->assertFalse(isset($view->vars['type']));
|
$this->assertFalse(isset($view->vars['type']));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDateTypeChoiceErrorsBubbleUp()
|
public function testDateTypeChoiceErrorsBubbleUp()
|
||||||
{
|
{
|
||||||
$error = new FormError('Invalid!');
|
$error = new FormError('Invalid!');
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateTimeType', null);
|
$form = $this->factory->create(static::TESTED_TYPE, null);
|
||||||
|
|
||||||
$form['date']->addError($error);
|
$form['date']->addError($error);
|
||||||
|
|
||||||
@ -456,7 +457,7 @@ class DateTimeTypeTest extends TestCase
|
|||||||
public function testDateTypeSingleTextErrorsBubbleUp()
|
public function testDateTypeSingleTextErrorsBubbleUp()
|
||||||
{
|
{
|
||||||
$error = new FormError('Invalid!');
|
$error = new FormError('Invalid!');
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateTimeType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'date_widget' => 'single_text',
|
'date_widget' => 'single_text',
|
||||||
));
|
));
|
||||||
|
|
||||||
@ -469,7 +470,7 @@ class DateTimeTypeTest extends TestCase
|
|||||||
public function testTimeTypeChoiceErrorsBubbleUp()
|
public function testTimeTypeChoiceErrorsBubbleUp()
|
||||||
{
|
{
|
||||||
$error = new FormError('Invalid!');
|
$error = new FormError('Invalid!');
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateTimeType', null);
|
$form = $this->factory->create(static::TESTED_TYPE, null);
|
||||||
|
|
||||||
$form['time']->addError($error);
|
$form['time']->addError($error);
|
||||||
|
|
||||||
@ -480,7 +481,7 @@ class DateTimeTypeTest extends TestCase
|
|||||||
public function testTimeTypeSingleTextErrorsBubbleUp()
|
public function testTimeTypeSingleTextErrorsBubbleUp()
|
||||||
{
|
{
|
||||||
$error = new FormError('Invalid!');
|
$error = new FormError('Invalid!');
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateTimeType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'time_widget' => 'single_text',
|
'time_widget' => 'single_text',
|
||||||
));
|
));
|
||||||
|
|
||||||
@ -492,7 +493,7 @@ class DateTimeTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testPassDefaultChoiceTranslationDomain()
|
public function testPassDefaultChoiceTranslationDomain()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateTimeType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'with_seconds' => true,
|
'with_seconds' => true,
|
||||||
));
|
));
|
||||||
|
|
||||||
@ -508,7 +509,7 @@ class DateTimeTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testPassChoiceTranslationDomainAsString()
|
public function testPassChoiceTranslationDomainAsString()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateTimeType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'choice_translation_domain' => 'messages',
|
'choice_translation_domain' => 'messages',
|
||||||
'with_seconds' => true,
|
'with_seconds' => true,
|
||||||
));
|
));
|
||||||
@ -524,7 +525,7 @@ class DateTimeTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testPassChoiceTranslationDomainAsArray()
|
public function testPassChoiceTranslationDomainAsArray()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateTimeType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'choice_translation_domain' => array(
|
'choice_translation_domain' => array(
|
||||||
'year' => 'foo',
|
'year' => 'foo',
|
||||||
'month' => 'test',
|
'month' => 'test',
|
||||||
@ -542,4 +543,41 @@ class DateTimeTypeTest extends TestCase
|
|||||||
$this->assertFalse($view['time']['minute']->vars['choice_translation_domain']);
|
$this->assertFalse($view['time']['minute']->vars['choice_translation_domain']);
|
||||||
$this->assertSame('test', $view['time']['second']->vars['choice_translation_domain']);
|
$this->assertSame('test', $view['time']['second']->vars['choice_translation_domain']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testSubmitNull($expected = null, $norm = null, $view = null)
|
||||||
|
{
|
||||||
|
parent::testSubmitNull($expected, $norm, array(
|
||||||
|
// View data is an array of choice values array
|
||||||
|
'date' => array('year' => '', 'month' => '', 'day' => ''),
|
||||||
|
'time' => array('hour' => '', 'minute' => ''),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSubmitNullWithText()
|
||||||
|
{
|
||||||
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
|
'widget' => 'text',
|
||||||
|
));
|
||||||
|
$form->submit(null);
|
||||||
|
|
||||||
|
$this->assertNull($form->getData());
|
||||||
|
$this->assertNull($form->getNormData());
|
||||||
|
$this->assertSame(array(
|
||||||
|
// View data is an array of choice values array
|
||||||
|
'date' => array('year' => '', 'month' => '', 'day' => ''),
|
||||||
|
'time' => array('hour' => '', 'minute' => ''),
|
||||||
|
), $form->getViewData());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSubmitNullWithSingleText()
|
||||||
|
{
|
||||||
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
|
'widget' => 'single_text',
|
||||||
|
));
|
||||||
|
$form->submit(null);
|
||||||
|
|
||||||
|
$this->assertNull($form->getData());
|
||||||
|
$this->assertNull($form->getNormData());
|
||||||
|
$this->assertSame('', $form->getViewData());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,11 +13,12 @@ namespace Symfony\Component\Form\Tests\Extension\Core\Type;
|
|||||||
|
|
||||||
use Symfony\Component\Form\ChoiceList\View\ChoiceView;
|
use Symfony\Component\Form\ChoiceList\View\ChoiceView;
|
||||||
use Symfony\Component\Form\FormError;
|
use Symfony\Component\Form\FormError;
|
||||||
use Symfony\Component\Form\Test\TypeTestCase as TestCase;
|
|
||||||
use Symfony\Component\Intl\Util\IntlTestHelper;
|
use Symfony\Component\Intl\Util\IntlTestHelper;
|
||||||
|
|
||||||
class DateTypeTest extends TestCase
|
class DateTypeTest extends BaseTypeTest
|
||||||
{
|
{
|
||||||
|
const TESTED_TYPE = 'Symfony\Component\Form\Extension\Core\Type\DateType';
|
||||||
|
|
||||||
private $defaultTimezone;
|
private $defaultTimezone;
|
||||||
|
|
||||||
protected function setUp()
|
protected function setUp()
|
||||||
@ -37,7 +38,7 @@ class DateTypeTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testInvalidWidgetOption()
|
public function testInvalidWidgetOption()
|
||||||
{
|
{
|
||||||
$this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
$this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'widget' => 'fake_widget',
|
'widget' => 'fake_widget',
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
@ -47,14 +48,14 @@ class DateTypeTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testInvalidInputOption()
|
public function testInvalidInputOption()
|
||||||
{
|
{
|
||||||
$this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
$this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'input' => 'fake_input',
|
'input' => 'fake_input',
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSubmitFromSingleTextDateTimeWithDefaultFormat()
|
public function testSubmitFromSingleTextDateTimeWithDefaultFormat()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'model_timezone' => 'UTC',
|
'model_timezone' => 'UTC',
|
||||||
'view_timezone' => 'UTC',
|
'view_timezone' => 'UTC',
|
||||||
'widget' => 'single_text',
|
'widget' => 'single_text',
|
||||||
@ -69,7 +70,7 @@ class DateTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testSubmitFromSingleTextDateTimeWithCustomFormat()
|
public function testSubmitFromSingleTextDateTimeWithCustomFormat()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'model_timezone' => 'UTC',
|
'model_timezone' => 'UTC',
|
||||||
'view_timezone' => 'UTC',
|
'view_timezone' => 'UTC',
|
||||||
'widget' => 'single_text',
|
'widget' => 'single_text',
|
||||||
@ -90,7 +91,7 @@ class DateTypeTest extends TestCase
|
|||||||
|
|
||||||
\Locale::setDefault('de_DE');
|
\Locale::setDefault('de_DE');
|
||||||
|
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'format' => \IntlDateFormatter::MEDIUM,
|
'format' => \IntlDateFormatter::MEDIUM,
|
||||||
'model_timezone' => 'UTC',
|
'model_timezone' => 'UTC',
|
||||||
'view_timezone' => 'UTC',
|
'view_timezone' => 'UTC',
|
||||||
@ -111,7 +112,7 @@ class DateTypeTest extends TestCase
|
|||||||
|
|
||||||
\Locale::setDefault('de_DE');
|
\Locale::setDefault('de_DE');
|
||||||
|
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'format' => \IntlDateFormatter::MEDIUM,
|
'format' => \IntlDateFormatter::MEDIUM,
|
||||||
'model_timezone' => 'UTC',
|
'model_timezone' => 'UTC',
|
||||||
'view_timezone' => 'UTC',
|
'view_timezone' => 'UTC',
|
||||||
@ -132,7 +133,7 @@ class DateTypeTest extends TestCase
|
|||||||
|
|
||||||
\Locale::setDefault('de_DE');
|
\Locale::setDefault('de_DE');
|
||||||
|
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'format' => \IntlDateFormatter::MEDIUM,
|
'format' => \IntlDateFormatter::MEDIUM,
|
||||||
'model_timezone' => 'UTC',
|
'model_timezone' => 'UTC',
|
||||||
'view_timezone' => 'UTC',
|
'view_timezone' => 'UTC',
|
||||||
@ -155,7 +156,7 @@ class DateTypeTest extends TestCase
|
|||||||
|
|
||||||
\Locale::setDefault('de_DE');
|
\Locale::setDefault('de_DE');
|
||||||
|
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'format' => \IntlDateFormatter::MEDIUM,
|
'format' => \IntlDateFormatter::MEDIUM,
|
||||||
'model_timezone' => 'UTC',
|
'model_timezone' => 'UTC',
|
||||||
'view_timezone' => 'UTC',
|
'view_timezone' => 'UTC',
|
||||||
@ -177,7 +178,7 @@ class DateTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testSubmitFromText()
|
public function testSubmitFromText()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'model_timezone' => 'UTC',
|
'model_timezone' => 'UTC',
|
||||||
'view_timezone' => 'UTC',
|
'view_timezone' => 'UTC',
|
||||||
'widget' => 'text',
|
'widget' => 'text',
|
||||||
@ -199,7 +200,7 @@ class DateTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testSubmitFromChoice()
|
public function testSubmitFromChoice()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'model_timezone' => 'UTC',
|
'model_timezone' => 'UTC',
|
||||||
'view_timezone' => 'UTC',
|
'view_timezone' => 'UTC',
|
||||||
'widget' => 'choice',
|
'widget' => 'choice',
|
||||||
@ -222,7 +223,7 @@ class DateTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testSubmitFromChoiceEmpty()
|
public function testSubmitFromChoiceEmpty()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'model_timezone' => 'UTC',
|
'model_timezone' => 'UTC',
|
||||||
'view_timezone' => 'UTC',
|
'view_timezone' => 'UTC',
|
||||||
'widget' => 'choice',
|
'widget' => 'choice',
|
||||||
@ -243,7 +244,7 @@ class DateTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testSubmitFromInputDateTimeDifferentPattern()
|
public function testSubmitFromInputDateTimeDifferentPattern()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'model_timezone' => 'UTC',
|
'model_timezone' => 'UTC',
|
||||||
'view_timezone' => 'UTC',
|
'view_timezone' => 'UTC',
|
||||||
'format' => 'MM*yyyy*dd',
|
'format' => 'MM*yyyy*dd',
|
||||||
@ -259,7 +260,7 @@ class DateTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testSubmitFromInputStringDifferentPattern()
|
public function testSubmitFromInputStringDifferentPattern()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'model_timezone' => 'UTC',
|
'model_timezone' => 'UTC',
|
||||||
'view_timezone' => 'UTC',
|
'view_timezone' => 'UTC',
|
||||||
'format' => 'MM*yyyy*dd',
|
'format' => 'MM*yyyy*dd',
|
||||||
@ -275,7 +276,7 @@ class DateTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testSubmitFromInputTimestampDifferentPattern()
|
public function testSubmitFromInputTimestampDifferentPattern()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'model_timezone' => 'UTC',
|
'model_timezone' => 'UTC',
|
||||||
'view_timezone' => 'UTC',
|
'view_timezone' => 'UTC',
|
||||||
'format' => 'MM*yyyy*dd',
|
'format' => 'MM*yyyy*dd',
|
||||||
@ -293,7 +294,7 @@ class DateTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testSubmitFromInputRawDifferentPattern()
|
public function testSubmitFromInputRawDifferentPattern()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'model_timezone' => 'UTC',
|
'model_timezone' => 'UTC',
|
||||||
'view_timezone' => 'UTC',
|
'view_timezone' => 'UTC',
|
||||||
'format' => 'MM*yyyy*dd',
|
'format' => 'MM*yyyy*dd',
|
||||||
@ -318,11 +319,10 @@ class DateTypeTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testDatePatternWithFormatOption($format, $pattern)
|
public function testDatePatternWithFormatOption($format, $pattern)
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'format' => $format,
|
'format' => $format,
|
||||||
));
|
))
|
||||||
|
->createView();
|
||||||
$view = $form->createView();
|
|
||||||
|
|
||||||
$this->assertEquals($pattern, $view->vars['date_pattern']);
|
$this->assertEquals($pattern, $view->vars['date_pattern']);
|
||||||
}
|
}
|
||||||
@ -344,7 +344,7 @@ class DateTypeTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testThrowExceptionIfFormatIsNoPattern()
|
public function testThrowExceptionIfFormatIsNoPattern()
|
||||||
{
|
{
|
||||||
$this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
$this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'format' => '0',
|
'format' => '0',
|
||||||
'widget' => 'single_text',
|
'widget' => 'single_text',
|
||||||
'input' => 'string',
|
'input' => 'string',
|
||||||
@ -357,7 +357,7 @@ class DateTypeTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testThrowExceptionIfFormatDoesNotContainYearMonthAndDay()
|
public function testThrowExceptionIfFormatDoesNotContainYearMonthAndDay()
|
||||||
{
|
{
|
||||||
$this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
$this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'months' => array(6, 7),
|
'months' => array(6, 7),
|
||||||
'format' => 'yy',
|
'format' => 'yy',
|
||||||
));
|
));
|
||||||
@ -369,7 +369,7 @@ class DateTypeTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testThrowExceptionIfFormatMissesYearMonthAndDayWithSingleTextWidget()
|
public function testThrowExceptionIfFormatMissesYearMonthAndDayWithSingleTextWidget()
|
||||||
{
|
{
|
||||||
$this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
$this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'widget' => 'single_text',
|
'widget' => 'single_text',
|
||||||
'format' => 'wrong',
|
'format' => 'wrong',
|
||||||
));
|
));
|
||||||
@ -380,7 +380,7 @@ class DateTypeTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testThrowExceptionIfFormatIsNoConstant()
|
public function testThrowExceptionIfFormatIsNoConstant()
|
||||||
{
|
{
|
||||||
$this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
$this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'format' => 105,
|
'format' => 105,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
@ -390,7 +390,7 @@ class DateTypeTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testThrowExceptionIfFormatIsInvalid()
|
public function testThrowExceptionIfFormatIsInvalid()
|
||||||
{
|
{
|
||||||
$this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
$this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'format' => array(),
|
'format' => array(),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
@ -400,7 +400,7 @@ class DateTypeTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testThrowExceptionIfYearsIsInvalid()
|
public function testThrowExceptionIfYearsIsInvalid()
|
||||||
{
|
{
|
||||||
$this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
$this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'years' => 'bad value',
|
'years' => 'bad value',
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
@ -410,7 +410,7 @@ class DateTypeTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testThrowExceptionIfMonthsIsInvalid()
|
public function testThrowExceptionIfMonthsIsInvalid()
|
||||||
{
|
{
|
||||||
$this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
$this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'months' => 'bad value',
|
'months' => 'bad value',
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
@ -420,7 +420,7 @@ class DateTypeTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testThrowExceptionIfDaysIsInvalid()
|
public function testThrowExceptionIfDaysIsInvalid()
|
||||||
{
|
{
|
||||||
$this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
$this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'days' => 'bad value',
|
'days' => 'bad value',
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
@ -432,7 +432,7 @@ class DateTypeTest extends TestCase
|
|||||||
|
|
||||||
\Locale::setDefault('de_DE');
|
\Locale::setDefault('de_DE');
|
||||||
|
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'format' => \IntlDateFormatter::MEDIUM,
|
'format' => \IntlDateFormatter::MEDIUM,
|
||||||
'model_timezone' => 'UTC',
|
'model_timezone' => 'UTC',
|
||||||
'view_timezone' => 'America/New_York',
|
'view_timezone' => 'America/New_York',
|
||||||
@ -454,7 +454,7 @@ class DateTypeTest extends TestCase
|
|||||||
|
|
||||||
\Locale::setDefault('de_DE');
|
\Locale::setDefault('de_DE');
|
||||||
|
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'format' => \IntlDateFormatter::MEDIUM,
|
'format' => \IntlDateFormatter::MEDIUM,
|
||||||
'model_timezone' => 'UTC',
|
'model_timezone' => 'UTC',
|
||||||
'view_timezone' => 'America/New_York',
|
'view_timezone' => 'America/New_York',
|
||||||
@ -474,7 +474,7 @@ class DateTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testYearsOption()
|
public function testYearsOption()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'years' => array(2010, 2011),
|
'years' => array(2010, 2011),
|
||||||
));
|
));
|
||||||
|
|
||||||
@ -488,7 +488,7 @@ class DateTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testMonthsOption()
|
public function testMonthsOption()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'months' => array(6, 7),
|
'months' => array(6, 7),
|
||||||
'format' => \IntlDateFormatter::SHORT,
|
'format' => \IntlDateFormatter::SHORT,
|
||||||
));
|
));
|
||||||
@ -508,7 +508,7 @@ class DateTypeTest extends TestCase
|
|||||||
|
|
||||||
\Locale::setDefault('de_AT');
|
\Locale::setDefault('de_AT');
|
||||||
|
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'months' => array(1, 4),
|
'months' => array(1, 4),
|
||||||
'format' => 'dd.MMM.yy',
|
'format' => 'dd.MMM.yy',
|
||||||
));
|
));
|
||||||
@ -528,12 +528,11 @@ class DateTypeTest extends TestCase
|
|||||||
|
|
||||||
\Locale::setDefault('de_AT');
|
\Locale::setDefault('de_AT');
|
||||||
|
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'months' => array(1, 4),
|
'months' => array(1, 4),
|
||||||
'format' => 'dd.MMMM.yy',
|
'format' => 'dd.MMMM.yy',
|
||||||
));
|
))
|
||||||
|
->createView();
|
||||||
$view = $form->createView();
|
|
||||||
|
|
||||||
$this->assertEquals(array(
|
$this->assertEquals(array(
|
||||||
new ChoiceView(1, '1', 'Jänner'),
|
new ChoiceView(1, '1', 'Jänner'),
|
||||||
@ -548,12 +547,11 @@ class DateTypeTest extends TestCase
|
|||||||
|
|
||||||
\Locale::setDefault('de_AT');
|
\Locale::setDefault('de_AT');
|
||||||
|
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'months' => array(1, 4),
|
'months' => array(1, 4),
|
||||||
'format' => 'dd.MMMM.yy',
|
'format' => 'dd.MMMM.yy',
|
||||||
));
|
))
|
||||||
|
->createView();
|
||||||
$view = $form->createView();
|
|
||||||
|
|
||||||
$this->assertEquals(array(
|
$this->assertEquals(array(
|
||||||
new ChoiceView(1, '1', 'Jänner'),
|
new ChoiceView(1, '1', 'Jänner'),
|
||||||
@ -563,11 +561,10 @@ class DateTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testIsDayWithinRangeReturnsTrueIfWithin()
|
public function testIsDayWithinRangeReturnsTrueIfWithin()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'days' => array(6, 7),
|
'days' => array(6, 7),
|
||||||
));
|
))
|
||||||
|
->createView();
|
||||||
$view = $form->createView();
|
|
||||||
|
|
||||||
$this->assertEquals(array(
|
$this->assertEquals(array(
|
||||||
new ChoiceView(6, '6', '06'),
|
new ChoiceView(6, '6', '06'),
|
||||||
@ -575,26 +572,9 @@ class DateTypeTest extends TestCase
|
|||||||
), $view['day']->vars['choices']);
|
), $view['day']->vars['choices']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testIsPartiallyFilledReturnsFalseIfSingleText()
|
public function testIsSynchronizedReturnsTrueIfChoiceAndCompletelyEmpty()
|
||||||
{
|
{
|
||||||
$this->markTestIncomplete('Needs to be reimplemented using validators');
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
|
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
|
||||||
'model_timezone' => 'UTC',
|
|
||||||
'view_timezone' => 'UTC',
|
|
||||||
'widget' => 'single_text',
|
|
||||||
));
|
|
||||||
|
|
||||||
$form->submit('7.6.2010');
|
|
||||||
|
|
||||||
$this->assertFalse($form->isPartiallyFilled());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testIsPartiallyFilledReturnsFalseIfChoiceAndCompletelyEmpty()
|
|
||||||
{
|
|
||||||
$this->markTestIncomplete('Needs to be reimplemented using validators');
|
|
||||||
|
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
|
||||||
'model_timezone' => 'UTC',
|
'model_timezone' => 'UTC',
|
||||||
'view_timezone' => 'UTC',
|
'view_timezone' => 'UTC',
|
||||||
'widget' => 'choice',
|
'widget' => 'choice',
|
||||||
@ -606,33 +586,29 @@ class DateTypeTest extends TestCase
|
|||||||
'year' => '',
|
'year' => '',
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->assertFalse($form->isPartiallyFilled());
|
$this->assertTrue($form->isSynchronized());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testIsPartiallyFilledReturnsFalseIfChoiceAndCompletelyFilled()
|
public function testIsSynchronizedReturnsTrueIfChoiceAndCompletelyFilled()
|
||||||
{
|
{
|
||||||
$this->markTestIncomplete('Needs to be reimplemented using validators');
|
$form = $this->factory->create(static::TESTED_TYPE, new \DateTime(), array(
|
||||||
|
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
|
||||||
'model_timezone' => 'UTC',
|
'model_timezone' => 'UTC',
|
||||||
'view_timezone' => 'UTC',
|
'view_timezone' => 'UTC',
|
||||||
'widget' => 'choice',
|
'widget' => 'choice',
|
||||||
));
|
));
|
||||||
|
|
||||||
$form->submit(array(
|
$form->submit(array(
|
||||||
'day' => '2',
|
'day' => '0',
|
||||||
'month' => '6',
|
'month' => '6',
|
||||||
'year' => '2010',
|
'year' => '2010',
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->assertFalse($form->isPartiallyFilled());
|
$this->assertTrue($form->isSynchronized());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testIsPartiallyFilledReturnsTrueIfChoiceAndDayEmpty()
|
public function testIsSynchronizedReturnsFalseIfChoiceAndDayEmpty()
|
||||||
{
|
{
|
||||||
$this->markTestIncomplete('Needs to be reimplemented using validators');
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
|
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
|
||||||
'model_timezone' => 'UTC',
|
'model_timezone' => 'UTC',
|
||||||
'view_timezone' => 'UTC',
|
'view_timezone' => 'UTC',
|
||||||
'widget' => 'choice',
|
'widget' => 'choice',
|
||||||
@ -644,7 +620,7 @@ class DateTypeTest extends TestCase
|
|||||||
'year' => '2010',
|
'year' => '2010',
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->assertTrue($form->isPartiallyFilled());
|
$this->assertFalse($form->isSynchronized());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testPassDatePatternToView()
|
public function testPassDatePatternToView()
|
||||||
@ -654,8 +630,8 @@ class DateTypeTest extends TestCase
|
|||||||
|
|
||||||
\Locale::setDefault('de_AT');
|
\Locale::setDefault('de_AT');
|
||||||
|
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType');
|
$view = $this->factory->create(static::TESTED_TYPE)
|
||||||
$view = $form->createView();
|
->createView();
|
||||||
|
|
||||||
$this->assertSame('{{ day }}{{ month }}{{ year }}', $view->vars['date_pattern']);
|
$this->assertSame('{{ day }}{{ month }}{{ year }}', $view->vars['date_pattern']);
|
||||||
}
|
}
|
||||||
@ -667,43 +643,40 @@ class DateTypeTest extends TestCase
|
|||||||
|
|
||||||
\Locale::setDefault('de_AT');
|
\Locale::setDefault('de_AT');
|
||||||
|
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'format' => \IntlDateFormatter::LONG,
|
'format' => \IntlDateFormatter::LONG,
|
||||||
));
|
))
|
||||||
|
->createView();
|
||||||
$view = $form->createView();
|
|
||||||
|
|
||||||
$this->assertSame('{{ day }}{{ month }}{{ year }}', $view->vars['date_pattern']);
|
$this->assertSame('{{ day }}{{ month }}{{ year }}', $view->vars['date_pattern']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testPassDatePatternToViewDifferentPattern()
|
public function testPassDatePatternToViewDifferentPattern()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'format' => 'MMyyyydd',
|
'format' => 'MMyyyydd',
|
||||||
));
|
))
|
||||||
|
->createView();
|
||||||
$view = $form->createView();
|
|
||||||
|
|
||||||
$this->assertSame('{{ month }}{{ year }}{{ day }}', $view->vars['date_pattern']);
|
$this->assertSame('{{ month }}{{ year }}{{ day }}', $view->vars['date_pattern']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testPassDatePatternToViewDifferentPatternWithSeparators()
|
public function testPassDatePatternToViewDifferentPatternWithSeparators()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'format' => 'MM*yyyy*dd',
|
'format' => 'MM*yyyy*dd',
|
||||||
));
|
))
|
||||||
|
->createView();
|
||||||
$view = $form->createView();
|
|
||||||
|
|
||||||
$this->assertSame('{{ month }}*{{ year }}*{{ day }}', $view->vars['date_pattern']);
|
$this->assertSame('{{ month }}*{{ year }}*{{ day }}', $view->vars['date_pattern']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDontPassDatePatternIfText()
|
public function testDontPassDatePatternIfText()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'widget' => 'single_text',
|
'widget' => 'single_text',
|
||||||
));
|
))
|
||||||
$view = $form->createView();
|
->createView();
|
||||||
|
|
||||||
$this->assertFalse(isset($view->vars['date_pattern']));
|
$this->assertFalse(isset($view->vars['date_pattern']));
|
||||||
}
|
}
|
||||||
@ -715,22 +688,21 @@ class DateTypeTest extends TestCase
|
|||||||
|
|
||||||
\Locale::setDefault('es_ES');
|
\Locale::setDefault('es_ES');
|
||||||
|
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
// EEEE, d 'de' MMMM 'de' y
|
// EEEE, d 'de' MMMM 'de' y
|
||||||
'format' => \IntlDateFormatter::FULL,
|
'format' => \IntlDateFormatter::FULL,
|
||||||
));
|
))
|
||||||
|
->createView();
|
||||||
$view = $form->createView();
|
|
||||||
|
|
||||||
$this->assertEquals('{{ day }}{{ month }}{{ year }}', $view->vars['date_pattern']);
|
$this->assertEquals('{{ day }}{{ month }}{{ year }}', $view->vars['date_pattern']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testPassWidgetToView()
|
public function testPassWidgetToView()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'widget' => 'single_text',
|
'widget' => 'single_text',
|
||||||
));
|
))
|
||||||
$view = $form->createView();
|
->createView();
|
||||||
|
|
||||||
$this->assertSame('single_text', $view->vars['widget']);
|
$this->assertSame('single_text', $view->vars['widget']);
|
||||||
}
|
}
|
||||||
@ -739,26 +711,26 @@ class DateTypeTest extends TestCase
|
|||||||
{
|
{
|
||||||
// Throws an exception if "data_class" option is not explicitly set
|
// Throws an exception if "data_class" option is not explicitly set
|
||||||
// to null in the type
|
// to null in the type
|
||||||
$this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', new \DateTime());
|
$this->factory->create(static::TESTED_TYPE, new \DateTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSingleTextWidgetShouldUseTheRightInputType()
|
public function testSingleTextWidgetShouldUseTheRightInputType()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'widget' => 'single_text',
|
'widget' => 'single_text',
|
||||||
));
|
))
|
||||||
|
->createView();
|
||||||
|
|
||||||
$view = $form->createView();
|
|
||||||
$this->assertEquals('date', $view->vars['type']);
|
$this->assertEquals('date', $view->vars['type']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testPassDefaultPlaceholderToViewIfNotRequired()
|
public function testPassDefaultPlaceholderToViewIfNotRequired()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'required' => false,
|
'required' => false,
|
||||||
));
|
))
|
||||||
|
->createView();
|
||||||
|
|
||||||
$view = $form->createView();
|
|
||||||
$this->assertSame('', $view['year']->vars['placeholder']);
|
$this->assertSame('', $view['year']->vars['placeholder']);
|
||||||
$this->assertSame('', $view['month']->vars['placeholder']);
|
$this->assertSame('', $view['month']->vars['placeholder']);
|
||||||
$this->assertSame('', $view['day']->vars['placeholder']);
|
$this->assertSame('', $view['day']->vars['placeholder']);
|
||||||
@ -766,11 +738,11 @@ class DateTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testPassNoPlaceholderToViewIfRequired()
|
public function testPassNoPlaceholderToViewIfRequired()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'required' => true,
|
'required' => true,
|
||||||
));
|
))
|
||||||
|
->createView();
|
||||||
|
|
||||||
$view = $form->createView();
|
|
||||||
$this->assertNull($view['year']->vars['placeholder']);
|
$this->assertNull($view['year']->vars['placeholder']);
|
||||||
$this->assertNull($view['month']->vars['placeholder']);
|
$this->assertNull($view['month']->vars['placeholder']);
|
||||||
$this->assertNull($view['day']->vars['placeholder']);
|
$this->assertNull($view['day']->vars['placeholder']);
|
||||||
@ -778,11 +750,11 @@ class DateTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testPassPlaceholderAsString()
|
public function testPassPlaceholderAsString()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'placeholder' => 'Empty',
|
'placeholder' => 'Empty',
|
||||||
));
|
))
|
||||||
|
->createView();
|
||||||
|
|
||||||
$view = $form->createView();
|
|
||||||
$this->assertSame('Empty', $view['year']->vars['placeholder']);
|
$this->assertSame('Empty', $view['year']->vars['placeholder']);
|
||||||
$this->assertSame('Empty', $view['month']->vars['placeholder']);
|
$this->assertSame('Empty', $view['month']->vars['placeholder']);
|
||||||
$this->assertSame('Empty', $view['day']->vars['placeholder']);
|
$this->assertSame('Empty', $view['day']->vars['placeholder']);
|
||||||
@ -790,15 +762,15 @@ class DateTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testPassPlaceholderAsArray()
|
public function testPassPlaceholderAsArray()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'placeholder' => array(
|
'placeholder' => array(
|
||||||
'year' => 'Empty year',
|
'year' => 'Empty year',
|
||||||
'month' => 'Empty month',
|
'month' => 'Empty month',
|
||||||
'day' => 'Empty day',
|
'day' => 'Empty day',
|
||||||
),
|
),
|
||||||
));
|
))
|
||||||
|
->createView();
|
||||||
|
|
||||||
$view = $form->createView();
|
|
||||||
$this->assertSame('Empty year', $view['year']->vars['placeholder']);
|
$this->assertSame('Empty year', $view['year']->vars['placeholder']);
|
||||||
$this->assertSame('Empty month', $view['month']->vars['placeholder']);
|
$this->assertSame('Empty month', $view['month']->vars['placeholder']);
|
||||||
$this->assertSame('Empty day', $view['day']->vars['placeholder']);
|
$this->assertSame('Empty day', $view['day']->vars['placeholder']);
|
||||||
@ -806,15 +778,15 @@ class DateTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testPassPlaceholderAsPartialArrayAddEmptyIfNotRequired()
|
public function testPassPlaceholderAsPartialArrayAddEmptyIfNotRequired()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'required' => false,
|
'required' => false,
|
||||||
'placeholder' => array(
|
'placeholder' => array(
|
||||||
'year' => 'Empty year',
|
'year' => 'Empty year',
|
||||||
'day' => 'Empty day',
|
'day' => 'Empty day',
|
||||||
),
|
),
|
||||||
));
|
))
|
||||||
|
->createView();
|
||||||
|
|
||||||
$view = $form->createView();
|
|
||||||
$this->assertSame('Empty year', $view['year']->vars['placeholder']);
|
$this->assertSame('Empty year', $view['year']->vars['placeholder']);
|
||||||
$this->assertSame('', $view['month']->vars['placeholder']);
|
$this->assertSame('', $view['month']->vars['placeholder']);
|
||||||
$this->assertSame('Empty day', $view['day']->vars['placeholder']);
|
$this->assertSame('Empty day', $view['day']->vars['placeholder']);
|
||||||
@ -822,15 +794,15 @@ class DateTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testPassPlaceholderAsPartialArrayAddNullIfRequired()
|
public function testPassPlaceholderAsPartialArrayAddNullIfRequired()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'required' => true,
|
'required' => true,
|
||||||
'placeholder' => array(
|
'placeholder' => array(
|
||||||
'year' => 'Empty year',
|
'year' => 'Empty year',
|
||||||
'day' => 'Empty day',
|
'day' => 'Empty day',
|
||||||
),
|
),
|
||||||
));
|
))
|
||||||
|
->createView();
|
||||||
|
|
||||||
$view = $form->createView();
|
|
||||||
$this->assertSame('Empty year', $view['year']->vars['placeholder']);
|
$this->assertSame('Empty year', $view['year']->vars['placeholder']);
|
||||||
$this->assertNull($view['month']->vars['placeholder']);
|
$this->assertNull($view['month']->vars['placeholder']);
|
||||||
$this->assertSame('Empty day', $view['day']->vars['placeholder']);
|
$this->assertSame('Empty day', $view['day']->vars['placeholder']);
|
||||||
@ -838,43 +810,43 @@ class DateTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testPassHtml5TypeIfSingleTextAndHtml5Format()
|
public function testPassHtml5TypeIfSingleTextAndHtml5Format()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'widget' => 'single_text',
|
'widget' => 'single_text',
|
||||||
));
|
))
|
||||||
|
->createView();
|
||||||
|
|
||||||
$view = $form->createView();
|
|
||||||
$this->assertSame('date', $view->vars['type']);
|
$this->assertSame('date', $view->vars['type']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDontPassHtml5TypeIfHtml5NotAllowed()
|
public function testDontPassHtml5TypeIfHtml5NotAllowed()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'widget' => 'single_text',
|
'widget' => 'single_text',
|
||||||
'html5' => false,
|
'html5' => false,
|
||||||
));
|
))
|
||||||
|
->createView();
|
||||||
|
|
||||||
$view = $form->createView();
|
|
||||||
$this->assertFalse(isset($view->vars['type']));
|
$this->assertFalse(isset($view->vars['type']));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDontPassHtml5TypeIfNotHtml5Format()
|
public function testDontPassHtml5TypeIfNotHtml5Format()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'widget' => 'single_text',
|
'widget' => 'single_text',
|
||||||
'format' => \IntlDateFormatter::MEDIUM,
|
'format' => \IntlDateFormatter::MEDIUM,
|
||||||
));
|
))
|
||||||
|
->createView();
|
||||||
|
|
||||||
$view = $form->createView();
|
|
||||||
$this->assertFalse(isset($view->vars['type']));
|
$this->assertFalse(isset($view->vars['type']));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDontPassHtml5TypeIfNotSingleText()
|
public function testDontPassHtml5TypeIfNotSingleText()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'widget' => 'text',
|
'widget' => 'text',
|
||||||
));
|
))
|
||||||
|
->createView();
|
||||||
|
|
||||||
$view = $form->createView();
|
|
||||||
$this->assertFalse(isset($view->vars['type']));
|
$this->assertFalse(isset($view->vars['type']));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -892,7 +864,7 @@ class DateTypeTest extends TestCase
|
|||||||
public function testYearErrorsBubbleUp($widget)
|
public function testYearErrorsBubbleUp($widget)
|
||||||
{
|
{
|
||||||
$error = new FormError('Invalid!');
|
$error = new FormError('Invalid!');
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'widget' => $widget,
|
'widget' => $widget,
|
||||||
));
|
));
|
||||||
$form['year']->addError($error);
|
$form['year']->addError($error);
|
||||||
@ -907,7 +879,7 @@ class DateTypeTest extends TestCase
|
|||||||
public function testMonthErrorsBubbleUp($widget)
|
public function testMonthErrorsBubbleUp($widget)
|
||||||
{
|
{
|
||||||
$error = new FormError('Invalid!');
|
$error = new FormError('Invalid!');
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'widget' => $widget,
|
'widget' => $widget,
|
||||||
));
|
));
|
||||||
$form['month']->addError($error);
|
$form['month']->addError($error);
|
||||||
@ -922,7 +894,7 @@ class DateTypeTest extends TestCase
|
|||||||
public function testDayErrorsBubbleUp($widget)
|
public function testDayErrorsBubbleUp($widget)
|
||||||
{
|
{
|
||||||
$error = new FormError('Invalid!');
|
$error = new FormError('Invalid!');
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'widget' => $widget,
|
'widget' => $widget,
|
||||||
));
|
));
|
||||||
$form['day']->addError($error);
|
$form['day']->addError($error);
|
||||||
@ -937,11 +909,10 @@ class DateTypeTest extends TestCase
|
|||||||
$this->markTestSkipped('PHP 32 bit is required.');
|
$this->markTestSkipped('PHP 32 bit is required.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'years' => range(1900, 2040),
|
'years' => range(1900, 2040),
|
||||||
));
|
))
|
||||||
|
->createView();
|
||||||
$view = $form->createView();
|
|
||||||
|
|
||||||
$listChoices = array();
|
$listChoices = array();
|
||||||
foreach (range(1902, 2037) as $y) {
|
foreach (range(1902, 2037) as $y) {
|
||||||
@ -953,7 +924,7 @@ class DateTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testPassDefaultChoiceTranslationDomain()
|
public function testPassDefaultChoiceTranslationDomain()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType');
|
$form = $this->factory->create(static::TESTED_TYPE);
|
||||||
|
|
||||||
$view = $form->createView();
|
$view = $form->createView();
|
||||||
$this->assertFalse($view['year']->vars['choice_translation_domain']);
|
$this->assertFalse($view['year']->vars['choice_translation_domain']);
|
||||||
@ -963,7 +934,7 @@ class DateTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testPassChoiceTranslationDomainAsString()
|
public function testPassChoiceTranslationDomainAsString()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'choice_translation_domain' => 'messages',
|
'choice_translation_domain' => 'messages',
|
||||||
));
|
));
|
||||||
|
|
||||||
@ -975,7 +946,7 @@ class DateTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testPassChoiceTranslationDomainAsArray()
|
public function testPassChoiceTranslationDomainAsArray()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'choice_translation_domain' => array(
|
'choice_translation_domain' => array(
|
||||||
'year' => 'foo',
|
'year' => 'foo',
|
||||||
'day' => 'test',
|
'day' => 'test',
|
||||||
@ -987,4 +958,21 @@ class DateTypeTest extends TestCase
|
|||||||
$this->assertFalse($view['month']->vars['choice_translation_domain']);
|
$this->assertFalse($view['month']->vars['choice_translation_domain']);
|
||||||
$this->assertSame('test', $view['day']->vars['choice_translation_domain']);
|
$this->assertSame('test', $view['day']->vars['choice_translation_domain']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testSubmitNull($expected = null, $norm = null, $view = null)
|
||||||
|
{
|
||||||
|
parent::testSubmitNull($expected, $norm, array('year' => '', 'month' => '', 'day' => ''));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSubmitNullWithSingleText()
|
||||||
|
{
|
||||||
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
|
'widget' => 'single_text',
|
||||||
|
));
|
||||||
|
$form->submit(null);
|
||||||
|
|
||||||
|
$this->assertNull($form->getData());
|
||||||
|
$this->assertNull($form->getNormData());
|
||||||
|
$this->assertSame('', $form->getViewData());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,24 +11,27 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\Form\Tests\Extension\Core\Type;
|
namespace Symfony\Component\Form\Tests\Extension\Core\Type;
|
||||||
|
|
||||||
use Symfony\Component\Form\Test\TypeTestCase;
|
class FileTypeTest extends BaseTypeTest
|
||||||
|
|
||||||
class FileTypeTest extends TypeTestCase
|
|
||||||
{
|
{
|
||||||
|
const TESTED_TYPE = 'Symfony\Component\Form\Extension\Core\Type\FileType';
|
||||||
|
|
||||||
// https://github.com/symfony/symfony/pull/5028
|
// https://github.com/symfony/symfony/pull/5028
|
||||||
public function testSetData()
|
public function testSetData()
|
||||||
{
|
{
|
||||||
$form = $this->factory->createBuilder('Symfony\Component\Form\Extension\Core\Type\FileType')->getForm();
|
$form = $this->factory->createBuilder(static::TESTED_TYPE)->getForm();
|
||||||
$data = $this->createUploadedFileMock('abcdef', 'original.jpg', true);
|
$data = $this->getMockBuilder('Symfony\Component\HttpFoundation\File\File')
|
||||||
|
->setConstructorArgs(array(__DIR__.'/../../../Fixtures/foo', 'foo'))
|
||||||
|
->getMock();
|
||||||
|
|
||||||
$form->setData($data);
|
$form->setData($data);
|
||||||
|
|
||||||
|
// Ensures the data class is defined to accept File instance
|
||||||
$this->assertSame($data, $form->getData());
|
$this->assertSame($data, $form->getData());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSubmit()
|
public function testSubmit()
|
||||||
{
|
{
|
||||||
$form = $this->factory->createBuilder('Symfony\Component\Form\Extension\Core\Type\FileType')->getForm();
|
$form = $this->factory->createBuilder(static::TESTED_TYPE)->getForm();
|
||||||
$data = $this->createUploadedFileMock('abcdef', 'original.jpg', true);
|
$data = $this->createUploadedFileMock('abcdef', 'original.jpg', true);
|
||||||
|
|
||||||
$form->submit($data);
|
$form->submit($data);
|
||||||
@ -36,31 +39,9 @@ class FileTypeTest extends TypeTestCase
|
|||||||
$this->assertSame($data, $form->getData());
|
$this->assertSame($data, $form->getData());
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://github.com/symfony/symfony/issues/6134
|
|
||||||
public function testSubmitEmpty()
|
|
||||||
{
|
|
||||||
$form = $this->factory->createBuilder('Symfony\Component\Form\Extension\Core\Type\FileType')->getForm();
|
|
||||||
|
|
||||||
$form->submit(null);
|
|
||||||
|
|
||||||
$this->assertNull($form->getData());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testSubmitEmptyMultiple()
|
|
||||||
{
|
|
||||||
$form = $this->factory->createBuilder('Symfony\Component\Form\Extension\Core\Type\FileType', null, array(
|
|
||||||
'multiple' => true,
|
|
||||||
))->getForm();
|
|
||||||
|
|
||||||
// submitted data when an input file is uploaded without choosing any file
|
|
||||||
$form->submit(array(null));
|
|
||||||
|
|
||||||
$this->assertSame(array(), $form->getData());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testSetDataMultiple()
|
public function testSetDataMultiple()
|
||||||
{
|
{
|
||||||
$form = $this->factory->createBuilder('Symfony\Component\Form\Extension\Core\Type\FileType', null, array(
|
$form = $this->factory->createBuilder(static::TESTED_TYPE, null, array(
|
||||||
'multiple' => true,
|
'multiple' => true,
|
||||||
))->getForm();
|
))->getForm();
|
||||||
|
|
||||||
@ -75,7 +56,7 @@ class FileTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testSubmitMultiple()
|
public function testSubmitMultiple()
|
||||||
{
|
{
|
||||||
$form = $this->factory->createBuilder('Symfony\Component\Form\Extension\Core\Type\FileType', null, array(
|
$form = $this->factory->createBuilder(static::TESTED_TYPE, null, array(
|
||||||
'multiple' => true,
|
'multiple' => true,
|
||||||
))->getForm();
|
))->getForm();
|
||||||
|
|
||||||
@ -94,13 +75,38 @@ class FileTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testDontPassValueToView()
|
public function testDontPassValueToView()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\FileType');
|
$form = $this->factory->create(static::TESTED_TYPE);
|
||||||
$form->submit(array(
|
$form->submit(array(
|
||||||
'Symfony\Component\Form\Extension\Core\Type\FileType' => $this->createUploadedFileMock('abcdef', 'original.jpg', true),
|
'file' => $this->createUploadedFileMock('abcdef', 'original.jpg', true),
|
||||||
));
|
));
|
||||||
$view = $form->createView();
|
|
||||||
|
|
||||||
$this->assertEquals('', $view->vars['value']);
|
$this->assertEquals('', $form->createView()->vars['value']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPassMultipartFalseToView()
|
||||||
|
{
|
||||||
|
$view = $this->factory->create(static::TESTED_TYPE)
|
||||||
|
->createView();
|
||||||
|
|
||||||
|
$this->assertTrue($view->vars['multipart']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSubmitNull($expected = null, $norm = null, $view = null)
|
||||||
|
{
|
||||||
|
parent::testSubmitNull($expected, $norm, '');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSubmitNullWhenMultiple()
|
||||||
|
{
|
||||||
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
|
'multiple' => true,
|
||||||
|
));
|
||||||
|
// submitted data when an input file is uploaded without choosing any file
|
||||||
|
$form->submit(array(null));
|
||||||
|
|
||||||
|
$this->assertSame(array(), $form->getData());
|
||||||
|
$this->assertSame(array(), $form->getNormData());
|
||||||
|
$this->assertSame(array(), $form->getViewData());
|
||||||
}
|
}
|
||||||
|
|
||||||
private function createUploadedFileMock($name, $originalName, $valid)
|
private function createUploadedFileMock($name, $originalName, $valid)
|
||||||
|
@ -51,27 +51,29 @@ class FormTest_AuthorWithoutRefSetter
|
|||||||
|
|
||||||
class FormTypeTest extends BaseTypeTest
|
class FormTypeTest extends BaseTypeTest
|
||||||
{
|
{
|
||||||
|
const TESTED_TYPE = 'Symfony\Component\Form\Extension\Core\Type\FormType';
|
||||||
|
|
||||||
public function testCreateFormInstances()
|
public function testCreateFormInstances()
|
||||||
{
|
{
|
||||||
$this->assertInstanceOf('Symfony\Component\Form\Form', $this->factory->create('Symfony\Component\Form\Extension\Core\Type\FormType'));
|
$this->assertInstanceOf('Symfony\Component\Form\Form', $this->factory->create(static::TESTED_TYPE));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testPassRequiredAsOption()
|
public function testPassRequiredAsOption()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\FormType', null, array('required' => false));
|
$form = $this->factory->create(static::TESTED_TYPE, null, array('required' => false));
|
||||||
|
|
||||||
$this->assertFalse($form->isRequired());
|
$this->assertFalse($form->isRequired());
|
||||||
|
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\FormType', null, array('required' => true));
|
$form = $this->factory->create(static::TESTED_TYPE, null, array('required' => true));
|
||||||
|
|
||||||
$this->assertTrue($form->isRequired());
|
$this->assertTrue($form->isRequired());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSubmittedDataIsTrimmedBeforeTransforming()
|
public function testSubmittedDataIsTrimmedBeforeTransforming()
|
||||||
{
|
{
|
||||||
$form = $this->factory->createBuilder('Symfony\Component\Form\Extension\Core\Type\FormType')
|
$form = $this->factory->createBuilder(static::TESTED_TYPE)
|
||||||
->addViewTransformer(new FixedDataTransformer(array(
|
->addViewTransformer(new FixedDataTransformer(array(
|
||||||
null => '',
|
'' => '',
|
||||||
'reverse[a]' => 'a',
|
'reverse[a]' => 'a',
|
||||||
)))
|
)))
|
||||||
->setCompound(false)
|
->setCompound(false)
|
||||||
@ -85,9 +87,9 @@ class FormTypeTest extends BaseTypeTest
|
|||||||
|
|
||||||
public function testSubmittedDataIsNotTrimmedBeforeTransformingIfNoTrimming()
|
public function testSubmittedDataIsNotTrimmedBeforeTransformingIfNoTrimming()
|
||||||
{
|
{
|
||||||
$form = $this->factory->createBuilder('Symfony\Component\Form\Extension\Core\Type\FormType', null, array('trim' => false))
|
$form = $this->factory->createBuilder(static::TESTED_TYPE, null, array('trim' => false))
|
||||||
->addViewTransformer(new FixedDataTransformer(array(
|
->addViewTransformer(new FixedDataTransformer(array(
|
||||||
null => '',
|
'' => '',
|
||||||
'reverse[ a ]' => ' a ',
|
'reverse[ a ]' => ' a ',
|
||||||
)))
|
)))
|
||||||
->setCompound(false)
|
->setCompound(false)
|
||||||
@ -101,8 +103,8 @@ class FormTypeTest extends BaseTypeTest
|
|||||||
|
|
||||||
public function testNonReadOnlyFormWithReadOnlyParentIsReadOnly()
|
public function testNonReadOnlyFormWithReadOnlyParentIsReadOnly()
|
||||||
{
|
{
|
||||||
$view = $this->factory->createNamedBuilder('parent', 'Symfony\Component\Form\Extension\Core\Type\FormType', null, array('attr' => array('readonly' => true)))
|
$view = $this->factory->createNamedBuilder('parent', static::TESTED_TYPE, null, array('attr' => array('readonly' => true)))
|
||||||
->add('child', 'Symfony\Component\Form\Extension\Core\Type\FormType')
|
->add('child', static::TESTED_TYPE)
|
||||||
->getForm()
|
->getForm()
|
||||||
->createView();
|
->createView();
|
||||||
|
|
||||||
@ -111,8 +113,8 @@ class FormTypeTest extends BaseTypeTest
|
|||||||
|
|
||||||
public function testReadOnlyFormWithNonReadOnlyParentIsReadOnly()
|
public function testReadOnlyFormWithNonReadOnlyParentIsReadOnly()
|
||||||
{
|
{
|
||||||
$view = $this->factory->createNamedBuilder('parent', 'Symfony\Component\Form\Extension\Core\Type\FormType')
|
$view = $this->factory->createNamedBuilder('parent', static::TESTED_TYPE)
|
||||||
->add('child', 'Symfony\Component\Form\Extension\Core\Type\FormType', array('attr' => array('readonly' => true)))
|
->add('child', static::TESTED_TYPE, array('attr' => array('readonly' => true)))
|
||||||
->getForm()
|
->getForm()
|
||||||
->createView();
|
->createView();
|
||||||
|
|
||||||
@ -121,8 +123,8 @@ class FormTypeTest extends BaseTypeTest
|
|||||||
|
|
||||||
public function testNonReadOnlyFormWithNonReadOnlyParentIsNotReadOnly()
|
public function testNonReadOnlyFormWithNonReadOnlyParentIsNotReadOnly()
|
||||||
{
|
{
|
||||||
$view = $this->factory->createNamedBuilder('parent', 'Symfony\Component\Form\Extension\Core\Type\FormType')
|
$view = $this->factory->createNamedBuilder('parent', static::TESTED_TYPE)
|
||||||
->add('child', 'Symfony\Component\Form\Extension\Core\Type\FormType')
|
->add('child', static::TESTED_TYPE)
|
||||||
->getForm()
|
->getForm()
|
||||||
->createView();
|
->createView();
|
||||||
|
|
||||||
@ -131,29 +133,29 @@ class FormTypeTest extends BaseTypeTest
|
|||||||
|
|
||||||
public function testPassMaxLengthToView()
|
public function testPassMaxLengthToView()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\FormType', null, array('attr' => array('maxlength' => 10)));
|
$view = $this->factory->create(static::TESTED_TYPE, null, array('attr' => array('maxlength' => 10)))
|
||||||
$view = $form->createView();
|
->createView();
|
||||||
|
|
||||||
$this->assertSame(10, $view->vars['attr']['maxlength']);
|
$this->assertSame(10, $view->vars['attr']['maxlength']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDataClassMayBeNull()
|
public function testDataClassMayBeNull()
|
||||||
{
|
{
|
||||||
$this->factory->createBuilder('Symfony\Component\Form\Extension\Core\Type\FormType', null, array(
|
$this->factory->createBuilder(static::TESTED_TYPE, null, array(
|
||||||
'data_class' => null,
|
'data_class' => null,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDataClassMayBeAbstractClass()
|
public function testDataClassMayBeAbstractClass()
|
||||||
{
|
{
|
||||||
$this->factory->createBuilder('Symfony\Component\Form\Extension\Core\Type\FormType', null, array(
|
$this->factory->createBuilder(static::TESTED_TYPE, null, array(
|
||||||
'data_class' => 'Symfony\Component\Form\Tests\Fixtures\AbstractAuthor',
|
'data_class' => 'Symfony\Component\Form\Tests\Fixtures\AbstractAuthor',
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDataClassMayBeInterface()
|
public function testDataClassMayBeInterface()
|
||||||
{
|
{
|
||||||
$this->factory->createBuilder('Symfony\Component\Form\Extension\Core\Type\FormType', null, array(
|
$this->factory->createBuilder(static::TESTED_TYPE, null, array(
|
||||||
'data_class' => 'Symfony\Component\Form\Tests\Fixtures\AuthorInterface',
|
'data_class' => 'Symfony\Component\Form\Tests\Fixtures\AuthorInterface',
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
@ -163,22 +165,23 @@ class FormTypeTest extends BaseTypeTest
|
|||||||
*/
|
*/
|
||||||
public function testDataClassMustBeValidClassOrInterface()
|
public function testDataClassMustBeValidClassOrInterface()
|
||||||
{
|
{
|
||||||
$this->factory->createBuilder('Symfony\Component\Form\Extension\Core\Type\FormType', null, array(
|
$this->factory->createBuilder(static::TESTED_TYPE, null, array(
|
||||||
'data_class' => 'foobar',
|
'data_class' => 'foobar',
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSubmitWithEmptyDataCreatesObjectIfClassAvailable()
|
public function testSubmitWithEmptyDataCreatesObjectIfClassAvailable()
|
||||||
{
|
{
|
||||||
$builder = $this->factory->createBuilder('Symfony\Component\Form\Extension\Core\Type\FormType', null, array(
|
$form = $this->factory->createBuilder(static::TESTED_TYPE, null, array(
|
||||||
'data_class' => 'Symfony\Component\Form\Tests\Fixtures\Author',
|
'data_class' => 'Symfony\Component\Form\Tests\Fixtures\Author',
|
||||||
'required' => false,
|
'required' => false,
|
||||||
));
|
))
|
||||||
$builder->add('firstName', 'Symfony\Component\Form\Extension\Core\Type\TextType');
|
->add('firstName', TextTypeTest::TESTED_TYPE)
|
||||||
$builder->add('lastName', 'Symfony\Component\Form\Extension\Core\Type\TextType');
|
->add('lastName', TextTypeTest::TESTED_TYPE)
|
||||||
$form = $builder->getForm();
|
->getForm();
|
||||||
|
|
||||||
|
$this->assertNull($form->getData());
|
||||||
|
|
||||||
$form->setData(null);
|
|
||||||
// partially empty, still an object is created
|
// partially empty, still an object is created
|
||||||
$form->submit(array('firstName' => 'Bernhard', 'lastName' => ''));
|
$form->submit(array('firstName' => 'Bernhard', 'lastName' => ''));
|
||||||
|
|
||||||
@ -189,19 +192,19 @@ class FormTypeTest extends BaseTypeTest
|
|||||||
$this->assertEquals($author, $form->getData());
|
$this->assertEquals($author, $form->getData());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSubmitWithEmptyDataCreatesObjectIfInitiallySubmittedWithObject()
|
public function testSubmitWithDefaultDataDontCreateObject()
|
||||||
{
|
{
|
||||||
$builder = $this->factory->createBuilder('Symfony\Component\Form\Extension\Core\Type\FormType', null, array(
|
$defaultAuthor = new Author();
|
||||||
|
$form = $this->factory->createBuilder(static::TESTED_TYPE, null, array(
|
||||||
// data class is inferred from the passed object
|
// data class is inferred from the passed object
|
||||||
'data' => new Author(),
|
'data' => $defaultAuthor,
|
||||||
'required' => false,
|
'required' => false,
|
||||||
));
|
))
|
||||||
$builder->add('firstName', 'Symfony\Component\Form\Extension\Core\Type\TextType');
|
->add('firstName', TextTypeTest::TESTED_TYPE)
|
||||||
$builder->add('lastName', 'Symfony\Component\Form\Extension\Core\Type\TextType');
|
->add('lastName', TextTypeTest::TESTED_TYPE)
|
||||||
$form = $builder->getForm();
|
->getForm();
|
||||||
|
|
||||||
$form->setData(null);
|
// partially empty
|
||||||
// partially empty, still an object is created
|
|
||||||
$form->submit(array('firstName' => 'Bernhard', 'lastName' => ''));
|
$form->submit(array('firstName' => 'Bernhard', 'lastName' => ''));
|
||||||
|
|
||||||
$author = new Author();
|
$author = new Author();
|
||||||
@ -209,34 +212,37 @@ class FormTypeTest extends BaseTypeTest
|
|||||||
$author->setLastName('');
|
$author->setLastName('');
|
||||||
|
|
||||||
$this->assertEquals($author, $form->getData());
|
$this->assertEquals($author, $form->getData());
|
||||||
|
$this->assertSame($defaultAuthor, $form->getData());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSubmitWithEmptyDataCreatesArrayIfDataClassIsNull()
|
public function testSubmitWithEmptyDataCreatesArrayIfDataClassIsNull()
|
||||||
{
|
{
|
||||||
$builder = $this->factory->createBuilder('Symfony\Component\Form\Extension\Core\Type\FormType', null, array(
|
$form = $this->factory->createBuilder(static::TESTED_TYPE, null, array(
|
||||||
'data_class' => null,
|
'data_class' => null,
|
||||||
'required' => false,
|
'required' => false,
|
||||||
));
|
))
|
||||||
$builder->add('firstName', 'Symfony\Component\Form\Extension\Core\Type\TextType');
|
->add('firstName', TextTypeTest::TESTED_TYPE)
|
||||||
$form = $builder->getForm();
|
->getForm();
|
||||||
|
|
||||||
|
$this->assertNull($form->getData());
|
||||||
|
|
||||||
$form->setData(null);
|
|
||||||
$form->submit(array('firstName' => 'Bernhard'));
|
$form->submit(array('firstName' => 'Bernhard'));
|
||||||
|
|
||||||
$this->assertSame(array('firstName' => 'Bernhard'), $form->getData());
|
$this->assertSame(array('firstName' => 'Bernhard'), $form->getData());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSubmitEmptyWithEmptyDataCreatesNoObjectIfNotRequired()
|
public function testSubmitEmptyWithEmptyDataDontCreateObjectIfNotRequired()
|
||||||
{
|
{
|
||||||
$builder = $this->factory->createBuilder('Symfony\Component\Form\Extension\Core\Type\FormType', null, array(
|
$form = $this->factory->createBuilder(static::TESTED_TYPE, null, array(
|
||||||
'data_class' => 'Symfony\Component\Form\Tests\Fixtures\Author',
|
'data_class' => 'Symfony\Component\Form\Tests\Fixtures\Author',
|
||||||
'required' => false,
|
'required' => false,
|
||||||
));
|
))
|
||||||
$builder->add('firstName', 'Symfony\Component\Form\Extension\Core\Type\TextType');
|
->add('firstName', TextTypeTest::TESTED_TYPE)
|
||||||
$builder->add('lastName', 'Symfony\Component\Form\Extension\Core\Type\TextType');
|
->add('lastName', TextTypeTest::TESTED_TYPE)
|
||||||
$form = $builder->getForm();
|
->getForm();
|
||||||
|
|
||||||
|
$this->assertNull($form->getData());
|
||||||
|
|
||||||
$form->setData(null);
|
|
||||||
$form->submit(array('firstName' => '', 'lastName' => ''));
|
$form->submit(array('firstName' => '', 'lastName' => ''));
|
||||||
|
|
||||||
$this->assertNull($form->getData());
|
$this->assertNull($form->getData());
|
||||||
@ -244,15 +250,16 @@ class FormTypeTest extends BaseTypeTest
|
|||||||
|
|
||||||
public function testSubmitEmptyWithEmptyDataCreatesObjectIfRequired()
|
public function testSubmitEmptyWithEmptyDataCreatesObjectIfRequired()
|
||||||
{
|
{
|
||||||
$builder = $this->factory->createBuilder('Symfony\Component\Form\Extension\Core\Type\FormType', null, array(
|
$form = $this->factory->createBuilder(static::TESTED_TYPE, null, array(
|
||||||
'data_class' => 'Symfony\Component\Form\Tests\Fixtures\Author',
|
'data_class' => 'Symfony\Component\Form\Tests\Fixtures\Author',
|
||||||
'required' => true,
|
'required' => true,
|
||||||
));
|
))
|
||||||
$builder->add('firstName', 'Symfony\Component\Form\Extension\Core\Type\TextType');
|
->add('firstName', TextTypeTest::TESTED_TYPE)
|
||||||
$builder->add('lastName', 'Symfony\Component\Form\Extension\Core\Type\TextType');
|
->add('lastName', TextTypeTest::TESTED_TYPE)
|
||||||
$form = $builder->getForm();
|
->getForm();
|
||||||
|
|
||||||
|
$this->assertNull($form->getData());
|
||||||
|
|
||||||
$form->setData(null);
|
|
||||||
$form->submit(array('firstName' => '', 'lastName' => ''));
|
$form->submit(array('firstName' => '', 'lastName' => ''));
|
||||||
|
|
||||||
$this->assertEquals(new Author(), $form->getData());
|
$this->assertEquals(new Author(), $form->getData());
|
||||||
@ -263,11 +270,12 @@ class FormTypeTest extends BaseTypeTest
|
|||||||
*/
|
*/
|
||||||
public function testSubmitWithEmptyDataStoresArrayIfNoClassAvailable()
|
public function testSubmitWithEmptyDataStoresArrayIfNoClassAvailable()
|
||||||
{
|
{
|
||||||
$form = $this->factory->createBuilder('Symfony\Component\Form\Extension\Core\Type\FormType')
|
$form = $this->factory->createBuilder(static::TESTED_TYPE)
|
||||||
->add('firstName', 'Symfony\Component\Form\Extension\Core\Type\TextType')
|
->add('firstName', TextTypeTest::TESTED_TYPE)
|
||||||
->getForm();
|
->getForm();
|
||||||
|
|
||||||
$form->setData(null);
|
$this->assertNull($form->getData());
|
||||||
|
|
||||||
$form->submit(array('firstName' => 'Bernhard'));
|
$form->submit(array('firstName' => 'Bernhard'));
|
||||||
|
|
||||||
$this->assertSame(array('firstName' => 'Bernhard'), $form->getData());
|
$this->assertSame(array('firstName' => 'Bernhard'), $form->getData());
|
||||||
@ -275,31 +283,40 @@ class FormTypeTest extends BaseTypeTest
|
|||||||
|
|
||||||
public function testSubmitWithEmptyDataPassesEmptyStringToTransformerIfNotCompound()
|
public function testSubmitWithEmptyDataPassesEmptyStringToTransformerIfNotCompound()
|
||||||
{
|
{
|
||||||
$form = $this->factory->createBuilder('Symfony\Component\Form\Extension\Core\Type\FormType')
|
$form = $this->factory->createBuilder(static::TESTED_TYPE)
|
||||||
->addViewTransformer(new FixedDataTransformer(array(
|
->addViewTransformer(new FixedDataTransformer(array(
|
||||||
// required for the initial, internal setData(null)
|
// required for the initial, internal setData(null)
|
||||||
null => 'null',
|
'' => 'null',
|
||||||
// required to test that submit(null) is converted to ''
|
// required to test that submit(null) is converted to ''
|
||||||
'empty' => '',
|
'empty' => '',
|
||||||
)))
|
)))
|
||||||
->setCompound(false)
|
->setCompound(false)
|
||||||
->getForm();
|
->getForm();
|
||||||
|
|
||||||
|
$this->assertNull($form->getData());
|
||||||
|
$this->assertNull($form->getNormData());
|
||||||
|
$this->assertSame('null', $form->getViewData());
|
||||||
|
|
||||||
$form->submit(null);
|
$form->submit(null);
|
||||||
|
|
||||||
$this->assertSame('empty', $form->getData());
|
$this->assertSame('empty', $form->getData());
|
||||||
|
$this->assertSame('empty', $form->getNormData());
|
||||||
|
$this->assertSame('', $form->getViewData());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSubmitWithEmptyDataUsesEmptyDataOption()
|
public function testSubmitWithEmptyDataUsesEmptyDataOption()
|
||||||
{
|
{
|
||||||
$author = new Author();
|
$author = new Author();
|
||||||
|
|
||||||
$builder = $this->factory->createBuilder('Symfony\Component\Form\Extension\Core\Type\FormType', null, array(
|
$form = $this->factory->createBuilder(static::TESTED_TYPE, null, array(
|
||||||
'data_class' => 'Symfony\Component\Form\Tests\Fixtures\Author',
|
'data_class' => 'Symfony\Component\Form\Tests\Fixtures\Author',
|
||||||
'empty_data' => $author,
|
'empty_data' => $author,
|
||||||
));
|
))
|
||||||
$builder->add('firstName', 'Symfony\Component\Form\Extension\Core\Type\TextType');
|
->add('firstName', TextTypeTest::TESTED_TYPE)
|
||||||
$form = $builder->getForm();
|
->getForm();
|
||||||
|
|
||||||
|
$this->assertNull($form->getData());
|
||||||
|
$this->assertNull($form->getViewData());
|
||||||
|
|
||||||
$form->submit(array('firstName' => 'Bernhard'));
|
$form->submit(array('firstName' => 'Bernhard'));
|
||||||
|
|
||||||
@ -307,62 +324,34 @@ class FormTypeTest extends BaseTypeTest
|
|||||||
$this->assertEquals('Bernhard', $author->firstName);
|
$this->assertEquals('Bernhard', $author->firstName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function provideZeros()
|
|
||||||
{
|
|
||||||
return array(
|
|
||||||
array(0, '0'),
|
|
||||||
array('0', '0'),
|
|
||||||
array('00000', '00000'),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @dataProvider provideZeros
|
|
||||||
*
|
|
||||||
* @see https://github.com/symfony/symfony/issues/1986
|
|
||||||
*/
|
|
||||||
public function testSetDataThroughParamsWithZero($data, $dataAsString)
|
|
||||||
{
|
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\FormType', null, array(
|
|
||||||
'data' => $data,
|
|
||||||
'compound' => false,
|
|
||||||
));
|
|
||||||
$view = $form->createView();
|
|
||||||
|
|
||||||
$this->assertFalse($form->isEmpty());
|
|
||||||
|
|
||||||
$this->assertSame($dataAsString, $view->vars['value']);
|
|
||||||
$this->assertSame($dataAsString, $form->getData());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
|
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
|
||||||
*/
|
*/
|
||||||
public function testAttributesException()
|
public function testAttributesException()
|
||||||
{
|
{
|
||||||
$this->factory->create('Symfony\Component\Form\Extension\Core\Type\FormType', null, array('attr' => ''));
|
$this->factory->create(static::TESTED_TYPE, null, array('attr' => ''));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testNameCanBeEmptyString()
|
public function testNameCanBeEmptyString()
|
||||||
{
|
{
|
||||||
$form = $this->factory->createNamed('', 'Symfony\Component\Form\Extension\Core\Type\FormType');
|
$form = $this->factory->createNamed('', static::TESTED_TYPE);
|
||||||
|
|
||||||
$this->assertEquals('', $form->getName());
|
$this->assertEquals('', $form->getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSubformDoesntCallSetters()
|
public function testSubformDoesntCallSettersForReferences()
|
||||||
{
|
{
|
||||||
$author = new FormTest_AuthorWithoutRefSetter(new Author());
|
$author = new FormTest_AuthorWithoutRefSetter(new Author());
|
||||||
|
|
||||||
$builder = $this->factory->createBuilder('Symfony\Component\Form\Extension\Core\Type\FormType', $author);
|
$builder = $this->factory->createBuilder(static::TESTED_TYPE, $author);
|
||||||
$builder->add('reference', 'Symfony\Component\Form\Extension\Core\Type\FormType', array(
|
$builder->add('reference', static::TESTED_TYPE, array(
|
||||||
'data_class' => 'Symfony\Component\Form\Tests\Fixtures\Author',
|
'data_class' => 'Symfony\Component\Form\Tests\Fixtures\Author',
|
||||||
));
|
));
|
||||||
$builder->get('reference')->add('firstName', 'Symfony\Component\Form\Extension\Core\Type\TextType');
|
$builder->get('reference')->add('firstName', TextTypeTest::TESTED_TYPE);
|
||||||
$form = $builder->getForm();
|
$form = $builder->getForm();
|
||||||
|
|
||||||
$form->submit(array(
|
$form->submit(array(
|
||||||
// reference has a getter, but not setter
|
// reference has a getter, but no setter
|
||||||
'reference' => array(
|
'reference' => array(
|
||||||
'firstName' => 'Foo',
|
'firstName' => 'Foo',
|
||||||
),
|
),
|
||||||
@ -377,11 +366,11 @@ class FormTypeTest extends BaseTypeTest
|
|||||||
$author = new FormTest_AuthorWithoutRefSetter(null);
|
$author = new FormTest_AuthorWithoutRefSetter(null);
|
||||||
$newReference = new Author();
|
$newReference = new Author();
|
||||||
|
|
||||||
$builder = $this->factory->createBuilder('Symfony\Component\Form\Extension\Core\Type\FormType', $author);
|
$builder = $this->factory->createBuilder(static::TESTED_TYPE, $author);
|
||||||
$builder->add('referenceCopy', 'Symfony\Component\Form\Extension\Core\Type\FormType', array(
|
$builder->add('referenceCopy', static::TESTED_TYPE, array(
|
||||||
'data_class' => 'Symfony\Component\Form\Tests\Fixtures\Author',
|
'data_class' => 'Symfony\Component\Form\Tests\Fixtures\Author',
|
||||||
));
|
));
|
||||||
$builder->get('referenceCopy')->add('firstName', 'Symfony\Component\Form\Extension\Core\Type\TextType');
|
$builder->get('referenceCopy')->add('firstName', TextTypeTest::TESTED_TYPE);
|
||||||
$form = $builder->getForm();
|
$form = $builder->getForm();
|
||||||
|
|
||||||
$form['referenceCopy']->setData($newReference); // new author object
|
$form['referenceCopy']->setData($newReference); // new author object
|
||||||
@ -400,12 +389,12 @@ class FormTypeTest extends BaseTypeTest
|
|||||||
{
|
{
|
||||||
$author = new FormTest_AuthorWithoutRefSetter(new Author());
|
$author = new FormTest_AuthorWithoutRefSetter(new Author());
|
||||||
|
|
||||||
$builder = $this->factory->createBuilder('Symfony\Component\Form\Extension\Core\Type\FormType', $author);
|
$builder = $this->factory->createBuilder(static::TESTED_TYPE, $author);
|
||||||
$builder->add('referenceCopy', 'Symfony\Component\Form\Extension\Core\Type\FormType', array(
|
$builder->add('referenceCopy', static::TESTED_TYPE, array(
|
||||||
'data_class' => 'Symfony\Component\Form\Tests\Fixtures\Author',
|
'data_class' => 'Symfony\Component\Form\Tests\Fixtures\Author',
|
||||||
'by_reference' => false,
|
'by_reference' => false,
|
||||||
));
|
));
|
||||||
$builder->get('referenceCopy')->add('firstName', 'Symfony\Component\Form\Extension\Core\Type\TextType');
|
$builder->get('referenceCopy')->add('firstName', TextTypeTest::TESTED_TYPE);
|
||||||
$form = $builder->getForm();
|
$form = $builder->getForm();
|
||||||
|
|
||||||
$form->submit(array(
|
$form->submit(array(
|
||||||
@ -423,8 +412,8 @@ class FormTypeTest extends BaseTypeTest
|
|||||||
{
|
{
|
||||||
$author = new FormTest_AuthorWithoutRefSetter('scalar');
|
$author = new FormTest_AuthorWithoutRefSetter('scalar');
|
||||||
|
|
||||||
$builder = $this->factory->createBuilder('Symfony\Component\Form\Extension\Core\Type\FormType', $author);
|
$builder = $this->factory->createBuilder(static::TESTED_TYPE, $author);
|
||||||
$builder->add('referenceCopy', 'Symfony\Component\Form\Extension\Core\Type\FormType');
|
$builder->add('referenceCopy', static::TESTED_TYPE);
|
||||||
$builder->get('referenceCopy')->addViewTransformer(new CallbackTransformer(
|
$builder->get('referenceCopy')->addViewTransformer(new CallbackTransformer(
|
||||||
function () {},
|
function () {},
|
||||||
function ($value) { // reverseTransform
|
function ($value) { // reverseTransform
|
||||||
@ -447,9 +436,9 @@ class FormTypeTest extends BaseTypeTest
|
|||||||
$ref2 = new Author();
|
$ref2 = new Author();
|
||||||
$author = array('referenceCopy' => $ref1);
|
$author = array('referenceCopy' => $ref1);
|
||||||
|
|
||||||
$builder = $this->factory->createBuilder('Symfony\Component\Form\Extension\Core\Type\FormType');
|
$builder = $this->factory->createBuilder(static::TESTED_TYPE);
|
||||||
$builder->setData($author);
|
$builder->setData($author);
|
||||||
$builder->add('referenceCopy', 'Symfony\Component\Form\Extension\Core\Type\FormType');
|
$builder->add('referenceCopy', static::TESTED_TYPE);
|
||||||
$builder->get('referenceCopy')->addViewTransformer(new CallbackTransformer(
|
$builder->get('referenceCopy')->addViewTransformer(new CallbackTransformer(
|
||||||
function () {},
|
function () {},
|
||||||
function ($value) use ($ref2) { // reverseTransform
|
function ($value) use ($ref2) { // reverseTransform
|
||||||
@ -459,7 +448,7 @@ class FormTypeTest extends BaseTypeTest
|
|||||||
$form = $builder->getForm();
|
$form = $builder->getForm();
|
||||||
|
|
||||||
$form->submit(array(
|
$form->submit(array(
|
||||||
'referenceCopy' => array('a' => 'b'), // doesn't matter actually
|
'referenceCopy' => array(), // doesn't matter actually
|
||||||
));
|
));
|
||||||
|
|
||||||
// the new reference was inserted into the array
|
// the new reference was inserted into the array
|
||||||
@ -469,9 +458,9 @@ class FormTypeTest extends BaseTypeTest
|
|||||||
|
|
||||||
public function testPassMultipartTrueIfAnyChildIsMultipartToView()
|
public function testPassMultipartTrueIfAnyChildIsMultipartToView()
|
||||||
{
|
{
|
||||||
$view = $this->factory->createBuilder('Symfony\Component\Form\Extension\Core\Type\FormType')
|
$view = $this->factory->createBuilder(static::TESTED_TYPE)
|
||||||
->add('foo', 'Symfony\Component\Form\Extension\Core\Type\TextType')
|
->add('foo', TextTypeTest::TESTED_TYPE)
|
||||||
->add('bar', 'Symfony\Component\Form\Extension\Core\Type\FileType')
|
->add('bar', FileTypeTest::TESTED_TYPE)
|
||||||
->getForm()
|
->getForm()
|
||||||
->createView();
|
->createView();
|
||||||
|
|
||||||
@ -480,8 +469,8 @@ class FormTypeTest extends BaseTypeTest
|
|||||||
|
|
||||||
public function testViewIsNotRenderedByDefault()
|
public function testViewIsNotRenderedByDefault()
|
||||||
{
|
{
|
||||||
$view = $this->factory->createBuilder('Symfony\Component\Form\Extension\Core\Type\FormType')
|
$view = $this->factory->createBuilder(static::TESTED_TYPE)
|
||||||
->add('foo', 'Symfony\Component\Form\Extension\Core\Type\FormType')
|
->add('foo', static::TESTED_TYPE)
|
||||||
->getForm()
|
->getForm()
|
||||||
->createView();
|
->createView();
|
||||||
|
|
||||||
@ -490,16 +479,14 @@ class FormTypeTest extends BaseTypeTest
|
|||||||
|
|
||||||
public function testErrorBubblingIfCompound()
|
public function testErrorBubblingIfCompound()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\FormType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE);
|
||||||
'compound' => true,
|
|
||||||
));
|
|
||||||
|
|
||||||
$this->assertTrue($form->getConfig()->getErrorBubbling());
|
$this->assertTrue($form->getConfig()->getErrorBubbling());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testNoErrorBubblingIfNotCompound()
|
public function testNoErrorBubblingIfNotCompound()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\FormType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'compound' => false,
|
'compound' => false,
|
||||||
));
|
));
|
||||||
|
|
||||||
@ -508,7 +495,7 @@ class FormTypeTest extends BaseTypeTest
|
|||||||
|
|
||||||
public function testOverrideErrorBubbling()
|
public function testOverrideErrorBubbling()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\FormType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'compound' => false,
|
'compound' => false,
|
||||||
'error_bubbling' => true,
|
'error_bubbling' => true,
|
||||||
));
|
));
|
||||||
@ -518,7 +505,7 @@ class FormTypeTest extends BaseTypeTest
|
|||||||
|
|
||||||
public function testPropertyPath()
|
public function testPropertyPath()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\FormType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'property_path' => 'foo',
|
'property_path' => 'foo',
|
||||||
));
|
));
|
||||||
|
|
||||||
@ -528,7 +515,7 @@ class FormTypeTest extends BaseTypeTest
|
|||||||
|
|
||||||
public function testPropertyPathNullImpliesDefault()
|
public function testPropertyPathNullImpliesDefault()
|
||||||
{
|
{
|
||||||
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\FormType', null, array(
|
$form = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||||
'property_path' => null,
|
'property_path' => null,
|
||||||
));
|
));
|
||||||
|
|
||||||
@ -538,7 +525,7 @@ class FormTypeTest extends BaseTypeTest
|
|||||||
|
|
||||||
public function testNotMapped()
|
public function testNotMapped()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\FormType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'property_path' => 'foo',
|
'property_path' => 'foo',
|
||||||
'mapped' => false,
|
'mapped' => false,
|
||||||
));
|
));
|
||||||
@ -549,38 +536,40 @@ class FormTypeTest extends BaseTypeTest
|
|||||||
|
|
||||||
public function testViewValidNotSubmitted()
|
public function testViewValidNotSubmitted()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\FormType');
|
$view = $this->factory->create(static::TESTED_TYPE)
|
||||||
$view = $form->createView();
|
->createView();
|
||||||
|
|
||||||
$this->assertTrue($view->vars['valid']);
|
$this->assertTrue($view->vars['valid']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testViewNotValidSubmitted()
|
public function testViewNotValidSubmitted()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\FormType');
|
$form = $this->factory->create(static::TESTED_TYPE);
|
||||||
$form->submit(array());
|
$form->submit(array());
|
||||||
$form->addError(new FormError('An error'));
|
$form->addError(new FormError('An error'));
|
||||||
$view = $form->createView();
|
|
||||||
$this->assertFalse($view->vars['valid']);
|
$this->assertFalse($form->createView()->vars['valid']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testViewSubmittedNotSubmitted()
|
public function testViewSubmittedNotSubmitted()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\FormType');
|
$view = $this->factory->create(static::TESTED_TYPE)
|
||||||
$view = $form->createView();
|
->createView();
|
||||||
|
|
||||||
$this->assertFalse($view->vars['submitted']);
|
$this->assertFalse($view->vars['submitted']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testViewSubmittedSubmitted()
|
public function testViewSubmittedSubmitted()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\FormType');
|
$form = $this->factory->create(static::TESTED_TYPE);
|
||||||
$form->submit(array());
|
$form->submit(array());
|
||||||
$view = $form->createView();
|
|
||||||
$this->assertTrue($view->vars['submitted']);
|
$this->assertTrue($form->createView()->vars['submitted']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDataOptionSupersedesSetDataCalls()
|
public function testDataOptionSupersedesSetDataCalls()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\FormType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'data' => 'default',
|
'data' => 'default',
|
||||||
'compound' => false,
|
'compound' => false,
|
||||||
));
|
));
|
||||||
@ -590,9 +579,20 @@ class FormTypeTest extends BaseTypeTest
|
|||||||
$this->assertSame('default', $form->getData());
|
$this->assertSame('default', $form->getData());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testPassedDataSupersedesSetDataCalls()
|
||||||
|
{
|
||||||
|
$form = $this->factory->create(static::TESTED_TYPE, 'default', array(
|
||||||
|
'compound' => false,
|
||||||
|
));
|
||||||
|
|
||||||
|
$form->setData('foobar');
|
||||||
|
|
||||||
|
$this->assertSame('default', $form->getData());
|
||||||
|
}
|
||||||
|
|
||||||
public function testDataOptionSupersedesSetDataCallsIfNull()
|
public function testDataOptionSupersedesSetDataCallsIfNull()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\FormType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'data' => null,
|
'data' => null,
|
||||||
'compound' => false,
|
'compound' => false,
|
||||||
));
|
));
|
||||||
@ -604,22 +604,25 @@ class FormTypeTest extends BaseTypeTest
|
|||||||
|
|
||||||
public function testNormDataIsPassedToView()
|
public function testNormDataIsPassedToView()
|
||||||
{
|
{
|
||||||
$view = $this->factory->createBuilder('Symfony\Component\Form\Extension\Core\Type\FormType')
|
$view = $this->factory->createBuilder(static::TESTED_TYPE)
|
||||||
->addViewTransformer(new FixedDataTransformer(array(
|
->addModelTransformer(new FixedDataTransformer(array(
|
||||||
'foo' => 'bar',
|
'foo' => 'bar',
|
||||||
)))
|
)))
|
||||||
|
->addViewTransformer(new FixedDataTransformer(array(
|
||||||
|
'bar' => 'baz',
|
||||||
|
)))
|
||||||
->setData('foo')
|
->setData('foo')
|
||||||
->getForm()
|
->getForm()
|
||||||
->createView();
|
->createView();
|
||||||
|
|
||||||
$this->assertSame('foo', $view->vars['data']);
|
$this->assertSame('bar', $view->vars['data']);
|
||||||
$this->assertSame('bar', $view->vars['value']);
|
$this->assertSame('baz', $view->vars['value']);
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://github.com/symfony/symfony/issues/6862
|
// https://github.com/symfony/symfony/issues/6862
|
||||||
public function testPassZeroLabelToView()
|
public function testPassZeroLabelToView()
|
||||||
{
|
{
|
||||||
$view = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\FormType', null, array(
|
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'label' => '0',
|
'label' => '0',
|
||||||
))
|
))
|
||||||
->createView();
|
->createView();
|
||||||
@ -627,8 +630,8 @@ class FormTypeTest extends BaseTypeTest
|
|||||||
$this->assertSame('0', $view->vars['label']);
|
$this->assertSame('0', $view->vars['label']);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getTestedType()
|
public function testSubmitNull($expected = null, $norm = null, $view = null)
|
||||||
{
|
{
|
||||||
return 'Symfony\Component\Form\Extension\Core\Type\FormType';
|
parent::testSubmitNull(array(), array(), array());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,11 +11,12 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\Form\Tests\Extension\Core\Type;
|
namespace Symfony\Component\Form\Tests\Extension\Core\Type;
|
||||||
|
|
||||||
use Symfony\Component\Form\Test\TypeTestCase as TestCase;
|
|
||||||
use Symfony\Component\Intl\Util\IntlTestHelper;
|
use Symfony\Component\Intl\Util\IntlTestHelper;
|
||||||
|
|
||||||
class IntegerTypeTest extends TestCase
|
class IntegerTypeTest extends BaseTypeTest
|
||||||
{
|
{
|
||||||
|
const TESTED_TYPE = 'Symfony\Component\Form\Extension\Core\Type\IntegerType';
|
||||||
|
|
||||||
protected function setUp()
|
protected function setUp()
|
||||||
{
|
{
|
||||||
IntlTestHelper::requireIntl($this, false);
|
IntlTestHelper::requireIntl($this, false);
|
||||||
@ -25,11 +26,16 @@ class IntegerTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testSubmitCastsToInteger()
|
public function testSubmitCastsToInteger()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\IntegerType');
|
$form = $this->factory->create(static::TESTED_TYPE);
|
||||||
|
|
||||||
$form->submit('1.678');
|
$form->submit('1.678');
|
||||||
|
|
||||||
$this->assertSame(1, $form->getData());
|
$this->assertSame(1, $form->getData());
|
||||||
$this->assertSame('1', $form->getViewData());
|
$this->assertSame('1', $form->getViewData());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testSubmitNull($expected = null, $norm = null, $view = null)
|
||||||
|
{
|
||||||
|
parent::testSubmitNull($expected, $norm, '');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,12 +11,13 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\Form\Tests\Extension\Core\Type;
|
namespace Symfony\Component\Form\Tests\Extension\Core\Type;
|
||||||
|
|
||||||
use Symfony\Component\Form\Test\TypeTestCase as TestCase;
|
|
||||||
use Symfony\Component\Form\ChoiceList\View\ChoiceView;
|
use Symfony\Component\Form\ChoiceList\View\ChoiceView;
|
||||||
use Symfony\Component\Intl\Util\IntlTestHelper;
|
use Symfony\Component\Intl\Util\IntlTestHelper;
|
||||||
|
|
||||||
class LanguageTypeTest extends TestCase
|
class LanguageTypeTest extends BaseTypeTest
|
||||||
{
|
{
|
||||||
|
const TESTED_TYPE = 'Symfony\Component\Form\Extension\Core\Type\LanguageType';
|
||||||
|
|
||||||
protected function setUp()
|
protected function setUp()
|
||||||
{
|
{
|
||||||
IntlTestHelper::requireIntl($this, false);
|
IntlTestHelper::requireIntl($this, false);
|
||||||
@ -26,9 +27,8 @@ class LanguageTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testCountriesAreSelectable()
|
public function testCountriesAreSelectable()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\LanguageType');
|
$choices = $this->factory->create(static::TESTED_TYPE)
|
||||||
$view = $form->createView();
|
->createView()->vars['choices'];
|
||||||
$choices = $view->vars['choices'];
|
|
||||||
|
|
||||||
$this->assertContains(new ChoiceView('en', 'en', 'English'), $choices, '', false, false);
|
$this->assertContains(new ChoiceView('en', 'en', 'English'), $choices, '', false, false);
|
||||||
$this->assertContains(new ChoiceView('en_GB', 'en_GB', 'British English'), $choices, '', false, false);
|
$this->assertContains(new ChoiceView('en_GB', 'en_GB', 'British English'), $choices, '', false, false);
|
||||||
@ -39,10 +39,14 @@ class LanguageTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testMultipleLanguagesIsNotIncluded()
|
public function testMultipleLanguagesIsNotIncluded()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\LanguageType', 'Symfony\Component\Form\Extension\Core\Type\LanguageType');
|
$choices = $this->factory->create(static::TESTED_TYPE, 'language')
|
||||||
$view = $form->createView();
|
->createView()->vars['choices'];
|
||||||
$choices = $view->vars['choices'];
|
|
||||||
|
|
||||||
$this->assertNotContains(new ChoiceView('mul', 'mul', 'Mehrsprachig'), $choices, '', false, false);
|
$this->assertNotContains(new ChoiceView('mul', 'mul', 'Mehrsprachig'), $choices, '', false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testSubmitNull($expected = null, $norm = null, $view = null)
|
||||||
|
{
|
||||||
|
parent::testSubmitNull($expected, $norm, '');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,12 +11,13 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\Form\Tests\Extension\Core\Type;
|
namespace Symfony\Component\Form\Tests\Extension\Core\Type;
|
||||||
|
|
||||||
use Symfony\Component\Form\Test\TypeTestCase as TestCase;
|
|
||||||
use Symfony\Component\Form\ChoiceList\View\ChoiceView;
|
use Symfony\Component\Form\ChoiceList\View\ChoiceView;
|
||||||
use Symfony\Component\Intl\Util\IntlTestHelper;
|
use Symfony\Component\Intl\Util\IntlTestHelper;
|
||||||
|
|
||||||
class LocaleTypeTest extends TestCase
|
class LocaleTypeTest extends BaseTypeTest
|
||||||
{
|
{
|
||||||
|
const TESTED_TYPE = 'Symfony\Component\Form\Extension\Core\Type\LocaleType';
|
||||||
|
|
||||||
protected function setUp()
|
protected function setUp()
|
||||||
{
|
{
|
||||||
IntlTestHelper::requireIntl($this, false);
|
IntlTestHelper::requireIntl($this, false);
|
||||||
@ -26,12 +27,16 @@ class LocaleTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testLocalesAreSelectable()
|
public function testLocalesAreSelectable()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\LocaleType');
|
$choices = $this->factory->create(static::TESTED_TYPE)
|
||||||
$view = $form->createView();
|
->createView()->vars['choices'];
|
||||||
$choices = $view->vars['choices'];
|
|
||||||
|
|
||||||
$this->assertContains(new ChoiceView('en', 'en', 'English'), $choices, '', false, false);
|
$this->assertContains(new ChoiceView('en', 'en', 'English'), $choices, '', false, false);
|
||||||
$this->assertContains(new ChoiceView('en_GB', 'en_GB', 'English (United Kingdom)'), $choices, '', false, false);
|
$this->assertContains(new ChoiceView('en_GB', 'en_GB', 'English (United Kingdom)'), $choices, '', false, false);
|
||||||
$this->assertContains(new ChoiceView('zh_Hant_MO', 'zh_Hant_MO', 'Chinese (Traditional, Macau SAR China)'), $choices, '', false, false);
|
$this->assertContains(new ChoiceView('zh_Hant_MO', 'zh_Hant_MO', 'Chinese (Traditional, Macau SAR China)'), $choices, '', false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testSubmitNull($expected = null, $norm = null, $view = null)
|
||||||
|
{
|
||||||
|
parent::testSubmitNull($expected, $norm, '');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,11 +11,12 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\Form\Tests\Extension\Core\Type;
|
namespace Symfony\Component\Form\Tests\Extension\Core\Type;
|
||||||
|
|
||||||
use Symfony\Component\Form\Test\TypeTestCase as TestCase;
|
|
||||||
use Symfony\Component\Intl\Util\IntlTestHelper;
|
use Symfony\Component\Intl\Util\IntlTestHelper;
|
||||||
|
|
||||||
class MoneyTypeTest extends TestCase
|
class MoneyTypeTest extends BaseTypeTest
|
||||||
{
|
{
|
||||||
|
const TESTED_TYPE = 'Symfony\Component\Form\Extension\Core\Type\MoneyType';
|
||||||
|
|
||||||
protected function setUp()
|
protected function setUp()
|
||||||
{
|
{
|
||||||
// we test against different locales, so we need the full
|
// we test against different locales, so we need the full
|
||||||
@ -29,8 +30,8 @@ class MoneyTypeTest extends TestCase
|
|||||||
{
|
{
|
||||||
\Locale::setDefault('de_DE');
|
\Locale::setDefault('de_DE');
|
||||||
|
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\MoneyType');
|
$view = $this->factory->create(static::TESTED_TYPE)
|
||||||
$view = $form->createView();
|
->createView();
|
||||||
|
|
||||||
$this->assertSame('{{ widget }} €', $view->vars['money_pattern']);
|
$this->assertSame('{{ widget }} €', $view->vars['money_pattern']);
|
||||||
}
|
}
|
||||||
@ -39,8 +40,9 @@ class MoneyTypeTest extends TestCase
|
|||||||
{
|
{
|
||||||
\Locale::setDefault('en_US');
|
\Locale::setDefault('en_US');
|
||||||
|
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\MoneyType', null, array('currency' => 'JPY'));
|
$view = $this->factory->create(static::TESTED_TYPE, null, array('currency' => 'JPY'))
|
||||||
$view = $form->createView();
|
->createView();
|
||||||
|
|
||||||
$this->assertTrue((bool) strstr($view->vars['money_pattern'], '¥'));
|
$this->assertTrue((bool) strstr($view->vars['money_pattern'], '¥'));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,12 +51,15 @@ class MoneyTypeTest extends TestCase
|
|||||||
{
|
{
|
||||||
\Locale::setDefault('de_DE');
|
\Locale::setDefault('de_DE');
|
||||||
|
|
||||||
$form1 = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\MoneyType', null, array('currency' => 'GBP'));
|
$view1 = $this->factory->create(static::TESTED_TYPE, null, array('currency' => 'GBP'))->createView();
|
||||||
$form2 = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\MoneyType', null, array('currency' => 'EUR'));
|
$view2 = $this->factory->create(static::TESTED_TYPE, null, array('currency' => 'EUR'))->createView();
|
||||||
$view1 = $form1->createView();
|
|
||||||
$view2 = $form2->createView();
|
|
||||||
|
|
||||||
$this->assertSame('{{ widget }} £', $view1->vars['money_pattern']);
|
$this->assertSame('{{ widget }} £', $view1->vars['money_pattern']);
|
||||||
$this->assertSame('{{ widget }} €', $view2->vars['money_pattern']);
|
$this->assertSame('{{ widget }} €', $view2->vars['money_pattern']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testSubmitNull($expected = null, $norm = null, $view = null)
|
||||||
|
{
|
||||||
|
parent::testSubmitNull($expected, $norm, '');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,11 +11,12 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\Form\Tests\Extension\Core\Type;
|
namespace Symfony\Component\Form\Tests\Extension\Core\Type;
|
||||||
|
|
||||||
use Symfony\Component\Form\Test\TypeTestCase as TestCase;
|
|
||||||
use Symfony\Component\Intl\Util\IntlTestHelper;
|
use Symfony\Component\Intl\Util\IntlTestHelper;
|
||||||
|
|
||||||
class NumberTypeTest extends TestCase
|
class NumberTypeTest extends BaseTypeTest
|
||||||
{
|
{
|
||||||
|
const TESTED_TYPE = 'Symfony\Component\Form\Extension\Core\Type\NumberType';
|
||||||
|
|
||||||
protected function setUp()
|
protected function setUp()
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
@ -28,37 +29,38 @@ class NumberTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testDefaultFormatting()
|
public function testDefaultFormatting()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\NumberType');
|
$form = $this->factory->create(static::TESTED_TYPE);
|
||||||
$form->setData('12345.67890');
|
$form->setData('12345.67890');
|
||||||
$view = $form->createView();
|
|
||||||
|
|
||||||
$this->assertSame('12345,679', $view->vars['value']);
|
$this->assertSame('12345,679', $form->createView()->vars['value']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDefaultFormattingWithGrouping()
|
public function testDefaultFormattingWithGrouping()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\NumberType', null, array('grouping' => true));
|
$form = $this->factory->create(static::TESTED_TYPE, null, array('grouping' => true));
|
||||||
$form->setData('12345.67890');
|
$form->setData('12345.67890');
|
||||||
$view = $form->createView();
|
|
||||||
|
|
||||||
$this->assertSame('12.345,679', $view->vars['value']);
|
$this->assertSame('12.345,679', $form->createView()->vars['value']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDefaultFormattingWithScale()
|
public function testDefaultFormattingWithScale()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\NumberType', null, array('scale' => 2));
|
$form = $this->factory->create(static::TESTED_TYPE, null, array('scale' => 2));
|
||||||
$form->setData('12345.67890');
|
$form->setData('12345.67890');
|
||||||
$view = $form->createView();
|
|
||||||
|
|
||||||
$this->assertSame('12345,68', $view->vars['value']);
|
$this->assertSame('12345,68', $form->createView()->vars['value']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDefaultFormattingWithRounding()
|
public function testDefaultFormattingWithRounding()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\NumberType', null, array('scale' => 0, 'rounding_mode' => \NumberFormatter::ROUND_UP));
|
$form = $this->factory->create(static::TESTED_TYPE, null, array('scale' => 0, 'rounding_mode' => \NumberFormatter::ROUND_UP));
|
||||||
$form->setData('12345.54321');
|
$form->setData('12345.54321');
|
||||||
$view = $form->createView();
|
|
||||||
|
|
||||||
$this->assertSame('12346', $view->vars['value']);
|
$this->assertSame('12346', $form->createView()->vars['value']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSubmitNull($expected = null, $norm = null, $view = null)
|
||||||
|
{
|
||||||
|
parent::testSubmitNull($expected, $norm, '');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,43 +11,44 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\Form\Tests\Extension\Core\Type;
|
namespace Symfony\Component\Form\Tests\Extension\Core\Type;
|
||||||
|
|
||||||
use Symfony\Component\Form\Test\TypeTestCase;
|
class PasswordTypeTest extends BaseTypeTest
|
||||||
|
|
||||||
class PasswordTypeTest extends TypeTestCase
|
|
||||||
{
|
{
|
||||||
|
const TESTED_TYPE = 'Symfony\Component\Form\Extension\Core\Type\PasswordType';
|
||||||
|
|
||||||
public function testEmptyIfNotSubmitted()
|
public function testEmptyIfNotSubmitted()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\PasswordType');
|
$form = $this->factory->create(static::TESTED_TYPE);
|
||||||
$form->setData('pAs5w0rd');
|
$form->setData('pAs5w0rd');
|
||||||
$view = $form->createView();
|
|
||||||
|
|
||||||
$this->assertSame('', $view->vars['value']);
|
$this->assertSame('', $form->createView()->vars['value']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testEmptyIfSubmitted()
|
public function testEmptyIfSubmitted()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\PasswordType');
|
$form = $this->factory->create(static::TESTED_TYPE);
|
||||||
$form->submit('pAs5w0rd');
|
$form->submit('pAs5w0rd');
|
||||||
$view = $form->createView();
|
|
||||||
|
|
||||||
$this->assertSame('', $view->vars['value']);
|
$this->assertSame('', $form->createView()->vars['value']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testNotEmptyIfSubmittedAndNotAlwaysEmpty()
|
public function testNotEmptyIfSubmittedAndNotAlwaysEmpty()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\PasswordType', null, array('always_empty' => false));
|
$form = $this->factory->create(static::TESTED_TYPE, null, array('always_empty' => false));
|
||||||
$form->submit('pAs5w0rd');
|
$form->submit('pAs5w0rd');
|
||||||
$view = $form->createView();
|
|
||||||
|
|
||||||
$this->assertSame('pAs5w0rd', $view->vars['value']);
|
$this->assertSame('pAs5w0rd', $form->createView()->vars['value']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testNotTrimmed()
|
public function testNotTrimmed()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\PasswordType', null);
|
$form = $this->factory->create(static::TESTED_TYPE, null);
|
||||||
$form->submit(' pAs5w0rd ');
|
$form->submit(' pAs5w0rd ');
|
||||||
$data = $form->getData();
|
|
||||||
|
|
||||||
$this->assertSame(' pAs5w0rd ', $data);
|
$this->assertSame(' pAs5w0rd ', $form->getData());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSubmitNull($expected = null, $norm = null, $view = null)
|
||||||
|
{
|
||||||
|
parent::testSubmitNull($expected, $norm, '');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,63 +11,67 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\Form\Tests\Extension\Core\Type;
|
namespace Symfony\Component\Form\Tests\Extension\Core\Type;
|
||||||
|
|
||||||
use Symfony\Component\Form\Test\TypeTestCase;
|
use Symfony\Component\Form\Form;
|
||||||
|
|
||||||
class RepeatedTypeTest extends TypeTestCase
|
class RepeatedTypeTest extends BaseTypeTest
|
||||||
{
|
{
|
||||||
|
const TESTED_TYPE = 'Symfony\Component\Form\Extension\Core\Type\RepeatedType';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Form
|
||||||
|
*/
|
||||||
protected $form;
|
protected $form;
|
||||||
|
|
||||||
protected function setUp()
|
protected function setUp()
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
$this->form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\RepeatedType', null, array(
|
$this->form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'type' => 'Symfony\Component\Form\Extension\Core\Type\TextType',
|
'type' => TextTypeTest::TESTED_TYPE,
|
||||||
));
|
));
|
||||||
$this->form->setData(null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSetData()
|
public function testSetData()
|
||||||
{
|
{
|
||||||
$this->form->setData('foobar');
|
$this->form->setData('foobar');
|
||||||
|
|
||||||
$this->assertEquals('foobar', $this->form['first']->getData());
|
$this->assertSame('foobar', $this->form['first']->getData());
|
||||||
$this->assertEquals('foobar', $this->form['second']->getData());
|
$this->assertSame('foobar', $this->form['second']->getData());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSetOptions()
|
public function testSetOptions()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\RepeatedType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'type' => 'Symfony\Component\Form\Extension\Core\Type\TextType',
|
'type' => TextTypeTest::TESTED_TYPE,
|
||||||
'options' => array('label' => 'Global'),
|
'options' => array('label' => 'Global'),
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->assertEquals('Global', $form['first']->getConfig()->getOption('label'));
|
$this->assertSame('Global', $form['first']->getConfig()->getOption('label'));
|
||||||
$this->assertEquals('Global', $form['second']->getConfig()->getOption('label'));
|
$this->assertSame('Global', $form['second']->getConfig()->getOption('label'));
|
||||||
$this->assertTrue($form['first']->isRequired());
|
$this->assertTrue($form['first']->isRequired());
|
||||||
$this->assertTrue($form['second']->isRequired());
|
$this->assertTrue($form['second']->isRequired());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSetOptionsPerChild()
|
public function testSetOptionsPerChild()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\RepeatedType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
// the global required value cannot be overridden
|
// the global required value cannot be overridden
|
||||||
'type' => 'Symfony\Component\Form\Extension\Core\Type\TextType',
|
'type' => TextTypeTest::TESTED_TYPE,
|
||||||
'first_options' => array('label' => 'Test', 'required' => false),
|
'first_options' => array('label' => 'Test', 'required' => false),
|
||||||
'second_options' => array('label' => 'Test2'),
|
'second_options' => array('label' => 'Test2'),
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->assertEquals('Test', $form['first']->getConfig()->getOption('label'));
|
$this->assertSame('Test', $form['first']->getConfig()->getOption('label'));
|
||||||
$this->assertEquals('Test2', $form['second']->getConfig()->getOption('label'));
|
$this->assertSame('Test2', $form['second']->getConfig()->getOption('label'));
|
||||||
$this->assertTrue($form['first']->isRequired());
|
$this->assertTrue($form['first']->isRequired());
|
||||||
$this->assertTrue($form['second']->isRequired());
|
$this->assertTrue($form['second']->isRequired());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSetRequired()
|
public function testSetRequired()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\RepeatedType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'required' => false,
|
'required' => false,
|
||||||
'type' => 'Symfony\Component\Form\Extension\Core\Type\TextType',
|
'type' => TextTypeTest::TESTED_TYPE,
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->assertFalse($form['first']->isRequired());
|
$this->assertFalse($form['first']->isRequired());
|
||||||
@ -79,8 +83,8 @@ class RepeatedTypeTest extends TypeTestCase
|
|||||||
*/
|
*/
|
||||||
public function testSetInvalidOptions()
|
public function testSetInvalidOptions()
|
||||||
{
|
{
|
||||||
$this->factory->create('Symfony\Component\Form\Extension\Core\Type\RepeatedType', null, array(
|
$this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'type' => 'Symfony\Component\Form\Extension\Core\Type\TextType',
|
'type' => TextTypeTest::TESTED_TYPE,
|
||||||
'options' => 'bad value',
|
'options' => 'bad value',
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
@ -90,8 +94,8 @@ class RepeatedTypeTest extends TypeTestCase
|
|||||||
*/
|
*/
|
||||||
public function testSetInvalidFirstOptions()
|
public function testSetInvalidFirstOptions()
|
||||||
{
|
{
|
||||||
$this->factory->create('Symfony\Component\Form\Extension\Core\Type\RepeatedType', null, array(
|
$this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'type' => 'Symfony\Component\Form\Extension\Core\Type\TextType',
|
'type' => TextTypeTest::TESTED_TYPE,
|
||||||
'first_options' => 'bad value',
|
'first_options' => 'bad value',
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
@ -101,15 +105,15 @@ class RepeatedTypeTest extends TypeTestCase
|
|||||||
*/
|
*/
|
||||||
public function testSetInvalidSecondOptions()
|
public function testSetInvalidSecondOptions()
|
||||||
{
|
{
|
||||||
$this->factory->create('Symfony\Component\Form\Extension\Core\Type\RepeatedType', null, array(
|
$this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'type' => 'Symfony\Component\Form\Extension\Core\Type\TextType',
|
'type' => TextTypeTest::TESTED_TYPE,
|
||||||
'second_options' => 'bad value',
|
'second_options' => 'bad value',
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSetErrorBubblingToTrue()
|
public function testSetErrorBubblingToTrue()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\RepeatedType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'error_bubbling' => true,
|
'error_bubbling' => true,
|
||||||
));
|
));
|
||||||
|
|
||||||
@ -120,7 +124,7 @@ class RepeatedTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testSetErrorBubblingToFalse()
|
public function testSetErrorBubblingToFalse()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\RepeatedType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'error_bubbling' => false,
|
'error_bubbling' => false,
|
||||||
));
|
));
|
||||||
|
|
||||||
@ -131,7 +135,7 @@ class RepeatedTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testSetErrorBubblingIndividually()
|
public function testSetErrorBubblingIndividually()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\RepeatedType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'error_bubbling' => true,
|
'error_bubbling' => true,
|
||||||
'options' => array('error_bubbling' => false),
|
'options' => array('error_bubbling' => false),
|
||||||
'second_options' => array('error_bubbling' => true),
|
'second_options' => array('error_bubbling' => true),
|
||||||
@ -144,14 +148,14 @@ class RepeatedTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testSetOptionsPerChildAndOverwrite()
|
public function testSetOptionsPerChildAndOverwrite()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\RepeatedType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'type' => 'Symfony\Component\Form\Extension\Core\Type\TextType',
|
'type' => TextTypeTest::TESTED_TYPE,
|
||||||
'options' => array('label' => 'Label'),
|
'options' => array('label' => 'Label'),
|
||||||
'second_options' => array('label' => 'Second label'),
|
'second_options' => array('label' => 'Second label'),
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->assertEquals('Label', $form['first']->getConfig()->getOption('label'));
|
$this->assertSame('Label', $form['first']->getConfig()->getOption('label'));
|
||||||
$this->assertEquals('Second label', $form['second']->getConfig()->getOption('label'));
|
$this->assertSame('Second label', $form['second']->getConfig()->getOption('label'));
|
||||||
$this->assertTrue($form['first']->isRequired());
|
$this->assertTrue($form['first']->isRequired());
|
||||||
$this->assertTrue($form['second']->isRequired());
|
$this->assertTrue($form['second']->isRequired());
|
||||||
}
|
}
|
||||||
@ -162,10 +166,10 @@ class RepeatedTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
$this->form->submit($input);
|
$this->form->submit($input);
|
||||||
|
|
||||||
$this->assertEquals('foo', $this->form['first']->getViewData());
|
$this->assertSame('foo', $this->form['first']->getViewData());
|
||||||
$this->assertEquals('bar', $this->form['second']->getViewData());
|
$this->assertSame('bar', $this->form['second']->getViewData());
|
||||||
$this->assertFalse($this->form->isSynchronized());
|
$this->assertFalse($this->form->isSynchronized());
|
||||||
$this->assertEquals($input, $this->form->getViewData());
|
$this->assertSame($input, $this->form->getViewData());
|
||||||
$this->assertNull($this->form->getData());
|
$this->assertNull($this->form->getData());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,10 +179,15 @@ class RepeatedTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
$this->form->submit($input);
|
$this->form->submit($input);
|
||||||
|
|
||||||
$this->assertEquals('foo', $this->form['first']->getViewData());
|
$this->assertSame('foo', $this->form['first']->getViewData());
|
||||||
$this->assertEquals('foo', $this->form['second']->getViewData());
|
$this->assertSame('foo', $this->form['second']->getViewData());
|
||||||
$this->assertTrue($this->form->isSynchronized());
|
$this->assertTrue($this->form->isSynchronized());
|
||||||
$this->assertEquals($input, $this->form->getViewData());
|
$this->assertSame($input, $this->form->getViewData());
|
||||||
$this->assertEquals('foo', $this->form->getData());
|
$this->assertSame('foo', $this->form->getData());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSubmitNull($expected = null, $norm = null, $view = null)
|
||||||
|
{
|
||||||
|
parent::testSubmitNull($expected, $norm, array('first' => null, 'second' => null));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,28 +11,28 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\Form\Tests\Extension\Core\Type;
|
namespace Symfony\Component\Form\Tests\Extension\Core\Type;
|
||||||
|
|
||||||
use Symfony\Component\Form\Test\TypeTestCase as TestCase;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||||
*/
|
*/
|
||||||
class SubmitTypeTest extends TestCase
|
class SubmitTypeTest extends ButtonTypeTest
|
||||||
{
|
{
|
||||||
|
const TESTED_TYPE = 'Symfony\Component\Form\Extension\Core\Type\SubmitType';
|
||||||
|
|
||||||
public function testCreateSubmitButtonInstances()
|
public function testCreateSubmitButtonInstances()
|
||||||
{
|
{
|
||||||
$this->assertInstanceOf('Symfony\Component\Form\SubmitButton', $this->factory->create('Symfony\Component\Form\Extension\Core\Type\SubmitType'));
|
$this->assertInstanceOf('Symfony\Component\Form\SubmitButton', $this->factory->create(static::TESTED_TYPE));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testNotClickedByDefault()
|
public function testNotClickedByDefault()
|
||||||
{
|
{
|
||||||
$button = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\SubmitType');
|
$button = $this->factory->create(static::TESTED_TYPE);
|
||||||
|
|
||||||
$this->assertFalse($button->isClicked());
|
$this->assertFalse($button->isClicked());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testNotClickedIfSubmittedWithNull()
|
public function testNotClickedIfSubmittedWithNull()
|
||||||
{
|
{
|
||||||
$button = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\SubmitType');
|
$button = $this->factory->create(static::TESTED_TYPE);
|
||||||
$button->submit(null);
|
$button->submit(null);
|
||||||
|
|
||||||
$this->assertFalse($button->isClicked());
|
$this->assertFalse($button->isClicked());
|
||||||
@ -40,7 +40,7 @@ class SubmitTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testClickedIfSubmittedWithEmptyString()
|
public function testClickedIfSubmittedWithEmptyString()
|
||||||
{
|
{
|
||||||
$button = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\SubmitType');
|
$button = $this->factory->create(static::TESTED_TYPE);
|
||||||
$button->submit('');
|
$button->submit('');
|
||||||
|
|
||||||
$this->assertTrue($button->isClicked());
|
$this->assertTrue($button->isClicked());
|
||||||
@ -48,7 +48,7 @@ class SubmitTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testClickedIfSubmittedWithUnemptyString()
|
public function testClickedIfSubmittedWithUnemptyString()
|
||||||
{
|
{
|
||||||
$button = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\SubmitType');
|
$button = $this->factory->create(static::TESTED_TYPE);
|
||||||
$button->submit('foo');
|
$button->submit('foo');
|
||||||
|
|
||||||
$this->assertTrue($button->isClicked());
|
$this->assertTrue($button->isClicked());
|
||||||
@ -57,9 +57,9 @@ class SubmitTypeTest extends TestCase
|
|||||||
public function testSubmitCanBeAddedToForm()
|
public function testSubmitCanBeAddedToForm()
|
||||||
{
|
{
|
||||||
$form = $this->factory
|
$form = $this->factory
|
||||||
->createBuilder('Symfony\Component\Form\Extension\Core\Type\FormType')
|
->createBuilder(FormTypeTest::TESTED_TYPE)
|
||||||
->getForm();
|
->getForm();
|
||||||
|
|
||||||
$this->assertSame($form, $form->add('send', 'Symfony\Component\Form\Extension\Core\Type\SubmitType'));
|
$this->assertSame($form, $form->add('send', static::TESTED_TYPE));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,27 +11,51 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\Form\Tests\Extension\Core\Type;
|
namespace Symfony\Component\Form\Tests\Extension\Core\Type;
|
||||||
|
|
||||||
use Symfony\Component\Form\Test\TypeTestCase as TestCase;
|
class TextTypeTest extends BaseTypeTest
|
||||||
|
|
||||||
class TextTypeTest extends TestCase
|
|
||||||
{
|
{
|
||||||
public function testSubmitNullReturnsNull()
|
const TESTED_TYPE = 'Symfony\Component\Form\Extension\Core\Type\TextType';
|
||||||
|
|
||||||
|
public function testSubmitNull($expected = null, $norm = null, $view = null)
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TextType', 'name');
|
parent::testSubmitNull($expected, $norm, '');
|
||||||
|
|
||||||
$form->submit(null);
|
|
||||||
|
|
||||||
$this->assertNull($form->getData());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSubmitNullReturnsEmptyStringWithEmptyDataAsString()
|
public function testSubmitNullReturnsNullWithEmptyDataAsString()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TextType', 'name', array(
|
$form = $this->factory->create(static::TESTED_TYPE, 'name', array(
|
||||||
'empty_data' => '',
|
'empty_data' => '',
|
||||||
));
|
));
|
||||||
|
|
||||||
$form->submit(null);
|
$form->submit(null);
|
||||||
|
|
||||||
$this->assertSame('', $form->getData());
|
$this->assertSame('', $form->getData());
|
||||||
|
$this->assertSame('', $form->getNormData());
|
||||||
|
$this->assertSame('', $form->getViewData());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function provideZeros()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
array(0, '0'),
|
||||||
|
array('0', '0'),
|
||||||
|
array('00000', '00000'),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider provideZeros
|
||||||
|
*
|
||||||
|
* @see https://github.com/symfony/symfony/issues/1986
|
||||||
|
*/
|
||||||
|
public function testSetDataThroughParamsWithZero($data, $dataAsString)
|
||||||
|
{
|
||||||
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
|
'data' => $data,
|
||||||
|
));
|
||||||
|
$view = $form->createView();
|
||||||
|
|
||||||
|
$this->assertFalse($form->isEmpty());
|
||||||
|
|
||||||
|
$this->assertSame($dataAsString, $view->vars['value']);
|
||||||
|
$this->assertSame($dataAsString, $form->getData());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,13 +13,14 @@ namespace Symfony\Component\Form\Tests\Extension\Core\Type;
|
|||||||
|
|
||||||
use Symfony\Component\Form\ChoiceList\View\ChoiceView;
|
use Symfony\Component\Form\ChoiceList\View\ChoiceView;
|
||||||
use Symfony\Component\Form\FormError;
|
use Symfony\Component\Form\FormError;
|
||||||
use Symfony\Component\Form\Test\TypeTestCase as TestCase;
|
|
||||||
|
|
||||||
class TimeTypeTest extends TestCase
|
class TimeTypeTest extends BaseTypeTest
|
||||||
{
|
{
|
||||||
|
const TESTED_TYPE = 'Symfony\Component\Form\Extension\Core\Type\TimeType';
|
||||||
|
|
||||||
public function testSubmitDateTime()
|
public function testSubmitDateTime()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'model_timezone' => 'UTC',
|
'model_timezone' => 'UTC',
|
||||||
'view_timezone' => 'UTC',
|
'view_timezone' => 'UTC',
|
||||||
'input' => 'datetime',
|
'input' => 'datetime',
|
||||||
@ -40,7 +41,7 @@ class TimeTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testSubmitString()
|
public function testSubmitString()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'model_timezone' => 'UTC',
|
'model_timezone' => 'UTC',
|
||||||
'view_timezone' => 'UTC',
|
'view_timezone' => 'UTC',
|
||||||
'input' => 'string',
|
'input' => 'string',
|
||||||
@ -59,7 +60,7 @@ class TimeTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testSubmitTimestamp()
|
public function testSubmitTimestamp()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'model_timezone' => 'UTC',
|
'model_timezone' => 'UTC',
|
||||||
'view_timezone' => 'UTC',
|
'view_timezone' => 'UTC',
|
||||||
'input' => 'timestamp',
|
'input' => 'timestamp',
|
||||||
@ -80,7 +81,7 @@ class TimeTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testSubmitArray()
|
public function testSubmitArray()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'model_timezone' => 'UTC',
|
'model_timezone' => 'UTC',
|
||||||
'view_timezone' => 'UTC',
|
'view_timezone' => 'UTC',
|
||||||
'input' => 'array',
|
'input' => 'array',
|
||||||
@ -99,7 +100,7 @@ class TimeTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testSubmitDatetimeSingleText()
|
public function testSubmitDatetimeSingleText()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'model_timezone' => 'UTC',
|
'model_timezone' => 'UTC',
|
||||||
'view_timezone' => 'UTC',
|
'view_timezone' => 'UTC',
|
||||||
'input' => 'datetime',
|
'input' => 'datetime',
|
||||||
@ -114,7 +115,7 @@ class TimeTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testSubmitDatetimeSingleTextWithoutMinutes()
|
public function testSubmitDatetimeSingleTextWithoutMinutes()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'model_timezone' => 'UTC',
|
'model_timezone' => 'UTC',
|
||||||
'view_timezone' => 'UTC',
|
'view_timezone' => 'UTC',
|
||||||
'input' => 'datetime',
|
'input' => 'datetime',
|
||||||
@ -130,7 +131,7 @@ class TimeTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testSubmitArraySingleText()
|
public function testSubmitArraySingleText()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'model_timezone' => 'UTC',
|
'model_timezone' => 'UTC',
|
||||||
'view_timezone' => 'UTC',
|
'view_timezone' => 'UTC',
|
||||||
'input' => 'array',
|
'input' => 'array',
|
||||||
@ -150,7 +151,7 @@ class TimeTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testSubmitArraySingleTextWithoutMinutes()
|
public function testSubmitArraySingleTextWithoutMinutes()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'model_timezone' => 'UTC',
|
'model_timezone' => 'UTC',
|
||||||
'view_timezone' => 'UTC',
|
'view_timezone' => 'UTC',
|
||||||
'input' => 'array',
|
'input' => 'array',
|
||||||
@ -170,7 +171,7 @@ class TimeTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testSubmitArraySingleTextWithSeconds()
|
public function testSubmitArraySingleTextWithSeconds()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'model_timezone' => 'UTC',
|
'model_timezone' => 'UTC',
|
||||||
'view_timezone' => 'UTC',
|
'view_timezone' => 'UTC',
|
||||||
'input' => 'array',
|
'input' => 'array',
|
||||||
@ -192,7 +193,7 @@ class TimeTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testSubmitStringSingleText()
|
public function testSubmitStringSingleText()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'model_timezone' => 'UTC',
|
'model_timezone' => 'UTC',
|
||||||
'view_timezone' => 'UTC',
|
'view_timezone' => 'UTC',
|
||||||
'input' => 'string',
|
'input' => 'string',
|
||||||
@ -207,7 +208,7 @@ class TimeTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testSubmitStringSingleTextWithoutMinutes()
|
public function testSubmitStringSingleTextWithoutMinutes()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'model_timezone' => 'UTC',
|
'model_timezone' => 'UTC',
|
||||||
'view_timezone' => 'UTC',
|
'view_timezone' => 'UTC',
|
||||||
'input' => 'string',
|
'input' => 'string',
|
||||||
@ -223,7 +224,7 @@ class TimeTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testSubmitWithSecondsAndBrowserOmissionSeconds()
|
public function testSubmitWithSecondsAndBrowserOmissionSeconds()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'model_timezone' => 'UTC',
|
'model_timezone' => 'UTC',
|
||||||
'view_timezone' => 'UTC',
|
'view_timezone' => 'UTC',
|
||||||
'input' => 'string',
|
'input' => 'string',
|
||||||
@ -239,7 +240,7 @@ class TimeTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testSetDataWithoutMinutes()
|
public function testSetDataWithoutMinutes()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'model_timezone' => 'UTC',
|
'model_timezone' => 'UTC',
|
||||||
'view_timezone' => 'UTC',
|
'view_timezone' => 'UTC',
|
||||||
'input' => 'datetime',
|
'input' => 'datetime',
|
||||||
@ -253,7 +254,7 @@ class TimeTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testSetDataWithSeconds()
|
public function testSetDataWithSeconds()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'model_timezone' => 'UTC',
|
'model_timezone' => 'UTC',
|
||||||
'view_timezone' => 'UTC',
|
'view_timezone' => 'UTC',
|
||||||
'input' => 'datetime',
|
'input' => 'datetime',
|
||||||
@ -267,7 +268,7 @@ class TimeTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testSetDataDifferentTimezones()
|
public function testSetDataDifferentTimezones()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'model_timezone' => 'America/New_York',
|
'model_timezone' => 'America/New_York',
|
||||||
'view_timezone' => 'Asia/Hong_Kong',
|
'view_timezone' => 'Asia/Hong_Kong',
|
||||||
'input' => 'string',
|
'input' => 'string',
|
||||||
@ -293,7 +294,7 @@ class TimeTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testSetDataDifferentTimezonesDateTime()
|
public function testSetDataDifferentTimezonesDateTime()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'model_timezone' => 'America/New_York',
|
'model_timezone' => 'America/New_York',
|
||||||
'view_timezone' => 'Asia/Hong_Kong',
|
'view_timezone' => 'Asia/Hong_Kong',
|
||||||
'input' => 'datetime',
|
'input' => 'datetime',
|
||||||
@ -320,7 +321,7 @@ class TimeTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testHoursOption()
|
public function testHoursOption()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'hours' => array(6, 7),
|
'hours' => array(6, 7),
|
||||||
));
|
));
|
||||||
|
|
||||||
@ -334,7 +335,7 @@ class TimeTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testIsMinuteWithinRangeReturnsTrueIfWithin()
|
public function testIsMinuteWithinRangeReturnsTrueIfWithin()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'minutes' => array(6, 7),
|
'minutes' => array(6, 7),
|
||||||
));
|
));
|
||||||
|
|
||||||
@ -348,7 +349,7 @@ class TimeTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testIsSecondWithinRangeReturnsTrueIfWithin()
|
public function testIsSecondWithinRangeReturnsTrueIfWithin()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'seconds' => array(6, 7),
|
'seconds' => array(6, 7),
|
||||||
'with_seconds' => true,
|
'with_seconds' => true,
|
||||||
));
|
));
|
||||||
@ -365,7 +366,7 @@ class TimeTypeTest extends TestCase
|
|||||||
{
|
{
|
||||||
$this->markTestIncomplete('Needs to be reimplemented using validators');
|
$this->markTestIncomplete('Needs to be reimplemented using validators');
|
||||||
|
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'widget' => 'choice',
|
'widget' => 'choice',
|
||||||
));
|
));
|
||||||
|
|
||||||
@ -381,7 +382,7 @@ class TimeTypeTest extends TestCase
|
|||||||
{
|
{
|
||||||
$this->markTestIncomplete('Needs to be reimplemented using validators');
|
$this->markTestIncomplete('Needs to be reimplemented using validators');
|
||||||
|
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'widget' => 'choice',
|
'widget' => 'choice',
|
||||||
'with_seconds' => true,
|
'with_seconds' => true,
|
||||||
));
|
));
|
||||||
@ -399,7 +400,7 @@ class TimeTypeTest extends TestCase
|
|||||||
{
|
{
|
||||||
$this->markTestIncomplete('Needs to be reimplemented using validators');
|
$this->markTestIncomplete('Needs to be reimplemented using validators');
|
||||||
|
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'widget' => 'choice',
|
'widget' => 'choice',
|
||||||
));
|
));
|
||||||
|
|
||||||
@ -415,7 +416,7 @@ class TimeTypeTest extends TestCase
|
|||||||
{
|
{
|
||||||
$this->markTestIncomplete('Needs to be reimplemented using validators');
|
$this->markTestIncomplete('Needs to be reimplemented using validators');
|
||||||
|
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'widget' => 'choice',
|
'widget' => 'choice',
|
||||||
'with_seconds' => true,
|
'with_seconds' => true,
|
||||||
));
|
));
|
||||||
@ -433,7 +434,7 @@ class TimeTypeTest extends TestCase
|
|||||||
{
|
{
|
||||||
$this->markTestIncomplete('Needs to be reimplemented using validators');
|
$this->markTestIncomplete('Needs to be reimplemented using validators');
|
||||||
|
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'widget' => 'choice',
|
'widget' => 'choice',
|
||||||
'with_seconds' => true,
|
'with_seconds' => true,
|
||||||
));
|
));
|
||||||
@ -451,7 +452,7 @@ class TimeTypeTest extends TestCase
|
|||||||
{
|
{
|
||||||
$this->markTestIncomplete('Needs to be reimplemented using validators');
|
$this->markTestIncomplete('Needs to be reimplemented using validators');
|
||||||
|
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'widget' => 'choice',
|
'widget' => 'choice',
|
||||||
'with_seconds' => true,
|
'with_seconds' => true,
|
||||||
));
|
));
|
||||||
@ -469,7 +470,7 @@ class TimeTypeTest extends TestCase
|
|||||||
{
|
{
|
||||||
$this->markTestIncomplete('Needs to be reimplemented using validators');
|
$this->markTestIncomplete('Needs to be reimplemented using validators');
|
||||||
|
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'widget' => 'choice',
|
'widget' => 'choice',
|
||||||
'with_seconds' => true,
|
'with_seconds' => true,
|
||||||
));
|
));
|
||||||
@ -487,12 +488,12 @@ class TimeTypeTest extends TestCase
|
|||||||
{
|
{
|
||||||
// Throws an exception if "data_class" option is not explicitly set
|
// Throws an exception if "data_class" option is not explicitly set
|
||||||
// to null in the type
|
// to null in the type
|
||||||
$this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', new \DateTime());
|
$this->factory->create(static::TESTED_TYPE, new \DateTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSingleTextWidgetShouldUseTheRightInputType()
|
public function testSingleTextWidgetShouldUseTheRightInputType()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'widget' => 'single_text',
|
'widget' => 'single_text',
|
||||||
));
|
));
|
||||||
|
|
||||||
@ -502,7 +503,7 @@ class TimeTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testSingleTextWidgetWithSecondsShouldHaveRightStepAttribute()
|
public function testSingleTextWidgetWithSecondsShouldHaveRightStepAttribute()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'widget' => 'single_text',
|
'widget' => 'single_text',
|
||||||
'with_seconds' => true,
|
'with_seconds' => true,
|
||||||
));
|
));
|
||||||
@ -514,7 +515,7 @@ class TimeTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testSingleTextWidgetWithSecondsShouldNotOverrideStepAttribute()
|
public function testSingleTextWidgetWithSecondsShouldNotOverrideStepAttribute()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'widget' => 'single_text',
|
'widget' => 'single_text',
|
||||||
'with_seconds' => true,
|
'with_seconds' => true,
|
||||||
'attr' => array(
|
'attr' => array(
|
||||||
@ -529,7 +530,7 @@ class TimeTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testDontPassHtml5TypeIfHtml5NotAllowed()
|
public function testDontPassHtml5TypeIfHtml5NotAllowed()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'widget' => 'single_text',
|
'widget' => 'single_text',
|
||||||
'html5' => false,
|
'html5' => false,
|
||||||
));
|
));
|
||||||
@ -540,7 +541,7 @@ class TimeTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testPassDefaultPlaceholderToViewIfNotRequired()
|
public function testPassDefaultPlaceholderToViewIfNotRequired()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'required' => false,
|
'required' => false,
|
||||||
'with_seconds' => true,
|
'with_seconds' => true,
|
||||||
));
|
));
|
||||||
@ -553,7 +554,7 @@ class TimeTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testPassNoPlaceholderToViewIfRequired()
|
public function testPassNoPlaceholderToViewIfRequired()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'required' => true,
|
'required' => true,
|
||||||
'with_seconds' => true,
|
'with_seconds' => true,
|
||||||
));
|
));
|
||||||
@ -566,7 +567,7 @@ class TimeTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testPassPlaceholderAsString()
|
public function testPassPlaceholderAsString()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'placeholder' => 'Empty',
|
'placeholder' => 'Empty',
|
||||||
'with_seconds' => true,
|
'with_seconds' => true,
|
||||||
));
|
));
|
||||||
@ -579,7 +580,7 @@ class TimeTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testPassPlaceholderAsArray()
|
public function testPassPlaceholderAsArray()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'placeholder' => array(
|
'placeholder' => array(
|
||||||
'hour' => 'Empty hour',
|
'hour' => 'Empty hour',
|
||||||
'minute' => 'Empty minute',
|
'minute' => 'Empty minute',
|
||||||
@ -596,7 +597,7 @@ class TimeTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testPassPlaceholderAsPartialArrayAddEmptyIfNotRequired()
|
public function testPassPlaceholderAsPartialArrayAddEmptyIfNotRequired()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'required' => false,
|
'required' => false,
|
||||||
'placeholder' => array(
|
'placeholder' => array(
|
||||||
'hour' => 'Empty hour',
|
'hour' => 'Empty hour',
|
||||||
@ -613,7 +614,7 @@ class TimeTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testPassPlaceholderAsPartialArrayAddNullIfRequired()
|
public function testPassPlaceholderAsPartialArrayAddNullIfRequired()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'required' => true,
|
'required' => true,
|
||||||
'placeholder' => array(
|
'placeholder' => array(
|
||||||
'hour' => 'Empty hour',
|
'hour' => 'Empty hour',
|
||||||
@ -642,7 +643,7 @@ class TimeTypeTest extends TestCase
|
|||||||
public function testHourErrorsBubbleUp($widget)
|
public function testHourErrorsBubbleUp($widget)
|
||||||
{
|
{
|
||||||
$error = new FormError('Invalid!');
|
$error = new FormError('Invalid!');
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'widget' => $widget,
|
'widget' => $widget,
|
||||||
));
|
));
|
||||||
$form['hour']->addError($error);
|
$form['hour']->addError($error);
|
||||||
@ -657,7 +658,7 @@ class TimeTypeTest extends TestCase
|
|||||||
public function testMinuteErrorsBubbleUp($widget)
|
public function testMinuteErrorsBubbleUp($widget)
|
||||||
{
|
{
|
||||||
$error = new FormError('Invalid!');
|
$error = new FormError('Invalid!');
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'widget' => $widget,
|
'widget' => $widget,
|
||||||
));
|
));
|
||||||
$form['minute']->addError($error);
|
$form['minute']->addError($error);
|
||||||
@ -672,7 +673,7 @@ class TimeTypeTest extends TestCase
|
|||||||
public function testSecondErrorsBubbleUp($widget)
|
public function testSecondErrorsBubbleUp($widget)
|
||||||
{
|
{
|
||||||
$error = new FormError('Invalid!');
|
$error = new FormError('Invalid!');
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'widget' => $widget,
|
'widget' => $widget,
|
||||||
'with_seconds' => true,
|
'with_seconds' => true,
|
||||||
));
|
));
|
||||||
@ -687,7 +688,7 @@ class TimeTypeTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testInitializeWithSecondsAndWithoutMinutes()
|
public function testInitializeWithSecondsAndWithoutMinutes()
|
||||||
{
|
{
|
||||||
$this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
$this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'with_minutes' => false,
|
'with_minutes' => false,
|
||||||
'with_seconds' => true,
|
'with_seconds' => true,
|
||||||
));
|
));
|
||||||
@ -698,7 +699,7 @@ class TimeTypeTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testThrowExceptionIfHoursIsInvalid()
|
public function testThrowExceptionIfHoursIsInvalid()
|
||||||
{
|
{
|
||||||
$this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
$this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'hours' => 'bad value',
|
'hours' => 'bad value',
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
@ -708,7 +709,7 @@ class TimeTypeTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testThrowExceptionIfMinutesIsInvalid()
|
public function testThrowExceptionIfMinutesIsInvalid()
|
||||||
{
|
{
|
||||||
$this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
$this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'minutes' => 'bad value',
|
'minutes' => 'bad value',
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
@ -718,14 +719,14 @@ class TimeTypeTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testThrowExceptionIfSecondsIsInvalid()
|
public function testThrowExceptionIfSecondsIsInvalid()
|
||||||
{
|
{
|
||||||
$this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
$this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'seconds' => 'bad value',
|
'seconds' => 'bad value',
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testPassDefaultChoiceTranslationDomain()
|
public function testPassDefaultChoiceTranslationDomain()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType');
|
$form = $this->factory->create(static::TESTED_TYPE);
|
||||||
|
|
||||||
$view = $form->createView();
|
$view = $form->createView();
|
||||||
$this->assertFalse($view['hour']->vars['choice_translation_domain']);
|
$this->assertFalse($view['hour']->vars['choice_translation_domain']);
|
||||||
@ -734,7 +735,7 @@ class TimeTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testPassChoiceTranslationDomainAsString()
|
public function testPassChoiceTranslationDomainAsString()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'choice_translation_domain' => 'messages',
|
'choice_translation_domain' => 'messages',
|
||||||
'with_seconds' => true,
|
'with_seconds' => true,
|
||||||
));
|
));
|
||||||
@ -747,7 +748,7 @@ class TimeTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testPassChoiceTranslationDomainAsArray()
|
public function testPassChoiceTranslationDomainAsArray()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'choice_translation_domain' => array(
|
'choice_translation_domain' => array(
|
||||||
'hour' => 'foo',
|
'hour' => 'foo',
|
||||||
'second' => 'test',
|
'second' => 'test',
|
||||||
@ -760,4 +761,11 @@ class TimeTypeTest extends TestCase
|
|||||||
$this->assertFalse($view['minute']->vars['choice_translation_domain']);
|
$this->assertFalse($view['minute']->vars['choice_translation_domain']);
|
||||||
$this->assertSame('test', $view['second']->vars['choice_translation_domain']);
|
$this->assertSame('test', $view['second']->vars['choice_translation_domain']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testSubmitNull($expected = null, $norm = null, $view = null)
|
||||||
|
{
|
||||||
|
$view = array('hour' => '', 'minute' => '');
|
||||||
|
|
||||||
|
parent::testSubmitNull($expected, $norm, $view);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,15 +12,15 @@
|
|||||||
namespace Symfony\Component\Form\Tests\Extension\Core\Type;
|
namespace Symfony\Component\Form\Tests\Extension\Core\Type;
|
||||||
|
|
||||||
use Symfony\Component\Form\ChoiceList\View\ChoiceView;
|
use Symfony\Component\Form\ChoiceList\View\ChoiceView;
|
||||||
use Symfony\Component\Form\Test\TypeTestCase;
|
|
||||||
|
|
||||||
class TimezoneTypeTest extends TypeTestCase
|
class TimezoneTypeTest extends BaseTypeTest
|
||||||
{
|
{
|
||||||
|
const TESTED_TYPE = 'Symfony\Component\Form\Extension\Core\Type\TimezoneType';
|
||||||
|
|
||||||
public function testTimezonesAreSelectable()
|
public function testTimezonesAreSelectable()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimezoneType');
|
$choices = $this->factory->create(static::TESTED_TYPE)
|
||||||
$view = $form->createView();
|
->createView()->vars['choices'];
|
||||||
$choices = $view->vars['choices'];
|
|
||||||
|
|
||||||
$this->assertArrayHasKey('Africa', $choices);
|
$this->assertArrayHasKey('Africa', $choices);
|
||||||
$this->assertContains(new ChoiceView('Africa/Kinshasa', 'Africa/Kinshasa', 'Kinshasa'), $choices['Africa'], '', false, false);
|
$this->assertContains(new ChoiceView('Africa/Kinshasa', 'Africa/Kinshasa', 'Kinshasa'), $choices['Africa'], '', false, false);
|
||||||
@ -28,4 +28,9 @@ class TimezoneTypeTest extends TypeTestCase
|
|||||||
$this->assertArrayHasKey('America', $choices);
|
$this->assertArrayHasKey('America', $choices);
|
||||||
$this->assertContains(new ChoiceView('America/New_York', 'America/New_York', 'New York'), $choices['America'], '', false, false);
|
$this->assertContains(new ChoiceView('America/New_York', 'America/New_York', 'New York'), $choices['America'], '', false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testSubmitNull($expected = null, $norm = null, $view = null)
|
||||||
|
{
|
||||||
|
parent::testSubmitNull($expected, $norm, '');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,13 +11,13 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\Form\Tests\Extension\Core\Type;
|
namespace Symfony\Component\Form\Tests\Extension\Core\Type;
|
||||||
|
|
||||||
use Symfony\Component\Form\Test\TypeTestCase as TestCase;
|
class UrlTypeTest extends TextTypeTest
|
||||||
|
|
||||||
class UrlTypeTest extends TestCase
|
|
||||||
{
|
{
|
||||||
|
const TESTED_TYPE = 'Symfony\Component\Form\Extension\Core\Type\UrlType';
|
||||||
|
|
||||||
public function testSubmitAddsDefaultProtocolIfNoneIsIncluded()
|
public function testSubmitAddsDefaultProtocolIfNoneIsIncluded()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\UrlType', 'name');
|
$form = $this->factory->create(static::TESTED_TYPE, 'name');
|
||||||
|
|
||||||
$form->submit('www.domain.com');
|
$form->submit('www.domain.com');
|
||||||
|
|
||||||
@ -27,7 +27,7 @@ class UrlTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testSubmitAddsNoDefaultProtocolIfAlreadyIncluded()
|
public function testSubmitAddsNoDefaultProtocolIfAlreadyIncluded()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\UrlType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'default_protocol' => 'http',
|
'default_protocol' => 'http',
|
||||||
));
|
));
|
||||||
|
|
||||||
@ -39,7 +39,7 @@ class UrlTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testSubmitAddsNoDefaultProtocolIfEmpty()
|
public function testSubmitAddsNoDefaultProtocolIfEmpty()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\UrlType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'default_protocol' => 'http',
|
'default_protocol' => 'http',
|
||||||
));
|
));
|
||||||
|
|
||||||
@ -51,7 +51,7 @@ class UrlTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testSubmitAddsNoDefaultProtocolIfNull()
|
public function testSubmitAddsNoDefaultProtocolIfNull()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\UrlType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'default_protocol' => 'http',
|
'default_protocol' => 'http',
|
||||||
));
|
));
|
||||||
|
|
||||||
@ -63,7 +63,7 @@ class UrlTypeTest extends TestCase
|
|||||||
|
|
||||||
public function testSubmitAddsNoDefaultProtocolIfSetToNull()
|
public function testSubmitAddsNoDefaultProtocolIfSetToNull()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\UrlType', null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'default_protocol' => null,
|
'default_protocol' => null,
|
||||||
));
|
));
|
||||||
|
|
||||||
@ -78,7 +78,7 @@ class UrlTypeTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testThrowExceptionIfDefaultProtocolIsInvalid()
|
public function testThrowExceptionIfDefaultProtocolIsInvalid()
|
||||||
{
|
{
|
||||||
$this->factory->create('Symfony\Component\Form\Extension\Core\Type\UrlType', null, array(
|
$this->factory->create(static::TESTED_TYPE, null, array(
|
||||||
'default_protocol' => array(),
|
'default_protocol' => array(),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
@ -517,6 +517,24 @@ class SimpleFormTest extends AbstractFormTest
|
|||||||
$this->assertSame('default', $form->getData());
|
$this->assertSame('default', $form->getData());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testPresSetDataChangesDataIfDataIsLocked()
|
||||||
|
{
|
||||||
|
$config = new FormConfigBuilder('name', null, $this->dispatcher);
|
||||||
|
$config
|
||||||
|
->setData('default')
|
||||||
|
->setDataLocked(true)
|
||||||
|
->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) {
|
||||||
|
$event->setData('foobar');
|
||||||
|
});
|
||||||
|
$form = new Form($config);
|
||||||
|
|
||||||
|
$form->submit(false);
|
||||||
|
|
||||||
|
$this->assertTrue($form->isValid());
|
||||||
|
|
||||||
|
$this->assertSame('foobar', $form->getData());
|
||||||
|
}
|
||||||
|
|
||||||
public function testSubmitConvertsEmptyToNullIfNoTransformer()
|
public function testSubmitConvertsEmptyToNullIfNoTransformer()
|
||||||
{
|
{
|
||||||
$form = $this->getBuilder()->getForm();
|
$form = $this->getBuilder()->getForm();
|
||||||
|
@ -96,6 +96,6 @@ class TimeZoneTransformer extends Transformer
|
|||||||
return 'Etc/GMT'.($hours !== 0 ? $signal.$hours : '');
|
return 'Etc/GMT'.($hours !== 0 ? $signal.$hours : '');
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new \InvalidArgumentException(sprintf("The GMT time zone '%s' does not match with the supported formats GMT[+-]HH:MM or GMT[+-]HHMM.", $formattedTimeZone));
|
throw new \InvalidArgumentException(sprintf('The GMT time zone "%s" does not match with the supported formats GMT[+-]HH:MM or GMT[+-]HHMM.', $formattedTimeZone));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -372,7 +372,10 @@ class XmlEncoder extends SerializerAwareEncoder implements EncoderInterface, Dec
|
|||||||
if (is_array($data) || ($data instanceof \Traversable && !$this->serializer->supportsNormalization($data, $this->format))) {
|
if (is_array($data) || ($data instanceof \Traversable && !$this->serializer->supportsNormalization($data, $this->format))) {
|
||||||
foreach ($data as $key => $data) {
|
foreach ($data as $key => $data) {
|
||||||
//Ah this is the magic @ attribute types.
|
//Ah this is the magic @ attribute types.
|
||||||
if (0 === strpos($key, '@') && is_scalar($data) && $this->isElementNameValid($attributeName = substr($key, 1))) {
|
if (0 === strpos($key, '@') && $this->isElementNameValid($attributeName = substr($key, 1))) {
|
||||||
|
if (!is_scalar($data)) {
|
||||||
|
$data = $this->serializer->normalize($data, $this->format, $this->context);
|
||||||
|
}
|
||||||
$parentNode->setAttribute($attributeName, $data);
|
$parentNode->setAttribute($attributeName, $data);
|
||||||
} elseif ($key === '#') {
|
} elseif ($key === '#') {
|
||||||
$append = $this->selectNodeType($parentNode, $data);
|
$append = $this->selectNodeType($parentNode, $data);
|
||||||
@ -477,7 +480,7 @@ class XmlEncoder extends SerializerAwareEncoder implements EncoderInterface, Dec
|
|||||||
} elseif ($val instanceof \Traversable) {
|
} elseif ($val instanceof \Traversable) {
|
||||||
$this->buildXml($node, $val);
|
$this->buildXml($node, $val);
|
||||||
} elseif (is_object($val)) {
|
} elseif (is_object($val)) {
|
||||||
return $this->buildXml($node, $this->serializer->normalize($val, $this->format, $this->context));
|
return $this->selectNodeType($node, $this->serializer->normalize($val, $this->format, $this->context));
|
||||||
} elseif (is_numeric($val)) {
|
} elseif (is_numeric($val)) {
|
||||||
return $this->appendText($node, (string) $val);
|
return $this->appendText($node, (string) $val);
|
||||||
} elseif (is_string($val) && $this->needsCdataWrapping($val)) {
|
} elseif (is_string($val) && $this->needsCdataWrapping($val)) {
|
||||||
|
@ -19,11 +19,17 @@ use Symfony\Component\Serializer\Encoder\XmlEncoder;
|
|||||||
use Symfony\Component\Serializer\Serializer;
|
use Symfony\Component\Serializer\Serializer;
|
||||||
use Symfony\Component\Serializer\Exception\UnexpectedValueException;
|
use Symfony\Component\Serializer\Exception\UnexpectedValueException;
|
||||||
use Symfony\Component\Serializer\Normalizer\CustomNormalizer;
|
use Symfony\Component\Serializer\Normalizer\CustomNormalizer;
|
||||||
|
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
|
||||||
|
|
||||||
class XmlEncoderTest extends TestCase
|
class XmlEncoderTest extends TestCase
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @var XmlEncoder
|
||||||
|
*/
|
||||||
private $encoder;
|
private $encoder;
|
||||||
|
|
||||||
|
private $exampleDateTimeString = '2017-02-19T15:16:08+0300';
|
||||||
|
|
||||||
protected function setUp()
|
protected function setUp()
|
||||||
{
|
{
|
||||||
$this->encoder = new XmlEncoder();
|
$this->encoder = new XmlEncoder();
|
||||||
@ -551,4 +557,89 @@ XML;
|
|||||||
|
|
||||||
return $obj;
|
return $obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testEncodeXmlWithBoolValue()
|
||||||
|
{
|
||||||
|
$expectedXml = <<<'XML'
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<response><foo>1</foo><bar>0</bar></response>
|
||||||
|
|
||||||
|
XML;
|
||||||
|
|
||||||
|
$actualXml = $this->encoder->encode(array('foo' => true, 'bar' => false), 'xml');
|
||||||
|
|
||||||
|
$this->assertEquals($expectedXml, $actualXml);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testEncodeXmlWithDateTimeObjectValue()
|
||||||
|
{
|
||||||
|
$xmlEncoder = $this->createXmlEncoderWithDateTimeNormalizer();
|
||||||
|
|
||||||
|
$actualXml = $xmlEncoder->encode(array('dateTime' => new \DateTime($this->exampleDateTimeString)), 'xml');
|
||||||
|
|
||||||
|
$this->assertEquals($this->createXmlWithDateTime(), $actualXml);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testEncodeXmlWithDateTimeObjectField()
|
||||||
|
{
|
||||||
|
$xmlEncoder = $this->createXmlEncoderWithDateTimeNormalizer();
|
||||||
|
|
||||||
|
$actualXml = $xmlEncoder->encode(array('foo' => array('@dateTime' => new \DateTime($this->exampleDateTimeString))), 'xml');
|
||||||
|
|
||||||
|
$this->assertEquals($this->createXmlWithDateTimeField(), $actualXml);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return XmlEncoder
|
||||||
|
*/
|
||||||
|
private function createXmlEncoderWithDateTimeNormalizer()
|
||||||
|
{
|
||||||
|
$encoder = new XmlEncoder();
|
||||||
|
$serializer = new Serializer(array($this->createMockDateTimeNormalizer()), array('xml' => new XmlEncoder()));
|
||||||
|
$encoder->setSerializer($serializer);
|
||||||
|
|
||||||
|
return $encoder;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return \PHPUnit_Framework_MockObject_MockObject|NormalizerInterface
|
||||||
|
*/
|
||||||
|
private function createMockDateTimeNormalizer()
|
||||||
|
{
|
||||||
|
$mock = $this->getMockBuilder('\Symfony\Component\Serializer\Normalizer\CustomNormalizer')->getMock();
|
||||||
|
|
||||||
|
$mock
|
||||||
|
->expects($this->once())
|
||||||
|
->method('normalize')
|
||||||
|
->with(new \DateTime($this->exampleDateTimeString), 'xml', array())
|
||||||
|
->willReturn($this->exampleDateTimeString);
|
||||||
|
|
||||||
|
$mock
|
||||||
|
->expects($this->once())
|
||||||
|
->method('supportsNormalization')
|
||||||
|
->with(new \DateTime($this->exampleDateTimeString), 'xml')
|
||||||
|
->willReturn(true);
|
||||||
|
|
||||||
|
return $mock;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
private function createXmlWithDateTime()
|
||||||
|
{
|
||||||
|
return sprintf('<?xml version="1.0"?>
|
||||||
|
<response><dateTime>%s</dateTime></response>
|
||||||
|
', $this->exampleDateTimeString);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
private function createXmlWithDateTimeField()
|
||||||
|
{
|
||||||
|
return sprintf('<?xml version="1.0"?>
|
||||||
|
<response><foo dateTime="%s"/></response>
|
||||||
|
', $this->exampleDateTimeString);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user