You are here

public function TwigExtensionFiltersTest::testAddFilter in Components! 3.x

Same name and namespace in other branches
  1. 8.2 tests/src/Unit/TwigExtensionFiltersTest.php \Drupal\Tests\components\Unit\TwigExtensionFiltersTest::testAddFilter()

Tests the add filter.

@covers ::addFilter

@dataProvider providerTestAddFilter

Parameters

string $at: The dotted-path to the deeply nested element to add.

mixed $value: The value(s) to add.

array $expected: The expected render array.

File

tests/src/Unit/TwigExtensionFiltersTest.php, line 272

Class

TwigExtensionFiltersTest
@coversDefaultClass \Drupal\components\Template\TwigExtension @group components

Namespace

Drupal\Tests\components\Unit

Code

public function testAddFilter(string $at, $value, array $expected) {
  $element = [
    'existing' => 'value',
    'element' => [
      '#type' => 'element',
      '#attributes' => [
        'class' => [
          'old-value-1',
          'old-value-2',
        ],
        'id' => 'element',
      ],
    ],
  ];
  $result = NULL;
  try {
    $result = TwigExtension::addFilter($element, $at, $value);
  } catch (\Exception $e) {
    $this
      ->fail('No Exception expected; "' . $e
      ->getMessage() . '" thrown during: ' . $this
      ->getName());
  }
  $this
    ->assertEquals($expected, $result, 'Failed to replace a value.');
}