You are here

public function ConditionalFieldDateTimeTest::testVisibleValueWidget in Conditional Fields 8

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

The target field is Visible when the control field has value from Widget.

Overrides ConditionalFieldValueInterface::testVisibleValueWidget

File

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

Class

ConditionalFieldDateTimeTest
Test Conditional Fields States.

Namespace

Drupal\Tests\conditional_fields\FunctionalJavascript

Code

public function testVisibleValueWidget() {
  $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_WIDGET,
    $this->fieldName . '[0][value][date]' => DrupalDateTime::createFromTimestamp(\Drupal::time()
      ->getRequestTime())
      ->format('m-d-Y'),
    '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, DrupalDateTime::createFromTimestamp(\Drupal::time()
    ->getRequestTime())
    ->format('Y-m-d'));
  $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');
}