You are here

public function ConditionalFieldDateTimeTest::testVisibleValueXor 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::testVisibleValueXor()

The target field is Visible when the control field has value with XOR condition.

Overrides ConditionalFieldValueInterface::testVisibleValueXor

File

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

Class

ConditionalFieldDateTimeTest
Test Conditional Fields States.

Namespace

Drupal\Tests\conditional_fields\FunctionalJavascript

Code

public function testVisibleValueXor() {
  $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-testDateTime' . __FUNCTION__ . '.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_XOR,
    'values' => implode("\r\n", $dates),
    'grouping' => 'AND',
    'state' => 'visible',
    'effect' => 'show',
  ];
  $this
    ->submitForm($data, 'Save settings');
  $this
    ->createScreenshot($this->screenshotPath . '02-testDateTime' . __FUNCTION__ . '.png');

  // Check if that configuration is saved.
  $this
    ->drupalGet('admin/structure/types/manage/article/conditionals');
  $this
    ->createScreenshot($this->screenshotPath . '03-testDateTime' . __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-testDateTime' . __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->fieldSelector, 'https://drupal.org');
  $this
    ->createScreenshot($this->screenshotPath . '05-testDateTime' . __FUNCTION__ . '.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-testDateTime' . __FUNCTION__ . '.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-testDateTime' . __FUNCTION__ . '.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-testDateTime' . __FUNCTION__ . '.png');
  $this
    ->waitUntilHidden('.field--name-body', 50, '0.5 Article Body field is visible');
}