You are here

public function TaxonomyTermReferenceAutocompleteSynonymsWebTestCase::testAutoCreation in Synonyms 7

Test auto-creation functionality.

Test the auto-creation functionality of the synonym friendly autocomplete widget type for taxonomy term reference field type.

File

./synonyms.test, line 917
Tests for the Synonyms module.

Class

TaxonomyTermReferenceAutocompleteSynonymsWebTestCase
Test synonyms friendly autocomplete widget for taxonomy term reference field.

Code

public function testAutoCreation() {

  // Trying enabled auto creation.
  $this->reference_instance['widget']['settings']['auto_creation'] = TRUE;
  field_update_instance($this->reference_instance);
  $new_term_name = $this->terms['no_synonyms']->{$this->fields['disabled']['field']['field_name']}[LANGUAGE_NONE][0]['value'];
  $this
    ->drupalPost('node/add/synonyms-test-content', array(
    'title' => $this
      ->randomName(),
    'synonyms_term_enabled[' . LANGUAGE_NONE . ']' => $this->terms['no_synonyms']->name . ', ' . $new_term_name . ', ' . $this->terms['one_synonym']->{$this->fields['enabled']['field']['field_name']}[LANGUAGE_NONE][0]['value'],
  ), 'Save');
  $this
    ->assertText($this->terms['no_synonyms']->name, 'Existing term was assigned to the new node');
  $this
    ->assertText($new_term_name, 'Auto created term was assigned to the new node when Auto creation is on.');
  $this
    ->assertText($this->terms['one_synonym']->name, 'Submitting a synonym into autocomplete widget results in the term, to which the synonym belongs, being assigned to the just created entity (when Auto creation is on).');
  $term = $this
    ->getLastTerm($this->vocabulary);
  $this
    ->assertEqual($term->name, $new_term_name, 'The auto created term has been created when Auto creation is on.');

  // Trying disabled auto creation.
  $this->reference_instance['widget']['settings']['auto_creation'] = FALSE;
  field_update_instance($this->reference_instance);
  $new_term_name = $this->terms['term1']->{$this->fields['disabled']['field']['field_name']}[LANGUAGE_NONE][0]['value'];
  $this
    ->drupalPost('node/add/synonyms-test-content', array(
    'title' => $this
      ->randomName(),
    'synonyms_term_enabled[' . LANGUAGE_NONE . ']' => $this->terms['no_synonyms']->name . ', ' . $new_term_name . ', ' . $this->terms['one_synonym']->{$this->fields['enabled']['field']['field_name']}[LANGUAGE_NONE][0]['value'],
  ), 'Save');
  $this
    ->assertText($this->terms['no_synonyms']->name, 'Existing term was assigned to the new node');
  $this
    ->assertNoText($new_term_name, 'Auto created term was not assigned to the new node when Auto creation is off.');
  $this
    ->assertText($this->terms['one_synonym']->name, 'Submitting a synonym into autocomplete widget results in the term, to which the synonym belongs, being assigned to the just created entity (when Auto creation is off).');
  $term = $this
    ->getLastTerm($this->vocabulary);
  $this
    ->assertNotEqual($term->name, $new_term_name, 'The auto created term has not been created when Auto creation is off.');
}