You are here

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

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

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

Overrides ConditionalFieldValueInterface::testVisibleValueRegExp

File

tests/src/FunctionalJavascript/ConditionalFieldSelectMultipleTest.php, line 154

Class

ConditionalFieldSelectMultipleTest
Test Conditional Fields SelectMultiple Plugin.

Namespace

Drupal\Tests\conditional_fields\FunctionalJavascript

Code

public function testVisibleValueRegExp() {
  $this
    ->baseTestSteps();

  // Visit a ConditionalFields configuration page for Content bundles.
  $this
    ->createCondition('body', 'field_' . $this->fieldName, 'visible', 'value');
  $this
    ->createScreenshot($this->screenshotPath . '01-add-list-options-filed-conditions.png');

  // Set up conditions.
  $data = [
    'condition' => 'value',
    'values_set' => ConditionalFieldsInterface::CONDITIONAL_FIELDS_DEPENDENCY_VALUES_REGEX,
    'regex' => '[0|1]',
    'grouping' => 'AND',
    'state' => 'visible',
    'effect' => 'show',
  ];
  $this
    ->submitForm($data, 'Save settings');
  $this
    ->createScreenshot($this->screenshotPath . '02-post-add-list-options-filed-conditions.png');

  // Check if that configuration is saved.
  $this
    ->drupalGet('admin/structure/types/manage/article/conditionals');
  $this
    ->createScreenshot($this->screenshotPath . '03-submit-list-options-filed-conditions.png');
  $this
    ->assertSession()
    ->pageTextContains('body ' . 'field_' . $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-body-invisible-when-controlled-field-has-no-value.png');
  $this
    ->waitUntilHidden('.field--name-body', 50, 'Article Body field is visible');

  // Change a select value set that should not show the body.
  $this
    ->changeField($this->fieldSelector, [
    0,
  ]);
  $this
    ->createScreenshot($this->screenshotPath . '05-body-invisible-when-controlled-field-has-wrong-value.png');
  $this
    ->waitUntilVisible('.field--name-body', 50, 'Article Body field is not visible');

  // Change a select value set to show the body.
  $this
    ->changeField($this->fieldSelector, [
    0,
    1,
  ]);
  $this
    ->createScreenshot($this->screenshotPath . '06-body-visible-when-controlled-field-has-value.png');
  $this
    ->waitUntilVisible('.field--name-body', 50, 'Article Body field is not visible');

  // Change a select value set that should not show the body.
  $this
    ->changeField($this->fieldSelector, [
    3,
  ]);
  $this
    ->createScreenshot($this->screenshotPath . '07-body-visible-when-controlled-field-has-value.png');
  $this
    ->waitUntilHidden('.field--name-body', 50, 'Article Body field is visible');

  // Change a select value set to show the body.
  $this
    ->changeField($this->fieldSelector, [
    0,
    3,
  ]);
  $this
    ->createScreenshot($this->screenshotPath . '08-body-visible-when-controlled-field-has-value.png');
  $this
    ->waitUntilVisible('.field--name-body', 50, 'Article Body field is not visible');

  // Change a select value set to hide the body again.
  $this
    ->changeField($this->fieldSelector, [
    '_none',
  ]);
  $this
    ->createScreenshot($this->screenshotPath . '09-body-invisible-when-controlled-field-has-no-value-again.png');
  $this
    ->waitUntilHidden('.field--name-body', 50, 'Article Body field is visible');
}