protected function AbstractSynonymsProviderFieldWebTestCase::assertSynonymsFind in Synonyms 7
Test synonymFind method.
Parameters
array $meta_data: Array of meta data. Each subarray represents a single term and whether it is expected to be included in the return of the method. Should have the following structure:
- items: (array) Array of field items. Terms will be automatically created with those items
- found_synonyms: (array) Array of synonyms that are expected to be found for the given term, i.e. if "found_synonyms" is empty, it means the term should not be found for the given $condition. If the "found_synonyms" is not empty, then each element of this array should trigger appearance of the term in the results for the given $condition
QueryConditionInterface $condition: Database condition that will be passed to the synonymsFind method
string $message: Any custom message to be added to the standard one and passed to SimpleTest assertion method
5 calls to AbstractSynonymsProviderFieldWebTestCase::assertSynonymsFind()
- CommercePriceSynonymsBehaviorWebTestCase::testCommercePrice in synonyms_commerce/
synonyms_commerce.test - Test synonyms extraction for 'commerce_price' field type.
- CommerceProductReferenceSynonymsBehaviorWebTestCase::testCommerceProductReference in synonyms_commerce/
synonyms_commerce.test - Test synonyms extraction for 'commerce_product_reference' field type.
- EntityReferenceSynonymsBehaviorWebTestCase::testEntityReference in synonyms_provider_field/
synonyms_provider_field.test - Test synonyms extraction for 'entityreference' field type.
- TaxonomySynonymsBehaviorWebTestCase::testTaxonomyTermReference in synonyms_provider_field/
synonyms_provider_field.test - Test synonyms extraction for 'taxonomy_term_reference' field type.
- TextSynonymsBehaviorWebTestCase::testText in synonyms_provider_field/
synonyms_provider_field.test - Test synonyms extraction for 'text' field type.
File
- synonyms_provider_field/
synonyms_provider_field.test, line 107 - Tests for the Synonyms field provider module.
Class
- AbstractSynonymsProviderFieldWebTestCase
- Base class for all tests that test field-based Synonyms providers.
Code
protected function assertSynonymsFind($meta_data, QueryConditionInterface $condition, $message = '') {
$message = $this->behavior_implementation['class'] . '::synonymsFind() pass: ' . $message;
$terms = array();
foreach ($meta_data as $v) {
$term = (object) array(
'name' => $this
->randomName(),
'vid' => $this->vocabulary->vid,
$this->fields['enabled']['field']['field_name'] => $v['items'],
);
taxonomy_term_save($term);
$term->found_synonyms = $v['found_synonyms'];
$terms[] = $term;
}
$return = $this->behavior_implementation['object']
->synonymsFind($condition);
$rows = array();
foreach ($return as $row) {
$rows[] = $row;
}
$success = TRUE;
$total_rows_standard = 0;
$total_rows = 0;
foreach ($terms as $term) {
foreach ($term->found_synonyms as $found_synonym) {
$total_rows_standard++;
$is_found = FALSE;
$total_rows = 0;
foreach ($rows as $row) {
$total_rows++;
if ($row->entity_id == $term->tid && $row->synonym == $found_synonym) {
$is_found = TRUE;
}
}
$success = $success && $is_found;
}
}
$success = $success && $total_rows_standard == $total_rows;
$this
->assertTrue($success, $message);
// Cleaning up.
foreach ($terms as $term) {
taxonomy_term_delete($term->tid);
}
}