public function AbstractAutocompleteSynonymsWebTestCase::testAutocompleteTextField in Synonyms 7
Test autocomplete text field validation.
In particular, this test does the following:
- test submitting a synonym into the text field (that should be converted into its entity)
- test submitting the same entity name twice (only one reference should be saved)
- test submitting entity name and one of its synonyms (only one reference should be saved)
- test submitting 2 different synonyms of the same entity (only one reference should be saved)
File
- ./
synonyms.test, line 528 - Tests for the Synonyms module.
Class
- AbstractAutocompleteSynonymsWebTestCase
- Test "Synonyms friendly autocomplete" widget of Synonyms module.
Code
public function testAutocompleteTextField() {
$this
->drupalPost('node/add/synonyms-test-content', array(
'title' => $this
->randomName(),
$this->reference_field['field_name'] . '[' . LANGUAGE_NONE . ']' => $this->terms['one_synonym']->{$this->fields['enabled']['field']['field_name']}[LANGUAGE_NONE][0]['value'],
), 'Save');
$this
->assertText($this
->entityLabel($this->terms['one_synonym']), 'Submitting a synonym into autocomplete text field results into term being saved.');
$this
->drupalPost('node/add/synonyms-test-content', array(
'title' => $this
->randomName(),
$this->reference_field['field_name'] . '[' . LANGUAGE_NONE . ']' => drupal_implode_tags(array(
$this
->entityLabel($this->terms['one_synonym']),
$this
->entityLabel($this->terms['one_synonym']),
)),
), 'Save');
$this
->assertUniqueText($this
->entityLabel($this->terms['one_synonym']), 'Submitting the same term name twice into autocomplete text field results in saving the term only once in the field.');
$this
->drupalPost('node/add/synonyms-test-content', array(
'title' => $this
->randomName(),
$this->reference_field['field_name'] . '[' . LANGUAGE_NONE . ']' => drupal_implode_tags(array(
$this
->entityLabel($this->terms['one_synonym']),
$this->terms['one_synonym']->{$this->fields['enabled']['field']['field_name']}[LANGUAGE_NONE][0]['value'],
)),
), 'Save');
$this
->assertUniqueText($this
->entityLabel($this->terms['one_synonym']), 'Submitting term name and one of its synonyms results in saving the term only once in the field.');
$this
->drupalPost('node/add/synonyms-test-content', array(
'title' => $this
->randomName(),
$this->reference_field['field_name'] . '[' . LANGUAGE_NONE . ']' => drupal_implode_tags(array(
$this->terms['two_synonyms']->{$this->fields['enabled']['field']['field_name']}[LANGUAGE_NONE][0]['value'],
$this->terms['two_synonyms']->{$this->fields['enabled']['field']['field_name']}[LANGUAGE_NONE][1]['value'],
)),
), 'Save');
$this
->assertUniqueText($this
->entityLabel($this->terms['two_synonyms']), 'Submitting 2 different synonyms of the same term results in saving the term only once in the field.');
}