You are here

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

Target field is Visible when control field has value with AND condition.

Overrides ConditionalFieldValueInterface::testVisibleValueAnd

File

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

Class

ConditionalFieldDateTimeTest
Test Conditional Fields States.

Namespace

Drupal\Tests\conditional_fields\FunctionalJavascript

Code

public function testVisibleValueAnd() {
  $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_AND,
    '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
    ->waitUntilHidden('.field--name-body', 50, '03. Article Body field is visible');

  // Change a date value to show the body.
  $this
    ->changeField($this->fieldSelector, $dates[1]);
  $this
    ->createScreenshot($this->screenshotPath . '07-testDateTime ' . __FUNCTION__ . '.png');
  $this
    ->waitUntilHidden('.field--name-body', 50, '04. Article Body field is 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.5Article Body field is visible');
}