You are here

public function ConditionalFieldNumberTest::testVisibleValueRegExp in Conditional Fields 8

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

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

Overrides ConditionalFieldValueInterface::testVisibleValueRegExp

File

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

Class

ConditionalFieldNumberTest
Test Conditional Fields Number 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-testNumberInteger-testVisibleValueWidget.png');

  // Set up conditions.
  $data = [
    'condition' => 'value',
    'values_set' => ConditionalFieldsInterface::CONDITIONAL_FIELDS_DEPENDENCY_VALUES_REGEX,
    'regex' => '^2019$',
    'grouping' => 'AND',
    'state' => 'visible',
    'effect' => 'show',
  ];
  $this
    ->submitForm($data, 'Save settings');
  $this
    ->createScreenshot($this->screenshotPath . '02-testNumberInteger-testVisibleValueWidget.png');

  // Check if that configuration is saved.
  $this
    ->drupalGet('admin/structure/types/manage/article/conditionals');
  $this
    ->createScreenshot($this->screenshotPath . '03-testNumberInteger-testVisibleValueWidget.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-testNumberInteger-testVisibleValueWidget.png');
  $this
    ->waitUntilHidden('.field--name-body', 50, '01. Article Body field is not visible');

  // Change the number field that should not show the body.
  $this
    ->changeField($this->fieldSelector, mt_rand(10, 100));
  $this
    ->createScreenshot($this->screenshotPath . '05-testNumberInteger-testVisibleValueWidget.png');
  $this
    ->waitUntilHidden('.field--name-body', 50, '02. Article Body field is not visible');

  // Change the number field to show the body.
  $this
    ->changeField($this->fieldSelector, $this->validValue);
  $this
    ->createScreenshot($this->screenshotPath . '06-testNumberInteger-testVisibleValueWidget.png');
  $this
    ->waitUntilVisible('.field--name-body', 50, '03. Article Body field is visible');

  // Set wrong value for number field to hide the body.
  $this
    ->changeField($this->fieldSelector, mt_rand(10, 100));
  $this
    ->createScreenshot($this->screenshotPath . '07-testNumberInteger-testVisibleValueWidget.png');
  $this
    ->waitUntilHidden('.field--name-body', 50, '04. Article Body field is not visible');

  // Set an empty value to hide body.
  $this
    ->changeField($this->fieldSelector, '');
  $this
    ->createScreenshot($this->screenshotPath . '08-testNumberInteger-testVisibleValueWidget.png');
  $this
    ->waitUntilHidden('.field--name-body', 50, '05. Article Body field is not visible');
}