Skip to content
Snippets Groups Projects
Commit 852b0bab authored by Alex Pott's avatar Alex Pott
Browse files

Issue #2417733 by joelpittet, martin107: Drupal 8 breaks Twig's round filter

parent a32a88cb
No related branches found
No related tags found
No related merge requests found
<?php
/**
* @file
* Contains \Drupal\Tests\Core\Theme\TwigEngineTest.
*/
namespace Drupal\Tests\Core\Theme;
use Drupal\Tests\UnitTestCase;
/**
* Test coverage for the file core/themes/engines/twig/twig.engine.
*
* @group Theme
*/
class TwigEngineTest extends UnitTestCase {
/**
* The mocked Twig environment.
*
* @var \Twig_Environment|\PHPUnit_Framework_MockObject_MockObject
*/
protected $twigEnvironment;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
// Ensure that twig.engine is loaded, it is needed to access
// twig_drupal_escape_filter().
require_once $this->root . '/core/themes/engines/twig/twig.engine';
$this->twigEnvironment = $this->getMock('\Twig_Environment');
}
/**
* Tests output of integer and double 0 values of twig_render_var().
*
* @see https://www.drupal.org/node/2417733
*/
public function testsRenderZeroValue() {
$this->assertSame(twig_render_var(0), 0, 'twig_render_var() renders zero correctly when provided as an integer.');
$this->assertSame(twig_render_var(0.0), 0, 'twig_render_var() renders zero correctly when provided as a double.');
}
/**
* Tests output of integer and double 0 values of twig_drupal_escape_filter().
*
* @see https://www.drupal.org/node/2417733
*/
public function testsRenderEscapedZeroValue() {
$this->assertSame(twig_drupal_escape_filter($this->twigEnvironment, 0), 0, 'twig_escape_filter() returns zero correctly when provided as an integer.');
$this->assertSame(twig_drupal_escape_filter($this->twigEnvironment, 0.0), 0, 'twig_escape_filter() returns zero correctly when provided as a double.');
}
}
......@@ -127,8 +127,8 @@ function twig_render_template($template_file, array $variables) {
* @see TwigNodeVisitor
*/
function twig_render_var($arg) {
// Check for numeric zero.
if ($arg === 0) {
// Check for a numeric zero int or float.
if ($arg === 0 || $arg === 0.0) {
return 0;
}
......@@ -213,8 +213,8 @@ function twig_without($element) {
* The escaped, rendered output, or NULL if there is no valid output.
*/
function twig_drupal_escape_filter(\Twig_Environment $env, $string, $strategy = 'html', $charset = NULL, $autoescape = FALSE) {
// Check for a numeric zero.
if ($string === 0) {
// Check for a numeric zero int or float.
if ($string === 0 || $string === 0.0) {
return 0;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment