trait DisableFieldTestTrait in Disable Field 8.2
Provides methods to simplify checking if a field is disabled or not.
This trait is meant to be used only by test classes.
Hierarchy
- trait \Drupal\Tests\disable_field\Traits\DisableFieldTestTrait
1 file declares its use of DisableFieldTestTrait
- DisableFieldTest.php in tests/
src/ Functional/ DisableFieldTest.php
File
- tests/
src/ Traits/ DisableFieldTestTrait.php, line 10
Namespace
Drupal\Tests\disable_field\TraitsView source
trait DisableFieldTestTrait {
/**
* Check if the given field exists, but is not disabled.
*
* @param string $field_name
* The field name to check.
*/
protected function checkIfFieldIsNotDisabledByFieldName(string $field_name) {
$this
->checkIfFieldIsNotDisabledById(sprintf('edit-%s-0-value', str_replace('_', '-', $field_name)));
}
/**
* Check if the given field with the given ID exists, but is not disabled.
*
* @param string $id
* The ID to check.
*/
protected function checkIfFieldIsNotDisabledById(string $id) {
$this
->assertSession()
->elementExists('css', sprintf('#%s', $id));
$this
->assertSession()
->elementNotExists('css', sprintf('#%s[disabled]', $id));
}
/**
* Check if the given field is disabled.
*
* @param string $field_name
* The field name to check.
*/
protected function checkIfFieldIsDisabledByFieldName(string $field_name) {
$this
->checkIfFieldIsDisabledById(sprintf('edit-%s-0-value', str_replace('_', '-', $field_name)));
}
/**
* Check if the element with the given ID is disabled.
*
* @param string $id
* The ID to check.
*/
protected function checkIfFieldIsDisabledById(string $id) {
$this
->assertSession()
->elementExists('css', sprintf('#%s[disabled]', $id));
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DisableFieldTestTrait:: |
protected | function | Check if the given field is disabled. | |
DisableFieldTestTrait:: |
protected | function | Check if the element with the given ID is disabled. | |
DisableFieldTestTrait:: |
protected | function | Check if the given field exists, but is not disabled. | |
DisableFieldTestTrait:: |
protected | function | Check if the given field with the given ID exists, but is not disabled. |