public function ComplexWidgetTest::testReferenceExistingValidation in Inline Entity Form 8
Test if invalid values get correct validation messages.
Tests validation in reference existing entity form. It also checks if existing entity reference form can be canceled.
File
- tests/
src/ FunctionalJavascript/ ComplexWidgetTest.php, line 523
Class
- ComplexWidgetTest
- IEF complex field widget tests.
Namespace
Drupal\Tests\inline_entity_form\FunctionalJavascriptCode
public function testReferenceExistingValidation() {
// Get the xpath selectors for the input fields in this test.
$node_field_xpath = $this
->getXpathForNthInputByLabelText('Node', 1);
$page = $this
->getSession()
->getPage();
$assert_session = $this
->assertSession();
$this
->updateSetting('allow_existing', TRUE);
$this
->drupalGet('node/add/ief_test_complex');
$this
->checkExistingValidationExpectation('', 'Node field is required.');
$this
->checkExistingValidationExpectation('Fake Title', 'There are no entities matching "Fake Title"');
// Check adding nodes that cannot be referenced by this field.
foreach ($this
->createNodeForEveryBundle() as $id => $title) {
$node = Node::load($id);
if ($node
->bundle() !== 'ief_reference_type') {
$this
->checkExistingValidationExpectation("{$title} ({$id})", "The referenced entity (node: {$id}) does not exist.");
}
}
foreach ($this
->createReferenceContent(2) as $title => $id) {
$this
->openMultiExistingForm();
$current_title = "{$title} ({$id})";
$assert_session
->elementExists('xpath', $node_field_xpath)
->setValue($current_title);
$page
->pressButton('Add node');
$this
->waitForRowByTitle($title);
$assert_session
->elementNotExists('xpath', $node_field_xpath);
// Try to add the same node again.
$this
->checkExistingValidationExpectation($current_title, 'The selected node has already been added.');
}
}