diff --git a/inline_entity_form.info b/inline_entity_form.info
index 92267a7..26b0f6b 100644
--- a/inline_entity_form.info
+++ b/inline_entity_form.info
@@ -10,3 +10,6 @@ files[] = includes/node.inline_entity_form.inc
 files[] = includes/taxonomy_term.inline_entity_form.inc
 files[] = includes/commerce_product.inline_entity_form.inc
 files[] = includes/commerce_line_item.inline_entity_form.inc
+files[] = tests/inline_entity_form_test_base.test
+files[] = tests/multiple_values_widget.test
+;files[] = tests/single_value_widget.test
diff --git a/tests/inline_entity_form_test_base.test b/tests/inline_entity_form_test_base.test
new file mode 100644
index 0000000..52026d8
--- /dev/null
+++ b/tests/inline_entity_form_test_base.test
@@ -0,0 +1,71 @@
+<?php
+
+
+/**
+ * Base Class for Inline Entity Form Tests.
+ */
+abstract class InlineEntityFormTestBase extends DrupalWebTestCase {
+
+  protected $user;
+
+  /**
+   * Gets IEF button name.
+   *
+   * @param array $xpath
+   *   Xpath of the button.
+   *
+   * @return string
+   *   The name of the button.
+   */
+  protected function getButtonName($xpath) {
+    $retval = '';
+    /** @var \SimpleXMLElement[] $elements */
+    if ($elements = $this->xpath($xpath)) {
+      foreach ($elements[0]->attributes() as $name => $value) {
+        if ($name == 'name') {
+          $retval = $value;
+          break;
+        }
+      }
+    }
+    return $retval;
+  }
+
+  /**
+   * Passes if no node is found for the title.
+   *
+   * @param $title
+   *   Node title to check.
+   * @param $message
+   *   Message to display.
+   */
+  protected function assertNoNodeByTitle($title, $message = '') {
+    if (!$message) {
+      $message = "No node with title: $title";
+    }
+    $node = $this->getNodeByTitle($title);
+
+    $this->assertTrue(empty($node), $message);
+  }
+
+  /**
+   * Passes if node is found for the title.
+   *
+   * @param $title
+   *   Node title to check.
+   * @param $message
+   *   Message to display.
+   */
+  protected function assertNodeByTitle($title, $bundle = NULL, $message = '') {
+    if (!$message) {
+      $message = "Node with title found: $title";
+    }
+    $node = $this->getNodeByTitle($title);
+    if ($this->assertTrue(!empty($node), $message)) {
+      if ($bundle) {
+        $this->assertEqual($node->bundle(), $bundle, "Node is correct bundle: $bundle");
+      }
+    }
+  }
+
+}
diff --git a/tests/modules/inline_entity_form_test/inline_entity_form_test.info b/tests/modules/inline_entity_form_test/inline_entity_form_test.info
new file mode 100644
index 0000000..6a6b557
--- /dev/null
+++ b/tests/modules/inline_entity_form_test/inline_entity_form_test.info
@@ -0,0 +1,11 @@
+name = Inline entity form test
+description = Contains all content types required for IEF testing
+core = 7.x
+package = Testing
+hidden = TRUE
+
+dependencies[] = entityreference
+dependencies[] = image
+dependencies[] = inline_entity_form
+dependencies[] = number
+dependencies[] = text
diff --git a/tests/modules/inline_entity_form_test/inline_entity_form_test.module b/tests/modules/inline_entity_form_test/inline_entity_form_test.module
new file mode 100644
index 0000000..72fbafa
--- /dev/null
+++ b/tests/modules/inline_entity_form_test/inline_entity_form_test.module
@@ -0,0 +1,368 @@
+<?php
+
+/**
+ * @file
+ * Support module for Inline Entity Form.
+ */
+
+
+/**
+ * Implements hook_install().
+ */
+function inline_entity_form_test_install() {
+
+  // Create content types.
+  $types = array(
+    array(
+      'type' => 'ief_reference_type',
+      'name' => t('IEF reference type'),
+      'base' => 'node_content',
+      'description' => t('Entity reference content type.'),
+      'custom' => 1,
+      'modified' => 1,
+      'locked' => 0,
+    ),
+    array(
+      'type' => 'ief_simple_single',
+      'name' => t('IEF simple single'),
+      'base' => 'node_content',
+      'description' => t('Content type for IEF simple widget testing.'),
+      'custom' => 1,
+      'modified' => 1,
+      'locked' => 0,
+    ),
+    array(
+      'type' => 'ief_test_complex',
+      'name' => t('IEF test complex'),
+      'base' => 'node_content',
+      'description' => t('Content type for IEF complex widget testing.'),
+      'custom' => 1,
+      'modified' => 1,
+      'locked' => 0,
+    ),
+    array(
+      'type' => 'ief_test_custom',
+      'name' => t('IEF test custom'),
+      'base' => 'node_content',
+      'description' => t('Content type for IEF custom form testing.'),
+      'custom' => 1,
+      'modified' => 1,
+      'locked' => 0,
+    ),
+    array(
+      'type' => 'ief_test_nested1',
+      'name' => t('IEF test nested1'),
+      'base' => 'node_content',
+      'description' => t('Content type for IEF custom form testing.'),
+      'custom' => 1,
+      'modified' => 1,
+      'locked' => 0,
+    ),
+    array(
+      'type' => 'ief_test_nested2',
+      'name' => t('IEF test nested2'),
+      'base' => 'node_content',
+      'description' => t('Content type for IEF custom form testing.'),
+      'custom' => 1,
+      'modified' => 1,
+      'locked' => 0,
+    ),
+    array(
+      'type' => 'ief_test_nested3',
+      'name' => t('IEF test nested3'),
+      'base' => 'node_content',
+      'description' => st("Use basic pages for your static content, such as an 'About us' page."),
+      'custom' => 1,
+      'modified' => 1,
+      'locked' => 0,
+    ),
+  );
+
+  foreach ($types as $type) {
+    $type = node_type_set_defaults($type);
+    node_type_save($type);
+  }
+
+
+// Create fields.
+  field_info_cache_clear();
+
+  $field = array(
+    'field_name' => 'field_all_bundles',
+    'type' => 'entityreference',
+    'cardinality' => -1,
+    'settings' => array(
+      'target_type' => 'node',
+      'handler' => 'base',
+      'handler_settings' => array(
+        'target_bundles' => array(),
+      ),
+    ),
+  );
+  field_create_field($field);
+
+  $field = array(
+    'field_name' => 'field_first_name',
+    'type' => 'text',
+    'cardinality' => 1,
+    'settings' => array(
+      'max_length' => 255,
+    ),
+  );
+  field_create_field($field);
+
+  $field = array(
+    'field_name' => 'field_unrelatedimage',
+    'type' => 'image',
+    'cardinality' => 1,
+    'settings' => array(
+      'default_image' => 0,
+      'uri_scheme' => 'public',
+    ),
+  );
+  field_create_field($field);
+
+  $field = array(
+    'field_name' => 'field_last_name',
+    'type' => 'text',
+    'cardinality' => 1,
+    'settings' => array(
+      'max_length' => 255,
+    ),
+  );
+  field_create_field($field);
+
+  $field = array(
+    'field_name' => 'field_multiple_nodes',
+    'type' => 'entityreference',
+    'cardinality' => -1,
+    'required' => TRUE,
+    'settings' => array(
+      'target_type' => 'node',
+      'handler' => 'base',
+      'handler_settings' => array(
+        'target_bundles' => array(
+          'ief_reference_type' => 'ief_reference_type',
+        ),
+      ),
+    ),
+  );
+  field_create_field($field);
+
+  $field_bases['field_positive_int'] = array(
+    'active' => 1,
+    'cardinality' => 1,
+    'deleted' => 0,
+    'entity_types' => array(),
+    'field_name' => 'field_positive_int',
+    'indexes' => array(),
+    'locked' => 0,
+    'module' => 'number',
+    'settings' => array(),
+    'translatable' => 0,
+    'type' => 'number_integer',
+  );
+
+  $field = array(
+    'field_name' => 'field_positive_int',
+    'type' => 'number_integer',
+    'cardinality' => 1,
+    'settings' => array(),
+  );
+  field_create_field($field);
+
+  $field = array(
+    'field_name' => 'field_single_node',
+    'type' => 'entityreference',
+    'cardinality' => 1,
+    'settings' => array(
+      'target_type' => 'node',
+      'handler' => 'base',
+      'handler_settings' => array(
+        'target_bundles' => array(
+          'ief_test_custom' => 'ief_test_custom',
+        ),
+      ),
+    ),
+  );
+  field_create_field($field);
+
+  $field = array(
+    'field_name' => 'field_test_ref_nested1',
+    'type' => 'entityreference',
+    'cardinality' => -1,
+    'settings' => array(
+      'target_type' => 'node',
+      'handler' => 'base',
+      'handler_settings' => array(
+        'target_bundles' => array(
+          'ief_test_nested2' => 'ief_test_nested2',
+        ),
+      ),
+    ),
+  );
+  field_create_field($field);
+
+  $field = array(
+    'field_name' => 'field_test_ref_nested2',
+    'type' => 'entityreference',
+    'cardinality' => -1,
+    'settings' => array(
+      'target_type' => 'node',
+      'handler' => 'base',
+      'handler_settings' => array(
+        'target_bundles' => array(
+          'ief_test_nested3' => 'ief_test_nested3',
+        ),
+      ),
+    ),
+  );
+  field_create_field($field);
+
+
+  // Create field instances.
+  $instance = array(
+    'bundle' => 'ief_reference_type',
+    'entity_type' => 'node',
+    'field_name' => 'field_first_name',
+    'label' => 'First name',
+    'required' => TRUE,
+    'widget' => array('type' => 'text_textfield'),
+  );
+  field_create_instance($instance);
+
+  $instance = array(
+    'bundle' => 'ief_reference_type',
+    'entity_type' => 'node',
+    'field_name' => 'field_last_name',
+    'label' => 'Last name',
+    'required' => TRUE,
+    'widget' => array('type' => 'text_textfield'),
+  );
+  field_create_instance($instance);
+
+  $instance = array(
+    'bundle' => 'ief_simple_single',
+    'entity_type' => 'node',
+    'field_name' => 'field_single_node',
+    'label' => 'Single node',
+    'widget' => array('type' => 'inline_entity_form_single'),
+  );
+  field_create_instance($instance);
+
+  $instance = array(
+    'bundle' => 'ief_test_complex',
+    'entity_type' => 'node',
+    'field_name' => 'field_all_bundles',
+    'label' => 'All bundles',
+    'widget' => array(
+      'type' => 'inline_entity_form',
+      'settings' => array(
+        'fields' => array(),
+        'type_settings' => array(
+          'allow_clone' => 0,
+          'allow_existing' => 1,
+          'allow_new' => 1,
+          'delete_references' => 0,
+          'label_plural' => 'nodes',
+          'label_singular' => 'node',
+          'match_operator' => 'CONTAINS',
+          'override_labels' => 0,
+        ),
+      ),
+    ),
+  );
+  field_create_instance($instance);
+
+  $instance = array(
+    'bundle' => 'ief_test_complex',
+    'entity_type' => 'node',
+    'field_name' => 'field_unrelatedimage',
+    'label' => 'Image',
+    'widget' => array('type' => 'image_image'),
+  );
+  field_create_instance($instance);
+
+  $instance = array(
+    'bundle' => 'ief_test_complex',
+    'entity_type' => 'node',
+    'field_name' => 'field_multiple_nodes',
+    'label' => 'Multiple nodes',
+    'required' => TRUE,
+    'widget' => array(
+      'type' => 'inline_entity_form',
+      'settings' => array(
+        'fields' => array(),
+        'type_settings' => array(
+          'allow_clone' => 0,
+          'allow_existing' => 0,
+          'allow_new' => 1,
+          'delete_references' => 0,
+          'label_plural' => 'nodes',
+          'label_singular' => 'node',
+          'match_operator' => 'CONTAINS',
+          'override_labels' => 0,
+        ),
+      ),
+    ),
+  );
+  field_create_instance($instance);
+
+  $instance = array(
+    'bundle' => 'ief_test_custom',
+    'entity_type' => 'node',
+    'field_name' => 'field_positive_int',
+    'label' => 'Positive int',
+    'widget' => array('type' => 'number'),
+  );
+  field_create_instance($instance);
+
+  $instance = array(
+    'bundle' => 'ief_test_nested1',
+    'entity_type' => 'node',
+    'field_name' => 'field_test_ref_nested1',
+    'label' => 'Multiple nodes',
+    'required' => TRUE,
+    'widget' => array(
+      'type' => 'inline_entity_form',
+      'settings' => array(
+        'fields' => array(),
+        'type_settings' => array(
+          'allow_existing' => 0,
+          'allow_new' => 1,
+          'delete_references' => 0,
+          'label_plural' => 'nodes 2',
+          'label_singular' => 'node 2',
+          'match_operator' => 'CONTAINS',
+          'override_labels' => 1,
+        ),
+      ),
+    ),
+  );
+  field_create_instance($instance);
+
+  $instance = array(
+    'bundle' => 'ief_test_nested2',
+    'entity_type' => 'node',
+    'field_name' => 'field_test_ref_nested2',
+    'label' => 'Multiple nodes',
+    'required' => TRUE,
+    'widget' => array(
+      'type' => 'inline_entity_form',
+      'settings' => array(
+        'fields' => array(),
+        'type_settings' => array(
+          'allow_existing' => 0,
+          'allow_new' => 1,
+          'delete_references' => 0,
+          'label_plural' => 'nodes 3',
+          'label_singular' => 'node 3',
+          'match_operator' => 'CONTAINS',
+          'override_labels' => 1,
+        ),
+      ),
+    ),
+  );
+  field_create_instance($instance);
+
+}
diff --git a/tests/multiple_values_widget.test b/tests/multiple_values_widget.test
new file mode 100644
index 0000000..58a8c23
--- /dev/null
+++ b/tests/multiple_values_widget.test
@@ -0,0 +1,705 @@
+<?php
+
+
+/**
+ * IEF multiple values field widget tests.
+ *
+ * @group inline_entity_form
+ */
+class MultipleValuesWidgetTest extends InlineEntityFormTestBase {
+
+  public static function getInfo() {
+    return array(
+      'name' => 'Multiple values widget',
+      'description' => 'Tests the "Inline Entity Form" multiple values widget.',
+      'group' => 'Inline entity form',
+    );
+  }
+
+  /**
+   * Modules to enable.
+   *
+   * @var array
+   */
+  public static $modules = array(
+    'inline_entity_form_test',
+    'field',
+    'field_ui',
+  );
+
+  /**
+   * URL to add new content.
+   *
+   * @var string
+   */
+  protected $formContentAddUrl;
+
+  /**
+   * Prepares environment for
+   */
+  protected function setUp() {
+    parent::setUp($this::$modules);
+
+    $this->administrator_user = $this->drupalCreateUser(array(
+      'create ief_reference_type content',
+      'edit any ief_reference_type content',
+      'delete any ief_reference_type content',
+      'create ief_test_complex content',
+      'edit any ief_test_complex content',
+      'delete any ief_test_complex content',
+      'edit any ief_test_nested1 content',
+      'edit any ief_test_nested2 content',
+      'edit any ief_test_nested3 content',
+      'view own unpublished content',
+      'administer content types',
+      'administer nodes',
+    ));
+    $this->drupalLogin($this->administrator_user);
+
+    $this->formContentAddUrl = 'node/add/ief-test-complex';
+
+  }
+
+  /**
+   * Tests if form behaves correctly when field is empty.
+   */
+  public function testEmptyFieldIEF() {
+    // Don't allow addition of existing nodes.
+    $this->setAllowExisting(FALSE);
+    $this->drupalGet($this->formContentAddUrl);
+
+    $this->assertFieldByName('field_multiple_nodes[und][form][title]', NULL, 'Title field on inline form exists.');
+    $this->assertFieldByName('field_multiple_nodes[und][form][field_first_name][und][0][value]', NULL, 'First name field on inline form exists.');
+    $this->assertFieldByName('field_multiple_nodes[und][form][field_last_name][und][0][value]', NULL, 'Last name field on inline form exists.');
+    $this->assertFieldByXpath('//input[@type="submit" and @value="Create node"]', NULL, 'Found "Create node" submit button');
+
+    // Allow addition of existing nodes.
+    $this->setAllowExisting(TRUE);
+    $this->drupalGet($this->formContentAddUrl);
+
+    $this->assertNoFieldByName('field_multiple_nodes[und][form][title]]', NULL, 'Title field does not appear.');
+    $this->assertNoFieldByName('field_multiple_nodes[und][form][field_first_name][und][0][value]', NULL, 'First name field does not appear.');
+    $this->assertNoFieldByName('field_multiple_nodes[und][form][field_last_name][und][0][value]', NULL, 'Last name field does not appear.');
+    $this->assertFieldByXpath('//input[@type="submit" and @value="Add new node"]', NULL, 'Found "Add new node" submit button');
+    $this->assertFieldByXpath('//input[@type="submit" and @value="Add existing node"]', NULL, 'Found "Add existing node" submit button');
+
+    // Now submit 'Add new node' button.
+    $this->drupalPostAjax(NULL, array(), $this->getButtonName('//input[@type="submit" and @value="Add new node" and @id="edit-field-multiple-nodes-und-actions-ief-add"]'));
+
+    $this->assertFieldByName('field_multiple_nodes[und][form][title]', NULL, 'Title field on inline form exists.');
+    $this->assertFieldByName('field_multiple_nodes[und][form][field_first_name][und][0][value]', NULL, 'First name field on inline form exists.');
+    $this->assertFieldByName('field_multiple_nodes[und][form][field_last_name][und][0][value]', NULL, 'Second name field on inline form exists.');
+    $this->assertFieldByXpath('//input[@type="submit" and @value="Create node"]', NULL, 'Found "Create node" submit button');
+    $this->assertFieldByXpath('//input[@type="submit" and @value="Cancel"]', NULL, 'Found "Cancel" submit button');
+
+    // Now submit 'Add Existing node' button.
+    $this->drupalGet($this->formContentAddUrl);
+    $this->drupalPostAjax(NULL, array(), $this->getButtonName('//input[@type="submit" and @value="Add existing node" and @id="edit-field-multiple-nodes-und-actions-ief-add-existing"]'));
+
+    $this->assertFieldByName('field_multiple_nodes[und][form][entity_id]', NULL, 'Existing entity reference autocomplete field found.');
+    $this->assertFieldByXpath('//input[@type="submit" and @value="Add node"]', NULL, 'Found "Add node" submit button');
+    $this->assertFieldByXpath('//input[@type="submit" and @value="Cancel"]', NULL, 'Found "Cancel" submit button');
+  }
+
+  /**
+   * Tests creation of entities.
+   */
+  public function testEntityCreation() {
+    // Allow addition of existing nodes.
+    $this->setAllowExisting(TRUE);
+    $this->drupalGet($this->formContentAddUrl);
+
+    $this->drupalPostAjax(NULL, array(), $this->getButtonName('//input[@type="submit" and @value="Add new node" and @id="edit-field-multiple-nodes-und-actions-ief-add"]'));
+    $this->assertResponse(200, 'Opening new inline form was successful.');
+
+    $this->drupalPostAjax(NULL, array(), $this->getButtonName('//input[@type="submit" and @value="Create node" and @id="edit-field-multiple-nodes-und-form-actions-ief-add-save"]'));
+    $this->assertResponse(200, 'Submitting empty form was successful.');
+    $this->assertText('First name field is required.', 'Validation failed for empty "First name" field.');
+    $this->assertText('Last name field is required.', 'Validation failed for empty "Last name" field.');
+    $this->assertText('Title field is required.', 'Validation failed for empty "Title" field.');
+
+    // Create ief_reference_type node in IEF.
+    $this->drupalGet($this->formContentAddUrl);
+    $this->drupalPostAjax(NULL, array(), $this->getButtonName('//input[@type="submit" and @value="Add new node" and @id="edit-field-multiple-nodes-und-actions-ief-add"]'));
+    $this->assertResponse(200, 'Opening new inline form was successful.');
+
+    $edit = array(
+      'field_multiple_nodes[und][form][title]' => 'Some reference',
+      'field_multiple_nodes[und][form][field_first_name][und][0][value]' => 'John',
+      'field_multiple_nodes[und][form][field_last_name][und][0][value]' => 'Doe',
+    );
+    $this->drupalPostAjax(NULL, $edit, $this->getButtonName('//input[@type="submit" and @value="Create node" and @id="edit-field-multiple-nodes-und-form-actions-ief-add-save"]'));
+    $this->assertResponse(200, 'Creating node via inline form was successful.');
+
+    // Tests if correct fields appear in the table.
+    $this->assertTrue((bool) $this->xpath('//td[@class="inline-entity-form-node-title" and contains(.,"Some reference")]'), 'Node title field appears in the table');
+    $this->assertTrue((bool) $this->xpath('//td[@class="inline-entity-form-node-status" and contains(.,"Published")]'), 'Node status field appears in the table');
+
+    // Tests if edit and remove buttons appear.
+    $this->assertTrue((bool) $this->xpath('//input[@type="submit" and @value="Edit"]'), 'Edit button appears in the table.');
+    $this->assertTrue((bool) $this->xpath('//input[@type="submit" and @value="Remove"]'), 'Remove button appears in the table.');
+
+    // Test edit functionality.
+    $this->drupalPostAjax(NULL, array(), $this->getButtonName('//input[@type="submit" and @value="Edit"]'));
+    $edit = array(
+      'field_multiple_nodes[und][entities][0][form][title]' => 'Some changed reference',
+    );
+    $this->drupalPostAjax(NULL, $edit, $this->getButtonName('//input[@type="submit" and @value="Update node"]'));
+    $this->assertTrue((bool) $this->xpath('//td[@class="inline-entity-form-node-title" and contains(.,"Some changed reference")]'), 'Node title field appears in the table');
+    $this->assertTrue((bool) $this->xpath('//td[@class="inline-entity-form-node-status" and contains(.,"Published")]'), 'Node status field appears in the table');
+
+    // Make sure unrelated AJAX submit doesn't save the referenced entity.
+    $this->drupalPostAjax(NULL, array(), $this->getButtonName('//input[@type="submit" and @value="Upload"]'));
+    $node = $this->drupalGetNodeByTitle('Some changed reference');
+    $this->assertFalse($node, 'Referenced node was not saved during unrelated AJAX submit.');
+
+    // Create ief_test_complex node.
+    $edit = array('title' => 'Some title');
+    $this->drupalPost(NULL, $edit, t('Save'));
+    $this->assertResponse(200, 'Saving parent entity was successful.');
+
+    // Checks values of created entities.
+    $node = $this->drupalGetNodeByTitle('Some changed reference');
+    $this->assertTrue($node, 'Created ief_reference_type node ' . $node->title);
+    $this->assertTrue($node->field_first_name[LANGUAGE_NONE][0]['value'] == 'John', 'First name in reference node set to John');
+    $this->assertTrue($node->field_last_name[LANGUAGE_NONE][0]['value'] == 'Doe', 'Last name in reference node set to Doe');
+
+    $parent_node = $this->drupalGetNodeByTitle('Some title');
+    $this->assertTrue($parent_node, 'Created ief_test_complex node ' . $parent_node->title);
+    $this->assertTrue($parent_node->field_multiple_nodes[LANGUAGE_NONE][0]['target_id'] == $node->nid, 'Refererence node id set to ' . $node->nid);
+  }
+
+  /**
+   * Tests the entity creation with different bundles nested in each other.
+   *
+   * ief_test_nested1 -> ief_test_nested2 -> ief_test_nested3
+   */
+  public function testNestedEntityCreationWithDifferentBundlesAjaxSubmit() {
+    $required_possibilities = array(
+      FALSE,
+      TRUE,
+    );
+    foreach ($required_possibilities as $required) {
+      $this->setupNestedComplexForm($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);
+        }
+      }
+    }
+  }
+
+  /**
+   * Checks that nested IEF entity references can be edit and saved.
+   *
+   * @param $node
+   *  Top level node of type ief_test_nested1 to check.
+   * @param bool $ajax_submit
+   *  Whether IEF form widgets should be submitted via AJax or left open.
+   *
+   */
+  protected function checkNestedEntityEditing($node, $ajax_submit = TRUE) {
+    $this->drupalGet("node/{$node->nid}/edit");
+    $level_1_node = node_load($node->field_test_ref_nested1[LANGUAGE_NONE][0]['target_id']);
+    $level_2_node = node_load($level_1_node->field_test_ref_nested2[LANGUAGE_NONE][0]['target_id']);
+    $level_2_node_update_title = $level_2_node->title . ' - updated';
+    //edit-test-ref-nested1-entities-0-actions-ief-entity-edit
+    $this->drupalPostAjax(NULL, array(), $this->getButtonName('//input[@type="submit" and @id="edit-field-test-ref-nested1-und-entities-0-actions-ief-entity-edit"]'));
+    //edit-test-ref-nested1-form-inline-entity-form-entities-0-form-test-ref-nested2-entities-0-actions-ief-entity-edit
+    $this->drupalPostAjax(NULL, array(), $this->getButtonName('//input[@type="submit" and @id="edit-field-test-ref-nested1-und-entities-0-form-field-test-ref-nested2-und-entities-0-actions-ief-entity-edit"]'));
+    $edit['field_test_ref_nested1[und][entities][0][form][field_test_ref_nested2][und][entities][0][form][title]'] = $level_2_node_update_title;
+    if ($ajax_submit) {
+      // Close IEF Forms with AJAX posts
+      //edit-test-ref-nested1-form-inline-entity-form-entities-0-form-test-ref-nested2-form-inline-entity-form-entities-0-form-actions-ief-edit-save
+      $this->drupalPostAjax(NULL, $edit, $this->getButtonName('//input[@type="submit" and @id="edit-field-test-ref-nested1-und-entities-0-form-field-test-ref-nested2-und-entities-0-form-actions-ief-edit-save"]'));
+      $this->drupalPostAjax(NULL, array(), $this->getButtonName('//input[@type="submit" and @id="edit-field-test-ref-nested1-und-entities-0-form-actions-ief-edit-save"]'));
+      $this->drupalPost(NULL, array(), t('Save'));
+    }
+    else {
+      $this->drupalPost(NULL, $edit, t('Save'));
+    }
+    $level_2_node = node_load($level_2_node->nid, NULL, TRUE);
+    $this->assertEqual($level_2_node_update_title, $level_2_node->title);
+  }
+
+  /**
+   * Tests the entity creation with different bundles nested in each other.
+   *
+   * ief_test_nested1 -> ief_test_nested2 -> ief_test_nested3
+   */
+  public function testNestedEntityCreationWithDifferentBundlesNoAjaxSubmit() {
+    $required_possibilities = array(
+      FALSE,
+      TRUE,
+    );
+
+    foreach ($required_possibilities as $required) {
+      $this->setupNestedComplexForm($required);
+
+      $nested3_title = 'nested3 title single ' . ($required ? 'required' : 'not required');
+      $nested2_title = 'nested2 title single ' . ($required ? 'required' : 'not required');
+      $nested1_title = 'nested1 title single ' . ($required ? 'required' : 'not required');
+
+      $edit = array(
+        'title' => $nested1_title,
+        'field_test_ref_nested1[und][form][title]' => $nested2_title,
+        'field_test_ref_nested1[und][form][field_test_ref_nested2][und][form][title]' => $nested3_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.");
+      $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.");
+      $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, FALSE);
+    }
+  }
+
+  /**
+   * Tests if editing and removing entities work.
+   */
+  public function testEntityEditingAndRemoving() {
+    // Allow addition of existing nodes.
+    $this->setAllowExisting(TRUE);
+
+    // Create three ief_reference_type entities.
+    $referenceNodes = $this->createReferenceContent(3);
+    $field_multiple_nodes = array();
+    foreach($referenceNodes as $nid){
+      $field_multiple_nodes[LANGUAGE_NONE][] = array('target_id' => $nid);
+    }
+    $this->drupalCreateNode(array(
+      'type' => 'ief_test_complex',
+      'title' => 'Some title',
+      'field_multiple_nodes' => $field_multiple_nodes,
+    ));
+    $parent_node = $this->drupalGetNodeByTitle('Some title');
+
+    // Edit the second entity.
+    $this->drupalGet('node/' . $parent_node->nid . '/edit');
+    $cell = $this->xpath('//table[@id="ief-entity-table-edit-field-multiple-nodes-und-entities"]/tbody/tr[@class="ief-row-entity draggable even"]/td[@class="inline-entity-form-node-title"]');
+    $title = (string) $cell[0];
+
+    $this->drupalPostAjax(NULL, array(), $this->getButtonName('//input[@type="submit" and @id="edit-field-multiple-nodes-und-entities-1-actions-ief-entity-edit"]'));
+    $this->assertResponse(200, 'Opening inline edit form was successful.');
+
+    $edit = array(
+      'field_multiple_nodes[und][entities][1][form][field_first_name][und][0][value]' => 'John',
+      'field_multiple_nodes[und][entities][1][form][field_last_name][und][0][value]' => 'Doe',
+    );
+    $this->drupalPostAjax(NULL, $edit, $this->getButtonName('//input[@type="submit" and @id="edit-field-multiple-nodes-und-entities-1-form-actions-ief-edit-save"]'));
+    $this->assertResponse(200, 'Saving inline edit form was successful.');
+
+    // Save the ief_test_complex node.
+    $this->drupalPost(NULL, array(), t('Save'));
+    $this->assertResponse(200, 'Saving parent entity was successful.');
+
+    // Checks values of changed entities.
+    $node = $this->drupalGetNodeByTitle($title, TRUE);
+    $this->assertTrue($node->field_first_name[LANGUAGE_NONE][0]['value'] == 'John', 'First name in reference node changed to John');
+    $this->assertTrue($node->field_last_name[LANGUAGE_NONE][0]['value'] == 'Doe', 'Last name in reference node changed to Doe');
+
+    // Delete the second entity.
+    $this->drupalGet('node/' . $parent_node->nid . '/edit');
+    $cell = $this->xpath('//table[@id="ief-entity-table-edit-field-multiple-nodes-und-entities"]/tbody/tr[@class="ief-row-entity draggable even"]/td[@class="inline-entity-form-node-title"]');
+    $title = (string) $cell[0];
+
+    $this->drupalPostAjax(NULL, array(), $this->getButtonName('//input[@type="submit" and @id="edit-field-multiple-nodes-und-entities-1-actions-ief-entity-remove"]'));
+    $this->assertResponse(200, 'Opening inline remove confirm form was successful.');
+    $this->assertText('Are you sure you want to remove', 'Remove warning message is displayed.');
+
+    $this->drupalPostAjax(NULL, array('field_multiple_nodes[und][entities][1][form][delete]' => '1'), $this->getButtonName('//input[@type="submit" and @id="edit-field-multiple-nodes-und-entities-1-form-actions-ief-remove-confirm"]'));
+    $this->assertResponse(200, 'Removing inline entity was successful.');
+    $this->assertNoText($title, 'Deleted inline entity is not present on the page.');
+
+    // Save the ief_test_complex node.
+    $this->drupalPost(NULL, array(), t('Save'));
+    $this->assertResponse(200, 'Saving parent node was successful.');
+
+    $deleted_node = $this->drupalGetNodeByTitle($title);
+    $this->assertTrue(empty($deleted_node), 'The inline entity was deleted from the site.');
+
+    // Checks that entity does nor appear in IEF.
+    $this->drupalGet('node/' . $parent_node->nid . '/edit');
+    $this->assertNoText($title, 'Deleted inline entity is not present on the page after saving parent.');
+
+    // Delete the third entity reference only, don't delete the node. The third
+    // entity now is second referenced entity because the second one was deleted
+    // in previous step.
+    $this->drupalGet('node/' . $parent_node->nid . '/edit');
+    $cell = $this->xpath('//table[@id="ief-entity-table-edit-field-multiple-nodes-und-entities"]/tbody/tr[@class="ief-row-entity draggable even"]/td[@class="inline-entity-form-node-title"]');
+    $title = (string) $cell[0];
+
+    $this->drupalPostAjax(NULL, array(), $this->getButtonName('//input[@type="submit" and @id="edit-field-multiple-nodes-und-entities-1-actions-ief-entity-remove"]'));
+    $this->assertResponse(200, 'Opening inline remove confirm form was successful.');
+
+    $this->drupalPostAjax(NULL, array(), $this->getButtonName('//input[@type="submit" and @id="edit-field-multiple-nodes-und-entities-1-form-actions-ief-remove-confirm"]'));
+    $this->assertResponse(200, 'Removing inline entity was successful.');
+
+    // Save the ief_test_complex node.
+    $this->drupalPost(NULL, array(), t('Save'));
+    $this->assertResponse(200, 'Saving parent node was successful.');
+
+    // Checks that entity does nor appear in IEF.
+    $this->drupalGet('node/' . $parent_node->nid . '/edit');
+    $this->assertNoText($title, 'Deleted inline entity is not present on the page after saving parent.');
+
+    // Checks that entity is not deleted.
+    $node = $this->drupalGetNodeByTitle($title, TRUE);
+    $this->assertTrue($node, 'Reference node not deleted');
+  }
+
+  /**
+   * Tests if referencing existing entities work.
+   */
+  public function testReferencingExistingEntities() {
+    // Allow addition of existing nodes.
+    $this->setAllowExisting(TRUE);
+
+    // Create three ief_reference_type entities.
+    $referenceNodes = $this->createReferenceContent(3);
+
+    // Create a node for every bundle available.
+    $bundle_nodes = $this->createNodeForEveryBundle();
+
+    // Create ief_test_complex node with first ief_reference_type node and first
+    // node from bundle nodes.
+    $this->drupalCreateNode(array(
+      'type' => 'ief_test_complex',
+      'title' => 'Some title',
+      'multi' => [1],
+      'all_bundles' => key($bundle_nodes),
+    ));
+    // Remove first node since we already added it.
+    unset($bundle_nodes[key($bundle_nodes)]);
+
+    $parent_node = $this->drupalGetNodeByTitle('Some title', TRUE);
+
+    // Add remaining existing reference nodes.
+    $this->drupalGet('node/' . $parent_node->nid . '/edit');
+    for ($i = 2; $i <= 3; $i++) {
+      $this->drupalPostAjax(NULL, array(), $this->getButtonName('//input[@type="submit" and @value="Add existing node" and @id="edit-field-multiple-nodes-und-actions-ief-add-existing"]'));
+      $this->assertResponse(200, 'Opening reference form was successful.');
+      $title = 'Some reference ' . $i;
+      $edit = array(
+        'field_multiple_nodes[und][form][entity_id]' => $title . ' (' . $referenceNodes[$title] . ')',
+      );
+      $this->drupalPostAjax(NULL, $edit, $this->getButtonName('//input[@type="submit" and @id="edit-field-multiple-nodes-und-form-actions-ief-reference-save"]'));
+      $this->assertResponse(200, 'Adding new referenced entity was successful.');
+    }
+    // Add all remaining nodes from all bundles.
+    foreach ($bundle_nodes as $id => $title) {
+      $this->drupalPostAjax(NULL, array(), $this->getButtonName('//input[@type="submit" and @value="Add existing node" and @id="edit-field-all-bundles-und-actions-ief-add-existing"]'));
+      $this->assertResponse(200, 'Opening reference form was successful.');
+      $edit = array(
+        'field_all_bundles[und][form][entity_id]' => $title . ' (' . $id . ')',
+      );
+      $this->drupalPostAjax(NULL, $edit, $this->getButtonName('//input[@type="submit" and @id="edit-field-all-bundles-und-form-actions-ief-reference-save"]'));
+      $this->assertResponse(200, 'Adding new referenced entity was successful.');
+    }
+    // Save the node.
+    $this->drupalPost(NULL, array(), t('Save'));
+    $this->assertResponse(200, 'Saving parent for was successful.');
+
+    // Check if entities are referenced.
+    $this->drupalGet('node/' . $parent_node->nid . '/edit');
+    for ($i = 2; $i <= 3; $i++) {
+      $cell = $this->xpath('//table[@id="ief-entity-table-edit-field-multiple-nodes-und-entities"]/tbody/tr[' . ($i - 1) . ']/td[@class="inline-entity-form-node-title"]');
+      $this->assertTrue($cell[0] == 'Some reference ' . $i, 'Found reference node title "Some reference ' . $i . '" in the IEF table.');
+    }
+    // Check if all remaining nodes from all bundles are referenced.
+    $count = 1;
+    foreach ($bundle_nodes as $id => $title) {
+      $cell = $this->xpath('//table[@id="ief-entity-table-edit-field-all-bundles-und-entities"]/tbody/tr[' . $count . ']/td[@class="inline-entity-form-node-title"]');
+      $this->assertTrue($cell[0] == $title, 'Found reference node title "' . $title . '" in the IEF table.');
+      $count++;
+    }
+  }
+
+  /**
+   * Tests if a referenced content can be edited while the referenced content is
+   * newer than the referencing parent node.
+   */
+  public function testEditedInlineEntityValidation() {
+    $this->setAllowExisting(TRUE);
+
+    // Create referenced content.
+    $referenced_nodes = $this->createReferenceContent(1);
+    $field_multiple_nodes = array();
+    foreach($referenced_nodes as $nid){
+      $field_multiple_nodes[LANGUAGE_NONE][] = array('target_id' => $nid);
+    }
+
+    // Create first referencing node.
+    $this->drupalCreateNode(array(
+      'type' => 'ief_test_complex',
+      'title' => 'First referencing node',
+      'field_multiple_nodes' => $field_multiple_nodes,
+    ));
+    $first_node = $this->drupalGetNodeByTitle('First referencing node');
+
+    // Create second referencing node.
+    $this->drupalCreateNode(array(
+      'type' => 'ief_test_complex',
+      'title' => 'Second referencing node',
+      'field_multiple_nodes' => $field_multiple_nodes,
+    ));
+    $second_node = $this->drupalGetNodeByTitle('Second referencing node');
+
+    // Edit referenced content in first node.
+    $this->drupalGet('node/' . $first_node->nid . '/edit');
+
+    // Edit referenced node.
+    $this->drupalPostAjax(NULL, array(), $this->getButtonName('//input[@type="submit" and @value="Edit" and @id="edit-field-multiple-nodes-und-entities-0-actions-ief-entity-edit"]'));
+    $edit = array(
+      'field_multiple_nodes[und][entities][0][form][title]' => 'Some reference updated',
+    );
+    $this->drupalPostAjax(NULL, $edit, $this->getButtonName('//input[@type="submit" and @value="Update node" and @id="edit-field-multiple-nodes-und-entities-0-form-actions-ief-edit-save"]'));
+
+    // Save the first node after editing the reference.
+    $edit = array('title' => 'First node updated');
+    $this->drupalPost(NULL, $edit, t('Save'));
+
+    // The changed value of the referenced content is now newer than the
+    // changed value of the second node.
+
+    // Edit referenced content in second node.
+    $this->drupalGet('node/' . $second_node->nid . '/edit');
+
+    // Edit referenced node.
+    $this->drupalPostAjax(NULL, array(), $this->getButtonName('//input[@type="submit" and @value="Edit" and @id="edit-field-multiple-nodes-und-entities-0-actions-ief-entity-edit"]'));
+    $edit = array(
+      'field_multiple_nodes[und][entities][0][form][title]' => 'Some reference updated the second time',
+    );
+    $this->drupalPostAjax(NULL, $edit, $this->getButtonName('//input[@type="submit" and @value="Update node" and @id="edit-field-multiple-nodes-und-entities-0-form-actions-ief-edit-save"]'));
+
+    // Save the second node after editing the reference.
+    $edit = array('title' => 'Second node updated');
+    $this->drupalPost(NULL, $edit, t('Save'));
+
+    // Check if the referenced content could be edited.
+    $this->assertNoText('The content has either been modified by another user, or you have already submitted modifications. As a result, your changes cannot be saved.', 'The referenced content could be edited.');
+  }
+
+  /**
+   * Creates ief_reference_type nodes which shall serve as reference nodes.
+   *
+   * @param int $numNodes
+   *   The number of nodes to create
+   * @return array
+   *   Array of created node ids keyed by labels.
+   */
+  protected function createReferenceContent($numNodes = 3) {
+    $retval = array();
+    for ($i = 1; $i <= $numNodes; $i++) {
+      $this->drupalCreateNode(array(
+        'type' => 'ief_reference_type',
+        'title' => 'Some reference ' . $i,
+        'field_first_name' => 'First Name ' . $i,
+        'field_last_name' => 'Last Name ' . $i,
+      ));
+      $node = $this->drupalGetNodeByTitle('Some reference ' . $i);
+      $this->assertTrue($node, 'Created ief_reference_type node "' . $node->title . '"');
+      $retval[$node->title] = $node->nid;
+    }
+    return $retval;
+  }
+
+  /**
+   * Sets allow_existing IEF setting.
+   *
+   * @param bool $flag
+   *   "allow_existing" flag to be set.
+   */
+  protected function setAllowExisting($flag) {
+    $edit = array(
+      'instance[widget][settings][type_settings][allow_existing]' => $flag,
+    );
+    $this->drupalPost('admin/structure/types/manage/ief-test-complex/fields/field_multiple_nodes', $edit, t('Save settings'));
+    $this->drupalGet('admin/structure/types/manage/ief-test-complex/fields/field_multiple_nodes');
+  }
+
+  /**
+   * Creates a node for every node bundle.
+   *
+   * @return array
+   *   Array of node titles keyed by ids.
+   */
+  protected function createNodeForEveryBundle() {
+    $retval = array();
+    $bundles = node_type_get_types();
+    foreach ($bundles as $id => $value) {
+      $this->drupalCreateNode(array('type' => $id, 'title' => $value->name));
+      $node = $this->drupalGetNodeByTitle($value->name);
+      $this->assertTrue($node, 'Created node "' . $node->title . '"');
+      $retval[$node->nid] = $value->name;
+    }
+    return $retval;
+  }
+
+  /**
+   * Set up the ief_test_nested1 node add form.
+   *
+   * Sets the nested fields' required settings.
+   * Gets the form.
+   * Opens the inline entity forms if they are not required.
+   *
+   * @param boolean $required
+   *   Whether the fields are required.
+   * @param array $permissions
+   *   (optional) Permissions to sign testing user in with. You may pass in an
+   *   empty array (default) to use the all the permissions necessary create and
+   *   edit nodes on the form.
+   */
+  protected function setupNestedComplexForm($required, $permissions = array()) {
+
+    $this->drupalLogin($this->administrator_user);
+    $edit = array(
+      'instance[required]' => $required,
+    );
+    $this->drupalPost('admin/structure/types/manage/ief-test-nested1/fields/field_test_ref_nested1', $edit, t('Save settings'));
+    $this->drupalPost('admin/structure/types/manage/ief-test-nested2/fields/field_test_ref_nested2', $edit, t('Save settings'));
+
+    if (!$permissions) {
+      $permissions = array(
+        'create ief_test_nested1 content',
+        'create ief_test_nested2 content',
+        'create ief_test_nested3 content',
+        'edit any ief_test_nested1 content',
+        'edit any ief_test_nested2 content',
+        'edit any ief_test_nested3 content',
+      );
+    }
+    $this->user = $this->drupalCreateUser($permissions);
+    $this->drupalLogin($this->user);
+
+    $this->drupalGet('node/add/ief-test-nested1');
+
+    if (!$required) {
+      // Open inline forms if not required.
+      if (in_array('create ief_test_nested2 content', $permissions)) {
+        $this->drupalPostAjax(NULL, array(), $this->getButtonName('//input[@type="submit" and @value="Add new node 2"]'));
+      }
+      if (in_array('create ief_test_nested3 content', $permissions)) {
+        $this->drupalPostAjax(NULL, array(), $this->getButtonName('//input[@type="submit" and @value="Add new node 3"]'));
+      }
+    }
+  }
+
+  /**
+   * Closes the existing node form on the "multi" field.
+   */
+  protected function cancelExistingMultiForm($edit) {
+    $this->drupalPostAjax(NULL, $edit, $this->getButtonName('//div[@id="edit-field-multiple-nodes"]//input[@type="submit" and @value="Cancel"]'));
+    $this->assertNoFieldByName('field_multiple_nodes[und][form][entity_id]', NULL, 'Existing entity reference autocomplete field removed.');
+  }
+
+  /**
+   * Opens the existing node form on the "multi" field.
+   */
+  protected function openMultiExistingForm() {
+    $this->drupalPostAjax(NULL, array(), $this->getButtonName('//input[@type="submit" and @value="Add existing node" and @id="edit-field-multiple-nodes-und-actions-ief-add-existing"]'));
+    $this->assertResponse(200, 'Opening reference form was successful.');
+    $this->assertFieldByName('field_multiple_nodes[und][form][entity_id]', NULL, 'Existing entity reference autocomplete field found.');
+  }
+
+  /**
+   * Checks that an invalid value for an existing node will be display the expected error.
+   *
+   * @param $existing_node_text
+   *  The text to enter into the existing node text field.
+   * @param $expected_error
+   *  The error message that is expected to be shown.
+   */
+  protected function checkExistingValidationExpectation($existing_node_text, $expected_error) {
+    $edit = array(
+      'field_multiple_nodes[und][form][entity_id]' => $existing_node_text,
+    );
+    $this->openMultiExistingForm();
+
+    $this->drupalPostAjax(NULL, $edit, $this->getButtonName('//input[@type="submit" and @id="edit-field-multiple-nodes-und-form-actions-ief-reference-save"]'));
+    $this->assertText($expected_error);
+    $this->cancelExistingMultiForm($edit);
+  }
+
+  /**
+   * Tests entity create access is correct on nested IEF forms.
+   */
+  public function testNestedEntityCreateAccess() {
+    $permissions = array(
+      'create ief_test_nested1 content',
+      'create ief_test_nested2 content',
+    );
+    $this->setupNestedComplexForm(TRUE, $permissions);
+    $this->assertFieldByName('title');
+    $this->assertFieldByName('field_test_ref_nested1[und][form][title]');
+    $this->assertNoFieldByName('field_test_ref_nested1[und][form][field_test_ref_nested2][und][form][title]', NULL);
+
+    $this->setupNestedComplexForm(FALSE, $permissions);
+    $this->assertNoFieldByXPath('//input[@type="submit" and @value="Create node 3"]');
+  }
+
+  /**
+   * Tests create access on IEF Complex content type.
+   */
+  public function testComplexEntityCreate() {
+    $user = $this->drupalCreateUser(array(
+      'create ief_test_complex content',
+    ));
+    $this->drupalLogin($user);
+
+    $this->drupalGet('node/add/ief-test-complex');
+    $this->assertNoFieldByName('field_all_bundles[und][actions][bundle]', NULL, 'Bundle select is not shown when only one bundle is available.');
+    $this->assertNoFieldByName('field_multiple_nodes[und][form][title]', NULL);
+
+    $user = $this->drupalCreateUser(array(
+      'create ief_test_complex content',
+      'create ief_reference_type content'
+    ));
+    $this->drupalLogin($user);
+
+    $this->drupalGet('node/add/ief-test-complex');
+    $this->assertFieldByName('field_all_bundles[und][actions][bundle]', NULL, 'Bundle select is shown when more than one bundle is available.');
+    $this->assertTrue((bool) $this->xpath('//select[@id="edit-field-all-bundles-und-actions-bundle"]//option[@value="ief_reference_type"]'), 'IEF Reference type is available');
+    $this->assertTrue((bool) $this->xpath('//select[@id="edit-field-all-bundles-und-actions-bundle"]//option[@value="ief_test_complex"]'), 'IEF test complex is available');
+    $this->assertFieldByName('field_multiple_nodes[und][form][title]');
+  }
+
+}
