Skip to content

Commit 51af90e

Browse files
committed
Merge branch '2.8' into 3.3
* 2.8: [DomCrawler] Fix conversion to int on GetPhpFiles Filtering empty uuids in ORMQueryBuilderLoader.
2 parents 7b7a69f + 400263a commit 51af90e

File tree

6 files changed

+118
-1
lines changed

6 files changed

+118
-1
lines changed

src/Symfony/Bridge/Doctrine/Form/ChoiceList/ORMQueryBuilderLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public function getEntitiesByIds($identifier, array $values)
7272
$values = array_values(array_filter($values, function ($v) {
7373
return (string) $v === (string) (int) $v || ctype_digit($v);
7474
}));
75-
} elseif ('guid' === $metadata->getTypeOfField($identifier)) {
75+
} elseif (in_array($metadata->getTypeOfField($identifier), array('uuid', 'guid'))) {
7676
$parameterType = Connection::PARAM_STR_ARRAY;
7777

7878
// Like above, but we just filter out empty strings.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bridge\Doctrine\Tests\Fixtures;
13+
14+
use Doctrine\ORM\Mapping\Id;
15+
use Doctrine\ORM\Mapping\Column;
16+
use Doctrine\ORM\Mapping\Entity;
17+
18+
/** @Entity */
19+
class GuidIdEntity
20+
{
21+
/** @Id @Column(type="guid") */
22+
protected $id;
23+
24+
public function __construct($id)
25+
{
26+
$this->id = $id;
27+
}
28+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bridge\Doctrine\Tests\Fixtures;
13+
14+
use Doctrine\ORM\Mapping\Id;
15+
use Doctrine\ORM\Mapping\Column;
16+
use Doctrine\ORM\Mapping\Entity;
17+
18+
/** @Entity */
19+
class UuidIdEntity
20+
{
21+
/** @Id @Column(type="uuid") */
22+
protected $id;
23+
24+
public function __construct($id)
25+
{
26+
$this->id = $id;
27+
}
28+
}

src/Symfony/Bridge/Doctrine/Tests/Form/ChoiceList/ORMQueryBuilderLoaderTest.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,38 @@ public function testFilterNonIntegerValues()
8787
$loader->getEntitiesByIds('id', array(1, '', 2, 3, 'foo', '9223372036854775808'));
8888
}
8989

90+
/**
91+
* @dataProvider provideGuidEntityClasses
92+
*/
93+
public function testFilterEmptyUuids($entityClass)
94+
{
95+
$em = DoctrineTestHelper::createTestEntityManager();
96+
97+
$query = $this->getMockBuilder('QueryMock')
98+
->setMethods(array('setParameter', 'getResult', 'getSql', '_doExecute'))
99+
->getMock();
100+
101+
$query->expects($this->once())
102+
->method('setParameter')
103+
->with('ORMQueryBuilderLoader_getEntitiesByIds_id', array('71c5fd46-3f16-4abb-bad7-90ac1e654a2d', 'b98e8e11-2897-44df-ad24-d2627eb7f499'), Connection::PARAM_STR_ARRAY)
104+
->willReturn($query);
105+
106+
$qb = $this->getMockBuilder('Doctrine\ORM\QueryBuilder')
107+
->setConstructorArgs(array($em))
108+
->setMethods(array('getQuery'))
109+
->getMock();
110+
111+
$qb->expects($this->once())
112+
->method('getQuery')
113+
->willReturn($query);
114+
115+
$qb->select('e')
116+
->from($entityClass, 'e');
117+
118+
$loader = new ORMQueryBuilderLoader($qb);
119+
$loader->getEntitiesByIds('id', array('71c5fd46-3f16-4abb-bad7-90ac1e654a2d', '', 'b98e8e11-2897-44df-ad24-d2627eb7f499'));
120+
}
121+
90122
public function testEmbeddedIdentifierName()
91123
{
92124
if (Version::compare('2.5.0') > 0) {
@@ -120,4 +152,12 @@ public function testEmbeddedIdentifierName()
120152
$loader = new ORMQueryBuilderLoader($qb);
121153
$loader->getEntitiesByIds('id.value', array(1, '', 2, 3, 'foo'));
122154
}
155+
156+
public function provideGuidEntityClasses()
157+
{
158+
return array(
159+
array('Symfony\Bridge\Doctrine\Tests\Fixtures\GuidIdEntity'),
160+
array('Symfony\Bridge\Doctrine\Tests\Fixtures\UuidIdEntity'),
161+
);
162+
}
123163
}

src/Symfony/Component/DomCrawler/Form.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,18 @@ public function getPhpFiles()
172172
if (!empty($qs)) {
173173
parse_str($qs, $expandedValue);
174174
$varName = substr($name, 0, strlen(key($expandedValue)));
175+
176+
array_walk_recursive(
177+
$expandedValue,
178+
function (&$value, $key) {
179+
if (ctype_digit($value) && ('size' === $key || 'error' === $key)) {
180+
$value = (int) $value;
181+
}
182+
}
183+
);
184+
185+
reset($expandedValue);
186+
175187
$values = array_replace_recursive($values, array($varName => current($expandedValue)));
176188
}
177189
}

src/Symfony/Component/DomCrawler/Tests/FormTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,15 @@ public function testGetPhpFiles()
462462

463463
$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>');
464464
$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');
465+
466+
$form = $this->createForm('<form method="post"><input type="file" name="foo[bar]" /><input type="text" name="bar" value="bar" /><input type="submit" /></form>');
467+
$files = $form->getPhpFiles();
468+
469+
$this->assertSame(0, $files['foo']['bar']['size'], '->getPhpFiles() converts size to int');
470+
$this->assertSame(4, $files['foo']['bar']['error'], '->getPhpFiles() converts error to int');
471+
472+
$form = $this->createForm('<form method="post"><input type="file" name="size[error]" /><input type="text" name="error" value="error" /><input type="submit" /></form>');
473+
$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');
465474
}
466475

467476
/**

0 commit comments

Comments
 (0)