You are here

public function ComplexWidgetTest::testNestedEntityCreationWithDifferentBundlesAjaxSubmit in Inline Entity Form 8

Tests the entity creation with different bundles nested in each other.

Ief_test_nested1 -> ief_test_nested2 -> ief_test_nested3

File

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

Class

ComplexWidgetTest
IEF complex field widget tests.

Namespace

Drupal\Tests\inline_entity_form\FunctionalJavascript

Code

public function testNestedEntityCreationWithDifferentBundlesAjaxSubmit() {

  // Get the xpath selectors for the input fields in this test.
  $top_title_field_xpath = $this
    ->getXpathForNthInputByLabelText('Title', 1);
  $nested_title_field_xpath = $this
    ->getXpathForNthInputByLabelText('Title', 2);
  $double_nested_title_field_xpath = $this
    ->getXpathForNthInputByLabelText('Title', 3);

  // Get the xpath selectors for the fieldset labels in this test.
  $top_fieldset_label_xpath = $this
    ->getXpathForFieldsetLabel('Multiple nodes', 1);
  $nested_fieldset_label_xpath = $this
    ->getXpathForFieldsetLabel('Multiple nodes', 2);
  $page = $this
    ->getSession()
    ->getPage();
  $assert_session = $this
    ->assertSession();
  foreach ([
    FALSE,
    TRUE,
  ] as $required) {
    $this
      ->setupNestedComplexForm($required);
    $assert_session
      ->elementExists('xpath', $top_fieldset_label_xpath);
    $assert_session
      ->elementExists('xpath', $nested_fieldset_label_xpath);
    $required_string = $required ? ' required' : ' unrequired';
    $double_nested_title = 'Dream within a dream' . $required_string;
    $nested_title = 'Dream' . $required_string;
    $top_level_title = 'Reality' . $required_string;
    $this
      ->assertNotEmpty($field = $assert_session
      ->waitForElement('xpath', $double_nested_title_field_xpath));
    $field
      ->setValue($double_nested_title);
    $page
      ->pressButton('Create node 3');
    $this
      ->waitForRowByTitle($double_nested_title);

    // Assert title of second nested node found.
    $this
      ->assertNoNodeByTitle($double_nested_title, 'Second nested entity is not saved yet.');
    $assert_session
      ->elementExists('xpath', $nested_title_field_xpath)
      ->setValue($nested_title);
    $page
      ->pressButton('Create node 2');
    $this
      ->waitForRowByTitle($nested_title);
    $this
      ->assertNoNodeByTitle($nested_title, 'First nested entity is not saved yet.');
    $assert_session
      ->elementExists('xpath', $top_title_field_xpath)
      ->setValue($top_level_title);
    $page
      ->pressButton('Save');
    $assert_session
      ->pageTextContains("IEF test nested 1 {$top_level_title} has been created.");
    $top_level_node = $this
      ->drupalGetNodeByTitle($top_level_title);
    $this
      ->assertNotEmpty($top_level_node);
    $nested_node = $this
      ->drupalGetNodeByTitle($nested_title);
    $this
      ->assertNotEmpty($nested_node);
    $double_nested_node = $this
      ->drupalGetNodeByTitle($double_nested_title);
    $this
      ->assertNotEmpty($double_nested_node);
    $this
      ->checkNestedNodes($top_level_node, $nested_node, $double_nested_node);
  }
}