You are here

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

Target field is Visible when control field has value with NOT condition.

Overrides ConditionalFieldValueInterface::testVisibleValueNot

File

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

Class

ConditionalFieldCheckboxesTest
Test Conditional Fields Checkboxes Plugin.

Namespace

Drupal\Tests\conditional_fields\FunctionalJavascript

Code

public function testVisibleValueNot() {
  $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_NOT);

  // 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
    ->waitUntilVisible('.field--name-body', 0, '01. Article Body field is not visible');

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

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

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

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