You are here

public function ConditionalFieldEmailTest::testVisibleValueNot in Conditional Fields 8

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

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

Overrides ConditionalFieldValueInterface::testVisibleValueNot

File

tests/src/FunctionalJavascript/ConditionalFieldEmailTest.php, line 342

Class

ConditionalFieldEmailTest
Test Conditional Fields Text Handler.

Namespace

Drupal\Tests\conditional_fields\FunctionalJavascript

Code

public function testVisibleValueNot() {
  $email = 'test@drupal.org';
  $email2 = 'test2@drupal.org';
  $this
    ->baseTestSteps();

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

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

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

  // Change email that should not show the body.
  $this
    ->changeField($this->fieldSelector, 'wrongmail@drupal.org');
  $this
    ->createScreenshot($this->screenshotPath . '05-testEmailTimeVisibleValueOr.png');
  $this
    ->waitUntilVisible('.field--name-body', 50, '02. Article Body field is not visible');

  // Change a email value to show the body.
  $this
    ->changeField($this->fieldSelector, $email);
  $this
    ->createScreenshot($this->screenshotPath . '06-testEmailTimeVisibleValueOr.png');
  $this
    ->waitUntilHidden('.field--name-body', 500, '03. Article Body field is visible');

  // Change a email value to show the body.
  $this
    ->changeField($this->fieldSelector, $email2);
  $this
    ->createScreenshot($this->screenshotPath . '07-testEmailTimeVisibleValueOr.png');
  $this
    ->waitUntilHidden('.field--name-body', 50, '04. Article Body field is visible');

  // Change a email value to hide the body again.
  $this
    ->changeField($this->fieldSelector, '');
  $this
    ->createScreenshot($this->screenshotPath . '08-testEmailTimeVisibleValueOr.png');
  $this
    ->waitUntilVisible('.field--name-body', 50, '05. Article Body field is not visible');
}