You are here

protected function SearchApiUnitTest::checkQueryParseKeys in Search API 7

Checks whether the keys are parsed correctly by the query class.

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

File

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

Class

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

Code

protected function checkQueryParseKeys() {
  $options['parse mode'] = 'direct';
  $mode =& $options['parse mode'];
  $query = new SearchApiQuery($this->index, $options);
  $query
    ->keys('foo');
  $this
    ->assertEqual($query
    ->getKeys(), 'foo', '"Direct query" parse mode, test 1.');
  $query
    ->keys('foo bar');
  $this
    ->assertEqual($query
    ->getKeys(), 'foo bar', '"Direct query" parse mode, test 2.');
  $query
    ->keys('(foo bar) OR "bar baz"');
  $this
    ->assertEqual($query
    ->getKeys(), '(foo bar) OR "bar baz"', '"Direct query" parse mode, test 3.');
  $mode = 'single';
  $query = new SearchApiQuery($this->index, $options);
  $query
    ->keys('foo');
  $this
    ->assertEqual($query
    ->getKeys(), array(
    '#conjunction' => 'AND',
    'foo',
  ), '"Single term" parse mode, test 1.');
  $query
    ->keys('foo bar');
  $this
    ->assertEqual($query
    ->getKeys(), array(
    '#conjunction' => 'AND',
    'foo bar',
  ), '"Single term" parse mode, test 2.');
  $query
    ->keys('(foo bar) OR "bar baz"');
  $this
    ->assertEqual($query
    ->getKeys(), array(
    '#conjunction' => 'AND',
    '(foo bar) OR "bar baz"',
  ), '"Single term" parse mode, test 3.');
  $mode = 'terms';
  $query = new SearchApiQuery($this->index, $options);
  $query
    ->keys('foo');
  $this
    ->assertEqual($query
    ->getKeys(), array(
    '#conjunction' => 'AND',
    'foo',
  ), '"Multiple terms" parse mode, test 1.');
  $query
    ->keys('foo bar');
  $this
    ->assertEqual($query
    ->getKeys(), array(
    '#conjunction' => 'AND',
    'foo',
    'bar',
  ), '"Multiple terms" parse mode, test 2.');
  $query
    ->keys('(foo bar) OR "bar baz"');
  $this
    ->assertEqual($query
    ->getKeys(), array(
    '(foo',
    'bar)',
    'OR',
    'bar baz',
    '#conjunction' => 'AND',
  ), '"Multiple terms" parse mode, test 3.');

  // http://drupal.org/node/1468678
  $query
    ->keys('"Münster"');
  $this
    ->assertEqual($query
    ->getKeys(), array(
    '#conjunction' => 'AND',
    'Münster',
  ), '"Multiple terms" parse mode, test 4.');
}