View source
<?php
namespace Drupal\Tests\conditional_fields\FunctionalJavascript;
use Drupal\conditional_fields\ConditionalFieldsInterface;
use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\Tests\field\Traits\EntityReferenceTestTrait;
use Drupal\node\Entity\Node;
use Drupal\Tests\conditional_fields\FunctionalJavascript\TestCases\ConditionalFieldFilledEmptyInterface;
use Drupal\Tests\conditional_fields\FunctionalJavascript\TestCases\ConditionalFieldValueInterface;
use Drupal\Tests\RandomGeneratorTrait;
class ConditionalFieldEntityReferenceTest extends ConditionalFieldTestBase implements ConditionalFieldValueInterface, ConditionalFieldFilledEmptyInterface {
use EntityReferenceTestTrait;
use RandomGeneratorTrait;
public static $modules = [
'conditional_fields',
'node',
];
protected $screenshotPath = 'sites/simpletest/conditional_fields/entity_reference/';
protected $fieldName = 'entity_reference';
protected $fieldSelector;
protected $fieldStorageDefinition;
protected $fieldStorage;
protected $field;
protected function setUp() {
parent::setUp();
$this->fieldSelector = '[name="field_' . $this->fieldName . '[0][target_id]"]';
$handler_settings = [
'target_bundles' => [
'article' => 'article',
],
];
$this
->createEntityReferenceField('node', 'article', 'field_' . $this->fieldName, $this->fieldName, 'node', 'default', $handler_settings, -1);
EntityFormDisplay::load('node.article.default')
->setComponent('field_' . $this->fieldName, [
'type' => 'entity_reference_autocomplete',
])
->save();
}
public function testVisibleValueWidget() {
$this
->baseTestSteps();
$node = Node::create([
'type' => 'article',
'title' => 'Referenced node',
]);
$node
->save();
$referenced_format_1 = sprintf("%s (%d)", $node
->label(), $node
->id());
$referenced_format_2 = sprintf("%s", $node
->label());
$referenced_format_wrong = sprintf("%s ", $node
->label(), $node
->id());
$this
->createCondition('body', 'field_' . $this->fieldName, 'visible', 'value');
$this
->createScreenshot($this->screenshotPath . '01-entity-reference-add-filed-conditions.png');
$data = [
'condition' => 'value',
'values_set' => ConditionalFieldsInterface::CONDITIONAL_FIELDS_DEPENDENCY_VALUES_WIDGET,
'field_' . $this->fieldName . '[0][target_id]' => $referenced_format_1,
'grouping' => 'AND',
'state' => 'visible',
'effect' => 'show',
];
$this
->submitForm($data, 'Save settings');
$this
->createScreenshot($this->screenshotPath . '02-entity-reference-post-add-list-options-filed-conditions.png');
$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 value');
$this
->drupalGet('node/add/article');
$this
->createScreenshot($this->screenshotPath . '04-entity-reference-body-invisible-when-controlled-field-has-no-value.png');
$this
->waitUntilHidden('.field--name-body', 50, '01. Article Body field is visible');
$this
->changeField($this->fieldSelector, $this
->randomMachineName());
$this
->createScreenshot($this->screenshotPath . '05-entity-reference-body-invisible-when-controlled-field-has-wrong-value.png');
$this
->waitUntilHidden('.field--name-body', 50, '02. Article Body field is visible');
$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
->waitUntilVisible('.field--name-body', 50, '03. Article Body field is not visible');
$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, '04. Article Body field is visible');
$this
->changeField($this->fieldSelector, $referenced_format_2);
$this
->createScreenshot($this->screenshotPath . '08-entity-reference-body-visible-when-controlled-field-has-value-format-2.png');
$this
->waitUntilVisible('.field--name-body', 50, '05. Article Body field is not visible');
$this
->changeField($this->fieldSelector, '');
$this
->createScreenshot($this->screenshotPath . '09-entity-reference-body-invisible-when-controlled-field-has-no-value-again.png');
$this
->waitUntilHidden('.field--name-body', 50, '06. Article Body field is visible');
}
public function testVisibleValueRegExp() {
$this
->baseTestSteps();
$node = Node::create([
'type' => 'article',
'title' => 'Referenced node',
]);
$node
->save();
$referenced_format_1 = sprintf("%s (%d)", $node
->label(), $node
->id());
$referenced_format_2 = sprintf("%s", $node
->label());
$referenced_format_wrong = sprintf("%s ", $node
->label());
$this
->createCondition('body', 'field_' . $this->fieldName, 'visible', 'value');
$this
->createScreenshot($this->screenshotPath . '01-entity-reference-add-filed-conditions.png');
$data = [
'condition' => 'value',
'values_set' => ConditionalFieldsInterface::CONDITIONAL_FIELDS_DEPENDENCY_VALUES_REGEX,
'regex' => '^.+\\s\\([\\d]+\\)',
'grouping' => 'AND',
'state' => 'visible',
'effect' => 'show',
];
$this
->submitForm($data, 'Save settings');
$this
->createScreenshot($this->screenshotPath . '02-entity-reference-post-add-list-options-filed-conditions.png');
$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 value');
$this
->drupalGet('node/add/article');
$this
->createScreenshot($this->screenshotPath . '04-entity-reference-body-invisible-when-controlled-field-has-no-value.png');
$this
->waitUntilHidden('.field--name-body', 50, '01. Article Body field is visible');
$this
->changeField($this->fieldSelector, $this
->randomMachineName());
$this
->createScreenshot($this->screenshotPath . '05-entity-reference-body-invisible-when-controlled-field-has-wrong-value.png');
$this
->waitUntilHidden('.field--name-body', 50, '02. Article Body field is visible');
$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
->waitUntilVisible('.field--name-body', 50, '03. Article Body field is not visible');
$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, '04. Article Body field is visible');
$this
->changeField($this->fieldSelector, $referenced_format_2);
$this
->createScreenshot($this->screenshotPath . '08-entity-reference-body-visible-when-controlled-field-has-value-format-2.png');
$this
->waitUntilHidden('.field--name-body', 50, '05. Article Body field is visible');
$this
->changeField($this->fieldSelector, '');
$this
->createScreenshot($this->screenshotPath . '09-entity-reference-body-invisible-when-controlled-field-has-no-value-again.png');
$this
->waitUntilHidden('.field--name-body', 50, '06. Article Body field is visible');
}
public function testVisibleValueAnd() {
$this
->baseTestSteps();
$node = Node::create([
'type' => 'article',
'title' => 'Referenced node',
]);
$node
->save();
$node_2 = Node::create([
'type' => 'article',
'title' => 'Referenced node 2',
]);
$node_2
->save();
$referenced_format_1 = sprintf("%s (%d)", $node
->label(), $node
->id());
$referenced_format_2 = sprintf("%s (%d)", $node_2
->label(), $node_2
->id());
$referenced_format_wrong = sprintf("%s ", $node
->label());
$this
->createCondition('body', 'field_' . $this->fieldName, 'visible', 'value');
$this
->createScreenshot($this->screenshotPath . '01-entity-reference-add-filed-conditions.png');
$data = [
'condition' => 'value',
'values_set' => ConditionalFieldsInterface::CONDITIONAL_FIELDS_DEPENDENCY_VALUES_AND,
'values' => "{$referenced_format_1}\r\n{$referenced_format_2}",
'grouping' => 'AND',
'state' => 'visible',
'effect' => 'show',
];
$this
->submitForm($data, 'Save settings');
$this
->createScreenshot($this->screenshotPath . '02-entity-reference-post-add-list-options-filed-conditions.png');
$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 value');
$this
->drupalGet('node/add/article');
$this
->createScreenshot($this->screenshotPath . '04-entity-reference-body-invisible-when-controlled-field-has-no-value.png');
$this
->waitUntilHidden('.field--name-body', 50, '01. Article Body field is visible');
$this
->changeField($this->fieldSelector, $this
->randomMachineName());
$this
->createScreenshot($this->screenshotPath . '05-entity-reference-body-invisible-when-controlled-field-has-wrong-value.png');
$this
->waitUntilHidden('.field--name-body', 50, '02. Article Body field is visible');
$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, '03. Article Body field is visible');
$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, '04. Article Body field is visible');
$this
->changeField($this->fieldSelector, $referenced_format_2);
$this
->createScreenshot($this->screenshotPath . '08-entity-reference-body-visible-when-controlled-field-has-value-format-2.png');
$this
->waitUntilHidden('.field--name-body', 50, '05. Article Body field is visible');
$this
->changeField($this->fieldSelector, '');
$this
->createScreenshot($this->screenshotPath . '09-entity-reference-body-invisible-when-controlled-field-has-no-value-again.png');
$this
->waitUntilHidden('.field--name-body', 50, '06. Article Body field is visible');
}
public function testVisibleValueOr() {
$this
->baseTestSteps();
$node = Node::create([
'type' => 'article',
'title' => 'Referenced node',
]);
$node
->save();
$node_2 = Node::create([
'type' => 'article',
'title' => 'Referenced node 2',
]);
$node_2
->save();
$referenced_format_1 = sprintf("%s (%d)", $node
->label(), $node
->id());
$referenced_format_2 = sprintf("%s (%d)", $node_2
->label(), $node_2
->id());
$referenced_format_wrong = sprintf("%s ", $node
->label());
$this
->createCondition('body', 'field_' . $this->fieldName, 'visible', 'value');
$this
->createScreenshot($this->screenshotPath . '01-entity-reference-add-filed-conditions.png');
$data = [
'condition' => 'value',
'values_set' => ConditionalFieldsInterface::CONDITIONAL_FIELDS_DEPENDENCY_VALUES_OR,
'values' => "{$referenced_format_1}\r\n{$referenced_format_2}",
'grouping' => 'AND',
'state' => 'visible',
'effect' => 'show',
];
$this
->submitForm($data, 'Save settings');
$this
->createScreenshot($this->screenshotPath . '02-entity-reference-post-add-list-options-filed-conditions.png');
$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 value');
$this
->drupalGet('node/add/article');
$this
->createScreenshot($this->screenshotPath . '04-entity-reference-body-invisible-when-controlled-field-has-no-value.png');
$this
->waitUntilHidden('.field--name-body', 50, '01. Article Body field is visible');
$this
->changeField($this->fieldSelector, $this
->randomMachineName());
$this
->createScreenshot($this->screenshotPath . '05-entity-reference-body-invisible-when-controlled-field-has-wrong-value.png');
$this
->waitUntilHidden('.field--name-body', 50, '02. Article Body field is visible');
$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
->waitUntilVisible('.field--name-body', 50, '03. Article Body field is not visible');
$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, '04. Article Body field is visible');
$this
->changeField($this->fieldSelector, $referenced_format_2);
$this
->createScreenshot($this->screenshotPath . '08-entity-reference-body-visible-when-controlled-field-has-value-format-2.png');
$this
->waitUntilVisible('.field--name-body', 50, '05. Article Body field is not visible');
$this
->changeField($this->fieldSelector, '');
$this
->createScreenshot($this->screenshotPath . '09-entity-reference-body-invisible-when-controlled-field-has-no-value-again.png');
$this
->waitUntilHidden('.field--name-body', 50, '06. Article Body field is visible');
}
public function testVisibleValueNot() {
$this
->baseTestSteps();
$node = Node::create([
'type' => 'article',
'title' => 'Referenced node',
]);
$node
->save();
$node_2 = Node::create([
'type' => 'article',
'title' => 'Referenced node 2',
]);
$node_2
->save();
$referenced_format_1 = sprintf("%s (%d)", $node
->label(), $node
->id());
$referenced_format_2 = sprintf("%s (%d)", $node_2
->label(), $node_2
->id());
$referenced_format_wrong = sprintf("%s ", $node
->label());
$this
->createCondition('body', 'field_' . $this->fieldName, 'visible', 'value');
$this
->createScreenshot($this->screenshotPath . '01-entity-reference-add-filed-conditions.png');
$data = [
'condition' => 'value',
'values_set' => ConditionalFieldsInterface::CONDITIONAL_FIELDS_DEPENDENCY_VALUES_NOT,
'values' => "{$referenced_format_1}\r\n{$referenced_format_2}",
'grouping' => 'AND',
'state' => 'visible',
'effect' => 'show',
];
$this
->submitForm($data, 'Save settings');
$this
->createScreenshot($this->screenshotPath . '02-entity-reference-post-add-list-options-filed-conditions.png');
$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 value');
$this
->drupalGet('node/add/article');
$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');
$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');
$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
->waitUntilVisible('.field--name-body', 50, '04. Article Body field is not visible');
$this
->changeField($this->fieldSelector, $referenced_format_2);
$this
->createScreenshot($this->screenshotPath . '08-entity-reference-body-visible-when-controlled-field-has-value-format-2.png');
$this
->waitUntilHidden('.field--name-body', 50, '05. Article Body field is visible');
$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, '06. Article Body field is not visible');
}
public function testVisibleValueXor() {
$this
->baseTestSteps();
$node = Node::create([
'type' => 'article',
'title' => 'Referenced node',
]);
$node
->save();
$node_2 = Node::create([
'type' => 'article',
'title' => 'Referenced node 2',
]);
$node_2
->save();
$referenced_format_1 = sprintf("%s (%d)", $node
->label(), $node
->id());
$referenced_format_2 = sprintf("%s (%d)", $node_2
->label(), $node_2
->id());
$referenced_format_wrong = sprintf("%s ", $node
->label());
$this
->createCondition('body', 'field_' . $this->fieldName, 'visible', 'value');
$this
->createScreenshot($this->screenshotPath . '01-entity-reference-add-filed-conditions.png');
$data = [
'condition' => 'value',
'values_set' => ConditionalFieldsInterface::CONDITIONAL_FIELDS_DEPENDENCY_VALUES_XOR,
'values' => "{$referenced_format_1}\r\n{$referenced_format_2}",
'grouping' => 'AND',
'state' => 'visible',
'effect' => 'show',
];
$this
->submitForm($data, 'Save settings');
$this
->createScreenshot($this->screenshotPath . '02-entity-reference-post-add-list-options-filed-conditions.png');
$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 value');
$this
->drupalGet('node/add/article');
$this
->createScreenshot($this->screenshotPath . '04-entity-reference-body-invisible-when-controlled-field-has-no-value.png');
$this
->waitUntilHidden('.field--name-body', 50, '01. Article Body field is visible');
$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
->waitUntilVisible('.field--name-body', 50, '02. Article Body field is not visible');
$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, '04. Article Body field is visible');
$this
->changeField($this->fieldSelector, $referenced_format_2);
$this
->createScreenshot($this->screenshotPath . '08-entity-reference-body-visible-when-controlled-field-has-value-format-2.png');
$this
->waitUntilVisible('.field--name-body', 50, '05. Article Body field is not visible');
$this
->changeField($this->fieldSelector, '');
$this
->createScreenshot($this->screenshotPath . '09-entity-reference-body-invisible-when-controlled-field-has-no-value-again.png');
$this
->waitUntilHidden('.field--name-body', 50, '06. Article Body field is visible');
}
public function testVisibleFilled() {
$this
->baseTestSteps();
$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());
$this
->createCondition('body', 'field_' . $this->fieldName, 'visible', '!empty');
$this
->createScreenshot($this->screenshotPath . '01-entity-reference-add-filed-conditions.png');
$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');
$this
->drupalGet('node/add/article');
$this
->createScreenshot($this->screenshotPath . '04-entity-reference-body-invisible-when-controlled-field-has-no-value.png');
$this
->waitUntilHidden('.field--name-body', 50, '01. Article Body field is visible');
$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
->waitUntilVisible('.field--name-body', 50, '02. Article Body field is not visible');
$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
->waitUntilVisible('.field--name-body', 50, '03. Article Body field is not visible');
$this
->changeField($this->fieldSelector, '');
$this
->createScreenshot($this->screenshotPath . '09-entity-reference-body-invisible-when-controlled-field-has-no-value-again.png');
$this
->waitUntilHidden('.field--name-body', 50, '04. Article Body field is visible');
}
public function testVisibleEmpty() {
$this
->baseTestSteps();
$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());
$this
->createCondition('body', 'field_' . $this->fieldName, 'visible', 'empty');
$this
->createScreenshot($this->screenshotPath . '01-entity-reference-add-filed-conditions.png');
$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');
$this
->drupalGet('node/add/article');
$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');
$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');
$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');
$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');
}
public function testInvisibleFilled() {
$this
->baseTestSteps();
$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());
$this
->createCondition('body', 'field_' . $this->fieldName, '!visible', '!empty');
$this
->createScreenshot($this->screenshotPath . '01-entity-reference-add-filed-conditions.png');
$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');
$this
->drupalGet('node/add/article');
$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');
$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');
$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');
$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');
}
public function testInvisibleEmpty() {
$this
->baseTestSteps();
$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());
$this
->createCondition('body', 'field_' . $this->fieldName, '!visible', 'empty');
$this
->createScreenshot($this->screenshotPath . '01-entity-reference-add-filed-conditions.png');
$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');
$this
->drupalGet('node/add/article');
$this
->createScreenshot($this->screenshotPath . '04-entity-reference-body-invisible-when-controlled-field-has-no-value.png');
$this
->waitUntilHidden('.field--name-body', 50, '01. Article Body field is visible');
$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
->waitUntilVisible('.field--name-body', 50, '02. Article Body field is not visible');
$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
->waitUntilVisible('.field--name-body', 50, '03. Article Body field is not visible');
$this
->changeField($this->fieldSelector, '');
$this
->createScreenshot($this->screenshotPath . '09-entity-reference-body-invisible-when-controlled-field-has-no-value-again.png');
$this
->waitUntilHidden('.field--name-body', 50, '04. Article Body field is visible');
}
}