Merge branch '2.8' into 3.4
* 2.8: fixed Twig URL Don't assume that file binary exists on *nix OS Fix that ESI/SSI processing can turn a \"private\" response \"public\" [Form] Fixed trimming choice values
This commit is contained in:
commit
437acb4357
@ -1,7 +1,7 @@
|
||||
Twig Bridge
|
||||
===========
|
||||
|
||||
Provides integration for [Twig](http://twig.sensiolabs.org/) with various
|
||||
Provides integration for [Twig](https://twig.symfony.com/) with various
|
||||
Symfony components.
|
||||
|
||||
Resources
|
||||
|
@ -336,6 +336,7 @@ class ChoiceType extends AbstractType
|
||||
// See https://github.com/symfony/symfony/pull/5582
|
||||
'data_class' => null,
|
||||
'choice_translation_domain' => true,
|
||||
'trim' => false,
|
||||
));
|
||||
|
||||
$resolver->setNormalizer('placeholder', $placeholderNormalizer);
|
||||
|
@ -1880,4 +1880,196 @@ class ChoiceTypeTest extends BaseTypeTest
|
||||
'multiple, expanded' => array(true, true, array(array())),
|
||||
);
|
||||
}
|
||||
|
||||
public function testInheritTranslationDomainFromParent()
|
||||
{
|
||||
$view = $this->factory
|
||||
->createNamedBuilder('parent', FormTypeTest::TESTED_TYPE, null, array(
|
||||
'translation_domain' => 'domain',
|
||||
))
|
||||
->add('child', static::TESTED_TYPE, array(
|
||||
'choices_as_values' => true,
|
||||
))
|
||||
->getForm()
|
||||
->createView();
|
||||
|
||||
$this->assertEquals('domain', $view['child']->vars['translation_domain']);
|
||||
}
|
||||
|
||||
public function testPassTranslationDomainToView()
|
||||
{
|
||||
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'choices_as_values' => true,
|
||||
'translation_domain' => 'domain',
|
||||
))
|
||||
->createView();
|
||||
|
||||
$this->assertSame('domain', $view->vars['translation_domain']);
|
||||
}
|
||||
|
||||
public function testPreferOwnTranslationDomain()
|
||||
{
|
||||
$view = $this->factory
|
||||
->createNamedBuilder('parent', FormTypeTest::TESTED_TYPE, null, array(
|
||||
'translation_domain' => 'parent_domain',
|
||||
))
|
||||
->add('child', static::TESTED_TYPE, array(
|
||||
'choices_as_values' => true,
|
||||
'translation_domain' => 'domain',
|
||||
))
|
||||
->getForm()
|
||||
->createView();
|
||||
|
||||
$this->assertEquals('domain', $view['child']->vars['translation_domain']);
|
||||
}
|
||||
|
||||
public function testDefaultTranslationDomain()
|
||||
{
|
||||
$view = $this->factory->createNamedBuilder('parent', FormTypeTest::TESTED_TYPE)
|
||||
->add('child', static::TESTED_TYPE, array(
|
||||
'choices_as_values' => true,
|
||||
))
|
||||
->getForm()
|
||||
->createView();
|
||||
|
||||
$this->assertNull($view['child']->vars['translation_domain']);
|
||||
}
|
||||
|
||||
public function testPassMultipartFalseToView()
|
||||
{
|
||||
$view = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'choices_as_values' => true,
|
||||
))
|
||||
->createView();
|
||||
|
||||
$this->assertFalse($view->vars['multipart']);
|
||||
}
|
||||
|
||||
public function testPassLabelToView()
|
||||
{
|
||||
$view = $this->factory->createNamed('__test___field', static::TESTED_TYPE, null, array(
|
||||
'label' => 'My label',
|
||||
'choices_as_values' => true,
|
||||
))
|
||||
->createView();
|
||||
|
||||
$this->assertSame('My label', $view->vars['label']);
|
||||
}
|
||||
|
||||
public function testPassIdAndNameToViewWithGrandParent()
|
||||
{
|
||||
$builder = $this->factory->createNamedBuilder('parent', FormTypeTest::TESTED_TYPE)
|
||||
->add('child', FormTypeTest::TESTED_TYPE);
|
||||
$builder->get('child')->add('grand_child', static::TESTED_TYPE, array(
|
||||
'choices_as_values' => true,
|
||||
));
|
||||
$view = $builder->getForm()->createView();
|
||||
|
||||
$this->assertEquals('parent_child_grand_child', $view['child']['grand_child']->vars['id']);
|
||||
$this->assertEquals('grand_child', $view['child']['grand_child']->vars['name']);
|
||||
$this->assertEquals('parent[child][grand_child]', $view['child']['grand_child']->vars['full_name']);
|
||||
}
|
||||
|
||||
public function testPassIdAndNameToViewWithParent()
|
||||
{
|
||||
$view = $this->factory->createNamedBuilder('parent', FormTypeTest::TESTED_TYPE)
|
||||
->add('child', static::TESTED_TYPE, array(
|
||||
'choices_as_values' => true,
|
||||
))
|
||||
->getForm()
|
||||
->createView();
|
||||
|
||||
$this->assertEquals('parent_child', $view['child']->vars['id']);
|
||||
$this->assertEquals('child', $view['child']->vars['name']);
|
||||
$this->assertEquals('parent[child]', $view['child']->vars['full_name']);
|
||||
}
|
||||
|
||||
public function testPassDisabledAsOption()
|
||||
{
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'disabled' => true,
|
||||
'choices_as_values' => true,
|
||||
));
|
||||
|
||||
$this->assertTrue($form->isDisabled());
|
||||
}
|
||||
|
||||
public function testPassIdAndNameToView()
|
||||
{
|
||||
$view = $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
|
||||
'choices_as_values' => true,
|
||||
))
|
||||
->createView();
|
||||
|
||||
$this->assertEquals('name', $view->vars['id']);
|
||||
$this->assertEquals('name', $view->vars['name']);
|
||||
$this->assertEquals('name', $view->vars['full_name']);
|
||||
}
|
||||
|
||||
public function testStripLeadingUnderscoresAndDigitsFromId()
|
||||
{
|
||||
$view = $this->factory->createNamed('_09name', static::TESTED_TYPE, null, array(
|
||||
'choices_as_values' => true,
|
||||
))
|
||||
->createView();
|
||||
|
||||
$this->assertEquals('name', $view->vars['id']);
|
||||
$this->assertEquals('_09name', $view->vars['name']);
|
||||
$this->assertEquals('_09name', $view->vars['full_name']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideTrimCases
|
||||
*/
|
||||
public function testTrimIsDisabled($multiple, $expanded)
|
||||
{
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'multiple' => $multiple,
|
||||
'expanded' => $expanded,
|
||||
'choices' => array(
|
||||
'a' => '1',
|
||||
),
|
||||
'choices_as_values' => true,
|
||||
));
|
||||
|
||||
$submittedData = ' 1';
|
||||
|
||||
$form->submit($multiple ? (array) $submittedData : $submittedData);
|
||||
|
||||
// When the choice does not exist the transformation fails
|
||||
$this->assertFalse($form->isSynchronized());
|
||||
$this->assertNull($form->getData());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideTrimCases
|
||||
*/
|
||||
public function testSubmitValueWithWhiteSpace($multiple, $expanded)
|
||||
{
|
||||
$valueWhitWhiteSpace = '1 ';
|
||||
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
||||
'multiple' => $multiple,
|
||||
'expanded' => $expanded,
|
||||
'choices' => array(
|
||||
'a' => $valueWhitWhiteSpace,
|
||||
),
|
||||
'choices_as_values' => true,
|
||||
));
|
||||
|
||||
$form->submit($multiple ? (array) $valueWhitWhiteSpace : $valueWhitWhiteSpace);
|
||||
|
||||
$this->assertTrue($form->isSynchronized());
|
||||
$this->assertSame($multiple ? (array) $valueWhitWhiteSpace : $valueWhitWhiteSpace, $form->getData());
|
||||
}
|
||||
|
||||
public function provideTrimCases()
|
||||
{
|
||||
return array(
|
||||
'Simple' => array(false, false),
|
||||
'Multiple' => array(true, false),
|
||||
'Simple expanded' => array(false, true),
|
||||
'Multiple expanded' => array(true, true),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -43,7 +43,21 @@ class FileBinaryMimeTypeGuesser implements MimeTypeGuesserInterface
|
||||
*/
|
||||
public static function isSupported()
|
||||
{
|
||||
return '\\' !== DIRECTORY_SEPARATOR && function_exists('passthru') && function_exists('escapeshellarg');
|
||||
static $supported = null;
|
||||
|
||||
if (null !== $supported) {
|
||||
return $supported;
|
||||
}
|
||||
|
||||
if ('\\' === DIRECTORY_SEPARATOR || !function_exists('passthru') || !function_exists('escapeshellarg')) {
|
||||
return $supported = false;
|
||||
}
|
||||
|
||||
ob_start();
|
||||
passthru('command -v file', $exitStatus);
|
||||
$binPath = trim(ob_get_clean());
|
||||
|
||||
return $supported = 0 === $exitStatus && '' !== $binPath;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -519,13 +519,19 @@ class Response
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the response is worth caching under any circumstance.
|
||||
* Returns true if the response may safely be kept in a shared (surrogate) cache.
|
||||
*
|
||||
* Responses marked "private" with an explicit Cache-Control directive are
|
||||
* considered uncacheable.
|
||||
*
|
||||
* Responses with neither a freshness lifetime (Expires, max-age) nor cache
|
||||
* validator (Last-Modified, ETag) are considered uncacheable.
|
||||
* validator (Last-Modified, ETag) are considered uncacheable because there is
|
||||
* no way to tell when or how to remove them from the cache.
|
||||
*
|
||||
* Note that RFC 7231 and RFC 7234 possibly allow for a more permissive implementation,
|
||||
* for example "status codes that are defined as cacheable by default [...]
|
||||
* can be reused by a cache with heuristic expiration unless otherwise indicated"
|
||||
* (https://tools.ietf.org/html/rfc7231#section-6.1)
|
||||
*
|
||||
* @return bool true if the response is worth caching, false otherwise
|
||||
*
|
||||
|
@ -72,7 +72,7 @@ class ResponseCacheStrategy implements ResponseCacheStrategyInterface
|
||||
$response->setLastModified(null);
|
||||
}
|
||||
|
||||
if (!$response->isFresh()) {
|
||||
if (!$response->isFresh() || !$response->isCacheable()) {
|
||||
$this->cacheable = false;
|
||||
}
|
||||
|
||||
|
@ -175,8 +175,26 @@ class ResponseCacheStrategyTest extends TestCase
|
||||
$cacheStrategy->update($masterResponse);
|
||||
|
||||
$this->assertTrue($masterResponse->headers->hasCacheControlDirective('private'));
|
||||
// Not sure if we should pass "max-age: 60" in this case, as long as the response is private and
|
||||
// that's the more conservative of both the master and embedded response...?
|
||||
$this->assertFalse($masterResponse->headers->hasCacheControlDirective('public'));
|
||||
}
|
||||
|
||||
public function testEmbeddingPublicResponseDoesNotMakeMainResponsePublic()
|
||||
{
|
||||
$cacheStrategy = new ResponseCacheStrategy();
|
||||
|
||||
$masterResponse = new Response();
|
||||
$masterResponse->setPrivate(); // this is the default, but let's be explicit
|
||||
$masterResponse->setMaxAge(100);
|
||||
|
||||
$embeddedResponse = new Response();
|
||||
$embeddedResponse->setPublic();
|
||||
$embeddedResponse->setSharedMaxAge(100);
|
||||
|
||||
$cacheStrategy->add($embeddedResponse);
|
||||
$cacheStrategy->update($masterResponse);
|
||||
|
||||
$this->assertTrue($masterResponse->headers->hasCacheControlDirective('private'));
|
||||
$this->assertFalse($masterResponse->headers->hasCacheControlDirective('public'));
|
||||
}
|
||||
|
||||
public function testResponseIsExiprableWhenEmbeddedResponseCombinesExpiryAndValidation()
|
||||
|
Reference in New Issue
Block a user