-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Form] [DoctrineBridge] added a failing test for EntityType #15328
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
The new test uses an entity whose primary key is a foreign key to another entity (an "association key"), as described here: http://doctrine-orm.readthedocs.org/en/latest/tutorials/composite-primary-keys.html#identity-through-foreign-entities
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Bridge\Doctrine\Tests\Fixtures; | ||
|
||
use Doctrine\ORM\Mapping AS ORM; | ||
|
||
/** | ||
* An entity whose primary key is a foreign key to another entity. | ||
* | ||
* @see http://doctrine-orm.readthedocs.org/en/latest/tutorials/composite-primary-keys.html#use-case-2-simple-derived-identity | ||
* @ORM\Entity | ||
*/ | ||
class AssociationKeyEntity | ||
{ | ||
/** | ||
* @ORM\Id @ORM\OneToOne(targetEntity="SingleIntIdEntity") | ||
* @var SingleIntIdEntity | ||
*/ | ||
public $single; | ||
|
||
/** | ||
* AssociationKeyEntity constructor. | ||
* @param SingleIntIdEntity $single | ||
*/ | ||
public function __construct(SingleIntIdEntity $single) | ||
{ | ||
$this->single = $single; | ||
} | ||
|
||
public function getName() | ||
{ | ||
return $this->single->name; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
use Symfony\Bridge\Doctrine\Form\DoctrineOrmTypeGuesser; | ||
use Symfony\Bridge\Doctrine\Form\Type\EntityType; | ||
use Symfony\Bridge\Doctrine\Test\DoctrineTestHelper; | ||
use Symfony\Bridge\Doctrine\Tests\Fixtures\AssociationKeyEntity; | ||
use Symfony\Bridge\Doctrine\Tests\Fixtures\CompositeIntIdEntity; | ||
use Symfony\Bridge\Doctrine\Tests\Fixtures\CompositeStringIdEntity; | ||
use Symfony\Bridge\Doctrine\Tests\Fixtures\GroupableEntity; | ||
|
@@ -42,6 +43,7 @@ class EntityTypeTest extends TypeTestCase | |
const SINGLE_ASSOC_IDENT_CLASS = 'Symfony\Bridge\Doctrine\Tests\Fixtures\SingleAssociationToIntIdEntity'; | ||
const COMPOSITE_IDENT_CLASS = 'Symfony\Bridge\Doctrine\Tests\Fixtures\CompositeIntIdEntity'; | ||
const COMPOSITE_STRING_IDENT_CLASS = 'Symfony\Bridge\Doctrine\Tests\Fixtures\CompositeStringIdEntity'; | ||
const ASSOCIATION_KEY_CLASS = 'Symfony\Bridge\Doctrine\Tests\Fixtures\AssociationKeyEntity'; | ||
|
||
/** | ||
* @var EntityManager | ||
|
@@ -69,6 +71,7 @@ protected function setUp() | |
$this->em->getClassMetadata(self::SINGLE_ASSOC_IDENT_CLASS), | ||
$this->em->getClassMetadata(self::COMPOSITE_IDENT_CLASS), | ||
$this->em->getClassMetadata(self::COMPOSITE_STRING_IDENT_CLASS), | ||
$this->em->getClassMetadata(self::ASSOCIATION_KEY_CLASS), | ||
); | ||
|
||
try { | ||
|
@@ -580,6 +583,26 @@ public function testSubmitMultipleExpandedWithNegativeIntegerId() | |
$this->assertFalse($field['2']->getData()); | ||
} | ||
|
||
public function testSubmitAssociationKey() | ||
{ | ||
$single = new SingleIntIdEntity(1, 'Foo'); | ||
$assoc = new AssociationKeyEntity($single); | ||
|
||
$this->persist(array($single, $assoc)); | ||
|
||
$field = $this->factory->createNamed('name', 'entity', null, array( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "entity" needs to be replaced by the entity form type FQCN There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hm, actually that only needs to be changed in 2.8 where this has been deprecated. So the merger would need to make the changes. |
||
'multiple' => false, | ||
'expanded' => false, | ||
'em' => 'default', | ||
'class' => self::ASSOCIATION_KEY_CLASS, | ||
'choice_label' => 'name', | ||
)); | ||
|
||
$field->submit('1'); | ||
|
||
$this->assertSame($assoc, $field->getData()); | ||
} | ||
|
||
public function testOverrideChoices() | ||
{ | ||
$entity1 = new SingleIntIdEntity(1, 'Foo'); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please put on separate lines