public function ConditionalFieldDateTimeTest::testVisibleValueOr in Conditional Fields 8
Same name and namespace in other branches
- 4.x tests/src/FunctionalJavascript/ConditionalFieldDateTimeTest.php \Drupal\Tests\conditional_fields\FunctionalJavascript\ConditionalFieldDateTimeTest::testVisibleValueOr()
The target field is Visible when the control field has value with OR condition.
Overrides ConditionalFieldValueInterface::testVisibleValueOr
File
- tests/
src/ FunctionalJavascript/ ConditionalFieldDateTimeTest.php, line 273
Class
- ConditionalFieldDateTimeTest
- Test Conditional Fields States.
Namespace
Drupal\Tests\conditional_fields\FunctionalJavascriptCode
public function testVisibleValueOr() {
$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-testDateTimeVisibleValueOr.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_OR,
'values' => implode("\r\n", $dates),
'grouping' => 'AND',
'state' => 'visible',
'effect' => 'show',
];
$this
->submitForm($data, 'Save settings');
$this
->createScreenshot($this->screenshotPath . '02-testDateTimeVisibleValueOr.png');
// Check if that configuration is saved.
$this
->drupalGet('admin/structure/types/manage/article/conditionals');
$this
->createScreenshot($this->screenshotPath . '03-testDateTimeVisibleValueOr.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-testDateTimeVisibleValueOr.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-testDateTimeVisibleValueOr.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-testDateTimeVisibleValueOr.png');
$this
->waitUntilVisible('.field--name-body', 50, '03. Article Body field is not visible');
// Change a date value to show the body.
$this
->changeField($this->fieldSelector, $dates[1]);
$this
->createScreenshot($this->screenshotPath . '07-testDateTimeVisibleValueOr.png');
$this
->waitUntilVisible('.field--name-body', 50, '04. Article Body field is not visible');
// Change a date value to hide the body again.
$this
->changeField($this->fieldSelector, '');
$this
->createScreenshot($this->screenshotPath . '08-testDateTimeVisibleValueOr.png');
$this
->waitUntilHidden('.field--name-body', 50, '0.5 Article Body field is visible');
}