public function TaxonomyTermArgumentSynonymsWebTestCase::testTermSynonymArgument in Synonyms 7
Test the term synonym argument.
File
- ./
synonyms.test, line 1883 - Tests for the Synonyms module.
Class
- TaxonomyTermArgumentSynonymsWebTestCase
- Test 'term_synonyms' cTools argument plugin implementation.
Code
public function testTermSynonymArgument() {
$term = (object) array(
'name' => 'Term name',
'vid' => $this->vocabulary->vid,
$this->fields['enabled']['field']['field_name'] => array(
LANGUAGE_NONE => array(
array(
'value' => 'Synonym of term',
),
),
),
);
taxonomy_term_save($term);
ctools_include('context');
$argument = array(
'name' => 'term_synonyms',
'vids' => array(),
'transform' => FALSE,
'identifier' => 'Just Testing',
'keyword' => 'term',
'id' => 0,
);
$result = ctools_context_get_context_from_argument($argument, $this
->randomName());
$this
->assertNull($result, 'Term synonym does not look up anything when random string is supplied.');
$result = ctools_context_get_context_from_argument($argument, drupal_strtolower($term->name));
$this
->assertEqual($result->data->tid, $term->tid, 'Term synonym argument correctly looks up the term by its name.');
$result = ctools_context_get_context_from_argument($argument, drupal_strtolower($term->{$this->fields['enabled']['field']['field_name']}[LANGUAGE_NONE][0]['value']));
$this
->assertEqual($result->data->tid, $term->tid, 'Term synonym argument correctly looks up the term by its synonym.');
$argument['transform'] = TRUE;
$result = ctools_context_get_context_from_argument($argument, str_replace(' ', '-', $term->name));
$this
->assertEqual($result->data->tid, $term->tid, 'Term synonym argument correctly looks up the term by its name, if the spaces are repaced with dashes.');
$result = ctools_context_get_context_from_argument($argument, str_replace(' ', '-', $term->{$this->fields['enabled']['field']['field_name']}[LANGUAGE_NONE][0]['value']));
$this
->assertEqual($result->data->tid, $term->tid, 'Term synonym argument correctly looks up the term by its synonym, if the spaces are repaced with dashes.');
$argument['transform'] = FALSE;
$another_vocabulary = (object) array(
'name' => $this
->randomName(),
'machine_name' => 'another_vocabulary',
);
taxonomy_vocabulary_save($another_vocabulary);
$argument['vids'][$another_vocabulary->vid] = $another_vocabulary->vid;
$result = ctools_context_get_context_from_argument($argument, drupal_strtolower($term->name));
$this
->assertNull($result, 'Term synonym argument does not look up anything when term name is supplied, but the search is limited to another vocabulary.');
$result = ctools_context_get_context_from_argument($argument, drupal_strtolower($term->{$this->fields['enabled']['field']['field_name']}[LANGUAGE_NONE][0]['value']));
$this
->assertNull($result, 'Term synonym argument does not look up anything when term synonym is supplied, but the search is limited to another vocabulary.');
}