Skip to content

Commit 400263a

Browse files
committed
Merge branch '2.7' into 2.8
* 2.7: [DomCrawler] Fix conversion to int on GetPhpFiles Filtering empty uuids in ORMQueryBuilderLoader.
2 parents d6dfb5b + bcfe152 commit 400263a

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
@@ -106,7 +106,7 @@ public function getEntitiesByIds($identifier, array $values)
106106
$values = array_values(array_filter($values, function ($v) {
107107
return (string) $v === (string) (int) $v || ctype_digit($v);
108108
}));
109-
} elseif ('guid' === $metadata->getTypeOfField($identifier)) {
109+
} elseif (in_array($metadata->getTypeOfField($identifier), array('uuid', 'guid'))) {
110110
$parameterType = Connection::PARAM_STR_ARRAY;
111111

112112
// 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
@@ -107,6 +107,38 @@ public function testFilterNonIntegerValues()
107107
$loader->getEntitiesByIds('id', array(1, '', 2, 3, 'foo', '9223372036854775808'));
108108
}
109109

110+
/**
111+
* @dataProvider provideGuidEntityClasses
112+
*/
113+
public function testFilterEmptyUuids($entityClass)
114+
{
115+
$em = DoctrineTestHelper::createTestEntityManager();
116+
117+
$query = $this->getMockBuilder('QueryMock')
118+
->setMethods(array('setParameter', 'getResult', 'getSql', '_doExecute'))
119+
->getMock();
120+
121+
$query->expects($this->once())
122+
->method('setParameter')
123+
->with('ORMQueryBuilderLoader_getEntitiesByIds_id', array('71c5fd46-3f16-4abb-bad7-90ac1e654a2d', 'b98e8e11-2897-44df-ad24-d2627eb7f499'), Connection::PARAM_STR_ARRAY)
124+
->willReturn($query);
125+
126+
$qb = $this->getMockBuilder('Doctrine\ORM\QueryBuilder')
127+
->setConstructorArgs(array($em))
128+
->setMethods(array('getQuery'))
129+
->getMock();
130+
131+
$qb->expects($this->once())
132+
->method('getQuery')
133+
->willReturn($query);
134+
135+
$qb->select('e')
136+
->from($entityClass, 'e');
137+
138+
$loader = new ORMQueryBuilderLoader($qb);
139+
$loader->getEntitiesByIds('id', array('71c5fd46-3f16-4abb-bad7-90ac1e654a2d', '', 'b98e8e11-2897-44df-ad24-d2627eb7f499'));
140+
}
141+
110142
public function testEmbeddedIdentifierName()
111143
{
112144
if (Version::compare('2.5.0') > 0) {
@@ -140,4 +172,12 @@ public function testEmbeddedIdentifierName()
140172
$loader = new ORMQueryBuilderLoader($qb);
141173
$loader->getEntitiesByIds('id.value', array(1, '', 2, 3, 'foo'));
142174
}
175+
176+
public function provideGuidEntityClasses()
177+
{
178+
return array(
179+
array('Symfony\Bridge\Doctrine\Tests\Fixtures\GuidIdEntity'),
180+
array('Symfony\Bridge\Doctrine\Tests\Fixtures\UuidIdEntity'),
181+
);
182+
}
143183
}

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
@@ -456,6 +456,15 @@ public function testGetPhpFiles()
456456

457457
$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>');
458458
$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');
459+
460+
$form = $this->createForm('<form method="post"><input type="file" name="foo[bar]" /><input type="text" name="bar" value="bar" /><input type="submit" /></form>');
461+
$files = $form->getPhpFiles();
462+
463+
$this->assertSame(0, $files['foo']['bar']['size'], '->getPhpFiles() converts size to int');
464+
$this->assertSame(4, $files['foo']['bar']['error'], '->getPhpFiles() converts error to int');
465+
466+
$form = $this->createForm('<form method="post"><input type="file" name="size[error]" /><input type="text" name="error" value="error" /><input type="submit" /></form>');
467+
$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');
459468
}
460469

461470
/**

0 commit comments

Comments
 (0)