You are here

public function ConditionalFieldCheckboxesTest::testVisibleValueWidget in Conditional Fields 4.x

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

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

Overrides ConditionalFieldValueInterface::testVisibleValueWidget

File

tests/src/FunctionalJavascript/ConditionalFieldCheckboxesTest.php, line 78

Class

ConditionalFieldCheckboxesTest
Test Conditional Fields Checkboxes Plugin.

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->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 values.
  $term_id_1 = mt_rand(1, $this->termsCount);
  do {
    $term_id_2 = mt_rand(1, $this->termsCount);
  } while ($term_id_2 == $term_id_1);
  $this
    ->changeSelect('#edit-field-' . $this->taxonomyName . '-' . $term_id_1, $term_id_1);

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

  // Check if that configuration is saved.
  $this
    ->drupalGet('admin/structure/types/manage/article/conditionals');
  $this
    ->assertSession()
    ->pageTextContains('body field_' . $this->taxonomyName . ' visible value');
  $this
    ->clickLink('Edit');
  $this
    ->createScreenshot($this->screenshotPath . '01. Checkboxes' . __FUNCTION__ . '.jpg');

  // 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 . '02. Checkboxes' . __FUNCTION__ . '.jpg');
  $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_1, $term_id_1);
  $this
    ->changeSelect('#edit-field-' . $this->taxonomyName . '-' . $term_id_2, $term_id_2);
  $this
    ->waitUntilHidden('.field--name-body', 60, '02. Article Body field is visible');
  $this
    ->changeSelect('#edit-field-' . $this->taxonomyName . '-' . $term_id_2, $term_id_2);
  $this
    ->waitUntilVisible('.field--name-body', 60, '03. Article Body field is not visible');
  $this
    ->changeSelect('#edit-field-' . $this->taxonomyName . '-' . $term_id_1, $term_id_1);
  $this
    ->waitUntilHidden('.field--name-body', 60, '04. Article Body field is visible');
}