protected function AssertLegacyTrait::assertFieldsByValue in Drupal 8
Same name and namespace in other branches
- 9 core/tests/Drupal/FunctionalTests/AssertLegacyTrait.php \Drupal\FunctionalTests\AssertLegacyTrait::assertFieldsByValue()
Asserts that a field exists in the current page with a given Xpath result.
Parameters
\Behat\Mink\Element\NodeElement[] $fields: Xml elements.
string $value: (optional) Value of the field to assert. You may pass in NULL (default) to skip checking the actual value, while still checking that the field exists.
string $message: (optional) A message to display with the assertion. Do not translate messages with t().
Deprecated in drupal:8.3.0 and is removed from drupal:10.0.0. Use iteration over the fields yourself instead and directly check the values in the test.
5 calls to AssertLegacyTrait::assertFieldsByValue()
- AssertLegacyTrait::assertFieldByXPath in core/
tests/ Drupal/ FunctionalTests/ AssertLegacyTrait.php - Asserts that a field exists in the current page by the given XPath.
- AssertLegacyTrait::assertNoFieldByXPath in core/
tests/ Drupal/ FunctionalTests/ AssertLegacyTrait.php - Asserts that a field does not exist or its value does not match, by XPath.
- BrowserTestBaseTest::testFieldAssertsForTextfields in core/
tests/ Drupal/ FunctionalTests/ BrowserTestBaseTest.php - Tests legacy field asserts using textfields.
- BrowserTestBaseTest::testXpathAsserts in core/
tests/ Drupal/ FunctionalTests/ BrowserTestBaseTest.php - Tests legacy field asserts which use xpath directly.
- MultiFormTest::testMultiForm in core/
tests/ Drupal/ FunctionalJavascriptTests/ Ajax/ MultiFormTest.php - Tests that pages with the 'node_page_form' included twice work correctly.
File
- core/
tests/ Drupal/ FunctionalTests/ AssertLegacyTrait.php, line 611
Class
- AssertLegacyTrait
- Provides convenience methods for assertions in browser tests.
Namespace
Drupal\FunctionalTestsCode
protected function assertFieldsByValue($fields, $value = NULL, $message = '') {
// If value specified then check array for match.
$found = TRUE;
if (isset($value)) {
$found = FALSE;
if ($fields) {
foreach ($fields as $field) {
if ($field
->getAttribute('type') == 'checkbox') {
if (is_bool($value)) {
$found = $field
->isChecked() == $value;
}
else {
$found = TRUE;
}
}
elseif ($field
->getAttribute('value') == $value) {
// Input element with correct value.
$found = TRUE;
}
elseif ($field
->find('xpath', '//option[@value = ' . (new Escaper())
->escapeLiteral($value) . ' and @selected = "selected"]')) {
// Select element with an option.
$found = TRUE;
}
elseif ($field
->getTagName() === 'textarea' && $field
->getValue() == $value) {
// Text area with correct text. Use getValue() here because
// getText() would remove any newlines in the value.
$found = TRUE;
}
elseif ($field
->getTagName() !== 'input' && $field
->getText() == $value) {
$found = TRUE;
}
}
}
}
$this
->assertTrue($fields && $found, $message);
}