You are here

public function ConditionalFieldTextWithSummaryTest::testVisibleValueAnd in Conditional Fields 8

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

Tests creating Conditional Field: Visible if has value from Title value.

Overrides ConditionalFieldValueInterface::testVisibleValueAnd

File

tests/src/FunctionalJavascript/ConditionalFieldTextWithSummaryTest.php, line 149

Class

ConditionalFieldTextWithSummaryTest
Test Conditional Fields Text Handler.

Namespace

Drupal\Tests\conditional_fields\FunctionalJavascript

Code

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

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

  // Set up conditions.
  $text = [
    'drupal text_with_summary text first',
    'drupal text_with_summary text second',
  ];
  $text_values = implode("\r\n", $text);
  $data = [
    'condition' => 'value',
    'values_set' => ConditionalFieldsInterface::CONDITIONAL_FIELDS_DEPENDENCY_VALUES_AND,
    'values' => $text_values,
    '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('body ' . 'field_' . $this->fieldName . ' visible value');
  $this
    ->clickLink('Edit');
  $this
    ->createScreenshot($this->screenshotPath . '04-' . $this->testName . __FUNCTION__ . '.png');

  // 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 . '05-' . $this->testName . __FUNCTION__ . '.png');
  $this
    ->waitUntilHidden('.field--name-body', 50, '01. Article Body field is visible');

  // Change field that should not show the body.
  $this
    ->changeField($this->fieldSelector, 'drupal.org');
  $this
    ->createScreenshot($this->screenshotPath . '06-' . $this->testName . __FUNCTION__ . '.png');
  $this
    ->waitUntilHidden('.field--name-body', 50, '02. Article Body field is visible');

  // Change field value to show the body.
  $this
    ->changeField($this->fieldSelector, implode('\\r\\n', $text));
  $this
    ->createScreenshot($this->screenshotPath . '07-' . $this->testName . __FUNCTION__ . '.png');
  $this
    ->waitUntilVisible('.field--name-body', 50, '03. Article Body field is not visible');

  // Change field value to hide the body again.
  $this
    ->changeField($this->fieldSelector, '');
  $this
    ->createScreenshot($this->screenshotPath . '08-' . $this->testName . __FUNCTION__ . '.png');
  $this
    ->waitUntilHidden('.field--name-body', 50, '04. Article Body field is visible');
}