public function ConditionalFieldCheckboxesTest::testVisibleValueAnd in Conditional Fields 4.x
Same name and namespace in other branches
- 8 tests/src/FunctionalJavascript/ConditionalFieldCheckboxesTest.php \Drupal\Tests\conditional_fields\FunctionalJavascript\ConditionalFieldCheckboxesTest::testVisibleValueAnd()
Target field is Visible when control field has value with AND condition.
Overrides ConditionalFieldValueInterface::testVisibleValueAnd
File
- tests/
src/ FunctionalJavascript/ ConditionalFieldCheckboxesTest.php, line 169
Class
- ConditionalFieldCheckboxesTest
- Test Conditional Fields Checkboxes Plugin.
Namespace
Drupal\Tests\conditional_fields\FunctionalJavascriptCode
public function testVisibleValueAnd() {
$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_AND);
// 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
->changeSelect('#edit-field-' . $this->taxonomyName . '-' . $term_id_2, $term_id_2);
$this
->createScreenshot($this->screenshotPath . 'scr1BodyVisCheckboxes.jpg');
$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');
$this
->changeSelect('#edit-field-' . $this->taxonomyName . '-' . $term_id_2, $term_id_2);
$this
->waitUntilHidden('.field--name-body', 60, '04. Article Body field is visible');
$this
->createScreenshot($this->screenshotPath . 'scr2BodyHidCheckboxes.jpg');
}