You are here

public function ConditionalFieldTextfieldTest::testVisibleValueXor 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::testVisibleValueXor()

Target field is Visible when control field has value with XOR condition.

Overrides ConditionalFieldValueInterface::testVisibleValueXor

File

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

Class

ConditionalFieldTextfieldTest
Test Conditional Fields Text Handler.

Namespace

Drupal\Tests\conditional_fields\FunctionalJavascript

Code

public function testVisibleValueXor() {
  $this
    ->baseTestSteps();
  $this
    ->createCondition($this->targetFieldName, 'field_' . $this->fieldName, 'visible', 'value');
  $text_1 = $this
    ->getRandomGenerator()
    ->word(7);
  $text_2 = $this
    ->getRandomGenerator()
    ->word(7);
  $data = [
    'condition' => 'value',
    'values_set' => ConditionalFieldsInterface::CONDITIONAL_FIELDS_DEPENDENCY_VALUES_XOR,
    'values' => implode("\n", [
      $text_1,
      $text_2,
    ]),
    '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');
  $this
    ->drupalGet('node/add/article');
  $this
    ->assertSession()
    ->elementExists('css', $this->targetFieldWrapp);
  $text_false = 'same unique value';
  $this
    ->waitUntilHidden($this->targetFieldWrapp, 0, '01. Article Body field is visible');
  $this
    ->changeField($this->fieldSelector, $text_false);
  $this
    ->waitUntilHidden($this->targetFieldWrapp, 50, '02. Article Body field is visible');
  $this
    ->changeField($this->fieldSelector, $text_1);
  $this
    ->waitUntilVisible($this->targetFieldWrapp, 50, '03. Article Body field is not visible');
  $this
    ->changeField($this->fieldSelector, "");
  $this
    ->waitUntilHidden($this->targetFieldWrapp, 50, '04. Article Body field is visible');
}