public function ConditionalFieldDateListTest::testVisibleValueAnd in Conditional Fields 4.x
Same name and namespace in other branches
- 8 tests/src/FunctionalJavascript/ConditionalFieldDateListTest.php \Drupal\Tests\conditional_fields\FunctionalJavascript\ConditionalFieldDateListTest::testVisibleValueAnd()
Target field is Visible when control field has value with AND condition.
Overrides ConditionalFieldValueInterface::testVisibleValueAnd
File
- tests/
src/ FunctionalJavascript/ ConditionalFieldDateListTest.php, line 204
Class
- ConditionalFieldDateListTest
- Test Conditional Fields States.
Namespace
Drupal\Tests\conditional_fields\FunctionalJavascriptCode
public function testVisibleValueAnd() {
$date = new DrupalDateTime();
$day = $date
->format('j');
$wrong_day = (int) $day + 1;
$month = $date
->format('n');
$year = $date
->format('Y');
$date_2 = new DrupalDateTime("-1 year");
$day_2 = $date_2
->format('j');
$month_2 = $date_2
->format('n');
$year_2 = $date_2
->format('Y');
$this
->baseTestSteps();
// Visit a ConditionalFields configuration page for Content bundles.
$this
->createCondition('body', $this->fieldName, 'visible', 'value');
$this
->createScreenshot($this->screenshotPath . '01-' . $this->testName . __FUNCTION__ . '.png');
// Set up conditions.
$data = [
'condition' => 'value',
'values_set' => ConditionalFieldsInterface::CONDITIONAL_FIELDS_DEPENDENCY_VALUES_AND,
'values' => implode("\r\n", [
$date
->format(DateTimeItemInterface::DATE_STORAGE_FORMAT),
$date_2
->format(DateTimeItemInterface::DATE_STORAGE_FORMAT),
]),
'grouping' => 'AND',
'state' => 'visible',
'effect' => 'show',
];
$this
->submitForm($data, 'Save settings');
$this
->createScreenshot($this->screenshotPath . '02-' . $this->testName . __FUNCTION__ . '.png');
// Check if that configuration is saved.
$this
->drupalGet('admin/structure/types/manage/article/conditionals');
$this
->createScreenshot($this->screenshotPath . '03-' . $this->testName . __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-' . $this->testName . __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->fieldSelectors['day'], $day);
$this
->changeField($this->fieldSelectors['month'], $month);
$this
->changeField($this->fieldSelectors['year'], $year);
$this
->createScreenshot($this->screenshotPath . '04-' . $this->testName . __FUNCTION__ . '.png');
$this
->waitUntilHidden('.field--name-body', 50, '02. Article Body field is visible');
// Change a date that should not show the body.
$this
->changeField($this->fieldSelectors['day'], $day_2);
$this
->changeField($this->fieldSelectors['month'], $month_2);
$this
->changeField($this->fieldSelectors['year'], $year_2);
$this
->createScreenshot($this->screenshotPath . '04-' . $this->testName . __FUNCTION__ . '.png');
$this
->waitUntilHidden('.field--name-body', 50, '03. Article Body field is visible');
// Change a date that should not show the body again.
$this
->changeField($this->fieldSelectors['day'], $wrong_day);
$this
->createScreenshot($this->screenshotPath . '06-' . $this->testName . __FUNCTION__ . '.png');
$this
->waitUntilHidden('.field--name-body', 50, '05. Article Body field is visible');
}