You are here

public function SynonymsProviderPropertyWebTestCase::testProperty in Synonyms 7

Test property-based synonyms provider.

File

synonyms_provider_property/synonyms_provider_property.test, line 47
Test cases for Property synonyms provider module.

Class

SynonymsProviderPropertyWebTestCase
Test PropertySynonymsBehavior class.

Code

public function testProperty() {
  $term = (object) array(
    'vid' => $this->vocabulary->vid,
    'name' => $this
      ->randomName(),
  );
  taxonomy_term_save($term);
  $term2 = (object) array(
    'vid' => $this->vocabulary->vid,
    'name' => $this
      ->randomName(),
  );
  taxonomy_term_save($term2);

  // Test extractSynonyms() method.
  $synonyms = $this->behavior_implementation['object']
    ->extractSynonyms($term);
  $this
    ->assertIdentical($synonyms, array(
    $term->tid,
  ), $this->behavior_implementation['class'] . '::extractSynonyms() passed.');

  // Test synonymsFind() method.
  $condition = db_and()
    ->condition(AbstractSynonymsBehavior::COLUMN_SYNONYM_PLACEHOLDER, 0);
  $this
    ->assertSynonymsFind($condition, array(), 'on non-existing synonym');
  $condition = db_and()
    ->condition(AbstractSynonymsBehavior::COLUMN_SYNONYM_PLACEHOLDER, $term->tid);
  $this
    ->assertSynonymsFind($condition, array(
    array(
      'entity_id' => $term->tid,
      'synonym' => $term->tid,
    ),
  ), 'on a synonym');
  $condition = db_and()
    ->condition(AbstractSynonymsBehavior::COLUMN_SYNONYM_PLACEHOLDER, $term->tid)
    ->condition(AbstractSynonymsBehavior::COLUMN_SYNONYM_PLACEHOLDER, $term2->tid);
  $this
    ->assertSynonymsFind($condition, array(), 'on a synonym AND on another synonym');
  $condition = db_or()
    ->condition(AbstractSynonymsBehavior::COLUMN_SYNONYM_PLACEHOLDER, $term->tid)
    ->condition(AbstractSynonymsBehavior::COLUMN_SYNONYM_PLACEHOLDER, $term2->tid);
  $this
    ->assertSynonymsFind($condition, array(
    array(
      'entity_id' => $term->tid,
      'synonym' => $term->tid,
    ),
    array(
      'entity_id' => $term2->tid,
      'synonym' => $term2->tid,
    ),
  ), 'on a synonym OR another synonym');
}