You are here

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

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

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

Overrides ConditionalFieldValueInterface::testVisibleValueRegExp

File

tests/src/FunctionalJavascript/ConditionalFieldTextfieldTest.php, line 126

Class

ConditionalFieldTextfieldTest
Test Conditional Fields Text Handler.

Namespace

Drupal\Tests\conditional_fields\FunctionalJavascript

Code

public function testVisibleValueRegExp() {
  $this
    ->baseTestSteps();
  $this
    ->createCondition($this->targetFieldName, 'field_' . $this->fieldName, 'visible', 'value');
  $data = [
    'condition' => 'value',
    'values_set' => ConditionalFieldsInterface::CONDITIONAL_FIELDS_DEPENDENCY_VALUES_REGEX,
    'regex' => '.*data\\=[\\d]+.*',
    'grouping' => 'AND',
    'state' => 'visible',
    'effect' => 'show',
  ];
  $text_without_expresion = 'The field in not empty';
  $text_with_expresion = 'The field has data=2 text';
  $this
    ->submitForm($data, 'Save settings');

  // Check if that configuration is saved.
  $this
    ->drupalGet('admin/structure/types/manage/article/conditionals');
  $this
    ->assertSession()
    ->pageTextContains($this->targetFieldName . ' ' . 'field_' . $this->fieldName . ' visible value');
  $this
    ->drupalGet('node/add/article');
  $this
    ->assertSession()
    ->elementExists('css', $this->targetFieldWrapp);
  $this
    ->waitUntilHidden($this->targetFieldWrapp, 0, '01. Article Body field is visible');
  $this
    ->changeField($this->fieldSelector, $text_without_expresion);
  $this
    ->waitUntilHidden($this->targetFieldWrapp, 50, '02. Article Body field is visible');
  $this
    ->changeField($this->fieldSelector, $text_with_expresion);
  $this
    ->waitUntilVisible($this->targetFieldWrapp, 50, '03. Article Body field is not visible');
}