You are here

public function EntityAutocompleteWebTestCase::testEntityAutocompleteCallback in Entity Autocomplete 7

Tests autocomplete callback.

See also

entity_autocomplete()

File

tests/entity_autocomplete.test, line 103
Tests suite for Entity Autocomplete module.

Class

EntityAutocompleteWebTestCase
Performs functional tests on advanced functionalities, such as administrative UI, etc.

Code

public function testEntityAutocompleteCallback() {
  $tests = array();

  // Define specific strings for various bundles. Disallowed characters are:
  // f g i k l n o r s t (used by "Look for string", see below).
  $entities = array(
    'bundle_1' => array(
      'cheap',
      'Cheap',
      'deep',
    ),
    'bundle_2' => array(
      'cheap',
      '@',
    ),
  );
  foreach ($entities as $bundle => $strings) {
    if (!node_type_get_type($bundle)) {
      $this
        ->drupalCreateContentType(array(
        'type' => $bundle,
        'name' => ucfirst($bundle),
      ));
    }
    $vocabulary = $this
      ->createVocabulary(array(
      'machine_name' => $bundle,
    ));
    $tests += array_fill_keys(array_unique(array_map('strtolower', $strings)), array(
      'bundle_1' => 0,
      'bundle_2' => 0,
    ));
    foreach ($strings as $string) {
      $tests[strtolower($string)][$bundle]++;
      $title = "Check for {$string} string!";
      $this
        ->drupalCreateNode(array(
        'type' => $bundle,
        'title' => $title,
        'uid' => $this->author->uid,
      ));
      $this
        ->createTerm($vocabulary, array(
        'name' => $title,
      ));
    }

    //end foreach
  }

  //end foreach
  foreach ($tests as $string => $bundles) {
    $all = array_sum($bundles);
    $bundles_path = implode('+', array_keys($bundles));
    foreach (array(
      'node',
      'taxonomy_term',
    ) as $entity_type) {
      $this
        ->drupalGet("entity-autocomplete/{$entity_type}/{$string}");
      $this
        ->assertEqual($this
        ->countResult(), $all);
      $this
        ->drupalGet("entity-autocomplete/bundle/{$entity_type}/{$bundles_path}/{$string}");
      $this
        ->assertEqual($this
        ->countResult(), $all);
      foreach ($bundles as $bundle => $occurrence) {
        $this
          ->drupalGet("entity-autocomplete/bundle/{$entity_type}/{$bundle}/{$string}");
        $this
          ->assertEqual($this
          ->countResult(), $occurrence);
      }

      //end foreach
    }

    //end foreach
  }

  //end foreach
}