public function ConditionalFieldSelectTest::testVisibleValueXor in Conditional Fields 4.x
Same name and namespace in other branches
- 8 tests/src/FunctionalJavascript/ConditionalFieldSelectTest.php \Drupal\Tests\conditional_fields\FunctionalJavascript\ConditionalFieldSelectTest::testVisibleValueXor()
Target field is Visible when control field has value with XOR condition.
Overrides ConditionalFieldValueInterface::testVisibleValueXor
File
- tests/
src/ FunctionalJavascript/ ConditionalFieldSelectTest.php, line 534
Class
- ConditionalFieldSelectTest
- Test Conditional Fields Select Plugin.
Namespace
Drupal\Tests\conditional_fields\FunctionalJavascriptCode
public function testVisibleValueXor() {
$this
->baseTestSteps();
$allowed_values = [
'select_single_entity_reference' => "1\n2",
'select_single_list_integer' => "1\n2",
'select_single_list_float' => "1.5\n2.5",
'select_single_list_string' => "one\ntwo",
];
$correct_values = [
'select_single_entity_reference' => 1,
'select_single_list_integer' => 1,
'select_single_list_float' => 1.5,
'select_single_list_string' => 'one',
];
// Visit a ConditionalFields configuration page for Content bundles.
foreach ($this->fieldNames as $fieldName) {
$this
->createCondition('body', $fieldName, 'visible', 'value');
$this
->createScreenshot($this->screenshotPath . '01-' . $fieldName . '_' . __FUNCTION__ . '.png');
// Set up conditions.
$data = [
'condition' => 'value',
'values_set' => ConditionalFieldsInterface::CONDITIONAL_FIELDS_DEPENDENCY_VALUES_XOR,
'values' => $allowed_values[$fieldName],
'grouping' => 'AND',
'state' => 'visible',
'effect' => 'show',
];
$this
->submitForm($data, 'Save settings');
$this
->createScreenshot($this->screenshotPath . '02-' . $fieldName . '_' . __FUNCTION__ . '.png');
// Check if that configuration is saved.
$this
->drupalGet('admin/structure/types/manage/article/conditionals');
$this
->createScreenshot($this->screenshotPath . '03-' . $fieldName . '_' . __FUNCTION__ . '.png');
$this
->assertSession()
->pageTextContains('body ' . $fieldName . ' visible value');
// Visit Article Add form to check that conditions are applied.
$this
->drupalGet('node/add/article');
// Check that the field Body is not visible.
$this
->createScreenshot($this->screenshotPath . '04-' . $fieldName . '_' . __FUNCTION__ . '.png');
$this
->waitUntilHidden('.field--name-body', 50, '04.' . $fieldName . '. Article Body field is visible');
// Change a select value set that should not show the body.
$this
->changeField($this->fieldSelectors[$fieldName], $correct_values[$fieldName]);
$this
->createScreenshot($this->screenshotPath . '05-' . $fieldName . '_' . __FUNCTION__ . '.png');
$this
->waitUntilVisible('.field--name-body', 50, '05.' . $fieldName . '. Article Body field is not visible');
// Change a select value set that should be show the body.
$this
->changeField($this->fieldSelectors[$fieldName], $correct_values[$fieldName]);
$this
->createScreenshot($this->screenshotPath . '05-' . $fieldName . '_' . __FUNCTION__ . '.png');
$this
->waitUntilVisible('.field--name-body', 50, '06.' . $fieldName . '. Article Body field is not visible');
// Change a select value set to hide the body again.
$this
->changeField($this->fieldSelectors[$fieldName], '_none');
$this
->createScreenshot($this->screenshotPath . '07-' . $fieldName . '_' . __FUNCTION__ . '.png');
$this
->waitUntilHidden('.field--name-body', 50, '07.' . $fieldName . '. Article Body field is visible');
// Return back to ConditionalFields configuration page for Article CT.
$this
->drupalGet('admin/structure/conditional_fields/node/article');
// Delete previous condition.
$this
->click('li > button > .dropbutton-arrow');
$this
->clickLink('Delete');
$this
->submitForm([], 'Confirm');
$this
->createScreenshot($this->screenshotPath . '08-' . $fieldName . '_' . __FUNCTION__ . '.png');
}
}