function RenderElementTest::providerTestSetAttributes
Provides test data for testSetAttributes().
File
-
core/
tests/ Drupal/ Tests/ Core/ Render/ Element/ RenderElementTest.php, line 127
Class
- RenderElementTest
- @coversDefaultClass \Drupal\Core\Render\Element\RenderElementBase @group Render
Namespace
Drupal\Tests\Core\Render\ElementCode
public static function providerTestSetAttributes() : array {
return [
'No-op' => [
'element' => [
'#type' => 'textfield',
],
'class' => [],
'expected' => [
'#type' => 'textfield',
],
],
'Add first class' => [
'element' => [
'#type' => 'textfield',
],
'class' => [
'foo',
'bar',
],
'expected' => [
'#type' => 'textfield',
'#attributes' => [
'class' => [
'foo',
'bar',
],
],
],
],
'Append classes' => [
'element' => [
'#type' => 'textfield',
'#attributes' => [
'class' => [
'foo',
'bar',
],
],
],
'class' => [
'baz',
],
'expected' => [
'#type' => 'textfield',
'#attributes' => [
'class' => [
'foo',
'bar',
'baz',
],
],
],
],
'Required' => [
'element' => [
'#type' => 'textfield',
'#required' => TRUE,
],
'class' => [],
'expected' => [
'#type' => 'textfield',
'#required' => TRUE,
'#attributes' => [
'class' => [
'required',
],
'required' => 'required',
],
],
],
'Parent with error' => [
'element' => [
'#type' => 'textfield',
'#parents' => [
'dummy_parent',
],
'#errors' => 'invalid',
'#validated' => TRUE,
],
'class' => [],
'expected' => [
'#type' => 'textfield',
'#parents' => [
'dummy_parent',
],
'#errors' => 'invalid',
'#validated' => TRUE,
'#attributes' => [
'class' => [
'error',
],
'aria-invalid' => 'true',
],
],
],
];
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.