function TwigExtensionTest::providerTestTwigSetAttribute

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

A data provider for ::testTwigSetAttribute().

Return value

\Iterator

File

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

Class

TwigExtensionTest
Tests the twig extension.

Namespace

Drupal\Tests\Core\Template

Code

public static function providerTestTwigSetAttribute() : \Iterator {
  (yield 'should add attributes on element' => [
    [
      '#theme' => 'image',
    ],
    'title',
    'Aloha',
    [
      '#theme' => 'image',
      '#attributes' => [
        'title' => 'Aloha',
      ],
    ],
  ]);
  (yield 'should merge existing attributes on element' => [
    [
      '#theme' => 'image',
      '#attributes' => [
        'title' => 'Aloha',
      ],
    ],
    'title',
    'Bonjour',
    [
      '#theme' => 'image',
      '#attributes' => [
        'title' => 'Bonjour',
      ],
    ],
  ]);
  (yield 'should add JSON attribute value correctly on element' => [
    [
      '#type' => 'container',
    ],
    'data-slider',
    Json::encode([
      'autoplay' => TRUE,
    ]),
    [
      '#type' => 'container',
      '#attributes' => [
        'data-slider' => '{"autoplay":true}',
      ],
    ],
  ]);
  (yield '#printed should be removed after setting attribute' => [
    [
      '#markup' => 'This content is already is rendered',
      '#printed' => TRUE,
    ],
    'title',
    NULL,
    [
      '#markup' => 'This content is already is rendered',
      '#attributes' => [
        'title' => NULL,
      ],
    ],
  ]);
}

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