You are here

public function ConditionalFieldEmailTest::testVisibleValueAnd 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::testVisibleValueAnd()

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

Overrides ConditionalFieldValueInterface::testVisibleValueAnd

File

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

Class

ConditionalFieldEmailTest
Test Conditional Fields Text Handler.

Namespace

Drupal\Tests\conditional_fields\FunctionalJavascript

Code

public function testVisibleValueAnd() {
  $email = 'first@drupal.org';
  $email_2 = 'second@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-testEmailVisibleValueWidget.png');

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

  // Check if that configuration is saved.
  $this
    ->drupalGet('admin/structure/types/manage/article/conditionals');
  $this
    ->createScreenshot($this->screenshotPath . '03-testEmailVisibleValueWidget.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');

  // Change a email that should not show the body.
  $this
    ->createScreenshot($this->screenshotPath . '04-testEmailVisibleValueWidget.png');
  $this
    ->waitUntilHidden('.field--name-body', 500, '01. Article Body field is visible');

  // Check that the field Body is visible.
  $this
    ->changeField($this->fieldSelector, $email);
  $this
    ->createScreenshot($this->screenshotPath . '05-testEmailVisibleValueWidget.png');
  $this
    ->waitUntilHidden('.field--name-body', 500, '02. Article Body field is visible');

  // Check that the field Body is not visible.
  $this
    ->changeField($this->fieldSelector, $email_2);
  $this
    ->createScreenshot($this->screenshotPath . '05-testEmailVisibleValueWidget.png');
  $this
    ->waitUntilHidden('.field--name-body', 500, '02. Article Body field is visible');

  // Change a email that should not show the body again.
  $this
    ->changeField($this->fieldSelector, '');
  $this
    ->createScreenshot($this->screenshotPath . '06-testEmailVisibleValueWidget.png');
  $this
    ->waitUntilHidden('.field--name-body', 50, '03. Article Body field is visible');
}