public function ConditionalFieldDateTimeTest::testVisibleValueRegExp in Conditional Fields 8
Same name and namespace in other branches
- 4.x tests/src/FunctionalJavascript/ConditionalFieldDateTimeTest.php \Drupal\Tests\conditional_fields\FunctionalJavascript\ConditionalFieldDateTimeTest::testVisibleValueRegExp()
The target field is Visible when the control field has value from Regular expression.
Overrides ConditionalFieldValueInterface::testVisibleValueRegExp
File
- tests/
src/ FunctionalJavascript/ ConditionalFieldDateTimeTest.php, line 156
Class
- ConditionalFieldDateTimeTest
- Test Conditional Fields States.
Namespace
Drupal\Tests\conditional_fields\FunctionalJavascriptCode
public function testVisibleValueRegExp() {
$date = new DrupalDateTime();
$date_formatted = $date
->format(DateTimeItemInterface::DATE_STORAGE_FORMAT);
$this
->baseTestSteps();
// Visit a ConditionalFields configuration page for Content bundles.
$this
->createCondition('body', $this->fieldName, 'visible', 'value');
$this
->createScreenshot($this->screenshotPath . '01-testDateTimeVisibleValueWidget.png');
// Set up conditions.
$data = [
'condition' => 'value',
'values_set' => ConditionalFieldsInterface::CONDITIONAL_FIELDS_DEPENDENCY_VALUES_REGEX,
'regex' => '^' . $date_formatted . '$',
'grouping' => 'AND',
'state' => 'visible',
'effect' => 'show',
];
$this
->submitForm($data, 'Save settings');
$this
->createScreenshot($this->screenshotPath . '02-testDateTimeVisibleValueWidget.png');
// Check if that configuration is saved.
$this
->drupalGet('admin/structure/types/manage/article/conditionals');
$this
->createScreenshot($this->screenshotPath . '03-testDateTimeVisibleValueWidget.png');
$this
->assertSession()
->pageTextContains('body ' . $this->fieldName . ' visible value');
// Visit Article Add form to check that conditions are applied.
$this
->drupalGet('node/add/article');
// Change a date that should not show the body.
$this
->changeField($this->fieldSelector, '');
$this
->createScreenshot($this->screenshotPath . '04-testDateTimeVisibleValueWidget.png');
$this
->waitUntilHidden('.field--name-body', 50, '01. Article Body field is visible');
// Check that the field Body is visible.
$this
->changeField($this->fieldSelector, $date_formatted);
$this
->createScreenshot($this->screenshotPath . '05-testDateTimeVisibleValueWidget.png');
$this
->waitUntilVisible('.field--name-body', 50, '02. Article Body field is not visible');
// Change a date that should not show the body again.
$this
->changeField($this->fieldSelector, '');
$this
->createScreenshot($this->screenshotPath . '06-testDateTimeVisibleValueWidget.png');
$this
->waitUntilHidden('.field--name-body', 50, 'Article Body field is visible');
}