function TwigExtensionTest::providerTestTwigAddClass

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

Provides data for ::testTwigAddClass().

Return value

\Iterator

File

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

Class

TwigExtensionTest
Tests the twig extension.

Namespace

Drupal\Tests\Core\Template

Code

public static function providerTestTwigAddClass() : \Iterator {
  (yield 'should add a class on element' => [
    [
      '#type' => 'container',
    ],
    'my-class',
    [
      '#type' => 'container',
      '#attributes' => [
        'class' => [
          'my-class',
        ],
      ],
    ],
  ]);
  (yield 'should add a class from a array of string keys on element' => [
    [
      '#type' => 'container',
    ],
    [
      'my-class',
    ],
    [
      '#type' => 'container',
      '#attributes' => [
        'class' => [
          'my-class',
        ],
      ],
    ],
  ]);
  (yield 'should add a class from a Markup value' => [
    [
      '#type' => 'container',
    ],
    [
      Markup::create('my-class'),
    ],
    [
      '#type' => 'container',
      '#attributes' => [
        'class' => [
          'my-class',
        ],
      ],
    ],
  ]);
  (yield '#printed should be removed after class(es) added' => [
    [
      '#markup' => 'This content is already is rendered',
      '#printed' => TRUE,
    ],
    '',
    [
      '#markup' => 'This content is already is rendered',
      '#attributes' => [
        'class' => [
          '',
        ],
      ],
    ],
  ]);
}

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