8000 Merge branch '3.1' · symfony/symfony@731b625 · GitHub
[go: up one dir, main page]

Skip to content

Commit 731b625

Browse files
Merge branch '3.1'
* 3.1: [VarDumper] Various minor fixes & cleanups Revert "bug #18935 [Form] Consider a violation even if the form is not submitted (egeloen)" [Config] Fix DirectoryResourceTest for symlinks [HttpKernel] Add missing SsiFragmentRendererTest [DoctrineBridge] Fix exception message and tests after misresolved merge Fixes the calendar in constructor to handle null
2 parents 2bc54e0 + 46843d3 commit 731b625

File tree

13 files changed

+167
-26
lines changed

13 files changed

+167
-26
lines changed

src/Symfony/Bridge/Doctrine/Security/User/EntityUserProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function loadUserByUsername($username)
5151
$user = $repository->findOneBy(array($this->property => $username));
5252
} else {
5353
if (!$repository instanceof UserLoaderInterface) {
54-
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)));
54+
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)));
5555
}
5656

5757
$user = $repository->loadUserByUsername($username);

src/Symfony/Bridge/Doctrine/Tests/Security/User/EntityUserProviderTest.php

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,37 @@ public function testLoadUserByUsername()
5353
$this->assertSame($user, $provider->loadUserByUsername('user1'));
5454
}
5555

56+
public function testLoadUserByUsernameWithUserLoaderRepositoryAndWithoutProperty()
57+
{
58+
$user = new User(1, 1, 'user1');
59+
60+
$repository = $this->getMockBuilder('Symfony\Bridge\Doctrine\Security\User\UserLoaderInterface')
61+
->disableOriginalConstructor()
62+
->getMock();
63+
$repository
64+
->expects($this->once())
65+
->method('loadUserByUsername')
66+
->with('user1')
67+
->willReturn($user);
68+
69+
$em = $this->getMockBuilder('Doctrine\ORM\EntityManager')
70+
->disableOriginalConstructor()
71+
->getMock();
72+
$em
73+
->expects($this->once())
74+
->method('getRepository')
75+
->with('Symfony\Bridge\Doctrine\Tests\Fixtures\User')
76+
->willReturn($repository);
77+
78+
$provider = new EntityUserProvider($this->getManager($em), 'Symfony\Bridge\Doctrine\Tests\Fixtures\User');
79+
$this->assertSame($user, $provider->loadUserByUsername('user1'));
80+
}
81+
5682
/**
5783
* @expectedException \InvalidArgumentException
58-
* @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.
84+
* @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.
5985
*/
60-
public function testLoadUserByUsernameWithNonUserProviderRepositoryAndWithoutProperty()
86+
public function testLoadUserByUsernameWithNonUserLoaderRepositoryAndWithoutProperty()
6187
{
6288
$em = DoctrineTestHelper::createTestEntityManager();
6389
$this->createSchema($em);

src/Symfony/Bridge/Twig/Extension/DumpExtension.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ public function dump(\Twig_Environment $env, $context)
6969
}
7070

7171
$dump = fopen('php://memory', 'r+b');
72+
$this->dumper->setCharset($env->getCharset());
7273

7374
foreach ($vars as $value) {
7475
$this->dumper->dump($this->cloner->cloneVar($value), $dump);

src/Symfony/Component/Config/Tests/Resource/DirectoryResourceTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ protected function removeDirectory($directory)
5353
public function testGetResource()
5454
{
5555
$resource = new DirectoryResource($this->directory);
56-
$this->assertSame($this->directory, $resource->getResource(), '->getResource() returns the path to the resource');
56+
$this->assertSame(realpath($this->directory), $resource->getResource(), '->getResource() returns the path to the resource');
5757
}
5858

5959
public function testGetPattern()
@@ -166,7 +166,7 @@ public function testSerializeUnserialize()
166166

167167
$unserialized = unserialize(serialize($resource));
168168

169-
$this->assertSame($this->directory, $resource->getResource());
169+
$this->assertSame(realpath($this->directory), $resource->getResource());
170170
$this->assertSame('/\.(foo|xml)$/', $resource->getPattern());
171171
}
172172

src/Symfony/Component/Form/Extension/Validator/ViolationMapper/ViolationMapper.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,9 @@ private function reconstructPath(ViolationPath $violationPath, FormInterface $or
275275
*/
276276
private function acceptsErrors(FormInterface $form)
277277
{
278-
return $this->allowNonSynchronized || $form->isSynchronized();
278+
// Ignore non-submitted forms. This happens, for example, in PATCH
279+
// requests.
280+
// https://github.com/symfony/symfony/pull/10567
281+
return $form->isSubmitted() && ($this->allowNonSynchronized || $form->isSynchronized());
279282
}
280283
}

src/Symfony/Component/Form/Tests/Extension/Validator/ViolationMapper/ViolationMapperTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ public function testAbortDotRuleMappingIfNotSynchronized()
212212
$this->assertCount(0, $grandChild->getErrors(), $grandChild->getName().' should not have an error, but has one');
213213
}
214214

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

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

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

238-
public function testDotRuleMappingIfNotSubmitted()
238+
public function testAbortDotRuleMappingIfNotSubmitted()
239239
{
240240
$violation = $this->getConstraintViolation('data.address');
241241
$parent = $this->getForm('parent');
@@ -255,9 +255,9 @@ public function testDotRuleMappingIfNotSubmitted()
255255

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

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

263263
public function provideDefaultTests()

src/Symfony/Component/HttpKernel/DataCollector/DumpDataCollector.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@ public function serialize()
165165
return 'a:0:{}';
166166
}
167167

168+
$this->data[] = $this->fileLinkFormat;
169+
$this->data[] = $this->charset;
168170
$ser = serialize($this->data);
169171
$this->data = array();
170172
$this->dataCount = 0;
@@ -179,8 +181,10 @@ public function serialize()
179181
public function unserialize($data)
180182
{
181183
parent::unserialize($data);
184+
$charset = array_pop($this->data);
185+
$fileLinkFormat = array_pop($this->data);
182186
$this->dataCount = count($this->data);
183-
self::__construct($this->stopwatch);
187+
self::__construct($this->stopwatch, $fileLinkFormat, $charset);
184188
}
185189

186190
public function getDumpsCount()

src/Symfony/Component/HttpKernel/Tests/DataCollector/DumpDataCollectorTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ public function testDump()
4949
);
5050
$this->assertEquals($xDump, $dump);
5151

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

5757
public function testCollectDefault()
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
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\Component\HttpKernel\Tests\Fragment;
13+
14+
use Symfony\Component\HttpKernel\Controller\ControllerReference;
15+
use Symfony\Component\HttpKernel\Fragment\SsiFragmentRenderer;
16+
use Symfony\Component\HttpKernel\HttpCache\Ssi;
17+
use Symfony\Component\HttpFoundation\Request;
18+
use Symfony\Component\HttpKernel\UriSigner;
19+
20+
class SsiFragmentRendererTest extends \PHPUnit_Framework_TestCase
21+
{
22+
public function testRenderFallbackToInlineStrategyIfSsiNotSupported()
23+
{
24+
$strategy = new SsiFragmentRenderer(new Ssi(), $this->getInlineStrategy(true));
25+
$strategy->render('/', Request::create('/'));
26+
}
27+
28+
public function testRender()
29+
{
30+
$strategy = new SsiFragmentRenderer(new Ssi(), $this->getInlineStrategy());
31+
32+
$request = Request::create('/');
33+
$request->setLocale('fr');
34+
$request->headers->set('Surrogate-Capability', 'SSI/1.0');
35+
36+
$this->assertEquals('<!--#include virtual="/" -->', $strategy->render('/', $request)->getContent());
37+
$this->assertEquals('<!--#include virtual="/" -->', $strategy->render('/', $request, array('comment' => 'This is a comment'))->getContent(), 'Strategy options should not impact the ssi include tag');
38+
}
39+
40+
public function testRenderControllerReference()
41+
{
42+
$signer = new UriSigner('foo');
43+
$strategy = new SsiFragmentRenderer(new Ssi(), $this->getInlineStrategy(), $signer);
44+
45+
$request = Request::create('/');
46+
$request->setLocale('fr');
47+
$request->headers->set('Surrogate-Capability', 'SSI/1.0');
48+
49+
$reference = new ControllerReference('main_controller', array(), array());
50+
$altReference = new ControllerReference('alt_controller', array(), array());
51+
52+
$this->assertEquals(
53+
'<!--#include virtual="/_fragment?_path=_format%3Dhtml%26_locale%3Dfr%26_controller%3Dmain_controller&_hash=Jz1P8NErmhKTeI6onI1EdAXTB85359MY3RIk5mSJ60w%3D" -->',
54+
$strategy->render($reference, $request, array('alt' => $altReference))->getContent()
55+
);
56+
}
57+
58+
/**
59+
* @expectedException \LogicException
60+
*/
61+
public function testRenderControllerReferenceWithoutSignerThrowsException()
62+
{
63+
$strategy = new SsiFragmentRenderer(new Ssi(), $this->getInlineStrategy());
64+
65+
$request = Request::create('/');
66+
$request->setLocale('fr');
67+
$request->headers->set('Surrogate-Capability', 'SSI/1.0');
68+
69+
$strategy->render(new ControllerReference('main_controller'), $request);
70+
}
71+
72+
/**
73+
* @expectedException \LogicException
74+
*/
75+
public function testRenderAltControllerReferenceWithoutSignerThrowsException()
76+
{
77+
$strategy = new SsiFragmentRenderer(new Ssi(), $this->getInlineStrategy());
78+
79+
$request = Request::create('/');
80+
$request->setLocale('fr');
81+
$request->headers->set('Surrogate-Capability', 'SSI/1.0');
82+
83+
$strategy->render('/', $request, array('alt' => new ControllerReference('alt_controller')));
84+
}
85+
86+
private function getInlineStrategy($called = false)
87+
{
88+
$inline = $this->getMockBuilder('Symfony\Component\HttpKernel\Fragment\InlineFragmentRenderer')->disableOriginalConstructor()->getMock();
89+
90+
if ($called) {
91+
$inline->expects($this->once())->method('render');
92+
}
93+
94+
return $inline;
95+
}
96+
}

src/Symfony/Component/Intl/DateFormatter/IntlDateFormatter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ class IntlDateFormatter
136136
* @param int $timetype Type of time formatting, one of the format type constants
137137
* @param mixed $timezone Timezone identifier
138138
* @param int $calendar Calendar to use for formatting or parsing. The only currently
139-
* supported value is IntlDateFormatter::GREGORIAN.
139+
* supported value is IntlDateFormatter::GREGORIAN (or null using the default calendar, i.e. "GREGORIAN")
140140
* @param string $pattern Optional pattern to use when formatting
141141
*
142142
* @see http://www.php.net/manual/en/intldateformatter.create.php
@@ -151,7 +151,7 @@ public function __construct($locale, $datetype, $timetype, $timezone = null, $ca
151151
throw new MethodArgumentValueNotImplementedException(__METHOD__, 'locale', $locale, 'Only the locale "en" is supported');
152152
}
153153

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

src/Symfony/Component/Intl/Tests/DateFormatter/IntlDateFormatterTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ public function testConstructorWithoutLocale()
2828
$this->assertEquals('y-M-d', $formatter->getPattern());
2929
}
3030

31+
public function testConstructorWithoutCalendar()
32+
{
33+
$formatter = new IntlDateFormatter('en', IntlDateFormatter::MEDIUM, IntlDateFormatter::SHORT, 'UTC', null, 'y-M-d');
34+
$this->assertEquals('y-M-d', $formatter->getPattern());
35+
}
36+
3137
/**
3238
* @expectedException \Symfony\Component\Intl\Exception\MethodArgumentValueNotImplementedException
3339
*/

src/Symfony/Component/VarDumper/Caster/StubCaster.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public static function castEnum(EnumStub $c, array $a, Stub $stub, $isNested)
6161

6262
if ($c->value) {
6363
foreach (array_keys($c->value) as $k) {
64-
$keys[] = Caster::PREFIX_VIRTUAL.$k;
64+
$keys[] = isset($k[0]) && "\0" !== $k[0] ? Caster::PREFIX_VIRTUAL.$k : $k;
6565
}
6666
// Preserve references with array_combine()
6767
$a = array_combine($keys, $c->value);

src/Symfony/Component/VarDumper/Dumper/HtmlDumper.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ protected function style($style, $value, $attr = array())
426426
return '';
427427
}
428428

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

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

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

456456
$map = static::$controlCharsMap;
@@ -509,3 +509,8 @@ protected function dumpLine($depth, $endOfValue = false)
509509
AbstractDumper::dumpLine($depth);
510510
}
511511
}
512+
513+
function esc($str)
514+
{
515+
return htmlspecialchars($str, ENT_QUOTES, 'UTF-8');
516+
}

0 commit comments

Comments
 (0)
0