Added group_by test for EntityType
This commit is contained in:
parent
882482a308
commit
7ad0f0527b
@ -12,6 +12,7 @@
|
||||
namespace Symfony\Tests\Bridge\Doctrine\Form\Type;
|
||||
|
||||
require_once __DIR__.'/../DoctrineOrmTestCase.php';
|
||||
require_once __DIR__.'/../../Fixtures/ItemGroupEntity.php';
|
||||
require_once __DIR__.'/../../Fixtures/SingleIdentEntity.php';
|
||||
require_once __DIR__.'/../../Fixtures/SingleStringIdentEntity.php';
|
||||
require_once __DIR__.'/../../Fixtures/CompositeIdentEntity.php';
|
||||
@ -20,6 +21,7 @@ require_once __DIR__.'/../../Fixtures/CompositeStringIdentEntity.php';
|
||||
use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
||||
use Symfony\Tests\Component\Form\Extension\Core\Type\TypeTestCase;
|
||||
use Symfony\Tests\Bridge\Doctrine\Form\DoctrineOrmTestCase;
|
||||
use Symfony\Tests\Bridge\Doctrine\Form\Fixtures\ItemGroupEntity;
|
||||
use Symfony\Tests\Bridge\Doctrine\Form\Fixtures\SingleIdentEntity;
|
||||
use Symfony\Tests\Bridge\Doctrine\Form\Fixtures\SingleStringIdentEntity;
|
||||
use Symfony\Tests\Bridge\Doctrine\Form\Fixtures\CompositeIdentEntity;
|
||||
@ -31,6 +33,7 @@ use Doctrine\Common\Collections\ArrayCollection;
|
||||
|
||||
class EntityTypeTest extends TypeTestCase
|
||||
{
|
||||
const ITEM_GROUP_CLASS = 'Symfony\Tests\Bridge\Doctrine\Form\Fixtures\ItemGroupEntity';
|
||||
const SINGLE_IDENT_CLASS = 'Symfony\Tests\Bridge\Doctrine\Form\Fixtures\SingleIdentEntity';
|
||||
const SINGLE_STRING_IDENT_CLASS = 'Symfony\Tests\Bridge\Doctrine\Form\Fixtures\SingleStringIdentEntity';
|
||||
const COMPOSITE_IDENT_CLASS = 'Symfony\Tests\Bridge\Doctrine\Form\Fixtures\CompositeIdentEntity';
|
||||
@ -50,6 +53,7 @@ class EntityTypeTest extends TypeTestCase
|
||||
|
||||
$schemaTool = new SchemaTool($this->em);
|
||||
$classes = array(
|
||||
$this->em->getClassMetadata(self::ITEM_GROUP_CLASS),
|
||||
$this->em->getClassMetadata(self::SINGLE_IDENT_CLASS),
|
||||
$this->em->getClassMetadata(self::SINGLE_STRING_IDENT_CLASS),
|
||||
$this->em->getClassMetadata(self::COMPOSITE_IDENT_CLASS),
|
||||
@ -461,6 +465,33 @@ class EntityTypeTest extends TypeTestCase
|
||||
$this->assertEquals(2, $field->getClientData());
|
||||
}
|
||||
|
||||
public function testGroupByChoices()
|
||||
{
|
||||
$item1 = new ItemGroupEntity(1, 'Foo', 'Group1');
|
||||
$item2 = new ItemGroupEntity(2, 'Bar', 'Group1');
|
||||
$item3 = new ItemGroupEntity(3, 'Baz', 'Group2');
|
||||
$item4 = new ItemGroupEntity(4, 'Boo!', null);
|
||||
|
||||
$this->persist(array($item1, $item2, $item3, $item4));
|
||||
|
||||
$field = $this->factory->createNamed('entity', 'name', null, array(
|
||||
'em' => 'default',
|
||||
'class' => self::ITEM_GROUP_CLASS,
|
||||
'choices' => array($item1, $item2, $item3, $item4),
|
||||
'property' => 'name',
|
||||
'group_by' => 'group_name',
|
||||
));
|
||||
|
||||
$field->bind('2');
|
||||
|
||||
$this->assertEquals(2, $field->getClientData());
|
||||
$this->assertEquals(array(
|
||||
'Group1' => array(1 => 'Foo', '2' => 'Bar'),
|
||||
'Group2' => array(3 => 'Baz'),
|
||||
'4' => 'Boo!'
|
||||
), $field->createView()->get('choices'));
|
||||
}
|
||||
|
||||
public function testDisallowChoicesThatAreNotIncluded_choicesSingleIdentifier()
|
||||
{
|
||||
$entity1 = new SingleIdentEntity(1, 'Foo');
|
||||
|
Reference in New Issue
Block a user