You are here

public function ConditionalFieldTextWithSummaryTest::testVisibleValueWidget 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::testVisibleValueWidget()

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

Overrides ConditionalFieldValueInterface::testVisibleValueWidget

File

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

Class

ConditionalFieldTextWithSummaryTest
Test Conditional Fields Text Handler.

Namespace

Drupal\Tests\conditional_fields\FunctionalJavascript

Code

public function testVisibleValueWidget() {
  $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 test text_with_summary';
  $data = [
    '[name="condition"]' => 'value',
    '[name="values_set"]' => ConditionalFieldsInterface::CONDITIONAL_FIELDS_DEPENDENCY_VALUES_WIDGET,
    $this->fieldSelector => $text,
    '[name="grouping"]' => 'AND',
    '[name="state"]' => 'visible',
    '[name="effect"]' => 'show',
  ];
  foreach ($data as $selector => $value) {
    $this
      ->changeField($selector, $value);
  }
  $this
    ->getSession()
    ->wait(1000, '!jQuery.active');
  $this
    ->getSession()
    ->executeScript("jQuery('#conditional-field-edit-form').submit();");
  $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');

  // Change field that should not show the body.
  $this
    ->createScreenshot($this->screenshotPath . '05-' . $this->testName . __FUNCTION__ . '.png');
  $this
    ->waitUntilHidden('.field--name-body', 50, '01. Article Body field is visible');

  // Check that the field Body is visible.
  $this
    ->changeField($this->fieldSelector, $text);
  $this
    ->createScreenshot($this->screenshotPath . '06-' . $this->testName . __FUNCTION__ . '.png');
  $this
    ->waitUntilVisible('.field--name-body', 50, '02. Article Body field is not visible');

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