public function ConditionalFieldDateTimeTest::testVisibleValueAnd in Conditional Fields 8
Same name and namespace in other branches
- 4.x tests/src/FunctionalJavascript/ConditionalFieldDateTimeTest.php \Drupal\Tests\conditional_fields\FunctionalJavascript\ConditionalFieldDateTimeTest::testVisibleValueAnd()
The target field is Visible when the control field has value with AND condition.
Overrides ConditionalFieldValueInterface::testVisibleValueAnd
File
- tests/
src/ FunctionalJavascript/ ConditionalFieldDateTimeTest.php, line 208
Class
- ConditionalFieldDateTimeTest
- Test Conditional Fields States.
Namespace
Drupal\Tests\conditional_fields\FunctionalJavascriptCode
public function testVisibleValueAnd() {
$date = new DrupalDateTime();
$date2 = new DrupalDateTime("-1 year");
$this
->baseTestSteps();
// Visit a ConditionalFields configuration page for Content bundles.
$this
->createCondition('body', $this->fieldName, 'visible', 'value');
$this
->createScreenshot($this->screenshotPath . '01-testDateTime ' . __FUNCTION__ . '.png');
// Set up conditions.
$dates = [
$date
->format(DateTimeItemInterface::DATE_STORAGE_FORMAT),
$date2
->format(DateTimeItemInterface::DATE_STORAGE_FORMAT),
];
$data = [
'condition' => 'value',
'values_set' => ConditionalFieldsInterface::CONDITIONAL_FIELDS_DEPENDENCY_VALUES_AND,
'values' => implode("\r\n", $dates),
'grouping' => 'AND',
'state' => 'visible',
'effect' => 'show',
];
$this
->submitForm($data, 'Save settings');
$this
->createScreenshot($this->screenshotPath . '02-testDateTime ' . __FUNCTION__ . '.png');
// Check if that configuration is saved.
$this
->drupalGet('admin/structure/types/manage/article/conditionals');
$this
->createScreenshot($this->screenshotPath . '03-testDateTime ' . __FUNCTION__ . '.png');
$this
->assertSession()
->pageTextContains('body ' . $this->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-testDateTime ' . __FUNCTION__ . '.png');
$this
->waitUntilHidden('.field--name-body', 50, '01. Article Body field is visible');
// Change a date that should not show the body.
$this
->changeField($this->fieldSelector, 'https://drupal.org');
$this
->createScreenshot($this->screenshotPath . '05-testDateTime ' . __FUNCTION__ . '.png');
$this
->waitUntilHidden('.field--name-body', 50, '02. Article Body field is visible');
// Change a date value to show the body.
$this
->changeField($this->fieldSelector, $dates[0]);
$this
->createScreenshot($this->screenshotPath . '06-testDateTime ' . __FUNCTION__ . '.png');
$this
->waitUntilHidden('.field--name-body', 50, '03. Article Body field is visible');
// Change a date value to show the body.
$this
->changeField($this->fieldSelector, $dates[1]);
$this
->createScreenshot($this->screenshotPath . '07-testDateTime ' . __FUNCTION__ . '.png');
$this
->waitUntilHidden('.field--name-body', 50, '04. Article Body field is visible');
// Change a date value to hide the body again.
$this
->changeField($this->fieldSelector, '');
$this
->createScreenshot($this->screenshotPath . '08-testDateTime ' . __FUNCTION__ . '.png');
$this
->waitUntilHidden('.field--name-body', 50, '0.5Article Body field is visible');
}