public function EntityReferenceSynonymsBehaviorWebTestCase::testEntityReference in Synonyms 7
Test synonyms extraction for 'entityreference' field type.
File
- synonyms_provider_field/
synonyms_provider_field.test, line 656 - Tests for the Synonyms field provider module.
Class
- EntityReferenceSynonymsBehaviorWebTestCase
- Test EntityReferenceSynonymsBehavior class.
Code
public function testEntityReference() {
// Testing synonymsExtract().
$this
->assertSynonymsExtract(array(), array(), 'on empty field.');
$synonym_entity = $this
->createNode();
$this
->assertSynonymsExtract(array(
LANGUAGE_NONE => array(
0 => array(
'target_id' => entity_id('node', $synonym_entity),
),
),
), array(
entity_label('node', $synonym_entity),
), 'on a field that holds one value.');
// Testing mergeEntityAsSynonym() method.
$node = $this
->createNode();
$this
->assertMergeEntityAsSynonym(array(), $node, 'node', array(
array(
'target_id' => $node->nid,
),
), 'on a node.');
// Testing synonymFind() method.
$this
->assertSynonymsFind(array(), db_and()
->condition(AbstractSynonymsBehavior::COLUMN_SYNONYM_PLACEHOLDER, $this
->randomName()), 'on empty field');
$meta_data = array();
$meta_data[] = array(
'items' => array(),
'found_synonyms' => array(),
);
$this
->assertSynonymsFind($meta_data, db_and()
->condition(AbstractSynonymsBehavior::COLUMN_SYNONYM_PLACEHOLDER, $this
->randomName()), 'on a field without values');
$meta_data = array();
$meta_data[] = array(
'items' => array(
LANGUAGE_NONE => array(
array(
'target_id' => entity_id('node', $this
->createNode()),
),
),
),
'found_synonyms' => array(),
);
$this
->assertSynonymsFind($meta_data, db_and()
->condition(AbstractSynonymsBehavior::COLUMN_SYNONYM_PLACEHOLDER, $this
->randomName()), 'on a field with a value but searching for another string');
$meta_data = array();
$synonym_entity = $this
->createNode();
$meta_data[] = array(
'items' => array(
LANGUAGE_NONE => array(
array(
'target_id' => entity_id('node', $synonym_entity),
),
),
),
'found_synonyms' => array(
entity_label('node', $synonym_entity),
),
);
$this
->assertSynonymsFind($meta_data, db_and()
->condition(AbstractSynonymsBehavior::COLUMN_SYNONYM_PLACEHOLDER, entity_label('node', $synonym_entity)), 'on a field with a single value searching for that string');
$meta_data = array();
$synonym_entity = $this
->createNode();
$meta_data[] = array(
'items' => array(
LANGUAGE_NONE => array(
array(
'target_id' => entity_id('node', $synonym_entity),
),
array(
'target_id' => entity_id('node', $this
->createNode()),
),
),
),
'found_synonyms' => array(
entity_label('node', $synonym_entity),
),
);
$this
->assertSynonymsFind($meta_data, db_and()
->condition(AbstractSynonymsBehavior::COLUMN_SYNONYM_PLACEHOLDER, entity_label('node', $synonym_entity)), 'on a field with 2 values searching for one of those 2 values');
$meta_data = array();
$synonym_entity = $this
->createNode();
$meta_data[] = array(
'items' => array(
LANGUAGE_NONE => array(
array(
'target_id' => entity_id('node', $synonym_entity),
),
array(
'target_id' => entity_id('node', $this
->createNode()),
),
),
),
'found_synonyms' => array(
entity_label('node', $synonym_entity),
),
);
$meta_data[] = array(
'items' => array(
LANGUAGE_NONE => array(
array(
'target_id' => entity_id('node', $this
->createNode()),
),
array(
'target_id' => entity_id('node', $this
->createNode()),
),
),
),
'found_synonyms' => array(),
);
$this
->assertSynonymsFind($meta_data, db_and()
->condition(AbstractSynonymsBehavior::COLUMN_SYNONYM_PLACEHOLDER, entity_label('node', $synonym_entity)), 'on 2 fields with 2 values each searching for one of those values');
$meta_data = array();
$synonym_entity = $this
->createNode();
$meta_data[] = array(
'items' => array(
LANGUAGE_NONE => array(
array(
'target_id' => entity_id('node', $synonym_entity),
),
),
),
'found_synonyms' => array(
entity_label('node', $synonym_entity),
),
);
$this
->assertSynonymsFind($meta_data, db_and()
->condition(AbstractSynonymsBehavior::COLUMN_SYNONYM_PLACEHOLDER, '%' . db_like(drupal_substr(entity_label('node', $synonym_entity), 1, -1)) . '%', 'LIKE'), 'on a field with a value searching for a string LIKE the %value%');
$meta_data = array();
$tag = $this
->randomName();
$synonym_entity1 = $this
->createNode($tag . $this
->randomName());
$synonym_entity2 = $this
->createNode($tag . $this
->randomName());
$meta_data[] = array(
'items' => array(
LANGUAGE_NONE => array(
array(
'target_id' => entity_id('node', $synonym_entity1),
),
array(
'target_id' => entity_id('node', $synonym_entity2),
),
),
),
'found_synonyms' => array(
entity_label('node', $synonym_entity1),
entity_label('node', $synonym_entity2),
),
);
$this
->assertSynonymsFind($meta_data, db_and()
->condition(AbstractSynonymsBehavior::COLUMN_SYNONYM_PLACEHOLDER, db_like($tag) . '%', 'LIKE'), 'on a field with 2 similar values searching a string like %both values%');
$meta_data = array();
$synonym_entity1 = $this
->createNode();
$synonym_entity2 = $this
->createNode();
$meta_data[] = array(
'items' => array(
LANGUAGE_NONE => array(
array(
'target_id' => entity_id('node', $synonym_entity1),
),
array(
'target_id' => entity_id('node', $synonym_entity2),
),
),
),
'found_synonyms' => array(
entity_label('node', $synonym_entity1),
entity_label('node', $synonym_entity2),
),
);
$condition = db_or()
->condition(AbstractSynonymsBehavior::COLUMN_SYNONYM_PLACEHOLDER, entity_label('node', $synonym_entity1))
->condition(AbstractSynonymsBehavior::COLUMN_SYNONYM_PLACEHOLDER, entity_label('node', $synonym_entity2));
$this
->assertSynonymsFind($meta_data, $condition, 'on a field with 2 values searching for value1 or value2');
$meta_data = array();
$synonym_entity = $this
->createNode();
$meta_data[] = array(
'items' => array(
LANGUAGE_NONE => array(
array(
'target_id' => entity_id('node', $synonym_entity),
),
array(
'target_id' => entity_id('node', $this
->createNode()),
),
),
),
'found_synonyms' => array(
entity_label('node', $synonym_entity),
),
);
$condition = db_and()
->condition(AbstractSynonymsBehavior::COLUMN_SYNONYM_PLACEHOLDER, entity_label('node', $synonym_entity))
->condition(AbstractSynonymsBehavior::COLUMN_SYNONYM_PLACEHOLDER, '%' . db_like(drupal_substr(entity_label('node', $synonym_entity), 1, -1)) . '%', 'LIKE');
$this
->assertSynonymsFind($meta_data, $condition, 'on a field with 2 values searching for value1 and LIKE value1%');
$meta_data = array();
$synonym_entity1 = $this
->createNode();
$synonym_entity2 = $this
->createNode();
$meta_data[] = array(
'items' => array(
LANGUAGE_NONE => array(
array(
'target_id' => entity_id('node', $synonym_entity1),
),
array(
'target_id' => entity_id('node', $synonym_entity2),
),
),
),
'found_synonyms' => array(
entity_label('node', $synonym_entity1),
entity_label('node', $synonym_entity2),
),
);
$condition = db_or()
->condition(AbstractSynonymsBehavior::COLUMN_SYNONYM_PLACEHOLDER, entity_label('node', $synonym_entity1))
->condition(db_and()
->condition(AbstractSynonymsBehavior::COLUMN_SYNONYM_PLACEHOLDER, entity_label('node', $synonym_entity2))
->condition(AbstractSynonymsBehavior::COLUMN_SYNONYM_PLACEHOLDER, '%' . db_like(drupal_substr(entity_label('node', $synonym_entity2), 1, -1)) . '%', 'LIKE'));
$this
->assertSynonymsFind($meta_data, $condition, 'on a field with 2 values searching for (value1 or (value2 AND value2%))');
$meta_data = array();
$synonym_entity1 = $this
->createNode($this
->randomName() . ' ' . $this
->randomName() . ' ' . $this
->randomName());
$synonym_entity2 = $this
->createNode(str_replace(' ', '-', entity_label('node', $synonym_entity1)));
$meta_data[] = array(
'items' => array(
LANGUAGE_NONE => array(
array(
'target_id' => entity_id('node', $synonym_entity1),
),
array(
'target_id' => entity_id('node', $synonym_entity2),
),
),
),
'found_synonyms' => array(
entity_label('node', $synonym_entity1),
entity_label('node', $synonym_entity2),
),
);
$condition = db_and()
->where("REPLACE(" . AbstractSynonymsBehavior::COLUMN_SYNONYM_PLACEHOLDER . ", ' ', '-') = :synonym", array(
':synonym' => entity_label('node', $synonym_entity2),
));
$this
->assertSynonymsFind($meta_data, $condition, "on a field with 2 values, where 2nd value replaces spaces with dashes in the 1st value, searching for REPLACE(column, ' ', '-') = value2");
}