Skip to content

Commit

Permalink
Merge branch '2.7' into 2.8
Browse files Browse the repository at this point in the history
* 2.7:
  [VarDumper] Various minor fixes & cleanups
  Revert "bug #18935 [Form] Consider a violation even if the form is not submitted (egeloen)"
  [HttpKernel] Add missing SsiFragmentRendererTest
  Fixes the calendar in constructor to handle null
  • Loading branch information
nicolas-grekas committed Aug 31, 2016
2 parents 2980fb8 + ac9ac83 commit 808333e
Show file tree
Hide file tree
Showing 10 changed files with 135 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/Twig/Extension/DumpExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function dump(\Twig_Environment $env, $context)
}

$dump = fopen('php://memory', 'r+b');
$dumper = new HtmlDumper($dump);
$dumper = new HtmlDumper($dump, $env->getCharset());

foreach ($vars as $value) {
$dumper->dump($this->cloner->cloneVar($value));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,9 @@ private function reconstructPath(ViolationPath $violationPath, FormInterface $or
*/
private function acceptsErrors(FormInterface $form)
{
return $this->allowNonSynchronized || $form->isSynchronized();
// Ignore non-submitted forms. This happens, for example, in PATCH
// requests.
// https://github.com/symfony/symfony/pull/10567
return $form->isSubmitted() && ($this->allowNonSynchronized || $form->isSynchronized());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public function testAbortDotRuleMappingIfNotSynchronized()
$this->assertCount(0, $grandChild->getErrors(), $grandChild->getName().' should not have an error, but has one');
}

public function testMappingIfNotSubmitted()
public function testAbortMappingIfNotSubmitted()
{
$violation = $this->getConstraintViolation('children[address].data.street');
$parent = $this->getForm('parent');
Expand All @@ -230,12 +230,12 @@ public function testMappingIfNotSubmitted()

$this->mapper->mapViolation($violation, $parent);

$this->assertCount(0, $parent->getErrors(), $parent->getName().' should not have an error');
$this->assertCount(0, $child->getErrors(), $child->getName().' should not have an error');
$this->assertCount(1, $grandChild->getErrors(), $grandChild->getName().' should have one error');
$this->assertCount(0, $parent->getErrors(), $parent->getName().' should not have an error, but has one');
$this->assertCount(0, $child->getErrors(), $child->getName().' should not have an error, but has one');
$this->assertCount(0, $grandChild->getErrors(), $grandChild->getName().' should not have an error, but has one');
}

public function testDotRuleMappingIfNotSubmitted()
public function testAbortDotRuleMappingIfNotSubmitted()
{
$violation = $this->getConstraintViolation('data.address');
$parent = $this->getForm('parent');
Expand All @@ -255,9 +255,9 @@ public function testDotRuleMappingIfNotSubmitted()

$this->mapper->mapViolation($violation, $parent);

$this->assertCount(0, $parent->getErrors(), $parent->getName().' should not have an error');
$this->assertCount(0, $child->getErrors(), $child->getName().' should not have an error');
$this->assertCount(1, $grandChild->getErrors(), $grandChild->getName().' should have an error');
$this->assertCount(0, $parent->getErrors(), $parent->getName().' should not have an error, but has one');
$this->assertCount(0, $child->getErrors(), $child->getName().' should not have an error, but has one');
$this->assertCount(0, $grandChild->getErrors(), $grandChild->getName().' should not have an error, but has one');
}

public function provideDefaultTests()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ public function serialize()
return 'a:0:{}';
}

$this->data[] = $this->fileLinkFormat;
$this->data[] = $this->charset;
$ser = serialize($this->data);
$this->data = array();
$this->dataCount = 0;
Expand All @@ -184,8 +186,10 @@ public function serialize()
public function unserialize($data)
{
parent::unserialize($data);
$charset = array_pop($this->data);
$fileLinkFormat = array_pop($this->data);
$this->dataCount = count($this->data);
self::__construct($this->stopwatch);
self::__construct($this->stopwatch, $fileLinkFormat, $charset);
}

public function getDumpsCount()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ public function testDump()
);
$this->assertSame($xDump, $dump);

$this->assertStringMatchesFormat('a:1:{i:0;a:5:{s:4:"data";O:39:"Symfony\Component\VarDumper\Cloner\Data":%a', $collector->serialize());
$this->assertStringMatchesFormat('a:3:{i:0;a:5:{s:4:"data";O:39:"Symfony\Component\VarDumper\Cloner\Data":%a', $collector->serialize());
$this->assertSame(0, $collector->getDumpsCount());
$this->assertSame('a:0:{}', $collector->serialize());
$this->assertSame('a:2:{i:0;b:0;i:1;s:5:"UTF-8";}', $collector->serialize());
}

public function testCollectDefault()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?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\Component\HttpKernel\Tests\Fragment;

use Symfony\Component\HttpKernel\Controller\ControllerReference;
use Symfony\Component\HttpKernel\Fragment\SsiFragmentRenderer;
use Symfony\Component\HttpKernel\HttpCache\Ssi;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\UriSigner;

class SsiFragmentRendererTest extends \PHPUnit_Framework_TestCase
{
public function testRenderFallbackToInlineStrategyIfSsiNotSupported()
{
$strategy = new SsiFragmentRenderer(new Ssi(), $this->getInlineStrategy(true));
$strategy->render('/', Request::create('/'));
}

public function testRender()
{
$strategy = new SsiFragmentRenderer(new Ssi(), $this->getInlineStrategy());

$request = Request::create('/');
$request->setLocale('fr');
$request->headers->set('Surrogate-Capability', 'SSI/1.0');

$this->assertEquals('<!--#include virtual="/" -->', $strategy->render('/', $request)->getContent());
$this->assertEquals('<!--#include virtual="/" -->', $strategy->render('/', $request, array('comment' => 'This is a comment'))->getContent(), 'Strategy options should not impact the ssi include tag');
}

public function testRenderControllerReference()
{
$signer = new UriSigner('foo');
$strategy = new SsiFragmentRenderer(new Ssi(), $this->getInlineStrategy(), $signer);

$request = Request::create('/');
$request->setLocale('fr');
$request->headers->set('Surrogate-Capability', 'SSI/1.0');

$reference = new ControllerReference('main_controller', array(), array());
$altReference = new ControllerReference('alt_controller', array(), array());

$this->assertEquals(
'<!--#include virtual="/_fragment?_path=_format%3Dhtml%26_locale%3Dfr%26_controller%3Dmain_controller&_hash=Jz1P8NErmhKTeI6onI1EdAXTB85359MY3RIk5mSJ60w%3D" -->',
$strategy->render($reference, $request, array('alt' => $altReference))->getContent()
);
}

/**
* @expectedException \LogicException
*/
public function testRenderControllerReferenceWithoutSignerThrowsException()
{
$strategy = new SsiFragmentRenderer(new Ssi(), $this->getInlineStrategy());

$request = Request::create('/');
$request->setLocale('fr');
$request->headers->set('Surrogate-Capability', 'SSI/1.0');

$strategy->render(new ControllerReference('main_controller'), $request);
}

/**
* @expectedException \LogicException
*/
public function testRenderAltControllerReferenceWithoutSignerThrowsException()
{
$strategy = new SsiFragmentRenderer(new Ssi(), $this->getInlineStrategy());

$request = Request::create('/');
$request->setLocale('fr');
$request->headers->set('Surrogate-Capability', 'SSI/1.0');

$strategy->render('/', $request, array('alt' => new ControllerReference('alt_controller')));
}

private function getInlineStrategy($called = false)
{
$inline = $this->getMockBuilder('Symfony\Component\HttpKernel\Fragment\InlineFragmentRenderer')->disableOriginalConstructor()->getMock();

if ($called) {
$inline->expects($this->once())->method('render');
}

return $inline;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class IntlDateFormatter
* @param int $timetype Type of time formatting, one of the format type constants
* @param mixed $timezone Timezone identifier
* @param int $calendar Calendar to use for formatting or parsing. The only currently
* supported value is IntlDateFormatter::GREGORIAN.
* supported value is IntlDateFormatter::GREGORIAN (or null using the default calendar, i.e. "GREGORIAN")
* @param string $pattern Optional pattern to use when formatting
*
* @see http://www.php.net/manual/en/intldateformatter.create.php
Expand All @@ -151,7 +151,7 @@ public function __construct($locale, $datetype, $timetype, $timezone = null, $ca
throw new MethodArgumentValueNotImplementedException(__METHOD__, 'locale', $locale, 'Only the locale "en" is supported');
}

if (self::GREGORIAN !== $calendar) {
if (self::GREGORIAN !== $calendar && null !== $calendar) {
throw new MethodArgumentValueNotImplementedException(__METHOD__, 'calendar', $calendar, 'Only the GREGORIAN calendar is supported');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ public function testConstructorWithoutLocale()
$this->assertEquals('y-M-d', $formatter->getPattern());
}

public function testConstructorWithoutCalendar()
{
$formatter = new IntlDateFormatter('en', IntlDateFormatter::MEDIUM, IntlDateFormatter::SHORT, 'UTC', null, 'y-M-d');
$this->assertEquals('y-M-d', $formatter->getPattern());
}

/**
* @expectedException \Symfony\Component\Intl\Exception\MethodArgumentValueNotImplementedException
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/VarDumper/Caster/StubCaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static function castEnum(EnumStub $c, array $a, Stub $stub, $isNested)

if ($c->value) {
foreach (array_keys($c->value) as $k) {
$keys[] = Caster::PREFIX_VIRTUAL.$k;
$keys[] = isset($k[0]) && "\0" !== $k[0] ? Caster::PREFIX_VIRTUAL.$k : $k;
}
// Preserve references with array_combine()
$a = array_combine($keys, $c->value);
Expand Down
15 changes: 10 additions & 5 deletions src/Symfony/Component/VarDumper/Dumper/HtmlDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ protected function style($style, $value, $attr = array())
return '';
}

$v = htmlspecialchars($value, ENT_QUOTES, 'UTF-8');
$v = esc($value);

if ('ref' === $style) {
if (empty($attr['count'])) {
Expand All @@ -373,18 +373,18 @@ protected function style($style, $value, $attr = array())
return sprintf('<a class=sf-dump-ref href=#%s-ref%s title="%d occurrences">%s</a>', $this->dumpId, $r, 1 + $attr['count'], $v);
}

if ('const' === $style && array_key_exists('value', $attr)) {
$style .= sprintf(' title="%s"', htmlspecialchars(json_encode($attr['value']), ENT_QUOTES, 'UTF-8'));
if ('const' === $style && isset($attr['value'])) {
$style .= sprintf(' title="%s"', esc(is_scalar($attr['value']) ? $attr['value'] : json_encode($attr['value'])));
} elseif ('public' === $style) {
$style .= sprintf(' title="%s"', empty($attr['dynamic']) ? 'Public property' : 'Runtime added dynamic property');
} elseif ('str' === $style && 1 < $attr['length']) {
$style .= sprintf(' title="%s%s characters"', $attr['length'], $attr['binary'] ? ' binary or non-UTF-8' : '');
$style .= sprintf(' title="%d%s characters"', $attr['length'], $attr['binary'] ? ' binary or non-UTF-8' : '');
} elseif ('note' === $style && false !== $c = strrpos($v, '\\')) {
return sprintf('<abbr title="%s" class=sf-dump-%s>%s</abbr>', $v, $style, substr($v, $c + 1));
} elseif ('protected' === $style) {
$style .= ' title="Protected property"';
} elseif ('private' === $style) {
$style .= sprintf(' title="Private property defined in class:&#10;`%s`"', $attr['class']);
$style .= sprintf(' title="Private property defined in class:&#10;`%s`"', esc($attr['class']));
}

$map = static::$controlCharsMap;
Expand Down Expand Up @@ -438,3 +438,8 @@ protected function dumpLine($depth, $endOfValue = false)
AbstractDumper::dumpLine($depth);
}
}

function esc($str)
{
return htmlspecialchars($str, ENT_QUOTES, 'UTF-8');
}

0 comments on commit 808333e

Please sign in to comment.