You are here

public function AbstractAutocompleteSynonymsWebTestCase::testWidgetSettingsSuggestOnlyUnique in Synonyms 7

Test 'Suggest only one entry per term' setting of autocomplete widget.

File

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

Class

AbstractAutocompleteSynonymsWebTestCase
Test "Synonyms friendly autocomplete" widget of Synonyms module.

Code

public function testWidgetSettingsSuggestOnlyUnique() {

  // Testing disabled "Suggest only one entry per term" setting.
  $this
    ->assertAutocompleteMenuPath($this
    ->entityLabel($this->terms['name_similar_synonym']), array(
    $this
      ->entityLabel($this->terms['name_similar_synonym']) => $this
      ->entityLabel($this->terms['name_similar_synonym']),
    $this
      ->entityLabel($this->terms['name_similar_synonym']) . ' ' => $this
      ->synonymAutocompleteResult($this->terms['name_similar_synonym'], $this->terms['name_similar_synonym']->{$this->fields['enabled']['field']['field_name']}[LANGUAGE_NONE][0]['value']),
  ), 'Both term and its synonym are shown when "Suggest only one entry per term" is off.');
  $this
    ->assertAutocompleteMenuPath(drupal_substr($this->terms['similar_synonyms']->{$this->fields['enabled']['field']['field_name']}[LANGUAGE_NONE][0]['value'], 0, 8), array(
    $this
      ->entityLabel($this->terms['similar_synonyms']) => $this
      ->synonymAutocompleteResult($this->terms['similar_synonyms'], $this->terms['similar_synonyms']->{$this->fields['enabled']['field']['field_name']}[LANGUAGE_NONE][0]['value']),
    $this
      ->entityLabel($this->terms['similar_synonyms']) . ' ' => $this
      ->synonymAutocompleteResult($this->terms['similar_synonyms'], $this->terms['similar_synonyms']->{$this->fields['enabled']['field']['field_name']}[LANGUAGE_NONE][1]['value']),
  ), 'Multiple synonyms are shown when "Suggest only one entry per term" is off.');

  // Testing enabled "Suggest only one entry per term" setting.
  $this->reference_instance['widget']['settings']['suggest_only_unique'] = TRUE;
  field_update_instance($this->reference_instance);
  $this
    ->assertAutocompleteMenuPath($this
    ->entityLabel($this->terms['name_similar_synonym']), array(
    $this
      ->entityLabel($this->terms['name_similar_synonym']) => $this
      ->entityLabel($this->terms['name_similar_synonym']),
  ), 'Only term is shown and synonym is not shown when "Suggest only one entry per term" is on.');
  $this
    ->assertAutocompleteMenuPath(drupal_substr($this->terms['similar_synonyms']->{$this->fields['enabled']['field']['field_name']}[LANGUAGE_NONE][0]['value'], 0, 8), array(
    $this
      ->entityLabel($this->terms['similar_synonyms']) => $this
      ->synonymAutocompleteResult($this->terms['similar_synonyms'], $this->terms['similar_synonyms']->{$this->fields['enabled']['field']['field_name']}[LANGUAGE_NONE][0]['value']),
  ), 'Only single synonym is shown when "Suggest only one entry per term" is on.');
}