View source
<?php
class MultipleValuesWidgetTest extends InlineEntityFormTestBase {
protected $formContentAddUrl;
public static function getInfo() {
return array(
'name' => 'Multiple values widget',
'description' => 'Tests the "Inline Entity Form" multiple values widget.',
'group' => 'Inline entity form',
);
}
protected function setUp() {
$modules = $modules = array(
'inline_entity_form_test',
'field',
'field_ui',
);
parent::setUp($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_multiple content',
'edit any ief_test_multiple content',
'delete any ief_test_multiple 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',
'administer fields',
));
$this
->drupalLogin($this->administrator_user);
$this->formContentAddUrl = 'node/add/ief-test-multiple';
}
public function testEmptyFieldIEF() {
$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');
$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');
$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');
$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');
}
public function testEntityCreation() {
$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.');
$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.');
$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');
$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.');
$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');
$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.');
$edit = array(
'title' => 'Some title',
);
$this
->drupalPost(NULL, $edit, t('Save'));
$this
->assertResponse(200, 'Saving parent entity was successful.');
$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_multiple 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);
}
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);
}
}
}
}
public function testNestedEntityCreationWithDifferentBundlesNoAjaxSubmit() {
$required_possibilities = array(
FALSE,
TRUE,
);
foreach ($required_possibilities as $required) {
$this
->setupNestedMultipleForm($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);
}
}
public function testEntityEditingAndRemoving() {
$this
->setAllowExisting(TRUE);
$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_multiple',
'title' => 'Some title',
'field_multiple_nodes' => $field_multiple_nodes,
));
$parent_node = $this
->drupalGetNodeByTitle('Some title');
$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.');
$this
->drupalPost(NULL, array(), t('Save'));
$this
->assertResponse(200, 'Saving parent entity was successful.');
$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');
$this
->drupalGet('node/' . $parent_node->nid . '/edit');
$cell = $this
->xpath('//table[@id="ief-entity-table-edit-field-multiple-nodes-und-entities"]/tbody//tr[3]//td[@class="inline-entity-form-node-title"]');
$title = (string) $cell[0];
$this
->drupalPost(NULL, array(), '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.');
$edit = array(
'field_multiple_nodes[und][entities][2][form][delete]' => '1',
);
$this
->drupalPost(NULL, $edit, 'Remove');
$this
->assertResponse(200, 'Removing inline entity was successful.');
$this
->assertNoText($title, 'Deleted inline entity is not present on the page.');
$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.');
$this
->drupalGet('node/' . $parent_node->nid . '/edit');
$this
->assertNoText($title, 'Deleted inline entity is not present on the page after saving parent.');
$this
->drupalGet('node/' . $parent_node->nid . '/edit');
$cell = $this
->xpath('//table[@id="ief-entity-table-edit-field-multiple-nodes-und-entities"]/tbody//tr[2]//td[@class="inline-entity-form-node-title"]');
$title = (string) $cell[0];
$this
->drupalPost(NULL, array(), 'Remove');
$this
->assertResponse(200, 'Opening inline remove confirm form was successful.');
$this
->drupalPost(NULL, array(), 'Remove');
$this
->assertResponse(200, 'Removing inline entity was successful.');
$this
->drupalPost(NULL, array(), t('Save'));
$this
->assertResponse(200, 'Saving parent node was successful.');
$this
->drupalGet('node/' . $parent_node->nid . '/edit');
$this
->assertNoText($title, 'Deleted inline entity is not present on the page after saving parent.');
$node = $this
->drupalGetNodeByTitle($title, TRUE);
$this
->assertTrue($node, 'Reference node not deleted');
}
public function testReferencingExistingEntities() {
$this
->setAllowExisting(TRUE);
$referenceNodes = $this
->createReferenceContent(3);
$bundle_nodes = $this
->createNodeForEveryBundle();
$this
->drupalCreateNode(array(
'type' => 'ief_test_multiple',
'title' => 'Some title',
'multi' => array(
1,
),
'all_bundles' => key($bundle_nodes),
));
unset($bundle_nodes[key($bundle_nodes)]);
$parent_node = $this
->drupalGetNodeByTitle('Some title', TRUE);
$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.');
}
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.');
}
$this
->drupalPost(NULL, array(), t('Save'));
$this
->assertResponse(200, 'Saving parent for was successful.');
$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.');
}
$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++;
}
}
public function testEditedInlineEntityValidation() {
$this
->setAllowExisting(TRUE);
$referenced_nodes = $this
->createReferenceContent(1);
$field_multiple_nodes = array();
foreach ($referenced_nodes as $nid) {
$field_multiple_nodes[LANGUAGE_NONE][] = array(
'target_id' => $nid,
);
}
$this
->drupalCreateNode(array(
'type' => 'ief_test_multiple',
'title' => 'First referencing node',
'field_multiple_nodes' => $field_multiple_nodes,
));
$first_node = $this
->drupalGetNodeByTitle('First referencing node');
$this
->drupalCreateNode(array(
'type' => 'ief_test_multiple',
'title' => 'Second referencing node',
'field_multiple_nodes' => $field_multiple_nodes,
));
$second_node = $this
->drupalGetNodeByTitle('Second referencing node');
$this
->drupalGet('node/' . $first_node->nid . '/edit');
$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"]'));
$edit = array(
'title' => 'First node updated',
);
$this
->drupalPost(NULL, $edit, t('Save'));
$this
->drupalGet('node/' . $second_node->nid . '/edit');
$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"]'));
$edit = array(
'title' => 'Second node updated',
);
$this
->drupalPost(NULL, $edit, t('Save'));
$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.');
}
public function testMultipleEntityCreate() {
$user = $this
->drupalCreateUser(array(
'create ief_test_multiple content',
));
$this
->drupalLogin($user);
$this
->drupalGet('node/add/ief-test-multiple');
$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_multiple content',
'create ief_reference_type content',
));
$this
->drupalLogin($user);
$this
->drupalGet('node/add/ief-test-multiple');
$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_multiple"]'), 'IEF test multiple is available');
$this
->assertFieldByName('field_multiple_nodes[und][form][title]');
}
public function testNestedEntityCreateAccess() {
$permissions = array(
'create ief_test_nested1 content',
'create ief_test_nested2 content',
);
$this
->setupNestedMultipleForm(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
->setupNestedMultipleForm(FALSE, $permissions);
$this
->assertNoFieldByXPath('//input[@type="submit" and @value="Create node 3"]');
}
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;
}
protected function setAllowExisting($flag) {
$edit = array(
'instance[widget][settings][type_settings][allow_existing]' => $flag,
);
$this
->drupalPost('admin/structure/types/manage/ief-test-multiple/fields/field_multiple_nodes', $edit, t('Save settings'));
$this
->drupalGet('admin/structure/types/manage/ief-test-multiple/fields/field_multiple_nodes');
}
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;
}
protected function setupNestedMultipleForm($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) {
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"]'));
}
}
}
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.');
}
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.');
}
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';
$this
->drupalPostAjax(NULL, array(), $this
->getButtonName('//input[@type="submit" and @id="edit-field-test-ref-nested1-und-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) {
$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);
}
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);
}
}