public function TwigExtensionFiltersTest::testAddFilter in Components! 8.2
Same name and namespace in other branches
- 3.x 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 357
Class
- TwigExtensionFiltersTest
- @coversDefaultClass \Drupal\components\Template\TwigExtension @group components
Namespace
Drupal\Tests\components\UnitCode
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.');
}