You are here

public function ConditionalFieldTextfieldTest::testVisibleValueOr in Conditional Fields 8

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

The target field is Visible when the control field has value with OR condition.

Overrides ConditionalFieldValueInterface::testVisibleValueOr

File

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

Class

ConditionalFieldTextfieldTest
Test Conditional Fields Text Handler.

Namespace

Drupal\Tests\conditional_fields\FunctionalJavascript

Code

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

  // Visit a ConditionalFields configuration page for Content bundles.
  $this
    ->createCondition($this->targetFieldName, 'field_' . $this->fieldName, 'visible', 'value');

  // Random term id to check necessary value.
  $text1 = $this
    ->getRandomGenerator()
    ->word(8);
  $text2 = $this
    ->getRandomGenerator()
    ->word(7);

  // Set up conditions.
  $values = implode("\r\n", [
    $text1,
    $text2,
  ]);
  $data = [
    'condition' => 'value',
    'values_set' => ConditionalFieldsInterface::CONDITIONAL_FIELDS_DEPENDENCY_VALUES_OR,
    'values' => $values,
    'grouping' => 'AND',
    'state' => 'visible',
    'effect' => 'show',
  ];
  $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');

  // Visit Article Add form to check that conditions are applied.
  $this
    ->drupalGet('node/add/article');

  // Check that the field Body is not visible.
  $this
    ->waitUntilHidden($this->targetFieldWrapp, 0, '01. Article Body field is visible');

  // Change value that should not show the body.
  $this
    ->changeField($this->fieldSelector, 'wrong');
  $this
    ->waitUntilHidden($this->targetFieldWrapp, 50, '02. Article Body field is visible');

  // Change a value value to show the body.
  $this
    ->changeField($this->fieldSelector, $text1);
  $this
    ->waitUntilVisible($this->targetFieldWrapp, 50, '03. Article Body field is not visible');

  // Change a value value to show the body.
  $this
    ->changeField($this->fieldSelector, $text2);
  $this
    ->waitUntilVisible($this->targetFieldWrapp, 50, '04. Article Body field is not visible');

  // Change a value value to hide the body again.
  $this
    ->changeField($this->fieldSelector, '');
  $this
    ->waitUntilHidden($this->targetFieldWrapp, 50, '05. Article Body field is visible');
}