8000 Merge branch '2.7' into 2.8 · symfony/symfony@2d174f2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2d174f2

Browse files
committed
Merge branch '2.7' into 2.8
* 2.7: revert typo fix [Form] Fix ChoiceType to ensure submitted data is not nested unnecessarily Test inline styles with non-decorated formatter Fix RuntimeException when an Emacs buffer is modified [Yaml] add tests for specific mapping keys
2 parents d8c964c + a786b5a commit 2d174f2

File tree

5 files changed

+70
-3
lines changed

5 files changed

+70
-3
lines changed

src/Symfony/Component/Config/Resource/DirectoryResource.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,15 @@ public function isFresh($timestamp)
8484
continue;
8585
}
8686

87+
// for broken links
88+
try {
89+
$fileMTime = $file->getMTime();
90+
} catch (\RuntimeException $e) {
91+
continue;
92+
}
93+
8794
// early return if a file's mtime exceeds the passed timestamp
88-
if ($timestamp < $file->getMTime()) {
95+
if ($timestamp < $fileMTime) {
8996
return false;
9097
}
9198
}

src/Symfony/Component/Console/Tests/Formatter/OutputFormatterTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,9 @@ public function testNotDecoratedFormatter()
196196
$this->assertEquals(
197197
'some question', $formatter->format('<question>some question</question>')
198198
);
199+
$this->assertEquals(
200+
'some text with inline style', $formatter->format('<fg=red>some text with inline style</>')
201+
);
199202

200203
$formatter->setDecorated(true);
201204

@@ -211,6 +214,9 @@ public function testNotDecoratedFormatter()
211214
$this->assertEquals(
212215
"\033[30;46msome question\033[39;49m", $formatter->format('<question>some question</question>')
213216
);
217+
$this->assertEquals(
218+
"\033[31msome text with inline style\033[39m", $formatter->format('<fg=red>some text with inline style</>')
219+
);
214220
}
215221

216222
public function testContentWithLineBreaks()

src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,22 @@ public function buildForm(FormBuilderInterface $builder, array $options)
160160
// transformation is merged back into the original collection
161161
$builder->addEventSubscriber(new MergeCollectionListener(true, true));
162162
}
163+
164+
// To avoid issues when the submitted choices are arrays (i.e. array to string conversions),
165+
// we have to ensure that all elements of the submitted choice data are strings or null.
166+
$builder->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) {
167+
$data = $event->getData();
168+
169+
if (!is_array($data)) {
170+
return;
171+
}
172+
173+
foreach ($data as $v) {
174+
if (null !== $v && !is_string($v)) {
175+
throw new TransformationFailedException('All choices submitted must be NULL or strings.');
176+
}
177+
}
178+
}, 256);
163179
}
164180

165181
/**
@@ -523,7 +539,7 @@ private function createChoiceListView(ChoiceListInterface $choiceList, array $op
523539
*
524540
* @param array|\Traversable $choices The choice labels indexed by choices
525541
* @param object $choiceLabels The object that receives the choice labels
526-
* indexed by generated keys.
542+
* indexed by generated keys
527543
* @param int $nextKey The next generated key
528544
*
529545
* @return array The choices in a normalized array with labels replaced by generated keys

src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414
use Symfony\Component\Form\ChoiceList\View\ChoiceGroupView;
1515
use Symfony\Component\Form\ChoiceList\View\ChoiceView;
1616
use Symfony\Component\Form\Extension\Core\ChoiceList\ObjectChoiceList;
17+
use Symfony\Component\Form\Test\TypeTestCase;
1718

18-
class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
19+
class ChoiceTypeTest extends TypeTestCase
1920
{
2021
private $choices = array(
2122
'Bernhard' => 'a',
@@ -2298,4 +2299,30 @@ public function testCustomChoiceTypeDoesNotInheritChoiceLabels()
22982299
// In this case the 'choice_label' closure returns null and not the closure from the first choice type.
22992300
$this->assertNull($form->get('subChoice')->getConfig()->getOption('choice_label'));
23002301
}
2302+
2303+
/**
2304+
* @dataProvider invalidNestedValueTestMatrix
2305+
*/
2306+
public function testSubmitInvalidNestedValue($multiple, $expanded, $submissionData)
2307+
{
2308+
$form = $this->factory->create('choice', null, array(
2309+
'choices' => $this->choices,
2310+
'multiple' => $multiple,
2311+
'expanded' => $expanded,
2312+
));
2313+
2314+
$form->submit($submissionData);
2315+
$this->assertFalse($form->isSynchronized());
2316+
$this->assertEquals('All choices submitted must be NULL or strings.', $form->getTransformationFailure()->getMessage());
2317+
}
2318+
2319+
public function invalidNestedValueTestMatrix()
2320+
{
2321+
return array(
2322+
'non-multiple, non-expanded' => array(false, false, array(array())),
2323+
'non-multiple, expanded' => array(false, true, array(array())),
2324+
'multiple, non-expanded' => array(true, false, array(array())),
2325+
'multiple, expanded' => array(true, true, array(array())),
2326+
);
2327+
}
23012328
}

src/Symfony/Component/Yaml/Tests/InlineTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,4 +468,15 @@ public function testVeryLongQuotedStrings()
468468

469469
$this->assertEquals($longStringWithQuotes, $arrayFromYaml['longStringWithQuotes']);
470470
}
471+
472+
public function testBooleanMappingKeysAreConvertedToStrings()
473+
{
474+
$this->assertSame(array('false' => 'foo'), Inline::parse('{false: foo}'));
475+
$this->assertSame(array('true' => 'foo'), Inline::parse('{true: foo}'));
476+
}
477+
478+
public function testTheEmptyStringIsAValidMappingKey()
479+
{
480+
$this->assertSame(array('' => 'foo'), Inline::parse('{ "": foo }'));
481+
}
471482
}

0 commit comments

Comments
 (0)
0