Skip to content

Commit

Permalink
Merge branch '2.8' into 3.1
Browse files Browse the repository at this point in the history
* 2.8:
  [VarDumper] Various minor fixes & cleanups
  Revert "bug #18935 [Form] Consider a violation even if the form is not submitted (egeloen)"
  [HttpKernel] Add missing SsiFragmentRendererTest
  [DoctrineBridge] Fix exception message and tests after misresolved merge
  Fixes the calendar in constructor to handle null
  • Loading branch information
nicolas-grekas committed Aug 31, 2016
2 parents 45c0c49 + 808333e commit 46843d3
Show file tree
Hide file tree
Showing 12 changed files with 164 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function loadUserByUsername($username)
$user = $repository->findOneBy(array($this->property => $username));
} else {
if (!$repository instanceof UserLoaderInterface) {
throw new \InvalidArgumentException(sprintf('You must either make the "%s" entity Doctrine Repository ("%s") implement "Symfony\Component\Security\Core\User\UserProviderInterface" or set the "property" option in the corresponding entity provider configuration.', $this->classOrAlias, get_class($repository)));
throw new \InvalidArgumentException(sprintf('You must either make the "%s" entity Doctrine Repository ("%s") implement "Symfony\Bridge\Doctrine\Security\User\UserLoaderInterface" or set the "property" option in the corresponding entity provider configuration.', $this->classOrAlias, get_class($repository)));
}

$user = $repository->loadUserByUsername($username);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,37 @@ public function testLoadUserByUsername()
$this->assertSame($user, $provider->loadUserByUsername('user1'));
}

public function testLoadUserByUsernameWithUserLoaderRepositoryAndWithoutProperty()
{
$user = new User(1, 1, 'user1');

$repository = $this->getMockBuilder('Symfony\Bridge\Doctrine\Security\User\UserLoaderInterface')
->disableOriginalConstructor()
->getMock();
$repository
->expects($this->once())
->method('loadUserByUsername')
->with('user1')
->willReturn($user);

$em = $this->getMockBuilder('Doctrine\ORM\EntityManager')
->disableOriginalConstructor()
->getMock();
$em
->expects($this->once())
->method('getRepository')
->with('Symfony\Bridge\Doctrine\Tests\Fixtures\User')
->willReturn($repository);

$provider = new EntityUserProvider($this->getManager($em), 'Symfony\Bridge\Doctrine\Tests\Fixtures\User');
$this->assertSame($user, $provider->loadUserByUsername('user1'));
}

/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage You must either make the "Symfony\Bridge\Doctrine\Tests\Fixtures\User" entity Doctrine Repository ("Doctrine\ORM\EntityRepository") implement "Symfony\Component\Security\Core\User\UserProviderInterface" or set the "property" option in the corresponding entity provider configuration.
* @expectedExceptionMessage You must either make the "Symfony\Bridge\Doctrine\Tests\Fixtures\User" entity Doctrine Repository ("Doctrine\ORM\EntityRepository") implement "Symfony\Bridge\Doctrine\Security\User\UserLoaderInterface" or set the "property" option in the corresponding entity provider configuration.
*/
public function testLoadUserByUsernameWithNonUserProviderRepositoryAndWithoutProperty()
public function testLoadUserByUsernameWithNonUserLoaderRepositoryAndWithoutProperty()
{
$em = DoctrineTestHelper::createTestEntityManager();
$this->createSchema($em);
Expand Down
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 @@ -165,6 +165,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 @@ -179,8 +181,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->assertEquals($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 46843d3

Please sign in to comment.