diff --git a/core/modules/simpletest/src/AssertContentTrait.php b/core/modules/simpletest/src/AssertContentTrait.php index 00898be..87e6c66 100644 --- a/core/modules/simpletest/src/AssertContentTrait.php +++ b/core/modules/simpletest/src/AssertContentTrait.php @@ -1173,6 +1173,44 @@ protected function assertNoFieldById($id, $value = '', $message = '', $group = ' } /** + * Asserts that a field in the current page is enabled. + * + * @param string $name + * Name of field to assert. + * @param string $message + * (optional) A message to display with the assertion. Do not translate + * messages: use \Drupal\Component\Utility\SafeMarkup::format() to embed + * variables in the message text, not t(). If left blank, a default message + * will be displayed. + * + * @return bool + * TRUE on pass, FALSE on fail. + */ + protected function assertFieldEnabled($name, $message = '') { + $elements = $this->xpath($this->constructFieldXpath('name', $name)); + return $this->assertTrue(isset($elements[0]) && empty($elements[0]['disabled']), $message ? $message : t('Field %name is enabled.', array('%name' => $name)), t('Browser')); + } + + /** + * Asserts that a field in the current page is disabled. + * + * @param string $name + * Name of field to assert. + * @param string $message + * (optional) A message to display with the assertion. Do not translate + * messages: use \Drupal\Component\Utility\SafeMarkup::format() to embed + * variables in the message text, not t(). If left blank, a default message + * will be displayed. + * + * @return bool + * TRUE on pass, FALSE on fail. + */ + protected function assertFieldDisabled($name, $message = '') { + $elements = $this->xpath($this->constructFieldXpath('name', $name)); + return $this->assertTrue(isset($elements[0]) && !empty($elements[0]['disabled']), $message ? $message : t('Field %name is disabled.', array('%name' => $name)), t('Browser')); + } + + /** * Asserts that a checkbox field in the current page is checked. * * @param string $id