public function TaxonomyTermReferenceSelectSynonymsWebTestCase::testWidget in Synonyms 7
Test main functionality of the widget.
Overrides AbstractSelectSynonymsWebTestCase::testWidget
File
- ./
synonyms.test, line 1390 - Tests for the Synonyms module.
Class
- TaxonomyTermReferenceSelectSynonymsWebTestCase
- Test synonyms friendly select widget for taxonomy term reference field.
Code
public function testWidget() {
$name = $this
->randomName();
$this
->drupalPost('node/add/synonyms-test-content', array(
'title' => $name,
$this->reference_field['field_name'] . '[' . LANGUAGE_NONE . '][]' => array(
$this
->synonymSelectKey($this->terms['parent_term'], $this->terms['parent_term']->{$this->fields['enabled']['field']['field_name']}[LANGUAGE_NONE][0]['value']),
$this->terms['child_term']->tid,
$this->terms['normal_term']->tid,
$this
->synonymSelectKey($this->terms['normal_term'], $this->terms['normal_term']->{$this->fields['enabled']['field']['field_name']}[LANGUAGE_NONE][0]['value']),
),
), 'Save');
$node = $this
->drupalGetNodeByTitle($name);
$this
->drupalGet('node/' . $node->nid);
$this
->assertText($this->terms['parent_term']->name, 'Term is saved when its synonym is submitted through synonyms friendly select for the unlimited cardinality.');
$this
->assertText($this->terms['child_term']->name, 'Term is saved when it is submitted through synonyms friendly select for the unlimited cardinality.');
$this
->assertUniqueText($this->terms['normal_term']->name, 'Term is saved only once when the term and its synonym are submitted through synonyms friendly select for the unlimited cardinality.');
$options = array();
$options[] = array(
'entity' => $this->terms['normal_term'],
'selected' => TRUE,
);
$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'],
'selected' => TRUE,
);
$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'],
'selected' => TRUE,
);
$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/' . $node->nid . '/edit');
$this
->assertSynonymsSelect($options, 'Default values are set correctly in the synonyms friendly select widget when working with field cardinality more than 1.');
$this->reference_field['cardinality'] = 2;
field_update_field($this->reference_field);
$name = $this
->randomName();
$this
->drupalPost('node/add/synonyms-test-content', array(
'title' => $name,
$this->reference_field['field_name'] . '[' . LANGUAGE_NONE . '][]' => array(
$this
->synonymSelectKey($this->terms['parent_term'], $this->terms['parent_term']->{$this->fields['enabled']['field']['field_name']}[LANGUAGE_NONE][0]['value']),
$this->terms['child_term']->tid,
$this->terms['normal_term']->tid,
),
), 'Save');
$this
->assertText('this field cannot hold more than 2 values.', 'Submitting 3 entries into a field with cardinality of 2, that refer to 3 terms, results in a form error.');
$this
->drupalPost('node/add/synonyms-test-content', array(
'title' => $name,
$this->reference_field['field_name'] . '[' . LANGUAGE_NONE . '][]' => array(
$this
->synonymSelectKey($this->terms['parent_term'], $this->terms['parent_term']->{$this->fields['enabled']['field']['field_name']}[LANGUAGE_NONE][0]['value']),
$this->terms['normal_term']->tid,
$this
->synonymSelectKey($this->terms['normal_term'], $this->terms['normal_term']->{$this->fields['enabled']['field']['field_name']}[LANGUAGE_NONE][0]['value']),
),
), 'Save');
$node = $this
->drupalGetNodeByTitle($name);
$this
->drupalGet('node/' . $node->nid);
$this
->assertUniqueText($this->terms['parent_term']->name, 'Submitting 3 entries into a field with cardinality of 2, that refer to only 2 terms, results in form getting submitted. Term #1 is saved.');
$this
->assertUniqueText($this->terms['normal_term']->name, 'Term #2 is saved.');
$this->reference_field['cardinality'] = 1;
field_update_field($this->reference_field);
$name = $this
->randomName();
$this
->drupalPost('node/add/synonyms-test-content', array(
'title' => $name,
$this->reference_field['field_name'] . '[' . LANGUAGE_NONE . ']' => $this
->synonymSelectKey($this->terms['parent_term'], $this->terms['parent_term']->{$this->fields['enabled']['field']['field_name']}[LANGUAGE_NONE][0]['value']),
), 'Save');
$node = $this
->drupalGetNodeByTitle($name);
$this
->drupalGet('node/' . $node->nid);
$this
->assertText($this->terms['parent_term']->name, 'Term is saved when its synonym is submitted through synonyms friendly select for the cardinality of 1.');
$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'],
'selected' => TRUE,
);
$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/' . $node->nid . '/edit');
$this
->assertSynonymsSelect($options, 'Default values are set correctly in the synonyms friendly select widget when working with the field cardinality of 1.');
$this
->drupalPost('node/' . $node->nid . '/edit', array(
$this->reference_field['field_name'] . '[' . LANGUAGE_NONE . ']' => $this->terms['child_term']->tid,
), 'Save');
$this
->drupalGet('node/' . $node->nid);
$this
->assertNoText($this->terms['parent_term']->name, 'After updating entity the old term is removed.');
$this
->assertText($this->terms['child_term']->name, 'Term is saved when it is submitted through synonyms friendly select for the cardinality of 1.');
$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'],
'selected' => TRUE,
);
$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/' . $node->nid . '/edit');
$this
->assertSynonymsSelect($options, 'Default values are set correctly in the synonyms friendly select widget when working with the field cardinality of 1.');
}