You are here

protected function AbstractSelectSynonymsWebTestCase::assertSynonymsSelect in Synonyms 7

Assert correctness of the synonyms-friendly select widget.

Parameters

array $options: Array of what options must be present in the select form element. It should consist of arrays that follow such structure:

  • entity: (object) Entity this option represents
  • synonym: (string) If the option comes from a synonym, then include it here
  • selected: (bool) Place here TRUE if this option should be selected by default

string $message: Assert message that will be passed on to SimpleTest internals

6 calls to AbstractSelectSynonymsWebTestCase::assertSynonymsSelect()
CommerceProductReferenceSelectSynonymsWebTestCase::testWidget in synonyms_commerce/synonyms_commerce.test
Test main functionality of the widget.
CommerceProductReferenceSelectSynonymsWebTestCase::testWidgetSorting in synonyms_commerce/synonyms_commerce.test
Test sorting options of the widget.
EntityReferenceSelectSynonymsWebTestCase::testWidget in ./synonyms.test
Test main functionality of the widget.
EntityReferenceSelectSynonymsWebTestCase::testWidgetSorting in ./synonyms.test
Test sorting options of the widget.
TaxonomyTermReferenceSelectSynonymsWebTestCase::testWidget in ./synonyms.test
Test main functionality of the widget.

... See full list

File

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

Class

AbstractSelectSynonymsWebTestCase
Test "Synonyms friendly select" widget of Synonyms module.

Code

protected function assertSynonymsSelect($options, $message = '') {
  $multiple = $this->reference_field['cardinality'] > 1 || $this->reference_field['cardinality'] == FIELD_CARDINALITY_UNLIMITED;
  $element = array(
    '#options' => array(),
    '#value' => $multiple ? array() : 'nothing',
  );
  if (!$multiple) {
    $element['#options'][''] = t('- None -');
  }
  foreach ($options as $v) {
    if (!isset($v['synonym'])) {
      $v['synonym'] = NULL;
    }
    $key = $this
      ->synonymSelectKey($v['entity'], $v['synonym']);
    $label = entity_label($this->behavior_implementation['entity_type'], $v['entity']);
    if ($v['synonym']) {
      $provider = synonyms_behavior_implementation_info($this->behavior_implementation['entity_type'], $this->behavior_implementation['bundle'], $this->behavior_implementation['behavior']);
      $provider = $provider[$this->behavior_implementation['provider']];
      $label = format_string($this->behavior_implementation['settings']['wording'], array(
        '@synonym' => $v['synonym'],
        '@entity' => $label,
        '@field_name' => $provider['label'],
      ));
    }
    if (isset($v['selected']) && $v['selected']) {
      if ($multiple) {
        $element['#value'][] = $key;
      }
      else {
        $element['#value'] = $key;
      }
    }
    $element['#options'][$key] = $this
      ->synonymsSelectOptionPrefix($v['entity'], $v['synonym']) . $label;
  }
  $this
    ->assertRaw('>' . form_select_options($element) . '</select>', $message, 'Synonyms friendly select');
}