public function MultipleValuesWidgetTest::testEntityCreation in Inline Entity Form 7
Tests creation of entities.
File
- tests/
multiple_values_widget.test, line 97
Class
- MultipleValuesWidgetTest
- IEF multiple values field widget tests.
Code
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_multiple 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_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);
}