class FormElementLabelTest
Same name and namespace in other branches
- 11.x core/modules/system/tests/src/Kernel/Form/FormElementLabelTest.php \Drupal\Tests\system\Kernel\Form\FormElementLabelTest
- 10 core/modules/system/tests/src/Kernel/Form/FormElementLabelTest.php \Drupal\Tests\system\Kernel\Form\FormElementLabelTest
- 8.9.x core/modules/system/tests/src/Kernel/Form/FormElementLabelTest.php \Drupal\Tests\system\Kernel\Form\FormElementLabelTest
Tests for form_element_label theme hook.
@group Form
Hierarchy
- class \Drupal\KernelTests\KernelTestBase implements \Drupal\Core\DependencyInjection\ServiceProviderInterface uses \Drupal\KernelTests\AssertLegacyTrait, \Drupal\KernelTests\AssertContentTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\ExtensionListTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\system\Kernel\Form\FormElementLabelTest extends \Drupal\KernelTests\KernelTestBase
Expanded class hierarchy of FormElementLabelTest
File
-
core/
modules/ system/ tests/ src/ Kernel/ Form/ FormElementLabelTest.php, line 13
Namespace
Drupal\Tests\system\Kernel\FormView source
class FormElementLabelTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = [
'system',
];
/**
* Ensures that attributes can be placed for form element label.
*/
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);
// Add label attributes to a form element.
$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);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.