You are here

public function ConditionalFieldLanguageSelectTest::testVisibleValueRegExp in Conditional Fields 8

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

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

Overrides ConditionalFieldValueInterface::testVisibleValueRegExp

File

tests/src/FunctionalJavascript/ConditionalFieldLanguageSelectTest.php, line 141

Class

ConditionalFieldLanguageSelectTest
Test Conditional Fields Language Select Plugin.

Namespace

Drupal\Tests\conditional_fields\FunctionalJavascript

Code

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

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

  // Set up conditions.
  $data = [
    'condition' => 'value',
    'values_set' => ConditionalFieldsInterface::CONDITIONAL_FIELDS_DEPENDENCY_VALUES_REGEX,
    "regex" => '^' . $this->langcodes[0] . '$',
    'grouping' => 'AND',
    'state' => 'visible',
    'effect' => 'show',
  ];
  $this
    ->submitForm($data, 'Save settings');
  $this
    ->createScreenshot($this->screenshotPath . '02-language-select-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-language-select-submit-list-options-filed-conditions.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 visible.
  $this
    ->createScreenshot($this->screenshotPath . '04-language-select-body-visible-when-controlled-field-has-default-value.png');
  $this
    ->waitUntilHidden('.field--name-body', 50, '01. Article Body field is visible');

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

  // Change a select value set to show the body.
  $this
    ->changeField($this->fieldSelector, $this->defaultLanguage);
  $this
    ->createScreenshot($this->screenshotPath . '06-language-select-body-visible-when-controlled-field-has-value.png');
  $this
    ->waitUntilHidden('.field--name-body', 50, '03. Article Body field is visible');

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