class TwigThemeTestUtils

Helper functions used by both test modules and test classes.

Hierarchy

Expanded class hierarchy of TwigThemeTestUtils

2 files declare their use of TwigThemeTestUtils
EngineTwigTest.php in core/modules/system/tests/src/Functional/Theme/EngineTwigTest.php
test_theme.theme in core/modules/system/tests/themes/test_theme/test_theme.theme

File

core/modules/system/tests/modules/twig_theme_test/src/TwigThemeTestUtils.php, line 10

Namespace

Drupal\twig_theme_test
View source
class TwigThemeTestUtils {
  
  /**
   * Helper function to test PHP variables in the Twig engine.
   */
  public static function phpValues() : array {
    // Prefix each variable with "twig_" so that Twig doesn't get confused
    // between a variable and a primitive. Arrays are not tested since they should
    // be a Drupal render array.
    return [
      'twig_null' => [
        'value' => NULL,
        'expected' => '',
      ],
      'twig_bool_false' => [
        'value' => FALSE,
        'expected' => '',
      ],
      'twig_bool_true' => [
        'value' => TRUE,
        'expected' => '1',
      ],
      'twig_int' => [
        'value' => 1,
        'expected' => '1',
      ],
      'twig_int_0' => [
        'value' => 0,
        'expected' => '0',
      ],
      'twig_float' => [
        'value' => 122.34343,
        'expected' => '122.34343',
      ],
      'twig_string' => [
        'value' => 'Hello world!',
        'expected' => 'Hello world!',
      ],
    ];
  }

}

Members

Title Sort descending Modifiers Object type Summary
TwigThemeTestUtils::phpValues public static function Helper function to test PHP variables in the Twig engine.

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