You are here

public function TaxonomyTermReferenceSelectSynonymsWebTestCase::testWidgetSorting in Synonyms 7

Test sorting options of the widget.

Overrides AbstractSelectSynonymsWebTestCase::testWidgetSorting

File

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

Class

TaxonomyTermReferenceSelectSynonymsWebTestCase
Test synonyms friendly select widget for taxonomy term reference field.

Code

public function testWidgetSorting() {
  $cardinality = array(
    1 => 1,
    FIELD_CARDINALITY_UNLIMITED => 'unlimited',
  );
  $required = array(
    TRUE => 'required',
    FALSE => 'not required',
  );
  foreach ($cardinality as $cardinality_k => $cardinality_v) {
    foreach ($required as $required_k => $required_v) {
      $this->reference_field['cardinality'] = $cardinality_k;
      field_update_field($this->reference_field);
      $this->reference_instance['required'] = $required_k;
      $this->reference_instance['widget']['settings']['sort'] = 'weight';
      field_update_instance($this->reference_instance);
      $this->terms['parent_term']->weight = 0;
      taxonomy_term_save($this->terms['parent_term']);
      $options = array();
      $options[] = array(
        'entity' => $this->terms['normal_term'],
      );
      $options[] = array(
        'entity' => $this->terms['normal_term'],
        'synonym' => $this->terms['normal_term']->{$this->fields['enabled']['field']['field_name']}[LANGUAGE_NONE][0]['value'],
      );
      $options[] = array(
        'entity' => $this->terms['normal_term'],
        'synonym' => $this->terms['normal_term']->{$this->fields['enabled']['field']['field_name']}[LANGUAGE_NONE][1]['value'],
      );
      $options[] = array(
        'entity' => $this->terms['parent_term'],
      );
      $options[] = array(
        'entity' => $this->terms['parent_term'],
        'synonym' => $this->terms['parent_term']->{$this->fields['enabled']['field']['field_name']}[LANGUAGE_NONE][0]['value'],
      );
      $options[] = array(
        'entity' => $this->terms['parent_term'],
        'synonym' => $this->terms['parent_term']->{$this->fields['enabled']['field']['field_name']}[LANGUAGE_NONE][1]['value'],
      );
      $options[] = array(
        'entity' => $this->terms['child_term'],
      );
      $options[] = array(
        'entity' => $this->terms['child_term'],
        'synonym' => $this->terms['child_term']->{$this->fields['enabled']['field']['field_name']}[LANGUAGE_NONE][0]['value'],
      );
      $options[] = array(
        'entity' => $this->terms['child_term'],
        'synonym' => $this->terms['child_term']->{$this->fields['enabled']['field']['field_name']}[LANGUAGE_NONE][1]['value'],
      );
      $this
        ->drupalGet('node/add/synonyms-test-content');
      $this
        ->assertSynonymsSelect($options, 'Synonyms select sorting by weight works for the cardinality of ' . $cardinality_v . ' and ' . $required_v);
      $this->terms['parent_term']->weight = -1000;
      taxonomy_term_save($this->terms['parent_term']);
      $options = array();
      $options[] = array(
        'entity' => $this->terms['parent_term'],
      );
      $options[] = array(
        'entity' => $this->terms['parent_term'],
        'synonym' => $this->terms['parent_term']->{$this->fields['enabled']['field']['field_name']}[LANGUAGE_NONE][0]['value'],
      );
      $options[] = array(
        'entity' => $this->terms['parent_term'],
        'synonym' => $this->terms['parent_term']->{$this->fields['enabled']['field']['field_name']}[LANGUAGE_NONE][1]['value'],
      );
      $options[] = array(
        'entity' => $this->terms['child_term'],
      );
      $options[] = array(
        'entity' => $this->terms['child_term'],
        'synonym' => $this->terms['child_term']->{$this->fields['enabled']['field']['field_name']}[LANGUAGE_NONE][0]['value'],
      );
      $options[] = array(
        'entity' => $this->terms['child_term'],
        'synonym' => $this->terms['child_term']->{$this->fields['enabled']['field']['field_name']}[LANGUAGE_NONE][1]['value'],
      );
      $options[] = array(
        'entity' => $this->terms['normal_term'],
      );
      $options[] = array(
        'entity' => $this->terms['normal_term'],
        'synonym' => $this->terms['normal_term']->{$this->fields['enabled']['field']['field_name']}[LANGUAGE_NONE][0]['value'],
      );
      $options[] = array(
        'entity' => $this->terms['normal_term'],
        'synonym' => $this->terms['normal_term']->{$this->fields['enabled']['field']['field_name']}[LANGUAGE_NONE][1]['value'],
      );
      $this
        ->drupalGet('node/add/synonyms-test-content');
      $this
        ->assertSynonymsSelect($options, 'Synonyms select sorting by weight works after changing weights of terms for the cardinality of ' . $cardinality_v . ' and ' . $required_v);
      $this->reference_instance['widget']['settings']['sort'] = 'name';
      field_update_instance($this->reference_instance);
      $options = array();
      $options[] = array(
        'entity' => $this->terms['normal_term'],
      );
      $options[] = array(
        'entity' => $this->terms['normal_term'],
        'synonym' => $this->terms['normal_term']->{$this->fields['enabled']['field']['field_name']}[LANGUAGE_NONE][0]['value'],
      );
      $options[] = array(
        'entity' => $this->terms['normal_term'],
        'synonym' => $this->terms['normal_term']->{$this->fields['enabled']['field']['field_name']}[LANGUAGE_NONE][1]['value'],
      );
      $options[] = array(
        'entity' => $this->terms['parent_term'],
      );
      $options[] = array(
        'entity' => $this->terms['child_term'],
      );
      $options[] = array(
        'entity' => $this->terms['child_term'],
        'synonym' => $this->terms['child_term']->{$this->fields['enabled']['field']['field_name']}[LANGUAGE_NONE][1]['value'],
      );
      $options[] = array(
        'entity' => $this->terms['child_term'],
        'synonym' => $this->terms['child_term']->{$this->fields['enabled']['field']['field_name']}[LANGUAGE_NONE][0]['value'],
      );
      $options[] = array(
        'entity' => $this->terms['parent_term'],
        'synonym' => $this->terms['parent_term']->{$this->fields['enabled']['field']['field_name']}[LANGUAGE_NONE][0]['value'],
      );
      $options[] = array(
        'entity' => $this->terms['parent_term'],
        'synonym' => $this->terms['parent_term']->{$this->fields['enabled']['field']['field_name']}[LANGUAGE_NONE][1]['value'],
      );
      $this
        ->drupalGet('node/add/synonyms-test-content');
      $this
        ->assertSynonymsSelect($options, 'Synonyms select sorting by name works for the cardinality of ' . $cardinality_v . ' and ' . $required_v);
    }
  }
}