You are here

public function ComplexWidgetTest::testReferencingExistingEntitiesNoSubmit in Inline Entity Form 8

Tests if referencing an existing entity works without submitting the form.

File

tests/src/FunctionalJavascript/ComplexWidgetTest.php, line 485

Class

ComplexWidgetTest
IEF complex field widget tests.

Namespace

Drupal\Tests\inline_entity_form\FunctionalJavascript

Code

public function testReferencingExistingEntitiesNoSubmit() {

  // Get the xpath selectors for the input fields in this test.
  $node_field_xpath = $this
    ->getXpathForNthInputByLabelText('Node', 1);
  $title_field_xpath = $this
    ->getXpathForNthInputByLabelText('Title', 1);

  // Allow addition of existing nodes.
  $this
    ->updateSetting('allow_existing', TRUE);
  $title = $this
    ->randomMachineName();
  $this
    ->drupalCreateNode([
    'type' => 'ief_reference_type',
    'title' => $title,
    'first_name' => $this
      ->randomMachineName(),
    'last_name' => $this
      ->randomMachineName(),
  ]);
  $node = $this
    ->drupalGetNodeByTitle($title);
  $this
    ->assertNotEmpty($node, 'Created ief_reference_type node "' . $node
    ->label() . '"');
  $this
    ->drupalGet($this->formContentAddUrl);
  $assert_session = $this
    ->assertSession();
  $page = $this
    ->getSession()
    ->getPage();
  $this
    ->openMultiExistingForm();
  $assert_session
    ->elementExists('xpath', $node_field_xpath)
    ->setValue($node
    ->getTitle() . ' (' . $node
    ->id() . ')');
  $parent_title = $this
    ->randomMachineName();
  $assert_session
    ->elementExists('xpath', $title_field_xpath)
    ->setValue($parent_title);
  $page
    ->pressButton('Save');
  $assert_session
    ->pageTextContains("IEF test complex {$parent_title} has been created.");
  $assert_session
    ->pageTextNotContains('This value should not be null.');
  $node = $this
    ->drupalGetNodeByTitle($parent_title);
  $this
    ->assertNotEmpty($node, 'Created ief_reference_type node.');
}