You are here

public function ConditionalFieldLinkFieldTest::testVisibleValueAnd in Conditional Fields 8

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

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

Overrides ConditionalFieldValueInterface::testVisibleValueAnd

File

tests/src/FunctionalJavascript/ConditionalFieldLinkFieldTest.php, line 213

Class

ConditionalFieldLinkFieldTest
Test Conditional Fields Link field plugin.

Namespace

Drupal\Tests\conditional_fields\FunctionalJavascript

Code

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

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

  // Set up conditions.
  $urls = [
    'node/add',
    'node/1',
  ];
  $data = [
    'condition' => 'value',
    'values_set' => ConditionalFieldsInterface::CONDITIONAL_FIELDS_DEPENDENCY_VALUES_AND,
    'values' => implode("\r\n", $urls),
    'grouping' => 'AND',
    'state' => 'visible',
    'effect' => 'show',
  ];
  $this
    ->submitForm($data, 'Save settings');
  $this
    ->createScreenshot($this->screenshotPath . '02-link-field-post-add-list-options-filed-conditions.png');

  // Check if that configuration is saved.
  $this
    ->drupalGet('admin/structure/types/manage/article/conditionals');
  $this
    ->createScreenshot($this->screenshotPath . '03-link-field-submit-options-filed-conditions.png');
  $this
    ->assertSession()
    ->pageTextContains('body ' . $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-link-field-body-invisible-when-controlled-field-has-no-value.png');
  $this
    ->waitUntilHidden('.field--name-body', 50, '01. Article Body field is visible');

  // Change a link that should not show the body.
  $this
    ->changeField($this->fieldSelector, 'https://drupal.org');
  $this
    ->createScreenshot($this->screenshotPath . '05-link-field-body-invisible-when-controlled-field-has-wrong-value.png');
  $this
    ->waitUntilHidden('.field--name-body', 50, '02. Article Body field is visible');

  // Change a link value to show the body.
  $this
    ->changeField($this->fieldSelector, $urls[0]);
  $this
    ->createScreenshot($this->screenshotPath . '06-link-field-body-visible-when-controlled-field-has-value.png');
  $this
    ->waitUntilHidden('.field--name-body', 50, '03. Article Body field is visible');

  // Change a link value to show the body.
  $this
    ->changeField($this->fieldSelector, $urls[1]);
  $this
    ->createScreenshot($this->screenshotPath . '07-link-field-body-visible-when-controlled-field-has-value.png');
  $this
    ->waitUntilHidden('.field--name-body', 50, '04. Article Body field is visible');

  // Change a link value to hide the body again.
  $this
    ->changeField($this->fieldSelector, '');
  $this
    ->createScreenshot($this->screenshotPath . '08-link-field-body-invisible-when-controlled-field-has-no-value-again.png');
  $this
    ->waitUntilHidden('.field--name-body', 50, '05. Article Body field is visible');
}