You are here

public function ConditionalFieldLinkFieldTest::testVisibleValueRegExp in Conditional Fields 4.x

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

Target field is Visible when the control field has value from regex.

Overrides ConditionalFieldValueInterface::testVisibleValueRegExp

File

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

Class

ConditionalFieldLinkFieldTest
Test Conditional Fields Link field plugin.

Namespace

Drupal\Tests\conditional_fields\FunctionalJavascript

Code

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

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

  // Set up conditions.
  $external_url = 'https://drupal.org';
  $data = [
    'condition' => 'value',
    'values_set' => ConditionalFieldsInterface::CONDITIONAL_FIELDS_DEPENDENCY_VALUES_REGEX,
    'regex' => '^https?:\\/\\/drupal\\.org',
    'grouping' => 'AND',
    'state' => 'visible',
    'effect' => 'show',
  ];
  $this
    ->submitForm($data, 'Save settings');
  $this
    ->createScreenshot($this->screenshotPath . '02-testFieldLinkVisibleValueWidget.png');

  // Check if that configuration is saved.
  $this
    ->drupalGet('admin/structure/types/manage/article/conditionals');
  $this
    ->createScreenshot($this->screenshotPath . '03-testFieldLinkVisibleValueWidget.png');
  $this
    ->assertSession()
    ->pageTextContains('body ' . $this->fieldName . ' visible value');

  // Visit Article Add form to check that conditions are applied.
  $this
    ->drupalGet('node/add/article');

  // Change a link that should not show the body.
  $this
    ->changeField($this->fieldSelector, '');
  $this
    ->createScreenshot($this->screenshotPath . '04-testFieldLinkVisibleValueWidget.png');
  $this
    ->waitUntilHidden('.field--name-body', 50, '01. Article Body field is not visible');

  // Check that the field Body is visible.
  $this
    ->changeField($this->fieldSelector, $external_url);
  $this
    ->createScreenshot($this->screenshotPath . '05-testFieldLinkVisibleValueWidget.png');
  $this
    ->waitUntilVisible('.field--name-body', 50, '02. Article Body field is visible');

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