You are here

public function EntityReferenceAutocreateTestCase::testEditWithCommas in Entityreference Autocreate 7

Verify autocreation behaviour when the target has commas in the title.

We used to discard those,

Desired outcome:

  • if a target with those commas exists verbatim, use that.
  • if targets matching those split names exist, use them?
  • if not: should we create one or more targets? Let's do one,

and not second-guess the data source that added commas.

File

./entityreference_autocreate.test, line 153
Tests for autocreation of entity references

Class

EntityReferenceAutocreateTestCase
Test for Entity Reference admin UI.

Code

public function testEditWithCommas() {

  // First configure the field edit properties.
  $this
    ->drupalGet('admin/structure/types/manage/song/fields/field_artist');
  $this
    ->assertText('Artist');
  $this
    ->assertText('EntityReference Autocreate settings');
  $edit = array(
    'instance[widget][settings][entityreference_autocreate][active]' => TRUE,
    'instance[widget][settings][entityreference_autocreate][status]' => -1,
    'field[cardinality]' => -1,
    'field[settings][handler]' => 'base',
    'field[settings][handler_settings][target_bundles][artist]' => 'artist',
  );
  $this
    ->drupalPost(NULL, $edit, t('Save settings'));

  // Also check that the Widget type is 'Autocomplete'
  // This is relevant to the UI.
  $widget_url = 'admin/structure/types/manage/song/fields/field_artist/widget-type';
  $edit = array(
    'widget_type' => 'entityreference_autocomplete',
  );
  $this
    ->drupalPost($widget_url, $edit, t('Continue'));

  // Add a node with a non-existing reference to a target with a comma.
  $edit = array(
    'title' => 'Puff (The Magic Dragon)',
    'field_artist[und][0][target_id]' => 'Peter, Paul and Mary',
  );
  $this
    ->drupalPost('node/add/' . $this->testBundle, $edit, t('Save'));

  // If there is a link with the title as the text, that's a good sign.
  $this
    ->clickLink('Peter, Paul and Mary');

  // Change the widget to 'Tags style'
  $edit = array(
    'widget_type' => 'entityreference_autocomplete_tags',
  );
  $this
    ->drupalPost($widget_url, $edit, t('Continue'));

  // Add a node with a non-existing reference to a target with a comma.
  // The field id is slightly different.
  $edit = array(
    'title' => 'Teach Your Children',
    'field_artist[und]' => 'Crosby, Stills, Nash & Young',
  );
  $this
    ->drupalPost('node/add/' . $this->testBundle, $edit, t('Save'));

  // If there is a link with the title as the text, that's a good sign.
  $this
    ->clickLink('Crosby, Stills, Nash & Young');
}