Merge branch '2.8' into 3.3
* 2.8: [DomCrawler] Fix conversion to int on GetPhpFiles Filtering empty uuids in ORMQueryBuilderLoader.
This commit is contained in:
commit
51af90e042
@ -72,7 +72,7 @@ class ORMQueryBuilderLoader implements EntityLoaderInterface
|
|||||||
$values = array_values(array_filter($values, function ($v) {
|
$values = array_values(array_filter($values, function ($v) {
|
||||||
return (string) $v === (string) (int) $v || ctype_digit($v);
|
return (string) $v === (string) (int) $v || ctype_digit($v);
|
||||||
}));
|
}));
|
||||||
} elseif ('guid' === $metadata->getTypeOfField($identifier)) {
|
} elseif (in_array($metadata->getTypeOfField($identifier), array('uuid', 'guid'))) {
|
||||||
$parameterType = Connection::PARAM_STR_ARRAY;
|
$parameterType = Connection::PARAM_STR_ARRAY;
|
||||||
|
|
||||||
// Like above, but we just filter out empty strings.
|
// Like above, but we just filter out empty strings.
|
||||||
|
28
src/Symfony/Bridge/Doctrine/Tests/Fixtures/GuidIdEntity.php
Normal file
28
src/Symfony/Bridge/Doctrine/Tests/Fixtures/GuidIdEntity.php
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<?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\Id;
|
||||||
|
use Doctrine\ORM\Mapping\Column;
|
||||||
|
use Doctrine\ORM\Mapping\Entity;
|
||||||
|
|
||||||
|
/** @Entity */
|
||||||
|
class GuidIdEntity
|
||||||
|
{
|
||||||
|
/** @Id @Column(type="guid") */
|
||||||
|
protected $id;
|
||||||
|
|
||||||
|
public function __construct($id)
|
||||||
|
{
|
||||||
|
$this->id = $id;
|
||||||
|
}
|
||||||
|
}
|
28
src/Symfony/Bridge/Doctrine/Tests/Fixtures/UuidIdEntity.php
Normal file
28
src/Symfony/Bridge/Doctrine/Tests/Fixtures/UuidIdEntity.php
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<?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\Id;
|
||||||
|
use Doctrine\ORM\Mapping\Column;
|
||||||
|
use Doctrine\ORM\Mapping\Entity;
|
||||||
|
|
||||||
|
/** @Entity */
|
||||||
|
class UuidIdEntity
|
||||||
|
{
|
||||||
|
/** @Id @Column(type="uuid") */
|
||||||
|
protected $id;
|
||||||
|
|
||||||
|
public function __construct($id)
|
||||||
|
{
|
||||||
|
$this->id = $id;
|
||||||
|
}
|
||||||
|
}
|
@ -87,6 +87,38 @@ class ORMQueryBuilderLoaderTest extends TestCase
|
|||||||
$loader->getEntitiesByIds('id', array(1, '', 2, 3, 'foo', '9223372036854775808'));
|
$loader->getEntitiesByIds('id', array(1, '', 2, 3, 'foo', '9223372036854775808'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider provideGuidEntityClasses
|
||||||
|
*/
|
||||||
|
public function testFilterEmptyUuids($entityClass)
|
||||||
|
{
|
||||||
|
$em = DoctrineTestHelper::createTestEntityManager();
|
||||||
|
|
||||||
|
$query = $this->getMockBuilder('QueryMock')
|
||||||
|
->setMethods(array('setParameter', 'getResult', 'getSql', '_doExecute'))
|
||||||
|
->getMock();
|
||||||
|
|
||||||
|
$query->expects($this->once())
|
||||||
|
->method('setParameter')
|
||||||
|
->with('ORMQueryBuilderLoader_getEntitiesByIds_id', array('71c5fd46-3f16-4abb-bad7-90ac1e654a2d', 'b98e8e11-2897-44df-ad24-d2627eb7f499'), Connection::PARAM_STR_ARRAY)
|
||||||
|
->willReturn($query);
|
||||||
|
|
||||||
|
$qb = $this->getMockBuilder('Doctrine\ORM\QueryBuilder')
|
||||||
|
->setConstructorArgs(array($em))
|
||||||
|
->setMethods(array('getQuery'))
|
||||||
|
->getMock();
|
||||||
|
|
||||||
|
$qb->expects($this->once())
|
||||||
|
->method('getQuery')
|
||||||
|
->willReturn($query);
|
||||||
|
|
||||||
|
$qb->select('e')
|
||||||
|
->from($entityClass, 'e');
|
||||||
|
|
||||||
|
$loader = new ORMQueryBuilderLoader($qb);
|
||||||
|
$loader->getEntitiesByIds('id', array('71c5fd46-3f16-4abb-bad7-90ac1e654a2d', '', 'b98e8e11-2897-44df-ad24-d2627eb7f499'));
|
||||||
|
}
|
||||||
|
|
||||||
public function testEmbeddedIdentifierName()
|
public function testEmbeddedIdentifierName()
|
||||||
{
|
{
|
||||||
if (Version::compare('2.5.0') > 0) {
|
if (Version::compare('2.5.0') > 0) {
|
||||||
@ -120,4 +152,12 @@ class ORMQueryBuilderLoaderTest extends TestCase
|
|||||||
$loader = new ORMQueryBuilderLoader($qb);
|
$loader = new ORMQueryBuilderLoader($qb);
|
||||||
$loader->getEntitiesByIds('id.value', array(1, '', 2, 3, 'foo'));
|
$loader->getEntitiesByIds('id.value', array(1, '', 2, 3, 'foo'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function provideGuidEntityClasses()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
array('Symfony\Bridge\Doctrine\Tests\Fixtures\GuidIdEntity'),
|
||||||
|
array('Symfony\Bridge\Doctrine\Tests\Fixtures\UuidIdEntity'),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -172,6 +172,18 @@ class Form extends Link implements \ArrayAccess
|
|||||||
if (!empty($qs)) {
|
if (!empty($qs)) {
|
||||||
parse_str($qs, $expandedValue);
|
parse_str($qs, $expandedValue);
|
||||||
$varName = substr($name, 0, strlen(key($expandedValue)));
|
$varName = substr($name, 0, strlen(key($expandedValue)));
|
||||||
|
|
||||||
|
array_walk_recursive(
|
||||||
|
$expandedValue,
|
||||||
|
function (&$value, $key) {
|
||||||
|
if (ctype_digit($value) && ('size' === $key || 'error' === $key)) {
|
||||||
|
$value = (int) $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
reset($expandedValue);
|
||||||
|
|
||||||
$values = array_replace_recursive($values, array($varName => current($expandedValue)));
|
$values = array_replace_recursive($values, array($varName => current($expandedValue)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -462,6 +462,15 @@ class FormTest extends TestCase
|
|||||||
|
|
||||||
$form = $this->createForm('<form method="post"><input type="file" name="f.o o[bar][ba.z]" /><input type="file" name="f.o o[bar][]" /><input type="text" name="bar" value="bar" /><input type="submit" /></form>');
|
$form = $this->createForm('<form method="post"><input type="file" name="f.o o[bar][ba.z]" /><input type="file" name="f.o o[bar][]" /><input type="text" name="bar" value="bar" /><input type="submit" /></form>');
|
||||||
$this->assertEquals(array('f.o o' => array('bar' => array('ba.z' => array('name' => '', 'type' => '', 'tmp_name' => '', 'error' => 4, 'size' => 0), array('name' => '', 'type' => '', 'tmp_name' => '', 'error' => 4, 'size' => 0)))), $form->getPhpFiles(), '->getPhpFiles() preserves periods and spaces in names recursively');
|
$this->assertEquals(array('f.o o' => array('bar' => array('ba.z' => array('name' => '', 'type' => '', 'tmp_name' => '', 'error' => 4, 'size' => 0), array('name' => '', 'type' => '', 'tmp_name' => '', 'error' => 4, 'size' => 0)))), $form->getPhpFiles(), '->getPhpFiles() preserves periods and spaces in names recursively');
|
||||||
|
|
||||||
|
$form = $this->createForm('<form method="post"><input type="file" name="foo[bar]" /><input type="text" name="bar" value="bar" /><input type="submit" /></form>');
|
||||||
|
$files = $form->getPhpFiles();
|
||||||
|
|
||||||
|
$this->assertSame(0, $files['foo']['bar']['size'], '->getPhpFiles() converts size to int');
|
||||||
|
$this->assertSame(4, $files['foo']['bar']['error'], '->getPhpFiles() converts error to int');
|
||||||
|
|
||||||
|
$form = $this->createForm('<form method="post"><input type="file" name="size[error]" /><input type="text" name="error" value="error" /><input type="submit" /></form>');
|
||||||
|
$this->assertEquals(array('size' => array('error' => array('name' => '', 'type' => '', 'tmp_name' => '', 'error' => 4, 'size' => 0))), $form->getPhpFiles(), '->getPhpFiles() int conversion does not collide with file names');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user