[Form] Fixed tests using legacy functionality
This commit is contained in:
parent
d6179c830b
commit
1d89922782
@ -228,7 +228,9 @@ abstract class DoctrineType extends AbstractType
|
||||
|
||||
// deprecation note
|
||||
$propertyNormalizer = function (Options $options, $propertyName) {
|
||||
trigger_error('The "property" option is deprecated since version 2.7 and will be removed in 3.0. Use "choice_label" instead.', E_USER_DEPRECATED);
|
||||
if ($propertyName) {
|
||||
trigger_error('The "property" option is deprecated since version 2.7 and will be removed in 3.0. Use "choice_label" instead.', E_USER_DEPRECATED);
|
||||
}
|
||||
|
||||
return $propertyName;
|
||||
};
|
||||
@ -249,7 +251,9 @@ abstract class DoctrineType extends AbstractType
|
||||
|
||||
// deprecation note
|
||||
$loaderNormalizer = function (Options $options, $loader) {
|
||||
trigger_error('The "loader" option is deprecated since version 2.7 and will be removed in 3.0. Override getLoader() instead.', E_USER_DEPRECATED);
|
||||
if ($loader) {
|
||||
trigger_error('The "loader" option is deprecated since version 2.7 and will be removed in 3.0. Override getLoader() instead.', E_USER_DEPRECATED);
|
||||
}
|
||||
|
||||
return $loader;
|
||||
};
|
||||
@ -300,6 +304,7 @@ abstract class DoctrineType extends AbstractType
|
||||
|
||||
$resolver->setAllowedTypes('em', array('null', 'string', 'Doctrine\Common\Persistence\ObjectManager'));
|
||||
$resolver->setAllowedTypes('loader', array('null', 'Symfony\Bridge\Doctrine\Form\ChoiceList\EntityLoaderInterface'));
|
||||
$resolver->setAllowedTypes('query_builder', array('null', 'callable', 'Doctrine\ORM\QueryBuilder'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -19,6 +19,9 @@ use Symfony\Bridge\Doctrine\Form\ChoiceList\EntityChoiceList;
|
||||
use Symfony\Component\Form\Extension\Core\View\ChoiceView;
|
||||
use Doctrine\ORM\Tools\SchemaTool;
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
class GenericEntityChoiceListTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
const SINGLE_INT_ID_CLASS = 'Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdEntity';
|
||||
@ -36,6 +39,8 @@ class GenericEntityChoiceListTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
|
||||
|
||||
$this->em = DoctrineTestHelper::createTestEntityManager();
|
||||
|
||||
$schemaTool = new SchemaTool($this->em);
|
||||
@ -70,7 +75,7 @@ class GenericEntityChoiceListTest extends \PHPUnit_Framework_TestCase
|
||||
* @expectedException \Symfony\Component\Form\Exception\StringCastException
|
||||
* @expectedMessage Entity "Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdEntity" passed to the choice field must have a "__toString()" method defined (or you can also override the "property" option).
|
||||
*/
|
||||
public function testEntitiesMustHaveAToStringMethod()
|
||||
public function testLegacyEntitiesMustHaveAToStringMethod()
|
||||
{
|
||||
$entity1 = new SingleIntIdNoToStringEntity(1, 'Foo');
|
||||
$entity2 = new SingleIntIdNoToStringEntity(2, 'Bar');
|
||||
@ -96,7 +101,7 @@ class GenericEntityChoiceListTest extends \PHPUnit_Framework_TestCase
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Form\Exception\RuntimeException
|
||||
*/
|
||||
public function testChoicesMustBeManaged()
|
||||
public function testLegacyChoicesMustBeManaged()
|
||||
{
|
||||
$entity1 = new SingleIntIdEntity(1, 'Foo');
|
||||
$entity2 = new SingleIntIdEntity(2, 'Bar');
|
||||
@ -118,7 +123,7 @@ class GenericEntityChoiceListTest extends \PHPUnit_Framework_TestCase
|
||||
$choiceList->getChoices();
|
||||
}
|
||||
|
||||
public function testInitExplicitChoices()
|
||||
public function testLegacyInitExplicitChoices()
|
||||
{
|
||||
$entity1 = new SingleIntIdEntity(1, 'Foo');
|
||||
$entity2 = new SingleIntIdEntity(2, 'Bar');
|
||||
@ -141,7 +146,7 @@ class GenericEntityChoiceListTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertSame(array(1 => $entity1, 2 => $entity2), $choiceList->getChoices());
|
||||
}
|
||||
|
||||
public function testInitEmptyChoices()
|
||||
public function testLegacyInitEmptyChoices()
|
||||
{
|
||||
$entity1 = new SingleIntIdEntity(1, 'Foo');
|
||||
$entity2 = new SingleIntIdEntity(2, 'Bar');
|
||||
@ -161,7 +166,7 @@ class GenericEntityChoiceListTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertSame(array(), $choiceList->getChoices());
|
||||
}
|
||||
|
||||
public function testInitNestedChoices()
|
||||
public function testLegacyInitNestedChoices()
|
||||
{
|
||||
$entity1 = new SingleIntIdEntity(1, 'Foo');
|
||||
$entity2 = new SingleIntIdEntity(2, 'Bar');
|
||||
@ -189,7 +194,7 @@ class GenericEntityChoiceListTest extends \PHPUnit_Framework_TestCase
|
||||
), $choiceList->getRemainingViews());
|
||||
}
|
||||
|
||||
public function testGroupByPropertyPath()
|
||||
public function testLegacyGroupByPropertyPath()
|
||||
{
|
||||
$item1 = new GroupableEntity(1, 'Foo', 'Group1');
|
||||
$item2 = new GroupableEntity(2, 'Bar', 'Group1');
|
||||
@ -224,7 +229,7 @@ class GenericEntityChoiceListTest extends \PHPUnit_Framework_TestCase
|
||||
), $choiceList->getRemainingViews());
|
||||
}
|
||||
|
||||
public function testGroupByInvalidPropertyPathReturnsFlatChoices()
|
||||
public function testLegacyGroupByInvalidPropertyPathReturnsFlatChoices()
|
||||
{
|
||||
$item1 = new GroupableEntity(1, 'Foo', 'Group1');
|
||||
$item2 = new GroupableEntity(2, 'Bar', 'Group1');
|
||||
@ -251,7 +256,7 @@ class GenericEntityChoiceListTest extends \PHPUnit_Framework_TestCase
|
||||
), $choiceList->getChoices());
|
||||
}
|
||||
|
||||
public function testInitShorthandEntityName()
|
||||
public function testLegacyInitShorthandEntityName()
|
||||
{
|
||||
$item1 = new SingleIntIdEntity(1, 'Foo');
|
||||
$item2 = new SingleIntIdEntity(2, 'Bar');
|
||||
@ -267,13 +272,8 @@ class GenericEntityChoiceListTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals(array(1, 2), $choiceList->getValuesForChoices(array($item1, $item2)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testLegacyInitShorthandEntityName()
|
||||
public function testLegacyInitShorthandEntityName2()
|
||||
{
|
||||
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
|
||||
|
||||
$item1 = new SingleIntIdEntity(1, 'Foo');
|
||||
$item2 = new SingleIntIdEntity(2, 'Bar');
|
||||
|
||||
|
@ -13,6 +13,7 @@ namespace Symfony\Bridge\Doctrine\Tests\Form\ChoiceList;
|
||||
|
||||
/**
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
* @group legacy
|
||||
*/
|
||||
class LoadedEntityChoiceListCompositeIdTest extends AbstractEntityChoiceListCompositeIdTest
|
||||
{
|
||||
|
@ -13,6 +13,7 @@ namespace Symfony\Bridge\Doctrine\Tests\Form\ChoiceList;
|
||||
|
||||
/**
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
* @group legacy
|
||||
*/
|
||||
class LoadedEntityChoiceListSingleIntIdTest extends AbstractEntityChoiceListSingleIntIdTest
|
||||
{
|
||||
|
@ -13,6 +13,7 @@ namespace Symfony\Bridge\Doctrine\Tests\Form\ChoiceList;
|
||||
|
||||
/**
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
* @group legacy
|
||||
*/
|
||||
class LoadedEntityChoiceListSingleStringIdTest extends AbstractEntityChoiceListSingleStringIdTest
|
||||
{
|
||||
|
@ -13,10 +13,11 @@ namespace Symfony\Bridge\Doctrine\Tests\Form\ChoiceList;
|
||||
|
||||
/**
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
* @group legacy
|
||||
*/
|
||||
class UnloadedEntityChoiceListCompositeIdTest extends AbstractEntityChoiceListCompositeIdTest
|
||||
{
|
||||
public function testGetIndicesForValuesIgnoresNonExistingValues()
|
||||
public function testLegacyGetIndicesForValuesIgnoresNonExistingValues()
|
||||
{
|
||||
$this->markTestSkipped('Non-existing values are not detected for unloaded choice lists.');
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ use Symfony\Bridge\Doctrine\Form\ChoiceList\ORMQueryBuilderLoader;
|
||||
|
||||
/**
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
* @group legacy
|
||||
*/
|
||||
class UnloadedEntityChoiceListCompositeIdWithQueryBuilderTest extends UnloadedEntityChoiceListCompositeIdTest
|
||||
{
|
||||
|
@ -13,17 +13,10 @@ namespace Symfony\Bridge\Doctrine\Tests\Form\ChoiceList;
|
||||
|
||||
/**
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
* @group legacy
|
||||
*/
|
||||
class UnloadedEntityChoiceListSingleIntIdTest extends AbstractEntityChoiceListSingleIntIdTest
|
||||
{
|
||||
public function testGetIndicesForValuesIgnoresNonExistingValues()
|
||||
{
|
||||
$this->markTestSkipped('Non-existing values are not detected for unloaded choice lists.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testLegacyGetIndicesForValuesIgnoresNonExistingValues()
|
||||
{
|
||||
$this->markTestSkipped('Non-existing values are not detected for unloaded choice lists.');
|
||||
|
@ -16,6 +16,7 @@ use Symfony\Bridge\Doctrine\Form\ChoiceList\ORMQueryBuilderLoader;
|
||||
|
||||
/**
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
* @group legacy
|
||||
*/
|
||||
class UnloadedEntityChoiceListSingleIntIdWithQueryBuilderTest extends UnloadedEntityChoiceListSingleIntIdTest
|
||||
{
|
||||
|
@ -13,10 +13,11 @@ namespace Symfony\Bridge\Doctrine\Tests\Form\ChoiceList;
|
||||
|
||||
/**
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
* @group legacy
|
||||
*/
|
||||
class UnloadedEntityChoiceListSingleStringIdTest extends AbstractEntityChoiceListSingleStringIdTest
|
||||
{
|
||||
public function testGetIndicesForValuesIgnoresNonExistingValues()
|
||||
public function testLegacyGetIndicesForValuesIgnoresNonExistingValues()
|
||||
{
|
||||
$this->markTestSkipped('Non-existing values are not detected for unloaded choice lists.');
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ use Symfony\Bridge\Doctrine\Form\ChoiceList\ORMQueryBuilderLoader;
|
||||
|
||||
/**
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
* @group legacy
|
||||
*/
|
||||
class UnloadedEntityChoiceListSingleStringIdWithQueryBuilderTest extends UnloadedEntityChoiceListSingleStringIdTest
|
||||
{
|
||||
|
@ -131,7 +131,7 @@ class EntityTypeTest extends TypeTestCase
|
||||
'em' => 'default',
|
||||
'class' => self::SINGLE_IDENT_CLASS,
|
||||
'required' => false,
|
||||
'property' => 'name',
|
||||
'choice_label' => 'name',
|
||||
));
|
||||
|
||||
$this->assertEquals(array(1 => new ChoiceView('Foo', '1', $entity1), 2 => new ChoiceView('Bar', '2', $entity2)), $field->createView()->vars['choices']);
|
||||
@ -165,7 +165,7 @@ class EntityTypeTest extends TypeTestCase
|
||||
'em' => 'default',
|
||||
'class' => self::SINGLE_IDENT_CLASS,
|
||||
'required' => false,
|
||||
'property' => 'name',
|
||||
'choice_label' => 'name',
|
||||
'query_builder' => $qb,
|
||||
));
|
||||
|
||||
@ -294,7 +294,7 @@ class EntityTypeTest extends TypeTestCase
|
||||
'expanded' => false,
|
||||
'em' => 'default',
|
||||
'class' => self::SINGLE_IDENT_CLASS,
|
||||
'property' => 'name',
|
||||
'choice_label' => 'name',
|
||||
));
|
||||
|
||||
$field->submit('2');
|
||||
@ -316,7 +316,7 @@ class EntityTypeTest extends TypeTestCase
|
||||
'expanded' => false,
|
||||
'em' => 'default',
|
||||
'class' => self::COMPOSITE_IDENT_CLASS,
|
||||
'property' => 'name',
|
||||
'choice_label' => 'name',
|
||||
));
|
||||
|
||||
// the collection key is used here
|
||||
@ -340,7 +340,7 @@ class EntityTypeTest extends TypeTestCase
|
||||
'expanded' => false,
|
||||
'em' => 'default',
|
||||
'class' => self::SINGLE_IDENT_CLASS,
|
||||
'property' => 'name',
|
||||
'choice_label' => 'name',
|
||||
));
|
||||
|
||||
$field->submit(array('1', '3'));
|
||||
@ -365,7 +365,7 @@ class EntityTypeTest extends TypeTestCase
|
||||
'expanded' => false,
|
||||
'em' => 'default',
|
||||
'class' => self::SINGLE_IDENT_CLASS,
|
||||
'property' => 'name',
|
||||
'choice_label' => 'name',
|
||||
));
|
||||
|
||||
$existing = new ArrayCollection(array(0 => $entity2));
|
||||
@ -396,7 +396,7 @@ class EntityTypeTest extends TypeTestCase
|
||||
'expanded' => false,
|
||||
'em' => 'default',
|
||||
'class' => self::COMPOSITE_IDENT_CLASS,
|
||||
'property' => 'name',
|
||||
'choice_label' => 'name',
|
||||
));
|
||||
|
||||
// because of the composite key collection keys are used
|
||||
@ -422,7 +422,7 @@ class EntityTypeTest extends TypeTestCase
|
||||
'expanded' => false,
|
||||
'em' => 'default',
|
||||
'class' => self::COMPOSITE_IDENT_CLASS,
|
||||
'property' => 'name',
|
||||
'choice_label' => 'name',
|
||||
));
|
||||
|
||||
$existing = new ArrayCollection(array(0 => $entity2));
|
||||
@ -452,7 +452,7 @@ class EntityTypeTest extends TypeTestCase
|
||||
'expanded' => true,
|
||||
'em' => 'default',
|
||||
'class' => self::SINGLE_IDENT_CLASS,
|
||||
'property' => 'name',
|
||||
'choice_label' => 'name',
|
||||
));
|
||||
|
||||
$field->submit('2');
|
||||
@ -478,7 +478,7 @@ class EntityTypeTest extends TypeTestCase
|
||||
'expanded' => true,
|
||||
'em' => 'default',
|
||||
'class' => self::SINGLE_IDENT_CLASS,
|
||||
'property' => 'name',
|
||||
'choice_label' => 'name',
|
||||
));
|
||||
|
||||
$field->submit(array('1', '3'));
|
||||
@ -508,7 +508,7 @@ class EntityTypeTest extends TypeTestCase
|
||||
'class' => self::SINGLE_IDENT_CLASS,
|
||||
// not all persisted entities should be displayed
|
||||
'choices' => array($entity1, $entity2),
|
||||
'property' => 'name',
|
||||
'choice_label' => 'name',
|
||||
));
|
||||
|
||||
$field->submit('2');
|
||||
@ -532,7 +532,7 @@ class EntityTypeTest extends TypeTestCase
|
||||
'em' => 'default',
|
||||
'class' => self::ITEM_GROUP_CLASS,
|
||||
'choices' => array($item1, $item2, $item3, $item4),
|
||||
'property' => 'name',
|
||||
'choice_label' => 'name',
|
||||
'group_by' => 'groupName',
|
||||
));
|
||||
|
||||
@ -563,7 +563,7 @@ class EntityTypeTest extends TypeTestCase
|
||||
'em' => 'default',
|
||||
'class' => self::SINGLE_IDENT_CLASS,
|
||||
'preferred_choices' => array($entity3, $entity2),
|
||||
'property' => 'name',
|
||||
'choice_label' => 'name',
|
||||
));
|
||||
|
||||
$this->assertEquals(array(3 => new ChoiceView('Baz', '3', $entity3), 2 => new ChoiceView('Bar', '2', $entity2)), $field->createView()->vars['preferred_choices']);
|
||||
@ -583,7 +583,7 @@ class EntityTypeTest extends TypeTestCase
|
||||
'class' => self::SINGLE_IDENT_CLASS,
|
||||
'choices' => array($entity2, $entity3),
|
||||
'preferred_choices' => array($entity3),
|
||||
'property' => 'name',
|
||||
'choice_label' => 'name',
|
||||
));
|
||||
|
||||
$this->assertEquals(array(3 => new ChoiceView('Baz', '3', $entity3)), $field->createView()->vars['preferred_choices']);
|
||||
@ -602,7 +602,7 @@ class EntityTypeTest extends TypeTestCase
|
||||
'em' => 'default',
|
||||
'class' => self::SINGLE_IDENT_CLASS,
|
||||
'choices' => array($entity1, $entity2),
|
||||
'property' => 'name',
|
||||
'choice_label' => 'name',
|
||||
));
|
||||
|
||||
$field->submit('3');
|
||||
@ -623,7 +623,7 @@ class EntityTypeTest extends TypeTestCase
|
||||
'em' => 'default',
|
||||
'class' => self::COMPOSITE_IDENT_CLASS,
|
||||
'choices' => array($entity1, $entity2),
|
||||
'property' => 'name',
|
||||
'choice_label' => 'name',
|
||||
));
|
||||
|
||||
$field->submit('2');
|
||||
@ -647,7 +647,7 @@ class EntityTypeTest extends TypeTestCase
|
||||
'class' => self::SINGLE_IDENT_CLASS,
|
||||
'query_builder' => $repository->createQueryBuilder('e')
|
||||
->where('e.id IN (1, 2)'),
|
||||
'property' => 'name',
|
||||
'choice_label' => 'name',
|
||||
));
|
||||
|
||||
$field->submit('3');
|
||||
@ -671,7 +671,7 @@ class EntityTypeTest extends TypeTestCase
|
||||
return $repository->createQueryBuilder('e')
|
||||
->where('e.id IN (1, 2)');
|
||||
},
|
||||
'property' => 'name',
|
||||
'choice_label' => 'name',
|
||||
));
|
||||
|
||||
$field->submit('3');
|
||||
@ -695,7 +695,7 @@ class EntityTypeTest extends TypeTestCase
|
||||
return $repository->createQueryBuilder('e')
|
||||
->where('e.id1 IN (10, 50)');
|
||||
},
|
||||
'property' => 'name',
|
||||
'choice_label' => 'name',
|
||||
));
|
||||
|
||||
$field->submit('2');
|
||||
@ -715,7 +715,7 @@ class EntityTypeTest extends TypeTestCase
|
||||
'expanded' => false,
|
||||
'em' => 'default',
|
||||
'class' => self::SINGLE_STRING_IDENT_CLASS,
|
||||
'property' => 'name',
|
||||
'choice_label' => 'name',
|
||||
));
|
||||
|
||||
$field->submit('foo');
|
||||
@ -736,7 +736,7 @@ class EntityTypeTest extends TypeTestCase
|
||||
'expanded' => false,
|
||||
'em' => 'default',
|
||||
'class' => self::COMPOSITE_STRING_IDENT_CLASS,
|
||||
'property' => 'name',
|
||||
'choice_label' => 'name',
|
||||
));
|
||||
|
||||
// the collection key is used here
|
||||
@ -760,7 +760,7 @@ class EntityTypeTest extends TypeTestCase
|
||||
$this->factory->createNamed('name', 'entity', null, array(
|
||||
'class' => self::SINGLE_IDENT_CLASS,
|
||||
'required' => false,
|
||||
'property' => 'name',
|
||||
'choice_label' => 'name',
|
||||
));
|
||||
}
|
||||
|
||||
@ -775,7 +775,7 @@ class EntityTypeTest extends TypeTestCase
|
||||
$this->factory->createNamed('name', 'entity', null, array(
|
||||
'em' => $this->em,
|
||||
'class' => self::SINGLE_IDENT_CLASS,
|
||||
'property' => 'name',
|
||||
'choice_label' => 'name',
|
||||
));
|
||||
}
|
||||
|
||||
@ -852,20 +852,42 @@ class EntityTypeTest extends TypeTestCase
|
||||
'em' => 'default',
|
||||
'class' => self::SINGLE_IDENT_CLASS,
|
||||
'required' => false,
|
||||
'property' => 'name',
|
||||
'choice_label' => 'name',
|
||||
));
|
||||
|
||||
$field2 = $this->factory->createNamed('name', 'entity', null, array(
|
||||
'em' => 'default',
|
||||
'class' => self::SINGLE_IDENT_CLASS,
|
||||
'required' => false,
|
||||
'property' => 'name',
|
||||
'choice_label' => 'name',
|
||||
));
|
||||
|
||||
$this->assertInstanceOf('Symfony\Component\Form\ChoiceList\ChoiceListInterface', $field1->getConfig()->getOption('choice_list'));
|
||||
$this->assertSame($field1->getConfig()->getOption('choice_list'), $field2->getConfig()->getOption('choice_list'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testLegacyPropertyOption()
|
||||
{
|
||||
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
|
||||
|
||||
$entity1 = new SingleIntIdEntity(1, 'Foo');
|
||||
$entity2 = new SingleIntIdEntity(2, 'Bar');
|
||||
|
||||
$this->persist(array($entity1, $entity2));
|
||||
|
||||
$field = $this->factory->createNamed('name', 'entity', null, array(
|
||||
'em' => 'default',
|
||||
'class' => self::SINGLE_IDENT_CLASS,
|
||||
'required' => false,
|
||||
'property' => 'name',
|
||||
));
|
||||
|
||||
$this->assertEquals(array(1 => new ChoiceView('Foo', '1', $entity1), 2 => new ChoiceView('Bar', '2', $entity2)), $field->createView()->vars['choices']);
|
||||
}
|
||||
|
||||
protected function createRegistryMock($name, $em)
|
||||
{
|
||||
$registry = $this->getMock('Doctrine\Common\Persistence\ManagerRegistry');
|
||||
|
@ -39,9 +39,6 @@ use Symfony\Component\Form\Exception\InvalidArgumentException;
|
||||
* ```
|
||||
*
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*
|
||||
* @deprecated Added for backwards compatibility in Symfony 2.7, to be removed
|
||||
* in Symfony 3.0. Use {@link ArrayChoiceList} instead.
|
||||
*/
|
||||
class ArrayKeyChoiceList extends ArrayChoiceList
|
||||
{
|
||||
@ -113,8 +110,6 @@ class ArrayKeyChoiceList extends ArrayChoiceList
|
||||
}
|
||||
|
||||
parent::__construct($choices, $value);
|
||||
|
||||
trigger_error('The '.__CLASS__.' class was added for backwards compatibility in version 2.7 and will be removed in 3.0. Use Symfony\Component\Form\ChoiceList\ArrayChoiceList instead.', E_USER_DEPRECATED);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -43,20 +43,12 @@ class ChoiceToValueTransformer implements DataTransformerInterface
|
||||
throw new TransformationFailedException('Expected a scalar.');
|
||||
}
|
||||
|
||||
// These are now valid ArrayChoiceList values, so we can return null
|
||||
// right away
|
||||
if ('' === $value || null === $value) {
|
||||
return;
|
||||
}
|
||||
|
||||
$choices = $this->choiceList->getChoicesForValues(array($value));
|
||||
$choices = $this->choiceList->getChoicesForValues(array((string) $value));
|
||||
|
||||
if (1 !== count($choices)) {
|
||||
throw new TransformationFailedException(sprintf('The choice "%s" does not exist or is not unique', $value));
|
||||
}
|
||||
|
||||
$choice = current($choices);
|
||||
|
||||
return '' === $choice ? null : $choice;
|
||||
return current($choices);
|
||||
}
|
||||
}
|
||||
|
@ -233,25 +233,6 @@ class ChoiceType extends AbstractType
|
||||
{
|
||||
$choiceListFactory = $this->choiceListFactory;
|
||||
|
||||
$choiceList = function (Options $options, $choiceList) use ($choiceListFactory) {
|
||||
if (null !== $options['choice_loader']) {
|
||||
return $choiceListFactory->createListFromLoader(
|
||||
$options['choice_loader'],
|
||||
$options['choice_value']
|
||||
);
|
||||
}
|
||||
|
||||
// Harden against NULL values (like in EntityType and ModelType)
|
||||
$choices = null !== $options['choices'] ? $options['choices'] : array();
|
||||
|
||||
// BC when choices are in the keys, not in the values
|
||||
if (!$options['choices_as_values']) {
|
||||
return $choiceListFactory->createListFromFlippedChoices($choices, $options['choice_value']);
|
||||
}
|
||||
|
||||
return $choiceListFactory->createListFromChoices($choices, $options['choice_value']);
|
||||
};
|
||||
|
||||
$emptyData = function (Options $options) {
|
||||
if ($options['multiple'] || $options['expanded']) {
|
||||
return array();
|
||||
@ -269,11 +250,29 @@ class ChoiceType extends AbstractType
|
||||
return $options['empty_value'];
|
||||
};
|
||||
|
||||
// deprecation note
|
||||
$choiceListNormalizer = function (Options $options, $choiceList) {
|
||||
trigger_error('The "choice_list" option is deprecated since version 2.7 and will be removed in 3.0. Use "choice_loader" instead.', E_USER_DEPRECATED);
|
||||
$choiceListNormalizer = function (Options $options, $choiceList) use ($choiceListFactory) {
|
||||
if ($choiceList) {
|
||||
trigger_error('The "choice_list" option is deprecated since version 2.7 and will be removed in 3.0. Use "choice_loader" instead.', E_USER_DEPRECATED);
|
||||
|
||||
return $choiceList;
|
||||
return $choiceList;
|
||||
}
|
||||
|
||||
if (null !== $options['choice_loader']) {
|
||||
return $choiceListFactory->createListFromLoader(
|
||||
$options['choice_loader'],
|
||||
$options['choice_value']
|
||||
);
|
||||
}
|
||||
|
||||
// Harden against NULL values (like in EntityType and ModelType)
|
||||
$choices = null !== $options['choices'] ? $options['choices'] : array();
|
||||
|
||||
// BC when choices are in the keys, not in the values
|
||||
if (!$options['choices_as_values']) {
|
||||
return $choiceListFactory->createListFromFlippedChoices($choices, $options['choice_value']);
|
||||
}
|
||||
|
||||
return $choiceListFactory->createListFromChoices($choices, $options['choice_value']);
|
||||
};
|
||||
|
||||
$placeholderNormalizer = function (Options $options, $placeholder) {
|
||||
@ -299,7 +298,7 @@ class ChoiceType extends AbstractType
|
||||
$resolver->setDefaults(array(
|
||||
'multiple' => false,
|
||||
'expanded' => false,
|
||||
'choice_list' => $choiceList, // deprecated
|
||||
'choice_list' => null, // deprecated
|
||||
'choices' => array(),
|
||||
'choices_as_values' => false,
|
||||
'choice_loader' => null,
|
||||
|
@ -123,6 +123,8 @@ abstract class AbstractChoiceListTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
|
||||
|
||||
parent::setUp();
|
||||
|
||||
$this->list = $this->createChoiceList();
|
||||
@ -151,19 +153,16 @@ abstract class AbstractChoiceListTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
}
|
||||
|
||||
public function testGetChoices()
|
||||
public function testLegacyGetChoices()
|
||||
{
|
||||
$this->assertSame($this->choices, $this->list->getChoices());
|
||||
}
|
||||
|
||||
public function testGetValues()
|
||||
public function testLegacyGetValues()
|
||||
{
|
||||
$this->assertSame($this->values, $this->list->getValues());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testLegacyGetIndicesForChoices()
|
||||
{
|
||||
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
|
||||
@ -172,9 +171,6 @@ abstract class AbstractChoiceListTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertSame(array($this->index1, $this->index2), $this->list->getIndicesForChoices($choices));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testLegacyGetIndicesForChoicesPreservesKeys()
|
||||
{
|
||||
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
|
||||
@ -183,9 +179,6 @@ abstract class AbstractChoiceListTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertSame(array(5 => $this->index1, 8 => $this->index2), $this->list->getIndicesForChoices($choices));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testLegacyGetIndicesForChoicesPreservesOrder()
|
||||
{
|
||||
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
|
||||
@ -194,9 +187,6 @@ abstract class AbstractChoiceListTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertSame(array($this->index2, $this->index1), $this->list->getIndicesForChoices($choices));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testLegacyGetIndicesForChoicesIgnoresNonExistingChoices()
|
||||
{
|
||||
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
|
||||
@ -205,9 +195,6 @@ abstract class AbstractChoiceListTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertSame(array($this->index1, $this->index2), $this->list->getIndicesForChoices($choices));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testLegacyGetIndicesForChoicesEmpty()
|
||||
{
|
||||
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
|
||||
@ -215,9 +202,6 @@ abstract class AbstractChoiceListTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertSame(array(), $this->list->getIndicesForChoices(array()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testLegacyGetIndicesForValues()
|
||||
{
|
||||
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
|
||||
@ -227,9 +211,6 @@ abstract class AbstractChoiceListTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertSame(array($this->index1, $this->index2), $this->list->getIndicesForValues($values));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testLegacyGetIndicesForValuesPreservesKeys()
|
||||
{
|
||||
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
|
||||
@ -239,9 +220,6 @@ abstract class AbstractChoiceListTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertSame(array(5 => $this->index1, 8 => $this->index2), $this->list->getIndicesForValues($values));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testLegacyGetIndicesForValuesPreservesOrder()
|
||||
{
|
||||
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
|
||||
@ -250,9 +228,6 @@ abstract class AbstractChoiceListTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertSame(array($this->index2, $this->index1), $this->list->getIndicesForValues($values));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testLegacyGetIndicesForValuesIgnoresNonExistingValues()
|
||||
{
|
||||
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
|
||||
@ -261,9 +236,6 @@ abstract class AbstractChoiceListTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertSame(array($this->index1, $this->index2), $this->list->getIndicesForValues($values));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testLegacyGetIndicesForValuesEmpty()
|
||||
{
|
||||
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
|
||||
@ -271,61 +243,61 @@ abstract class AbstractChoiceListTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertSame(array(), $this->list->getIndicesForValues(array()));
|
||||
}
|
||||
|
||||
public function testGetChoicesForValues()
|
||||
public function testLegacyGetChoicesForValues()
|
||||
{
|
||||
$values = array($this->value1, $this->value2);
|
||||
$this->assertSame(array($this->choice1, $this->choice2), $this->list->getChoicesForValues($values));
|
||||
}
|
||||
|
||||
public function testGetChoicesForValuesPreservesKeys()
|
||||
public function testLegacyGetChoicesForValuesPreservesKeys()
|
||||
{
|
||||
$values = array(5 => $this->value1, 8 => $this->value2);
|
||||
$this->assertSame(array(5 => $this->choice1, 8 => $this->choice2), $this->list->getChoicesForValues($values));
|
||||
}
|
||||
|
||||
public function testGetChoicesForValuesPreservesOrder()
|
||||
public function testLegacyGetChoicesForValuesPreservesOrder()
|
||||
{
|
||||
$values = array($this->value2, $this->value1);
|
||||
$this->assertSame(array($this->choice2, $this->choice1), $this->list->getChoicesForValues($values));
|
||||
}
|
||||
|
||||
public function testGetChoicesForValuesIgnoresNonExistingValues()
|
||||
public function testLegacyGetChoicesForValuesIgnoresNonExistingValues()
|
||||
{
|
||||
$values = array($this->value1, $this->value2, 'foobar');
|
||||
$this->assertSame(array($this->choice1, $this->choice2), $this->list->getChoicesForValues($values));
|
||||
}
|
||||
|
||||
// https://github.com/symfony/symfony/issues/3446
|
||||
public function testGetChoicesForValuesEmpty()
|
||||
public function testLegacyGetChoicesForValuesEmpty()
|
||||
{
|
||||
$this->assertSame(array(), $this->list->getChoicesForValues(array()));
|
||||
}
|
||||
|
||||
public function testGetValuesForChoices()
|
||||
public function testLegacyGetValuesForChoices()
|
||||
{
|
||||
$choices = array($this->choice1, $this->choice2);
|
||||
$this->assertSame(array($this->value1, $this->value2), $this->list->getValuesForChoices($choices));
|
||||
}
|
||||
|
||||
public function testGetValuesForChoicesPreservesKeys()
|
||||
public function testLegacyGetValuesForChoicesPreservesKeys()
|
||||
{
|
||||
$choices = array(5 => $this->choice1, 8 => $this->choice2);
|
||||
$this->assertSame(array(5 => $this->value1, 8 => $this->value2), $this->list->getValuesForChoices($choices));
|
||||
}
|
||||
|
||||
public function testGetValuesForChoicesPreservesOrder()
|
||||
public function testLegacyGetValuesForChoicesPreservesOrder()
|
||||
{
|
||||
$choices = array($this->choice2, $this->choice1);
|
||||
$this->assertSame(array($this->value2, $this->value1), $this->list->getValuesForChoices($choices));
|
||||
}
|
||||
|
||||
public function testGetValuesForChoicesIgnoresNonExistingChoices()
|
||||
public function testLegacyGetValuesForChoicesIgnoresNonExistingChoices()
|
||||
{
|
||||
$choices = array($this->choice1, $this->choice2, 'foobar');
|
||||
$this->assertSame(array($this->value1, $this->value2), $this->list->getValuesForChoices($choices));
|
||||
}
|
||||
|
||||
public function testGetValuesForChoicesEmpty()
|
||||
public function testLegacyGetValuesForChoicesEmpty()
|
||||
{
|
||||
$this->assertSame(array(), $this->list->getValuesForChoices(array()));
|
||||
}
|
||||
|
@ -14,6 +14,9 @@ namespace Symfony\Component\Form\Tests\Extension\Core\ChoiceList;
|
||||
use Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceList;
|
||||
use Symfony\Component\Form\Extension\Core\View\ChoiceView;
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
class ChoiceListTest extends AbstractChoiceListTest
|
||||
{
|
||||
private $obj1;
|
||||
@ -34,7 +37,7 @@ class ChoiceListTest extends AbstractChoiceListTest
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
public function testInitArray()
|
||||
public function testLegacyInitArray()
|
||||
{
|
||||
$this->list = new ChoiceList(
|
||||
array($this->obj1, $this->obj2, $this->obj3, $this->obj4),
|
||||
@ -53,7 +56,7 @@ class ChoiceListTest extends AbstractChoiceListTest
|
||||
* choices parameter. A choice itself that is an object implementing \Traversable
|
||||
* is not treated as hierarchical structure, but as-is.
|
||||
*/
|
||||
public function testInitNestedTraversable()
|
||||
public function testLegacyInitNestedTraversable()
|
||||
{
|
||||
$traversableChoice = new \ArrayIterator(array($this->obj3, $this->obj4));
|
||||
|
||||
@ -80,7 +83,7 @@ class ChoiceListTest extends AbstractChoiceListTest
|
||||
), $this->list->getRemainingViews());
|
||||
}
|
||||
|
||||
public function testInitNestedArray()
|
||||
public function testLegacyInitNestedArray()
|
||||
{
|
||||
$this->assertSame(array($this->obj1, $this->obj2, $this->obj3, $this->obj4), $this->list->getChoices());
|
||||
$this->assertSame(array('0', '1', '2', '3'), $this->list->getValues());
|
||||
@ -97,7 +100,7 @@ class ChoiceListTest extends AbstractChoiceListTest
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testInitWithInsufficientLabels()
|
||||
public function testLegacyInitWithInsufficientLabels()
|
||||
{
|
||||
$this->list = new ChoiceList(
|
||||
array($this->obj1, $this->obj2),
|
||||
@ -105,7 +108,7 @@ class ChoiceListTest extends AbstractChoiceListTest
|
||||
);
|
||||
}
|
||||
|
||||
public function testInitWithLabelsContainingNull()
|
||||
public function testLegacyInitWithLabelsContainingNull()
|
||||
{
|
||||
$this->list = new ChoiceList(
|
||||
array($this->obj1, $this->obj2),
|
||||
|
@ -15,8 +15,14 @@ use Symfony\Component\Form\Extension\Core\ChoiceList\SimpleChoiceList;
|
||||
use Symfony\Component\Form\Extension\Core\ChoiceList\LazyChoiceList;
|
||||
use Symfony\Component\Form\Extension\Core\View\ChoiceView;
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
class LazyChoiceListTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var LazyChoiceListTest_Impl
|
||||
*/
|
||||
private $list;
|
||||
|
||||
protected function setUp()
|
||||
@ -37,22 +43,22 @@ class LazyChoiceListTest extends \PHPUnit_Framework_TestCase
|
||||
$this->list = null;
|
||||
}
|
||||
|
||||
public function testGetChoices()
|
||||
public function testLegacyGetChoices()
|
||||
{
|
||||
$this->assertSame(array(0 => 'a', 1 => 'b', 2 => 'c'), $this->list->getChoices());
|
||||
}
|
||||
|
||||
public function testGetValues()
|
||||
public function testLegacyGetValues()
|
||||
{
|
||||
$this->assertSame(array(0 => 'a', 1 => 'b', 2 => 'c'), $this->list->getValues());
|
||||
}
|
||||
|
||||
public function testGetPreferredViews()
|
||||
public function testLegacyGetPreferredViews()
|
||||
{
|
||||
$this->assertEquals(array(1 => new ChoiceView('b', 'b', 'B')), $this->list->getPreferredViews());
|
||||
}
|
||||
|
||||
public function testGetRemainingViews()
|
||||
public function testLegacyGetRemainingViews()
|
||||
{
|
||||
$this->assertEquals(array(0 => new ChoiceView('a', 'a', 'A'), 2 => new ChoiceView('c', 'c', 'C')), $this->list->getRemainingViews());
|
||||
}
|
||||
@ -79,13 +85,13 @@ class LazyChoiceListTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertSame(array(1, 2), $this->list->getIndicesForValues($values));
|
||||
}
|
||||
|
||||
public function testGetChoicesForValues()
|
||||
public function testLegacyGetChoicesForValues()
|
||||
{
|
||||
$values = array('b', 'c');
|
||||
$this->assertSame(array('b', 'c'), $this->list->getChoicesForValues($values));
|
||||
}
|
||||
|
||||
public function testGetValuesForChoices()
|
||||
public function testLegacyGetValuesForChoices()
|
||||
{
|
||||
$choices = array('b', 'c');
|
||||
$this->assertSame(array('b', 'c'), $this->list->getValuesForChoices($choices));
|
||||
@ -94,7 +100,7 @@ class LazyChoiceListTest extends \PHPUnit_Framework_TestCase
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Form\Exception\InvalidArgumentException
|
||||
*/
|
||||
public function testLoadChoiceListShouldReturnChoiceList()
|
||||
public function testLegacyLoadChoiceListShouldReturnChoiceList()
|
||||
{
|
||||
$list = new LazyChoiceListTest_InvalidImpl();
|
||||
|
||||
|
@ -29,6 +29,9 @@ class ObjectChoiceListTest_EntityWithToString
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
class ObjectChoiceListTest extends AbstractChoiceListTest
|
||||
{
|
||||
private $obj1;
|
||||
@ -49,7 +52,7 @@ class ObjectChoiceListTest extends AbstractChoiceListTest
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
public function testInitArray()
|
||||
public function testLegacyInitArray()
|
||||
{
|
||||
$this->list = new ObjectChoiceList(
|
||||
array($this->obj1, $this->obj2, $this->obj3, $this->obj4),
|
||||
@ -63,7 +66,7 @@ class ObjectChoiceListTest extends AbstractChoiceListTest
|
||||
$this->assertEquals(array(0 => new ChoiceView($this->obj1, '0', 'A'), 2 => new ChoiceView($this->obj3, '2', 'C'), 3 => new ChoiceView($this->obj4, '3', 'D')), $this->list->getRemainingViews());
|
||||
}
|
||||
|
||||
public function testInitNestedArray()
|
||||
public function testLegacyInitNestedArray()
|
||||
{
|
||||
$this->assertSame(array($this->obj1, $this->obj2, $this->obj3, $this->obj4), $this->list->getChoices());
|
||||
$this->assertSame(array('0', '1', '2', '3'), $this->list->getValues());
|
||||
@ -77,7 +80,7 @@ class ObjectChoiceListTest extends AbstractChoiceListTest
|
||||
), $this->list->getRemainingViews());
|
||||
}
|
||||
|
||||
public function testInitArrayWithGroupPath()
|
||||
public function testLegacyInitArrayWithGroupPath()
|
||||
{
|
||||
$this->obj1 = (object) array('name' => 'A', 'category' => 'Group 1');
|
||||
$this->obj2 = (object) array('name' => 'B', 'category' => 'Group 1');
|
||||
@ -115,7 +118,7 @@ class ObjectChoiceListTest extends AbstractChoiceListTest
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testInitArrayWithGroupPathThrowsExceptionIfNestedArray()
|
||||
public function testLegacyInitArrayWithGroupPathThrowsExceptionIfNestedArray()
|
||||
{
|
||||
$this->obj1 = (object) array('name' => 'A', 'category' => 'Group 1');
|
||||
$this->obj2 = (object) array('name' => 'B', 'category' => 'Group 1');
|
||||
@ -133,7 +136,7 @@ class ObjectChoiceListTest extends AbstractChoiceListTest
|
||||
);
|
||||
}
|
||||
|
||||
public function testInitArrayWithValuePath()
|
||||
public function testLegacyInitArrayWithValuePath()
|
||||
{
|
||||
$this->obj1 = (object) array('name' => 'A', 'id' => 10);
|
||||
$this->obj2 = (object) array('name' => 'B', 'id' => 20);
|
||||
@ -154,7 +157,7 @@ class ObjectChoiceListTest extends AbstractChoiceListTest
|
||||
$this->assertEquals(array(0 => new ChoiceView($this->obj1, '10', 'A'), 3 => new ChoiceView($this->obj4, '40', 'D')), $this->list->getRemainingViews());
|
||||
}
|
||||
|
||||
public function testInitArrayUsesToString()
|
||||
public function testLegacyInitArrayUsesToString()
|
||||
{
|
||||
$this->obj1 = new ObjectChoiceListTest_EntityWithToString('A');
|
||||
$this->obj2 = new ObjectChoiceListTest_EntityWithToString('B');
|
||||
@ -173,7 +176,7 @@ class ObjectChoiceListTest extends AbstractChoiceListTest
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Form\Exception\StringCastException
|
||||
*/
|
||||
public function testInitArrayThrowsExceptionIfToStringNotFound()
|
||||
public function testLegacyInitArrayThrowsExceptionIfToStringNotFound()
|
||||
{
|
||||
$this->obj1 = new ObjectChoiceListTest_EntityWithToString('A');
|
||||
$this->obj2 = new ObjectChoiceListTest_EntityWithToString('B');
|
||||
@ -262,7 +265,7 @@ class ObjectChoiceListTest extends AbstractChoiceListTest
|
||||
$this->assertSame(array($this->index1, $this->index2), $this->list->getIndicesForChoices($choices));
|
||||
}
|
||||
|
||||
public function testGetValuesForChoicesWithValuePath()
|
||||
public function testLegacyGetValuesForChoicesWithValuePath()
|
||||
{
|
||||
$this->list = new ObjectChoiceList(
|
||||
array($this->obj1, $this->obj2, $this->obj3, $this->obj4),
|
||||
@ -276,7 +279,7 @@ class ObjectChoiceListTest extends AbstractChoiceListTest
|
||||
$this->assertSame(array('A', 'B'), $this->list->getValuesForChoices($choices));
|
||||
}
|
||||
|
||||
public function testGetValuesForChoicesWithValuePathPreservesKeys()
|
||||
public function testLegacyGetValuesForChoicesWithValuePathPreservesKeys()
|
||||
{
|
||||
$this->list = new ObjectChoiceList(
|
||||
array($this->obj1, $this->obj2, $this->obj3, $this->obj4),
|
||||
@ -290,7 +293,7 @@ class ObjectChoiceListTest extends AbstractChoiceListTest
|
||||
$this->assertSame(array(5 => 'A', 8 => 'B'), $this->list->getValuesForChoices($choices));
|
||||
}
|
||||
|
||||
public function testGetValuesForChoicesWithValuePathPreservesOrder()
|
||||
public function testLegacyGetValuesForChoicesWithValuePathPreservesOrder()
|
||||
{
|
||||
$this->list = new ObjectChoiceList(
|
||||
array($this->obj1, $this->obj2, $this->obj3, $this->obj4),
|
||||
@ -304,7 +307,7 @@ class ObjectChoiceListTest extends AbstractChoiceListTest
|
||||
$this->assertSame(array('B', 'A'), $this->list->getValuesForChoices($choices));
|
||||
}
|
||||
|
||||
public function testGetValuesForChoicesWithValuePathIgnoresNonExistingChoices()
|
||||
public function testLegacyGetValuesForChoicesWithValuePathIgnoresNonExistingChoices()
|
||||
{
|
||||
$this->list = new ObjectChoiceList(
|
||||
array($this->obj1, $this->obj2, $this->obj3, $this->obj4),
|
||||
|
@ -14,9 +14,12 @@ namespace Symfony\Component\Form\Tests\Extension\Core\ChoiceList;
|
||||
use Symfony\Component\Form\Extension\Core\ChoiceList\SimpleChoiceList;
|
||||
use Symfony\Component\Form\Extension\Core\View\ChoiceView;
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
class SimpleChoiceListTest extends AbstractChoiceListTest
|
||||
{
|
||||
public function testInitArray()
|
||||
public function testLegacyInitArray()
|
||||
{
|
||||
$choices = array('a' => 'A', 'b' => 'B', 'c' => 'C');
|
||||
$this->list = new SimpleChoiceList($choices, array('b'));
|
||||
@ -27,7 +30,7 @@ class SimpleChoiceListTest extends AbstractChoiceListTest
|
||||
$this->assertEquals(array(0 => new ChoiceView('a', 'a', 'A'), 2 => new ChoiceView('c', 'c', 'C')), $this->list->getRemainingViews());
|
||||
}
|
||||
|
||||
public function testInitNestedArray()
|
||||
public function testLegacyInitNestedArray()
|
||||
{
|
||||
$this->assertSame(array(0 => 'a', 1 => 'b', 2 => 'c', 3 => 'd'), $this->list->getChoices());
|
||||
$this->assertSame(array(0 => 'a', 1 => 'b', 2 => 'c', 3 => 'd'), $this->list->getValues());
|
||||
@ -44,7 +47,7 @@ class SimpleChoiceListTest extends AbstractChoiceListTest
|
||||
/**
|
||||
* @dataProvider dirtyValuesProvider
|
||||
*/
|
||||
public function testGetValuesForChoicesDealsWithDirtyValues($choice, $value)
|
||||
public function testLegacyGetValuesForChoicesDealsWithDirtyValues($choice, $value)
|
||||
{
|
||||
$choices = array(
|
||||
'0' => 'Zero',
|
||||
|
@ -13,11 +13,11 @@ namespace Symfony\Component\Form\Tests\Extension\Core\ChoiceList;
|
||||
|
||||
use Symfony\Component\Form\Extension\Core\ChoiceList\SimpleChoiceList;
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
class SimpleNumericChoiceListTest extends AbstractChoiceListTest
|
||||
{
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testLegacyGetIndicesForChoicesDealsWithNumericChoices()
|
||||
{
|
||||
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
|
||||
@ -27,9 +27,6 @@ class SimpleNumericChoiceListTest extends AbstractChoiceListTest
|
||||
$this->assertSame(array(0, 1), $this->list->getIndicesForChoices($choices));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testLegacyGetIndicesForValuesDealsWithNumericValues()
|
||||
{
|
||||
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
|
||||
@ -39,14 +36,14 @@ class SimpleNumericChoiceListTest extends AbstractChoiceListTest
|
||||
$this->assertSame(array(0, 1), $this->list->getIndicesForValues($values));
|
||||
}
|
||||
|
||||
public function testGetChoicesForValuesDealsWithNumericValues()
|
||||
public function testLegacyGetChoicesForValuesDealsWithNumericValues()
|
||||
{
|
||||
// Pass values as strings although they are integers
|
||||
$values = array('0', '1');
|
||||
$this->assertSame(array(0, 1), $this->list->getChoicesForValues($values));
|
||||
}
|
||||
|
||||
public function testGetValuesForChoicesDealsWithNumericValues()
|
||||
public function testLegacyGetValuesForChoicesDealsWithNumericValues()
|
||||
{
|
||||
// Pass values as strings although they are integers
|
||||
$values = array('0', '1');
|
||||
|
@ -11,7 +11,7 @@
|
||||
|
||||
namespace Symfony\Component\Form\Tests\Extension\Core\DataTransformer;
|
||||
|
||||
use Symfony\Component\Form\Extension\Core\ChoiceList\SimpleChoiceList;
|
||||
use Symfony\Component\Form\ChoiceList\ArrayChoiceList;
|
||||
use Symfony\Component\Form\Extension\Core\DataTransformer\ChoiceToValueTransformer;
|
||||
|
||||
class ChoiceToValueTransformerTest extends \PHPUnit_Framework_TestCase
|
||||
@ -20,7 +20,8 @@ class ChoiceToValueTransformerTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$list = new SimpleChoiceList(array('' => 'A', 0 => 'B', 1 => 'C'));
|
||||
$list = new ArrayChoiceList(array('', 0, 'X'));
|
||||
|
||||
$this->transformer = new ChoiceToValueTransformer($list);
|
||||
}
|
||||
|
||||
@ -33,9 +34,8 @@ class ChoiceToValueTransformerTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
return array(
|
||||
// more extensive test set can be found in FormUtilTest
|
||||
array(0, '0'),
|
||||
array(false, '0'),
|
||||
array('', ''),
|
||||
array('', '0'),
|
||||
array(0, '1'),
|
||||
);
|
||||
}
|
||||
|
||||
@ -52,9 +52,9 @@ class ChoiceToValueTransformerTest extends \PHPUnit_Framework_TestCase
|
||||
return array(
|
||||
// values are expected to be valid choice keys already and stay
|
||||
// the same
|
||||
array('0', 0),
|
||||
array('', null),
|
||||
array(null, null),
|
||||
array('0', ''),
|
||||
array('1', 0),
|
||||
array('2', 'X'),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -11,7 +11,7 @@
|
||||
|
||||
namespace Symfony\Component\Form\Tests\Extension\Core\DataTransformer;
|
||||
|
||||
use Symfony\Component\Form\Extension\Core\ChoiceList\SimpleChoiceList;
|
||||
use Symfony\Component\Form\ChoiceList\ArrayChoiceList;
|
||||
use Symfony\Component\Form\Extension\Core\DataTransformer\ChoicesToValuesTransformer;
|
||||
|
||||
class ChoicesToValuesTransformerTest extends \PHPUnit_Framework_TestCase
|
||||
@ -20,7 +20,7 @@ class ChoicesToValuesTransformerTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$list = new SimpleChoiceList(array(0 => 'A', 1 => 'B', 2 => 'C'));
|
||||
$list = new ArrayChoiceList(array('A', 'B', 'C'));
|
||||
$this->transformer = new ChoicesToValuesTransformer($list);
|
||||
}
|
||||
|
||||
@ -31,8 +31,7 @@ class ChoicesToValuesTransformerTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testTransform()
|
||||
{
|
||||
// Value strategy in SimpleChoiceList is to copy and convert to string
|
||||
$in = array(0, 1, 2);
|
||||
$in = array('A', 'B', 'C');
|
||||
$out = array('0', '1', '2');
|
||||
|
||||
$this->assertSame($out, $this->transformer->transform($in));
|
||||
@ -55,7 +54,7 @@ class ChoicesToValuesTransformerTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
// values are expected to be valid choices and stay the same
|
||||
$in = array('0', '1', '2');
|
||||
$out = array(0, 1, 2);
|
||||
$out = array('A', 'B', 'C');
|
||||
|
||||
$this->assertSame($out, $this->transformer->reverseTransform($in));
|
||||
}
|
||||
|
@ -15,12 +15,17 @@ use Symfony\Component\Form\FormEvent;
|
||||
use Symfony\Component\Form\Extension\Core\EventListener\FixRadioInputListener;
|
||||
use Symfony\Component\Form\Extension\Core\ChoiceList\SimpleChoiceList;
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
class FixRadioInputListenerTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
private $choiceList;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
|
||||
|
||||
parent::setUp();
|
||||
|
||||
$this->choiceList = new SimpleChoiceList(array('' => 'Empty', 0 => 'A', 1 => 'B'));
|
||||
@ -33,7 +38,7 @@ class FixRadioInputListenerTest extends \PHPUnit_Framework_TestCase
|
||||
$listener = null;
|
||||
}
|
||||
|
||||
public function testFixRadio()
|
||||
public function testLegacyFixRadio()
|
||||
{
|
||||
$data = '1';
|
||||
$form = $this->getMock('Symfony\Component\Form\Test\FormInterface');
|
||||
@ -46,7 +51,7 @@ class FixRadioInputListenerTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals(array(2 => '1'), $event->getData());
|
||||
}
|
||||
|
||||
public function testFixZero()
|
||||
public function testLegacyFixZero()
|
||||
{
|
||||
$data = '0';
|
||||
$form = $this->getMock('Symfony\Component\Form\Test\FormInterface');
|
||||
@ -59,7 +64,7 @@ class FixRadioInputListenerTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals(array(1 => '0'), $event->getData());
|
||||
}
|
||||
|
||||
public function testFixEmptyString()
|
||||
public function testLegacyFixEmptyString()
|
||||
{
|
||||
$data = '';
|
||||
$form = $this->getMock('Symfony\Component\Form\Test\FormInterface');
|
||||
@ -72,7 +77,7 @@ class FixRadioInputListenerTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals(array(0 => ''), $event->getData());
|
||||
}
|
||||
|
||||
public function testConvertEmptyStringToPlaceholderIfNotFound()
|
||||
public function testLegacyConvertEmptyStringToPlaceholderIfNotFound()
|
||||
{
|
||||
$list = new SimpleChoiceList(array(0 => 'A', 1 => 'B'));
|
||||
|
||||
@ -86,7 +91,7 @@ class FixRadioInputListenerTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals(array('placeholder' => ''), $event->getData());
|
||||
}
|
||||
|
||||
public function testDontConvertEmptyStringToPlaceholderIfNoPlaceholderUsed()
|
||||
public function testLegacyDontConvertEmptyStringToPlaceholderIfNoPlaceholderUsed()
|
||||
{
|
||||
$list = new SimpleChoiceList(array(0 => 'A', 1 => 'B'));
|
||||
|
||||
|
@ -368,8 +368,13 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
|
||||
$this->assertEquals('2', $form->getViewData());
|
||||
}
|
||||
|
||||
public function testSubmitSingleNonExpandedObjectChoicesBc()
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testLegacySubmitSingleNonExpandedObjectChoices()
|
||||
{
|
||||
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
|
||||
|
||||
$form = $this->factory->create('choice', null, array(
|
||||
'multiple' => false,
|
||||
'expanded' => false,
|
||||
@ -483,8 +488,13 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
|
||||
$this->assertEquals(array('2', '3'), $form->getViewData());
|
||||
}
|
||||
|
||||
public function testSubmitMultipleNonExpandedObjectChoicesBc()
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testLegacySubmitMultipleNonExpandedObjectChoices()
|
||||
{
|
||||
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
|
||||
|
||||
$form = $this->factory->create('choice', null, array(
|
||||
'multiple' => true,
|
||||
'expanded' => false,
|
||||
@ -959,8 +969,13 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
|
||||
$this->assertNull($form[4]->getViewData());
|
||||
}
|
||||
|
||||
public function testSubmitSingleExpandedObjectChoicesBc()
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testLegacySubmitSingleExpandedObjectChoices()
|
||||
{
|
||||
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
|
||||
|
||||
$form = $this->factory->create('choice', null, array(
|
||||
'multiple' => false,
|
||||
'expanded' => true,
|
||||
@ -1182,8 +1197,13 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
|
||||
$this->assertNull($form[4]->getViewData());
|
||||
}
|
||||
|
||||
public function testSubmitMultipleExpandedObjectChoicesBc()
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testLegacySubmitMultipleExpandedObjectChoices()
|
||||
{
|
||||
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
|
||||
|
||||
$form = $this->factory->create('choice', null, array(
|
||||
'multiple' => true,
|
||||
'expanded' => true,
|
||||
|
Reference in New Issue
Block a user