You are here

public function ComplexWidgetTest::testNestedEntityCreationWithDifferentBundlesNoAjaxSubmit 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 282

Class

ComplexWidgetTest
IEF complex field widget tests.

Namespace

Drupal\Tests\inline_entity_form\FunctionalJavascript

Code

public function testNestedEntityCreationWithDifferentBundlesNoAjaxSubmit() {

  // 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;
    $assert_session
      ->elementExists('xpath', $top_title_field_xpath)
      ->setValue($top_level_title);
    $assert_session
      ->elementExists('xpath', $nested_title_field_xpath)
      ->setValue($nested_title);
    $assert_session
      ->elementExists('xpath', $double_nested_title_field_xpath)
      ->setValue($double_nested_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);
  }
}