You are here

public function ConditionalFieldRadiosTest::testVisibleValueWidget in Conditional Fields 8

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

The target field is Visible when the control field has value from Widget.

Overrides ConditionalFieldValueInterface::testVisibleValueWidget

File

tests/src/FunctionalJavascript/ConditionalFieldRadiosTest.php, line 88

Class

ConditionalFieldRadiosTest
Test Conditional Fields States.

Namespace

Drupal\Tests\conditional_fields\FunctionalJavascript

Code

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

  // Visit a ConditionalFields configuration page for `Article` Content type.
  $this
    ->createCondition('body', 'field_' . $this->taxonomyName, 'visible', 'value');

  // Change a condition's values set and the value.
  $this
    ->changeField('#edit-values-set', ConditionalFieldsInterface::CONDITIONAL_FIELDS_DEPENDENCY_VALUES_WIDGET);

  // Random term id to check necessary value.
  $term_id = mt_rand(1, $this->termsCount);
  $this
    ->changeSelect('#edit-field-' . $this->taxonomyName . '-' . $term_id, $term_id);

  // Submit the form.
  $this
    ->getSession()
    ->executeScript("jQuery('#conditional-field-edit-form').submit();");

  // Check if that configuration is saved.
  $this
    ->drupalGet('admin/structure/conditional_fields/node/article');
  $this
    ->assertSession()
    ->pageTextContains('body field_' . $this->taxonomyName . ' 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
    ->waitUntilHidden('.field--name-body', 0, '01. Article Body field is visible');

  // Change a select value set to show the body.
  $this
    ->changeSelect('#edit-field-' . $this->taxonomyName . '-' . $term_id, $term_id);
  $this
    ->waitUntilVisible('.field--name-body', 50, '02. Article Body field is not visible');

  //    $this->createScreenshot('sites/simpletest/scr1BodyVisTerm.jpg');
  // Change a select value set to hide the body again.
  $this
    ->changeSelect('#edit-field-' . $this->taxonomyName . '-' . $term_id);
  $this
    ->waitUntilHidden('.field--name-body', 50, '03. Article Body field is visible');

  //    $this->createScreenshot('sites/simpletest/scr2BodyHid.jpg');
}