public function ConditionalFieldSelectTest::testVisibleValueAnd in Conditional Fields 8
Same name and namespace in other branches
- 4.x tests/src/FunctionalJavascript/ConditionalFieldSelectTest.php \Drupal\Tests\conditional_fields\FunctionalJavascript\ConditionalFieldSelectTest::testVisibleValueAnd()
The target field is Visible when the control field has value with AND condition.
Overrides ConditionalFieldValueInterface::testVisibleValueAnd
File
- tests/
src/ FunctionalJavascript/ ConditionalFieldSelectTest.php, line 300
Class
- ConditionalFieldSelectTest
- Test Conditional Fields Select Plugin.
Namespace
Drupal\Tests\conditional_fields\FunctionalJavascriptCode
public function testVisibleValueAnd() {
$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",
];
$test_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_AND,
'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');
$this
->clickLink('Edit');
$this
->createScreenshot($this->screenshotPath . '03.5-' . $fieldName . '_' . __FUNCTION__ . '.png');
// 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], $test_values[$fieldName]);
$this
->createScreenshot($this->screenshotPath . '05-' . $fieldName . '_' . __FUNCTION__ . '.png');
$this
->waitUntilHidden('.field--name-body', 50, '05.' . $fieldName . '. Article Body field is 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');
}
}