You are here

public function ConditionalFieldCheckboxesTest::testVisibleValueOr 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::testVisibleValueOr()

Target field is Visible when the control field has value with OR condition.

Overrides ConditionalFieldValueInterface::testVisibleValueOr

File

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

Class

ConditionalFieldCheckboxesTest
Test Conditional Fields Checkboxes Plugin.

Namespace

Drupal\Tests\conditional_fields\FunctionalJavascript

Code

public function testVisibleValueOr() {
  $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_OR);

  // 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);
  $values = $term_id_1 . '\\r\\n' . $term_id_2;
  $this
    ->changeField('#edit-values', $values);

  // 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');

  // 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_1, $term_id_1);
  $this
    ->waitUntilVisible('.field--name-body', 60, '02. Article Body field is not visible');

  // Change a select value set to hide the body again.
  $this
    ->changeSelect('#edit-field-' . $this->taxonomyName . '-' . $term_id_1, $term_id_1);
  $this
    ->waitUntilHidden('.field--name-body', 60, '03. Article Body field is visible');

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

  // Change a select value set to hide the body again.
  $this
    ->changeSelect('#edit-field-' . $this->taxonomyName . '-' . $term_id_2, $term_id_2);
  $this
    ->waitUntilHidden('.field--name-body', 60, '05. Article Body field is visible');
}