You are here

public function ConditionalFieldTextTextareaTest::testVisibleValueXor in Conditional Fields 8

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

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

Overrides ConditionalFieldValueInterface::testVisibleValueXor

File

tests/src/FunctionalJavascript/ConditionalFieldTextTextareaTest.php, line 375

Class

ConditionalFieldTextTextareaTest
Test Conditional Fields Text Handler.

Namespace

Drupal\Tests\conditional_fields\FunctionalJavascript

Code

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

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

  // Set up conditions.
  $text = [
    $this
      ->randomMachineName(),
    $this
      ->randomMachineName(),
  ];
  $data = [
    'condition' => 'value',
    'values_set' => ConditionalFieldsInterface::CONDITIONAL_FIELDS_DEPENDENCY_VALUES_XOR,
    'values' => implode("\r\n", $text),
    'grouping' => 'AND',
    'state' => 'visible',
    'effect' => 'show',
  ];
  $this
    ->submitForm($data, 'Save settings');
  $this
    ->createScreenshot($this->screenshotPath . '02-' . $this->testName . __FUNCTION__ . '.png');

  // Check if that configuration is saved.
  $this
    ->drupalGet('admin/structure/types/manage/article/conditionals');
  $this
    ->createScreenshot($this->screenshotPath . '03-' . $this->testName . __FUNCTION__ . '.png');
  $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 invisible.
  $this
    ->createScreenshot($this->screenshotPath . '04-' . $this->testName . __FUNCTION__ . '.png');
  $this
    ->waitUntilHidden($this->targetFieldWrapp, 50, 'Article \'' . $this->targetFieldName . '\' field is visible');

  // Change field that should not show the body.
  $this
    ->changeField($this->fieldSelector, $text[0]);
  $this
    ->createScreenshot($this->screenshotPath . '05-' . $this->testName . __FUNCTION__ . '.png');
  $this
    ->waitUntilVisible($this->targetFieldWrapp, 50, 'Article \'' . $this->targetFieldName . '\' field is not visible');

  // Change field that should not show the body again.
  $this
    ->changeField($this->fieldSelector, $text[1]);
  $this
    ->createScreenshot($this->screenshotPath . '06-' . $this->testName . __FUNCTION__ . '.png');
  $this
    ->waitUntilVisible($this->targetFieldWrapp, 50, 'Article \'' . $this->targetFieldName . '\' field is not visible');

  // Change field value to show the body.
  $this
    ->changeField($this->fieldSelector, '');
  $this
    ->createScreenshot($this->screenshotPath . '07-' . $this->testName . __FUNCTION__ . '.png');
  $this
    ->waitUntilHidden($this->targetFieldWrapp, 50, 'Article \'' . $this->targetFieldName . '\' field is visible');
}