You are here

public function MultipleValuesWidgetTest::testEmptyFieldIEF in Inline Entity Form 7

Tests if form behaves correctly when field is empty.

File

tests/multiple_values_widget.test, line 56

Class

MultipleValuesWidgetTest
IEF multiple values field widget tests.

Code

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');
}