function TwigDeprecationsTest::testParentVariableDeprecation

Same name and namespace in other branches
  1. 11.x core/tests/Drupal/KernelTests/Core/Theme/TwigDeprecationsTest.php \Drupal\KernelTests\Core\Theme\TwigDeprecationsTest::testParentVariableDeprecation()

Test deprecation of variables in parent does not leak to child.

File

core/tests/Drupal/KernelTests/Core/Theme/TwigDeprecationsTest.php, line 119

Class

TwigDeprecationsTest
Tests deprecating variables passed to twig templates.

Namespace

Drupal\KernelTests\Core\Theme

Code

public function testParentVariableDeprecation() : void {
  // 'foo' is used before the child template is processed, so this test
  // shows that processing the child does not lead to parent usage being
  // forgotten.
  // 'gaz' is used in the child template but only deprecated in the parent
  // template, so no deprecation error is triggered for it.
  $preprocess = [
    'contents' => [
      'child' => [
        '#theme' => 'theme_test_deprecations_child',
        '#foo' => 'foo-child',
        '#bar' => 'bar-child',
        '#gaz' => 'gaz-child',
      ],
    ],
    'deprecations' => [
      'foo' => $this->getDeprecationMessage('foo'),
      'gaz' => $this->getDeprecationMessage('gaz'),
    ],
  ];
  $this->assertRendered('foo|set_var|foo-child|gaz-child|bar', $preprocess);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.