You are here

protected function SearchApiUnitTest::checkIgnoreCaseProcessor in Search API 7

Tests the functionality of the "Ignore case" processor.

1 call to SearchApiUnitTest::checkIgnoreCaseProcessor()
SearchApiUnitTest::testUnits in ./search_api.test
Tests the functionality of several components of the module.

File

./search_api.test, line 913
Contains the SearchApiWebTest and the SearchApiUnitTest classes.

Class

SearchApiUnitTest
Class with unit tests testing small fragments of the Search API.

Code

protected function checkIgnoreCaseProcessor() {
  $orig = 'Foo bar BaZ, ÄÖÜÀÁ<>»«.';
  $processed = drupal_strtolower($orig);
  $items = array(
    1 => array(
      'name' => array(
        'type' => 'text',
        'original_type' => 'text',
        'value' => $orig,
      ),
      'mail' => array(
        'type' => 'string',
        'original_type' => 'text',
        'value' => $orig,
      ),
      'search_api_language' => array(
        'type' => 'string',
        'original_type' => 'string',
        'value' => LANGUAGE_NONE,
      ),
    ),
  );
  $keys1 = $keys2 = array(
    'foo',
    'bar baz',
    'foobar1',
    '#conjunction' => 'AND',
  );
  $filters1 = array(
    array(
      'name',
      'foo',
      '=',
    ),
    array(
      'mail',
      'BAR',
      '=',
    ),
  );
  $filters2 = array(
    array(
      'name',
      'foo',
      '=',
    ),
    array(
      'mail',
      'bar',
      '=',
    ),
  );
  $processor = new SearchApiIgnoreCase($this->index, array(
    'fields' => array(
      'name' => 'name',
    ),
  ));
  $tmp = $items;
  $processor
    ->preprocessIndexItems($tmp);
  $this
    ->assertEqual($tmp[1]['name']['value'], $processed, 'Name field was processed.');
  $this
    ->assertEqual($tmp[1]['mail']['value'], $orig, "Mail field wasn't processed.");
  $query = new SearchApiQuery($this->index);
  $query
    ->keys('Foo "baR BaZ" fOObAr1');
  $query
    ->condition('name', 'FOO');
  $query
    ->condition('mail', 'BAR');
  $processor
    ->preprocessSearchQuery($query);
  $this
    ->assertEqual($query
    ->getKeys(), $keys1, 'Search keys were processed correctly.');
  $this
    ->assertEqual($query
    ->getFilter()
    ->getFilters(), $filters1, 'Filters were processed correctly.');
  $processor = new SearchApiIgnoreCase($this->index, array(
    'fields' => array(
      'name' => 'name',
      'mail' => 'mail',
    ),
  ));
  $tmp = $items;
  $processor
    ->preprocessIndexItems($tmp);
  $this
    ->assertEqual($tmp[1]['name']['value'], $processed, 'Name field was processed.');
  $this
    ->assertEqual($tmp[1]['mail']['value'], $processed, 'Mail field was processed.');
  $query = new SearchApiQuery($this->index);
  $query
    ->keys('Foo "baR BaZ" fOObAr1');
  $query
    ->condition('name', 'FOO');
  $query
    ->condition('mail', 'BAR');
  $processor
    ->preprocessSearchQuery($query);
  $this
    ->assertEqual($query
    ->getKeys(), $keys2, 'Search keys were processed correctly.');
  $this
    ->assertEqual($query
    ->getFilter()
    ->getFilters(), $filters2, 'Filters were processed correctly.');
}