You are here

public function ConditionalFieldDateListTest::testVisibleValueRegExp in Conditional Fields 8

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

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

Overrides ConditionalFieldValueInterface::testVisibleValueRegExp

File

tests/src/FunctionalJavascript/ConditionalFieldDateListTest.php, line 146

Class

ConditionalFieldDateListTest
Test Conditional Fields States.

Namespace

Drupal\Tests\conditional_fields\FunctionalJavascript

Code

public function testVisibleValueRegExp() {
  $day = '11';
  $month = '12';
  $month_wrong = '5';
  $year = '2019';
  $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_REGEX,
    'regex' => '[\\d]{4}-[12]{2}-[\\d]{2}',
    '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
    ->createScreenshot($this->screenshotPath . '04-' . $this->testName . __FUNCTION__ . '.png');
  $this
    ->waitUntilHidden('.field--name-body', 50, '02. Article Body field is visible');
  $this
    ->changeField($this->fieldSelectors['month'], $month);
  $this
    ->createScreenshot($this->screenshotPath . '04-' . $this->testName . __FUNCTION__ . '.png');
  $this
    ->waitUntilHidden('.field--name-body', 50, '03. Article Body field is visible');

  // Check that the field Body is visible.
  $this
    ->changeField($this->fieldSelectors['year'], $year);
  $this
    ->createScreenshot($this->screenshotPath . '04-' . $this->testName . __FUNCTION__ . '.png');
  $this
    ->waitUntilVisible('.field--name-body', 50, '04. Article Body field is not visible');

  // Change a date that should not show the body again.
  $this
    ->changeField($this->fieldSelectors['day'], $month_wrong);
  $this
    ->createScreenshot($this->screenshotPath . '06-' . $this->testName . __FUNCTION__ . '.png');
  $this
    ->waitUntilHidden('.field--name-body', 50, '05. Article Body field is visible');
}