You are here

public function ConditionalFieldDateTimeTest::testVisibleValueRegExp in Conditional Fields 4.x

Same name and namespace in other branches
  1. 8 tests/src/FunctionalJavascript/ConditionalFieldDateTimeTest.php \Drupal\Tests\conditional_fields\FunctionalJavascript\ConditionalFieldDateTimeTest::testVisibleValueRegExp()

Target field is Visible when the control field has value from regex.

Overrides ConditionalFieldValueInterface::testVisibleValueRegExp

File

tests/src/FunctionalJavascript/ConditionalFieldDateTimeTest.php, line 155

Class

ConditionalFieldDateTimeTest
Test Conditional Fields States.

Namespace

Drupal\Tests\conditional_fields\FunctionalJavascript

Code

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');
}