Merge branch '2.0'
* 2.0:
[Form] fixed previous merge
[Form] simplified previous merge
Also identify FirePHP by the X-FirePHP-Version header
[TwigBundle] Extract output buffer cleaning to method
[TwigBundle] Do not clean output buffering below initial level
Fixed rendering of FileType (value is not a valid attribute for input[type=file])
Added tests for string fix in DateTimeToArrayTransformer (8351a11286
).
Added check for array fields to be integers in reverseTransform method. This prevents checkdate from getting strings as arguments and throwing incorrect ErrorException when submitting form with malformed (string) data in, for example, Date field. #2609
[Translation] removed unneeded methods
[Translation] added detection for circular references when adding a fallback catalogue
[DomCrawler] trim URI in getURI
[Yaml][Tests] Fixed missing locale string for Windows platforms which caused test to fail
This commit is contained in:
commit
21cec043d7
@ -42,7 +42,9 @@ class FirePHPHandler extends BaseFirePHPHandler
|
||||
return;
|
||||
}
|
||||
|
||||
if (!preg_match('{\bFirePHP/\d+\.\d+\b}', $event->getRequest()->headers->get('User-Agent'))) {
|
||||
if (!preg_match('{\bFirePHP/\d+\.\d+\b}', $event->getRequest()->headers->get('User-Agent'))
|
||||
&& !$event->getRequest()->headers->has('X-FirePHP-Version')) {
|
||||
|
||||
$this->sendHeaders = false;
|
||||
$this->headers = array();
|
||||
|
||||
|
@ -168,7 +168,7 @@
|
||||
{% block field_widget %}
|
||||
{% spaceless %}
|
||||
{% set type = type|default('text') %}
|
||||
<input type="{{ type }}" {{ block('widget_attributes') }} value="{{ value }}" />
|
||||
<input type="{{ type }}" {{ block('widget_attributes') }} {% if value is not empty %}value="{{ value }}" {% endif %}/>
|
||||
{% endspaceless %}
|
||||
{% endblock field_widget %}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
<input
|
||||
type="<?php echo isset($type) ? $view->escape($type) : "text" ?>"
|
||||
value="<?php echo $view->escape($value) ?>"
|
||||
<?php if (!empty($value)): ?>value="<?php echo $view->escape($value) ?>"<?php endif ?>
|
||||
<?php echo $view['form']->renderBlock('attributes') ?>
|
||||
/>
|
||||
|
@ -37,14 +37,7 @@ class ExceptionController extends ContainerAware
|
||||
{
|
||||
$this->container->get('request')->setRequestFormat($format);
|
||||
|
||||
// the count variable avoids an infinite loop on
|
||||
// some Windows configurations where ob_get_level()
|
||||
// never reaches 0
|
||||
$count = 100;
|
||||
$currentContent = '';
|
||||
while (ob_get_level() && --$count) {
|
||||
$currentContent .= ob_get_clean();
|
||||
}
|
||||
$currentContent = $this->getAndCleanOutputBuffering();
|
||||
|
||||
$templating = $this->container->get('templating');
|
||||
$code = $exception->getStatusCode();
|
||||
@ -66,6 +59,21 @@ class ExceptionController extends ContainerAware
|
||||
return $response;
|
||||
}
|
||||
|
||||
protected function getAndCleanOutputBuffering()
|
||||
{
|
||||
// the count variable avoids an infinite loop on
|
||||
// some Windows configurations where ob_get_level()
|
||||
// never reaches 0
|
||||
$count = 100;
|
||||
$startObLevel = $this->container->get('kernel')->getStartObLevel();
|
||||
$currentContent = '';
|
||||
while (ob_get_level() > $startObLevel && --$count) {
|
||||
$currentContent .= ob_get_clean();
|
||||
}
|
||||
|
||||
return $currentContent;
|
||||
}
|
||||
|
||||
protected function findTemplate($templating, $format, $code, $debug)
|
||||
{
|
||||
$name = $debug ? 'exception' : 'error';
|
||||
|
@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony framework.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
namespace Symfony\Bundle\TwigBundle\Tests\Controller;
|
||||
|
||||
use Symfony\Bundle\TwigBundle\Tests\TestCase;
|
||||
|
||||
use Symfony\Bundle\TwigBundle\Controller\ExceptionController;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Scope;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
|
||||
class ExceptionControllerTest extends TestCase
|
||||
{
|
||||
protected $controller;
|
||||
protected $container;
|
||||
protected $flatten;
|
||||
protected $templating;
|
||||
protected $kernel;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->flatten = $this->getMock('Symfony\Component\HttpKernel\Exception\FlattenException');
|
||||
$this->flatten
|
||||
->expects($this->once())
|
||||
->method('getStatusCode')
|
||||
->will($this->returnValue(404));
|
||||
$this->flatten
|
||||
->expects($this->once())
|
||||
->method('getHeaders')
|
||||
->will($this->returnValue(array()));
|
||||
$this->controller = new ExceptionController();
|
||||
$this->kernel = $this->getMock('Symfony\\Component\\HttpKernel\\KernelInterface');
|
||||
$this->templating = $this->getMockBuilder('Symfony\\Bundle\\TwigBundle\\TwigEngine')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->templating
|
||||
->expects($this->any())
|
||||
->method('renderResponse')
|
||||
->will($this->returnValue($this->getMock('Symfony\Component\HttpFoundation\Response')));
|
||||
$this->container = $this->getContainer();
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
parent::tearDown();
|
||||
|
||||
$this->controller = null;
|
||||
$this->container = null;
|
||||
$this->flatten = null;
|
||||
$this->templating = null;
|
||||
$this->kernel = null;
|
||||
}
|
||||
|
||||
public function testOnlyClearOwnOutputBuffers()
|
||||
{
|
||||
$this->container->enterScope('request');
|
||||
|
||||
$this->kernel
|
||||
->expects($this->once())
|
||||
->method('getStartObLevel')
|
||||
->will($this->returnValue(1));
|
||||
|
||||
$this->controller->setContainer($this->container);
|
||||
$this->controller->showAction($this->flatten);
|
||||
}
|
||||
|
||||
private function getContainer()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->addScope(new Scope('request'));
|
||||
$container->register('request', 'Symfony\\Component\\HttpFoundation\\Request')->setScope('request');
|
||||
$container->set('templating', $this->templating);
|
||||
$container->setParameter('kernel.bundles', array());
|
||||
$container->setParameter('kernel.cache_dir', __DIR__);
|
||||
$container->setParameter('kernel.root_dir', __DIR__);
|
||||
$container->set('kernel', $this->kernel);
|
||||
|
||||
return $container;
|
||||
}
|
||||
}
|
@ -77,7 +77,7 @@ class Link
|
||||
*/
|
||||
public function getUri()
|
||||
{
|
||||
$uri = $this->getRawUri();
|
||||
$uri = trim($this->getRawUri());
|
||||
|
||||
// absolute URL?
|
||||
if ('http' === substr($uri, 0, 4)) {
|
||||
|
@ -142,6 +142,18 @@ class DateTimeToArrayTransformer extends BaseDateTimeTransformer
|
||||
));
|
||||
}
|
||||
|
||||
if (isset($value['month']) && !ctype_digit($value['month'])) {
|
||||
throw new TransformationFailedException('This month an invalid');
|
||||
}
|
||||
|
||||
if (isset($value['day']) && !ctype_digit($value['day'])) {
|
||||
throw new TransformationFailedException('This day an invalid');
|
||||
}
|
||||
|
||||
if (isset($value['year']) && !ctype_digit($value['year'])) {
|
||||
throw new TransformationFailedException('This year an invalid');
|
||||
}
|
||||
|
||||
if (!empty($value['month']) && !empty($value['day']) && !empty($value['year']) && false === checkdate($value['month'], $value['day'], $value['year'])) {
|
||||
throw new TransformationFailedException('This is an invalid date');
|
||||
}
|
||||
|
@ -55,6 +55,7 @@ abstract class Kernel implements KernelInterface
|
||||
protected $booted;
|
||||
protected $name;
|
||||
protected $startTime;
|
||||
protected $startObLevel;
|
||||
protected $classes;
|
||||
|
||||
const VERSION = '2.1.0-DEV';
|
||||
@ -120,6 +121,8 @@ abstract class Kernel implements KernelInterface
|
||||
return;
|
||||
}
|
||||
|
||||
$this->startObLevel = ob_get_level();
|
||||
|
||||
// init bundles
|
||||
$this->initializeBundles();
|
||||
|
||||
@ -421,6 +424,16 @@ abstract class Kernel implements KernelInterface
|
||||
return $this->debug ? $this->startTime : -INF;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the ob_level at the start of the request
|
||||
*
|
||||
* @return integer The request start ob_level
|
||||
*/
|
||||
public function getStartObLevel()
|
||||
{
|
||||
return $this->startObLevel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the cache directory.
|
||||
*
|
||||
|
@ -179,6 +179,13 @@ interface KernelInterface extends HttpKernelInterface, \Serializable
|
||||
*/
|
||||
function getStartTime();
|
||||
|
||||
/**
|
||||
* Gets the ob_level at the start of the request
|
||||
*
|
||||
* @return integer The request start ob_level
|
||||
*/
|
||||
function getStartObLevel();
|
||||
|
||||
/**
|
||||
* Gets the cache directory.
|
||||
*
|
||||
|
@ -26,6 +26,7 @@ class MessageCatalogue implements MessageCatalogueInterface
|
||||
private $locale;
|
||||
private $resources;
|
||||
private $fallbackCatalogue;
|
||||
private $parent;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
@ -183,6 +184,15 @@ class MessageCatalogue implements MessageCatalogueInterface
|
||||
*/
|
||||
public function addFallbackCatalogue(MessageCatalogueInterface $catalogue)
|
||||
{
|
||||
// detect circular references
|
||||
$c = $this;
|
||||
do {
|
||||
if ($c->getLocale() === $catalogue->getLocale()) {
|
||||
throw new \LogicException(sprintf('Circular reference detected when adding a fallback catalogue for locale "%s".', $catalogue->getLocale()));
|
||||
}
|
||||
} while ($c = $c->parent);
|
||||
|
||||
$catalogue->parent = $this;
|
||||
$this->fallbackCatalogue = $catalogue;
|
||||
|
||||
foreach ($catalogue->getResources() as $resource) {
|
||||
|
@ -79,6 +79,10 @@ class LinkTest extends \PHPUnit_Framework_TestCase
|
||||
return array(
|
||||
array('/foo', 'http://localhost/bar/foo/', 'http://localhost/foo'),
|
||||
array('/foo', 'http://localhost/bar/foo', 'http://localhost/foo'),
|
||||
array('
|
||||
/foo', 'http://localhost/bar/foo/', 'http://localhost/foo'),
|
||||
array('/foo
|
||||
', 'http://localhost/bar/foo', 'http://localhost/foo'),
|
||||
|
||||
array('foo', 'http://localhost/bar/foo/', 'http://localhost/bar/foo/foo'),
|
||||
array('foo', 'http://localhost/bar/foo', 'http://localhost/bar/foo'),
|
||||
|
@ -1386,7 +1386,6 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
|
||||
'/input
|
||||
[@type="password"]
|
||||
[@name="na&me"]
|
||||
[@value=""]
|
||||
'
|
||||
);
|
||||
}
|
||||
@ -1419,7 +1418,6 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
|
||||
'/input
|
||||
[@type="password"]
|
||||
[@name="na&me"]
|
||||
[@value=""]
|
||||
[@maxlength="123"]
|
||||
'
|
||||
);
|
||||
|
@ -463,4 +463,52 @@ class DateTimeToArrayTransformerTest extends DateTimeTestCase
|
||||
'second' => '6',
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Symfony\Component\Form\Exception\TransformationFailedException
|
||||
*/
|
||||
public function testReverseTransformWithStringDay()
|
||||
{
|
||||
$transformer = new DateTimeToArrayTransformer();
|
||||
$transformer->reverseTransform(array(
|
||||
'year' => '2010',
|
||||
'month' => '2',
|
||||
'day' => 'bazinga',
|
||||
'hour' => '4',
|
||||
'minute' => '5',
|
||||
'second' => '6',
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Symfony\Component\Form\Exception\TransformationFailedException
|
||||
*/
|
||||
public function testReverseTransformWithStringMonth()
|
||||
{
|
||||
$transformer = new DateTimeToArrayTransformer();
|
||||
$transformer->reverseTransform(array(
|
||||
'year' => '2010',
|
||||
'month' => 'bazinga',
|
||||
'day' => '31',
|
||||
'hour' => '4',
|
||||
'minute' => '5',
|
||||
'second' => '6',
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Symfony\Component\Form\Exception\TransformationFailedException
|
||||
*/
|
||||
public function testReverseTransformWithStringYear()
|
||||
{
|
||||
$transformer = new DateTimeToArrayTransformer();
|
||||
$transformer->reverseTransform(array(
|
||||
'year' => 'bazinga',
|
||||
'month' => '2',
|
||||
'day' => '31',
|
||||
'hour' => '4',
|
||||
'minute' => '5',
|
||||
'second' => '6',
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -124,6 +124,18 @@ class MessageCatalogueTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals(array($r, $r1), $catalogue->getResources());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException LogicException
|
||||
*/
|
||||
public function testAddFallbackCatalogueWithCircularReference()
|
||||
{
|
||||
$main = new MessageCatalogue('en_US');
|
||||
$fallback = new MessageCatalogue('fr_FR');
|
||||
|
||||
$fallback->addFallbackCatalogue($main);
|
||||
$main->addFallbackCatalogue($fallback);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException LogicException
|
||||
*/
|
||||
|
@ -47,10 +47,10 @@ class InlineTest extends \PHPUnit_Framework_TestCase
|
||||
$this->markTestSkipped('Your platform does not support locales.');
|
||||
}
|
||||
|
||||
setlocale(LC_ALL, 'fr_FR.UTF-8', 'fr_FR.UTF8', 'fr_FR.utf-8', 'fr_FR.utf8');
|
||||
setlocale(LC_ALL, 'fr_FR.UTF-8', 'fr_FR.UTF8', 'fr_FR.utf-8', 'fr_FR.utf8', 'French_France.1252');
|
||||
|
||||
$this->assertEquals('1.2', Inline::dump(1.2));
|
||||
$this->assertContains('fr', setlocale(LC_NUMERIC, 0));
|
||||
$this->assertContains('fr', strtolower(setlocale(LC_NUMERIC, 0)));
|
||||
|
||||
setlocale(LC_ALL, $locale);
|
||||
}
|
||||
|
Reference in New Issue
Block a user