function TwigExtensionTest::providerTestTwigAddSuggestionFilter

Same name and namespace in other branches
  1. 11.x core/tests/Drupal/Tests/Core/Template/TwigExtensionTest.php \Drupal\Tests\Core\Template\TwigExtensionTest::providerTestTwigAddSuggestionFilter()

Provides data for ::testTwigAddSuggestionFilter().

Return value

\Iterator

File

core/tests/Drupal/Tests/Core/Template/TwigExtensionTest.php, line 452

Class

TwigExtensionTest
Tests the twig extension.

Namespace

Drupal\Tests\Core\Template

Code

public static function providerTestTwigAddSuggestionFilter() : \Iterator {
  yield 'suggestion should be added' => [
    [
      '#theme' => 'kitten',
      '#name' => 'Mila',
    ],
    'cute',
    [
      '#theme' => [
        'kitten__cute',
        'kitten',
      ],
      '#name' => 'Mila',
    ],
  ];
  yield 'suggestion should extend existing suggestions' => [
    [
      '#theme' => 'kitten__stripy',
      '#name' => 'Mila',
    ],
    'cute',
    [
      '#theme' => [
        'kitten__stripy__cute',
        'kitten__stripy',
      ],
      '#name' => 'Mila',
    ],
  ];
  yield 'suggestion should have highest priority' => [
    [
      '#theme' => [
        'kitten__stripy',
        'kitten',
      ],
      '#name' => 'Mila',
    ],
    'cute',
    [
      '#theme' => [
        'kitten__stripy__cute',
        'kitten__cute',
        'kitten__stripy',
        'kitten',
      ],
      '#name' => 'Mila',
    ],
  ];
  yield '#printed should be removed after suggestion was added' => [
    [
      '#theme' => 'kitten',
      '#name' => 'Mila',
      '#printed' => TRUE,
    ],
    'cute',
    [
      '#theme' => [
        'kitten__cute',
        'kitten',
      ],
      '#name' => 'Mila',
    ],
  ];
  yield 'cache key should be added' => [
    [
      '#theme' => 'kitten',
      '#name' => 'Mila',
      '#cache' => [
        'keys' => [
          'kitten',
        ],
      ],
    ],
    'cute',
    [
      '#theme' => [
        'kitten__cute',
        'kitten',
      ],
      '#name' => 'Mila',
      '#cache' => [
        'keys' => [
          'kitten',
          'cute',
        ],
      ],
    ],
  ];
  yield 'null/missing content should be ignored' => [
    NULL,
    'cute',
    NULL,
  ];
}

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