You are here

public function MultipleValuesWidgetTest::testNestedEntityCreationWithDifferentBundlesAjaxSubmit in Inline Entity Form 7

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

ief_test_nested1 -> ief_test_nested2 -> ief_test_nested3

File

tests/multiple_values_widget.test, line 167

Class

MultipleValuesWidgetTest
IEF multiple values field widget tests.

Code

public function testNestedEntityCreationWithDifferentBundlesAjaxSubmit() {
  $required_possibilities = array(
    FALSE,
    TRUE,
  );
  foreach ($required_possibilities as $required) {
    $this
      ->setupNestedMultipleForm($required);
    $nested3_title = 'nested3 title steps ' . ($required ? 'required' : 'not required');
    $nested2_title = 'nested2 title steps ' . ($required ? 'required' : 'not required');
    $nested1_title = 'nested1 title steps ' . ($required ? 'required' : 'not required');
    $edit = array(
      'field_test_ref_nested1[und][form][field_test_ref_nested2][und][form][title]' => $nested3_title,
    );
    $this
      ->drupalPostAjax(NULL, $edit, $this
      ->getButtonName('//input[@type="submit" and @value="Create node 3"]'));
    $this
      ->assertText($nested3_title, 'Title of second nested node found.');
    $this
      ->assertFalse($this
      ->drupalGetNodeByTitle($nested3_title), 'Second nested entity is not saved yet.');
    $edit = array(
      'field_test_ref_nested1[und][form][title]' => $nested2_title,
    );
    $this
      ->drupalPostAjax(NULL, $edit, $this
      ->getButtonName('//input[@type="submit" and @value="Create node 2"]'));
    $this
      ->assertText($nested2_title, 'Title of first nested node found.');
    $this
      ->assertFalse($this
      ->drupalGetNodeByTitle($nested2_title), 'First nested entity is not saved yet.');
    $edit = array(
      'title' => $nested1_title,
    );
    $this
      ->drupalPost(NULL, $edit, t('Save'));
    $nested1_node = $this
      ->drupalGetNodeByTitle($nested1_title);
    $this
      ->assertEqual($nested1_title, $nested1_node->title, "First node's title looks correct.");
    $this
      ->assertEqual('ief_test_nested1', $nested1_node->type, "First node's type looks correct.");
    if ($this
      ->assertNotNull($nested1_node->field_test_ref_nested1[LANGUAGE_NONE][0]['target_id'], 'Second node was created.')) {
      $creatednested2 = node_load($nested1_node->field_test_ref_nested1[LANGUAGE_NONE][0]['target_id']);
      $this
        ->assertEqual($nested2_title, $creatednested2->title, "Second node's title looks correct.");
      $this
        ->assertEqual('ief_test_nested2', $creatednested2->type, "Second node's type looks correct.");
      if ($this
        ->assertNotNull($creatednested2->field_test_ref_nested2[LANGUAGE_NONE][0]['target_id'], 'Third node was created')) {
        $creatednested3 = node_load($creatednested2->field_test_ref_nested2[LANGUAGE_NONE][0]['target_id']);
        $this
          ->assertEqual($nested3_title, $creatednested3->title, "Third node's title looks correct.");
        $this
          ->assertEqual('ief_test_nested3', $creatednested3->type, "Third node's type looks correct.");
        $this
          ->checkNestedEntityEditing($nested1_node, TRUE);
      }
    }
  }
}