Beispiel #1
0
 /**
  * Tests the processor's preprocessSearchQuery() method.
  */
 public function testPreprocessSearchQuery()
 {
     $index = $this->getMock('Drupal\\search_api\\IndexInterface');
     $index->expects($this->any())->method('status')->will($this->returnValue(TRUE));
     /** @var \Drupal\search_api\IndexInterface $index */
     $this->processor->setIndex($index);
     $query = Utility::createQuery($index);
     $keys = array('#conjunction' => 'AND', 'foo', 'bar', 'bar foo');
     $query->keys($keys);
     $this->processor->setConfiguration(array('stopwords' => array('foobar', 'bar', 'barfoo')));
     $this->processor->preprocessSearchQuery($query);
     unset($keys[1]);
     $this->assertEquals($keys, $query->getKeys());
     $results = Utility::createSearchResultSet($query);
     $this->processor->postprocessSearchResults($results);
     $this->assertEquals(array('bar'), $results->getIgnoredSearchKeys());
 }
  /**
   * Tests whether overriding processFilterValue() works correctly.
   */
  public function testProcessFilterValueOverride() {
    $override = function (&$value) {
      if (isset($value)) {
        $value = '';
      }
    };
    $this->processor->setMethodOverride('processFilterValue', $override);

    $query = Utility::createQuery($this->index);
    $query->condition('text_field', 'foo');
    $query->condition('string_field', NULL, '<>');
    $query->condition('integer_field', 'bar');

    $this->processor->preprocessSearchQuery($query);

    $expected = array(
      array('string_field', NULL, '<>'),
      array('integer_field', 'bar', '='),
    );
    $this->assertEquals($expected, array_merge($query->getFilter()->getFilters()), 'Filters were preprocessed correctly.');
  }
Beispiel #3
0
 /**
  * {@inheritdoc}
  */
 public function query(array $options = array())
 {
     if (!$this->status()) {
         throw new SearchApiException('Cannot search on a disabled index.');
     }
     return Utility::createQuery($this, $options);
 }
 /**
  * Tests building the query when content is accessible based on node grants.
  */
 public function testQueryAccessWithNodeGrants()
 {
     // Create user that will be passed into the query.
     $authenticated_user = $this->createUser(array('uid' => 2), array('access content'));
     db_insert('node_access')->fields(array('nid' => $this->nodes[0]->id(), 'langcode' => $this->nodes[0]->language()->getId(), 'gid' => $authenticated_user->id(), 'realm' => 'search_api_test', 'grant_view' => 1))->execute();
     $this->index->reindex();
     $this->index->index();
     $query = Utility::createQuery($this->index);
     $query->setOption('search_api_access_account', $authenticated_user);
     $result = $query->execute();
     $this->assertResults($result, array('user' => array(0, 2), 'node' => array(0)));
 }