public function ConditionalFieldEntityReferenceTest::testInvisibleFilled in Conditional Fields 8
Same name and namespace in other branches
- 4.x tests/src/FunctionalJavascript/ConditionalFieldEntityReferenceTest.php \Drupal\Tests\conditional_fields\FunctionalJavascript\ConditionalFieldEntityReferenceTest::testInvisibleFilled()
The target field is Invisible when the control field is Filled.
Overrides ConditionalFieldFilledEmptyInterface::testInvisibleFilled
File
- tests/
src/ FunctionalJavascript/ ConditionalFieldEntityReferenceTest.php, line 655
Class
- ConditionalFieldEntityReferenceTest
- Test Conditional Fields Entity Reference Plugin.
Namespace
Drupal\Tests\conditional_fields\FunctionalJavascriptCode
public function testInvisibleFilled() {
$this
->baseTestSteps();
// Create a node that we will use in reference field.
$node = Node::create([
'type' => 'article',
'title' => 'Referenced node',
]);
$node
->save();
$referenced_format_1 = sprintf("%s (%d)", $node
->label(), $node
->id());
$referenced_format_wrong = sprintf("%s ", $node
->label());
// Visit a ConditionalFields configuration page for Content bundles.
$this
->createCondition('body', 'field_' . $this->fieldName, '!visible', '!empty');
$this
->createScreenshot($this->screenshotPath . '01-entity-reference-add-filed-conditions.png');
// Check if that configuration is saved.
$this
->drupalGet('admin/structure/types/manage/article/conditionals');
$this
->createScreenshot($this->screenshotPath . '03-entity-reference-submit-entity-reference-filed-conditions.png');
$this
->assertSession()
->pageTextContains('body field_' . $this->fieldName . ' !visible !empty');
// 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 . '04-entity-reference-body-invisible-when-controlled-field-has-no-value.png');
$this
->waitUntilVisible('.field--name-body', 50, '01. Article Body field is not visible');
// Change an entity reference field in format 'Node title (nid)' to show the body.
$this
->changeField($this->fieldSelector, $referenced_format_1);
$this
->createScreenshot($this->screenshotPath . '06-entity-reference-body-visible-when-controlled-field-has-value-format-1.png');
$this
->waitUntilHidden('.field--name-body', 50, '02. Article Body field is visible');
// Set wrong format for an entity reference field to hide the body.
$this
->changeField($this->fieldSelector, $referenced_format_wrong);
$this
->createScreenshot($this->screenshotPath . '07-entity-reference-body-invisible-when-controlled-field-has-value-in-wrong-format.png');
$this
->waitUntilHidden('.field--name-body', 50, '03. Article Body field is visible');
// Set an empty value to hide body.
$this
->changeField($this->fieldSelector, '');
$this
->createScreenshot($this->screenshotPath . '09-entity-reference-body-invisible-when-controlled-field-has-no-value-again.png');
$this
->waitUntilVisible('.field--name-body', 50, '04. Article Body field is not visible');
}