Skip to content

Commit

Permalink
Merge branch '3.4' into 4.4
Browse files Browse the repository at this point in the history
* 3.4:
  [FrameworkBundle] fix "samesite" in XSD
  Update UserPasswordEncoderCommand.php
  [HttpFoundation][FrameworkBundle] fix support for samesite in session cookies
  [DoctrineBridge] Fixed submitting ids with query limit or offset
  • Loading branch information
nicolas-grekas committed Feb 7, 2020
2 parents b8d4311 + ab4a513 commit 0cc1d00
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Form/ChoiceList/ORMQueryBuilderLoader.php
Expand Up @@ -57,7 +57,7 @@ public function getEntitiesByIds($identifier, array $values)
$metadata = $this->queryBuilder->getEntityManager()->getClassMetadata(current($this->queryBuilder->getRootEntities()));

foreach ($this->getEntities() as $entity) {
if (\in_array(current($metadata->getIdentifierValues($entity)), $values, true)) {
if (\in_array((string) current($metadata->getIdentifierValues($entity)), $values, true)) {
$choices[] = $entity;
}
}
Expand Down
27 changes: 26 additions & 1 deletion Tests/Form/Type/EntityTypeTest.php
Expand Up @@ -953,7 +953,32 @@ public function testDisallowChoicesThatAreNotIncludedQueryBuilderSingleIdentifie
$this->assertNull($field->getData());
}

public function testDisallowChoicesThatAreNotIncludedQueryBuilderSingleIdentifierWithLimit()
public function testSingleIdentifierWithLimit()
{
$entity1 = new SingleIntIdEntity(1, 'Foo');
$entity2 = new SingleIntIdEntity(2, 'Bar');
$entity3 = new SingleIntIdEntity(3, 'Baz');

$this->persist([$entity1, $entity2, $entity3]);

$repository = $this->em->getRepository(self::SINGLE_IDENT_CLASS);

$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, [
'em' => 'default',
'class' => self::SINGLE_IDENT_CLASS,
'query_builder' => $repository->createQueryBuilder('e')
->where('e.id IN (1, 2, 3)')
->setMaxResults(1),
'choice_label' => 'name',
]);

$field->submit('1');

$this->assertTrue($field->isSynchronized());
$this->assertSame($entity1, $field->getData());
}

public function testDisallowChoicesThatAreNotIncludedByQueryBuilderSingleIdentifierWithLimit()
{
$entity1 = new SingleIntIdEntity(1, 'Foo');
$entity2 = new SingleIntIdEntity(2, 'Bar');
Expand Down

0 comments on commit 0cc1d00

Please sign in to comment.