FormElementLabelTest.php in Drupal 10
File
core/modules/system/tests/src/Kernel/Form/FormElementLabelTest.php
View source
<?php
namespace Drupal\Tests\system\Kernel\Form;
use Drupal\KernelTests\KernelTestBase;
use Symfony\Component\CssSelector\CssSelectorConverter;
class FormElementLabelTest extends KernelTestBase {
protected static $modules = [
'system',
];
public function testAttributes() {
$render_array = [
'#type' => 'label',
'#attributes' => [
'class' => [
'kitten',
],
],
'#title' => 'Kittens',
'#title_display' => 'above',
];
$css_selector_converter = new CssSelectorConverter();
$this
->render($render_array);
$elements = $this
->xpath($css_selector_converter
->toXPath('.kitten'));
$this
->assertCount(1, $elements);
$render_array = [
'#type' => 'textfield',
'#label_attributes' => [
'class' => [
'meow',
],
],
'#title' => 'Kitten sounds',
];
$this
->render($render_array);
$elements = $this
->xpath($css_selector_converter
->toXPath('label.meow'));
$this
->assertCount(1, $elements);
}
}