Example #1
0
  /**
   * {@inheritdoc}
   */
  public function setUp() {
    parent::setUp();

    $this->installSchema('search_api', array('search_api_item', 'search_api_task'));
    $this->installSchema('system', array('router'));
    $this->installSchema('user', array('users_data'));

    $this->setUpExampleStructure();

    $this->installConfig(array('search_api_test_db'));

    $this->insertExampleContent();

    // Create a test server.
    $this->server = Server::create(array(
      'name' => $this->randomString(),
      'id' => $this->randomMachineName(),
      'status' => 1,
      'backend' => 'search_api_test_backend',
    ));
    $this->server->save();

    $this->index = Index::load('database_search_index');
    $this->index->setServer($this->server);
  }
Example #2
0
  /**
   * {@inheritdoc}
   */
  public function setUp() {
    parent::setUp();

    $this->state = $this->container->get('state');

    $this->installEntitySchema('user');
    $this->installSchema('search_api', array('search_api_item', 'search_api_task'));

    // Create a test server.
    $this->server = Server::create(array(
      'name' => $this->randomString(),
      'id' => $this->randomMachineName(),
      'status' => 1,
      'backend' => 'search_api_test_backend',
    ));
    $this->server->save();

    // Create a test index.
    $this->index = Index::create(array(
      'name' => $this->randomString(),
      'id' => $this->randomMachineName(),
      'status' => 1,
      'datasources' => array('entity:user'),
      'tracker' => 'default',
      'server' => $this->server->id(),
      'options' => array('index_directly' => FALSE),
    ));
    $this->index->save();

    $this->serverTaskManager = $this->container->get('search_api.server_task_manager');
  }
  /**
   * {@inheritdoc}
   */
  public function setUp() {
    parent::setUp();

    $this->installSchema('search_api', array('search_api_item', 'search_api_task'));

    // Create a test server.
    $this->server = Server::create(array(
      'name' => $this->randomString(),
      'id' => $this->randomMachineName(),
      'status' => 1,
      'backend' => 'search_api_test_backend',
    ));
    $this->server->save();

    // Create a test index.
    $this->index = Index::create(array(
      'name' => $this->randomString(),
      'id' => $this->randomMachineName(),
      'status' => 1,
      'datasources' => array('entity:' . $this->testEntityTypeId),
      'tracker' => 'default',
      'server' => $this->server->id(),
      'options' => array('index_directly' => FALSE),
    ));
    $this->index->save();

    Utility::getIndexTaskManager()->addItemsAll($this->index);
  }
 /**
  * {@inheritdoc}
  */
 public function setUp()
 {
     parent::setUp();
     // Enable translation for the entity_test module.
     \Drupal::state()->set('entity_test.translation', TRUE);
     $this->installSchema('search_api', array('search_api_item', 'search_api_task'));
     $this->installEntitySchema('entity_test_mul');
     // Create the default languages.
     $this->installConfig(array('language'));
     $this->langcodes = array();
     for ($i = 0; $i < 3; ++$i) {
         /** @var \Drupal\language\Entity\ConfigurableLanguage $language */
         $language = ConfigurableLanguage::create(array('id' => 'l' . $i, 'label' => 'language - ' . $i, 'weight' => $i));
         $this->langcodes[$i] = $language->getId();
         $language->save();
     }
     // Do not use a batch for tracking the initial items after creating an
     // index when running the tests via the GUI. Otherwise, it seems Drupal's
     // Batch API gets confused and the test fails.
     \Drupal::state()->set('search_api_use_tracking_batch', FALSE);
     // Create a test server.
     $this->server = Server::create(array('name' => 'Test Server', 'id' => 'test_server', 'status' => 1, 'backend' => 'search_api_test_backend'));
     $this->server->save();
     // Create a test index.
     $this->index = Index::create(array('name' => 'Test Index', 'id' => 'test_index', 'status' => 1, 'datasource_settings' => array('entity:' . $this->testEntityTypeId => array('plugin_id' => 'entity:' . $this->testEntityTypeId, 'settings' => array())), 'tracker_settings' => array('default' => array('plugin_id' => 'default', 'settings' => array())), 'server' => $this->server->id(), 'options' => array('index_directly' => FALSE)));
     $this->index->save();
 }
Example #5
0
  /**
   * Performs setup tasks before each individual test method is run.
   *
   * Installs commonly used schemas and sets up a search server and an index,
   * with the specified processor enabled.
   *
   * @param string|null $processor
   *   (optional) The plugin ID of the processor that should be set up for
   *   testing.
   */
  public function setUp($processor = NULL) {
    parent::setUp();

    $this->installSchema('node', array('node_access'));
    $this->installSchema('search_api', array('search_api_item', 'search_api_task'));

    $server_name = $this->randomMachineName();
    $this->server = Server::create(array(
      'id' => strtolower($server_name),
      'name' => $server_name,
      'status' => TRUE,
      'backend' => 'search_api_db',
      'backend_config' => array(
        'min_chars' => 3,
        'database' => 'default:default',
      ),
    ));
    $this->server->save();

    $index_name = $this->randomMachineName();
    $this->index = Index::create(array(
      'id' => strtolower($index_name),
      'name' => $index_name,
      'status' => TRUE,
      'datasources' => array('entity:comment', 'entity:node'),
      'server' => $server_name,
      'tracker' => 'default',
    ));
    $this->index->setServer($this->server);
    $this->index->setOption('fields', array(
      'entity:comment/subject' => array(
        'type' => 'text',
      ),
      'entity:node/title' => array(
        'type' => 'text',
      ),
    ));
    if ($processor) {
      $this->index->setOption('processors', array(
        $processor => array(
          'processor_id' => $processor,
          'weights' => array(),
          'settings' => array(),
        ),
      ));

      /** @var \Drupal\search_api\Processor\ProcessorPluginManager $plugin_manager */
      $plugin_manager = \Drupal::service('plugin.manager.search_api.processor');
      $this->processor = $plugin_manager->createInstance($processor, array('index' => $this->index));
    }
    $this->index->save();
    \Drupal::configFactory()
      ->getEditable('search_api.settings')
      ->set('tracking_page_size', 100)
      ->save();
    Utility::getIndexTaskManager()->addItemsAll($this->index);
  }
 /**
  * Tests a backend with a dependency that gets removed.
  *
  * If the dependency does not get removed, proper cascading to the index is
  * also verified.
  *
  * @param bool $remove_dependency
  *   Whether to remove the dependency from the backend when the object
  *   depended on is deleted.
  *
  * @dataProvider dependencyTestDataProvider
  */
 public function testBackendDependency($remove_dependency)
 {
     $dependency_key = $this->dependency->getConfigDependencyKey();
     $dependency_name = $this->dependency->getConfigDependencyName();
     // Create a server using the test backend, and set the dependency in the
     // configuration.
     /** @var \Drupal\search_api\ServerInterface $server */
     $server = Server::create(array('id' => 'test_server', 'name' => 'Test server', 'backend' => 'search_api_test_backend', 'backend_config' => array('dependencies' => array($dependency_key => array($dependency_name)))));
     $server->save();
     $server_dependency_key = $server->getConfigDependencyKey();
     $server_dependency_name = $server->getConfigDependencyName();
     // Set the server on the index and save that, too. However, we don't want
     // the index enabled, since that would lead to all kinds of overhead which
     // is completely irrelevant for this test.
     $this->index->setServer($server);
     $this->index->disable();
     $this->index->save();
     // Check that the dependencies were calculated correctly.
     $server_dependencies = $server->getDependencies();
     $this->assertContains($dependency_name, $server_dependencies[$dependency_key], 'Backend dependency correctly inserted');
     $index_dependencies = $this->index->getDependencies();
     $this->assertContains($server_dependency_name, $index_dependencies[$server_dependency_key], 'Server dependency correctly inserted');
     // Set our magic state key to let the test plugin know whether the
     // dependency should be removed or not. See
     // \Drupal\search_api_test_backend\Plugin\search_api\backend\TestBackend::onDependencyRemoval().
     $key = 'search_api_test_backend.dependencies.remove';
     \Drupal::state()->set($key, $remove_dependency);
     // Delete the backend's dependency.
     $this->dependency->delete();
     // Reload the index and check it's still there.
     $this->reloadIndex();
     $this->assertInstanceOf('Drupal\\search_api\\IndexInterface', $this->index, 'Index not removed');
     // Reload the server.
     $storage = \Drupal::entityTypeManager()->getStorage('search_api_server');
     $storage->resetCache();
     $server = $storage->load($server->id());
     if ($remove_dependency) {
         $this->assertInstanceOf('Drupal\\search_api\\ServerInterface', $server, 'Server was not removed');
         $this->assertArrayNotHasKey('dependencies', $server->get('backend_config'), 'Backend config was adapted');
         // @todo Logically, this should not be changed: if the server does not get
         //   removed, there is no need to adapt the index's configuration.
         //   However, the way this config dependency cascading is actually
         //   implemented in
         //   \Drupal\Core\Config\ConfigManager::getConfigEntitiesToChangeOnDependencyRemoval()
         //   does not seem to follow that logic, but just computes the complete
         //   tree of dependencies once and operates generally on the assumption
         //   that all of them will be deleted. See #2642374.
         //      $this->assertEquals($server->id(), $this->index->getServerId(), "Index's server was not changed");
     } else {
         $this->assertNull($server, 'Server was removed');
         $this->assertEquals(NULL, $this->index->getServerId(), 'Index server was changed');
     }
 }
Example #7
0
 /**
  * Creates or deletes a server.
  *
  * @param string $name
  *   (optional) The name of the server.
  * @param string $id
  *   (optional) The ID of the server.
  * @param string $backend_id
  *   (optional) The ID of the backend to set for the server.
  * @param array $backend_config
  *   (optional) The backend configuration to set for the server.
  * @param bool $reset
  *   (optional) If TRUE, delete the server instead of creating it. (Only the
  *   server's ID is required in that case).
  *
  * @return \Drupal\search_api\ServerInterface
  *   A search server.
  */
 public function getTestServer($name = 'WebTest server', $id = 'webtest_server', $backend_id = 'search_api_test_backend', $backend_config = array(), $reset = FALSE)
 {
     if ($reset) {
         $server = Server::load($id);
         if ($server) {
             $server->delete();
         }
     } else {
         $server = Server::create(array('id' => $id, 'name' => $name, 'description' => $name, 'backend' => $backend_id, 'backend_config' => $backend_config));
         $server->save();
     }
     return $server;
 }
Example #8
0
 /**
  * {@inheritdoc}
  */
 public function setUp()
 {
     parent::setUp();
     $this->installSchema('search_api', array('search_api_item', 'search_api_task'));
     $this->installEntitySchema('entity_test');
     // Create a test server.
     $this->server = Server::create(array('name' => 'Test server', 'id' => 'test', 'status' => 1, 'backend' => 'search_api_test_backend'));
     $this->server->save();
     // Manually set the tracking page size since the module's default
     // configuration is not installed automatically in kernel tests.
     \Drupal::configFactory()->getEditable('search_api.settings')->set('tracking_page_size', 100)->save();
     // Disable the use of batches for item tracking to simulate a CLI
     // environment.
     \Drupal::state()->set('search_api_use_tracking_batch', FALSE);
 }
 /**
  * Performs setup tasks before each individual test method is run.
  *
  * Installs commonly used schemas and sets up a search server and an index,
  * with the specified processor enabled.
  *
  * @param string|null $processor
  *   (optional) The plugin ID of the processor that should be set up for
  *   testing.
  */
 public function setUp($processor = NULL)
 {
     parent::setUp();
     $this->installSchema('node', array('node_access'));
     $this->installSchema('search_api', array('search_api_item', 'search_api_task'));
     $this->installEntitySchema('user');
     $this->installEntitySchema('node');
     $this->installEntitySchema('comment');
     $this->installConfig(array('field'));
     Action::create(['id' => 'foo', 'label' => 'Foobaz', 'plugin' => 'comment_publish_action'])->save();
     \Drupal::configFactory()->getEditable('search_api.settings')->set('tracking_page_size', 100)->save();
     // Do not use a batch for tracking the initial items after creating an
     // index when running the tests via the GUI. Otherwise, it seems Drupal's
     // Batch API gets confused and the test fails.
     \Drupal::state()->set('search_api_use_tracking_batch', FALSE);
     $this->server = Server::create(array('id' => 'server', 'name' => 'Server & Name', 'status' => TRUE, 'backend' => 'search_api_db', 'backend_config' => array('min_chars' => 3, 'database' => 'default:default')));
     $this->server->save();
     $this->index = Index::create(array('id' => 'index', 'name' => 'Index name', 'status' => TRUE, 'datasource_settings' => array('entity:comment' => array('plugin_id' => 'entity:comment', 'settings' => array()), 'entity:node' => array('plugin_id' => 'entity:node', 'settings' => array())), 'server' => 'server', 'tracker_settings' => array('default' => array('plugin_id' => 'default', 'settings' => array()))));
     $this->index->setServer($this->server);
     $field_subject = new Field($this->index, 'subject');
     $field_subject->setType('text');
     $field_subject->setPropertyPath('subject');
     $field_subject->setDatasourceId('entity:comment');
     $field_subject->setLabel('Subject');
     $field_title = new Field($this->index, 'title');
     $field_title->setType('text');
     $field_title->setPropertyPath('title');
     $field_title->setDatasourceId('entity:node');
     $field_title->setLabel('Title');
     $this->index->addField($field_subject);
     $this->index->addField($field_title);
     if ($processor) {
         /** @var \Drupal\search_api\Processor\ProcessorPluginManager $plugin_manager */
         $plugin_manager = \Drupal::service('plugin.manager.search_api.processor');
         $this->processor = $plugin_manager->createInstance($processor, array('index' => $this->index));
         $this->index->addProcessor($this->processor);
     }
     $this->index->save();
 }
 /**
  * {@inheritdoc}
  */
 public function setUp()
 {
     parent::setUp();
     $this->installSchema('search_api', array('search_api_item', 'search_api_task'));
     $this->installSchema('system', array('router'));
     $this->installSchema('user', array('users_data'));
     $this->installEntitySchema('entity_test');
     // Do not use a batch for tracking the initial items after creating an
     // index when running the tests via the GUI. Otherwise, it seems Drupal's
     // Batch API gets confused and the test fails.
     \Drupal::state()->set('search_api_use_tracking_batch', FALSE);
     $this->installConfig(array('search_api_test_db'));
     // Create test entities.
     $this->entities[1] = EntityTest::create(array('name' => 'foo bar baz föö smile' . json_decode('"\\u1F601"'), 'body' => 'test test case Case casE', 'type' => 'item', 'keywords' => array('Orange', 'orange', 'örange', 'Orange'), 'category' => 'item_category'));
     $this->entities[2] = EntityTest::create(array('name' => 'foo bar baz föö smile', 'body' => 'test test case Case casE', 'type' => 'item', 'keywords' => array('strawberry', 'llama'), 'category' => 'item_category'));
     $this->entities[1]->save();
     $this->entities[2]->save();
     // Create a test server.
     $this->server = Server::create(array('name' => 'Server test ~', 'id' => 'test', 'status' => 1, 'backend' => 'search_api_test_backend'));
     $this->server->save();
     $this->index = Index::load('database_search_index');
     $this->index->setServer($this->server);
 }
Example #11
0
 /**
  * Executes regression tests for issues that were already fixed.
  */
 protected function regressionTests()
 {
     /** @var \Drupal\search_api\ServerInterface $second_server */
     $second_server = Server::create(array('id' => 'test2', 'backend' => 'search_api_db', 'backend_config' => array('database' => 'default:default')));
     $second_server->save();
     $query = $this->buildSearch();
     try {
         $second_server->search($query);
         $this->fail('Could execute a query for an index on a different server.');
     } catch (SearchApiException $e) {
         $this->assertTrue(TRUE, 'Executing a query for an index on a different server throws an exception.');
     }
     $second_server->delete();
     // Regression tests for #2007872.
     $results = $this->buildSearch('test')->sort('id', QueryInterface::SORT_ASC)->sort('type', QueryInterface::SORT_ASC)->execute();
     $this->assertEquals(4, $results->getResultCount(), 'Sorting on field with NULLs returned correct number of results.');
     $this->assertEquals($this->getItemIds(array(1, 2, 3, 4)), array_keys($results->getResultItems()), 'Sorting on field with NULLs returned correct result.');
     $this->assertIgnored($results);
     $this->assertWarnings($results);
     $query = $this->buildSearch();
     $conditions = $query->createConditionGroup('OR');
     $conditions->addCondition('id', 3);
     $conditions->addCondition('type', 'article');
     $query->addConditionGroup($conditions);
     $query->sort('id', QueryInterface::SORT_ASC);
     $results = $query->execute();
     $this->assertEquals(3, $results->getResultCount(), 'OR filter on field with NULLs returned correct number of results.');
     $this->assertEquals($this->getItemIds(array(3, 4, 5)), array_keys($results->getResultItems()), 'OR filter on field with NULLs returned correct result.');
     $this->assertIgnored($results);
     $this->assertWarnings($results);
     // Regression tests for #1863672.
     $query = $this->buildSearch();
     $conditions = $query->createConditionGroup('OR');
     $conditions->addCondition('keywords', 'orange');
     $conditions->addCondition('keywords', 'apple');
     $query->addConditionGroup($conditions);
     $query->sort('id', QueryInterface::SORT_ASC);
     $results = $query->execute();
     $this->assertEquals(4, $results->getResultCount(), 'OR filter on multi-valued field returned correct number of results.');
     $this->assertEquals($this->getItemIds(array(1, 2, 4, 5)), array_keys($results->getResultItems()), 'OR filter on multi-valued field returned correct result.');
     $this->assertIgnored($results);
     $this->assertWarnings($results);
     $query = $this->buildSearch();
     $conditions = $query->createConditionGroup('OR');
     $conditions->addCondition('keywords', 'orange');
     $conditions->addCondition('keywords', 'strawberry');
     $query->addConditionGroup($conditions);
     $conditions = $query->createConditionGroup('OR');
     $conditions->addCondition('keywords', 'apple');
     $conditions->addCondition('keywords', 'grape');
     $query->addConditionGroup($conditions);
     $query->sort('id', QueryInterface::SORT_ASC);
     $results = $query->execute();
     $this->assertEquals(3, $results->getResultCount(), 'Multiple OR filters on multi-valued field returned correct number of results.');
     $this->assertEquals($this->getItemIds(array(2, 4, 5)), array_keys($results->getResultItems()), 'Multiple OR filters on multi-valued field returned correct result.');
     $this->assertIgnored($results);
     $this->assertWarnings($results);
     $query = $this->buildSearch();
     $conditions1 = $query->createConditionGroup('OR');
     $conditions = $query->createConditionGroup('AND');
     $conditions->addCondition('keywords', 'orange');
     $conditions->addCondition('keywords', 'apple');
     $conditions1->addConditionGroup($conditions);
     $conditions = $query->createConditionGroup('AND');
     $conditions->addCondition('keywords', 'strawberry');
     $conditions->addCondition('keywords', 'grape');
     $conditions1->addConditionGroup($conditions);
     $query->addConditionGroup($conditions1);
     $query->sort('id', QueryInterface::SORT_ASC);
     $results = $query->execute();
     $this->assertEquals(3, $results->getResultCount(), 'Complex nested filters on multi-valued field returned correct number of results.');
     $this->assertEquals($this->getItemIds(array(2, 4, 5)), array_keys($results->getResultItems()), 'Complex nested filters on multi-valued field returned correct result.');
     $this->assertIgnored($results);
     $this->assertWarnings($results);
     // Regression tests for #2040543.
     $query = $this->buildSearch();
     $facets['category'] = array('field' => 'category', 'limit' => 0, 'min_count' => 1, 'missing' => TRUE);
     $query->setOption('search_api_facets', $facets);
     $query->range(0, 0);
     $results = $query->execute();
     $expected = array(array('count' => 2, 'filter' => '"article_category"'), array('count' => 2, 'filter' => '"item_category"'), array('count' => 1, 'filter' => '!'));
     $type_facets = $results->getExtraData('search_api_facets')['category'];
     usort($type_facets, array($this, 'facetCompare'));
     $this->assertEquals($expected, $type_facets, 'Correct facets were returned');
     $query = $this->buildSearch();
     $facets['category']['missing'] = FALSE;
     $query->setOption('search_api_facets', $facets);
     $query->range(0, 0);
     $results = $query->execute();
     $expected = array(array('count' => 2, 'filter' => '"article_category"'), array('count' => 2, 'filter' => '"item_category"'));
     $type_facets = $results->getExtraData('search_api_facets')['category'];
     usort($type_facets, array($this, 'facetCompare'));
     $this->assertEquals($expected, $type_facets, 'Correct facets were returned');
     // Regression tests for #2111753.
     $keys = array('#conjunction' => 'OR', 'foo', 'test');
     $query = $this->buildSearch($keys, array(), array('name'));
     $query->sort('id', QueryInterface::SORT_ASC);
     $results = $query->execute();
     $this->assertEquals(3, $results->getResultCount(), 'OR keywords returned correct number of results.');
     $this->assertEquals($this->getItemIds(array(1, 2, 4)), array_keys($results->getResultItems()), 'OR keywords returned correct result.');
     $this->assertIgnored($results);
     $this->assertWarnings($results);
     $query = $this->buildSearch($keys, array(), array('name', 'body'));
     $query->range(0, 0);
     $results = $query->execute();
     $this->assertEquals(5, $results->getResultCount(), 'Multi-field OR keywords returned correct number of results.');
     $this->assertFalse($results->getResultItems(), 'Multi-field OR keywords returned correct result.');
     $this->assertIgnored($results);
     $this->assertWarnings($results);
     $keys = array('#conjunction' => 'OR', 'foo', 'test', array('#conjunction' => 'AND', 'bar', 'baz'));
     $query = $this->buildSearch($keys, array(), array('name'));
     $query->sort('id', QueryInterface::SORT_ASC);
     $results = $query->execute();
     $this->assertEquals(4, $results->getResultCount(), 'Nested OR keywords returned correct number of results.');
     $this->assertEquals($this->getItemIds(array(1, 2, 4, 5)), array_keys($results->getResultItems()), 'Nested OR keywords returned correct result.');
     $this->assertIgnored($results);
     $this->assertWarnings($results);
     $keys = array('#conjunction' => 'OR', array('#conjunction' => 'AND', 'foo', 'test'), array('#conjunction' => 'AND', 'bar', 'baz'));
     $query = $this->buildSearch($keys, array(), array('name', 'body'));
     $query->sort('id', QueryInterface::SORT_ASC);
     $results = $query->execute();
     $this->assertEquals(4, $results->getResultCount(), 'Nested multi-field OR keywords returned correct number of results.');
     $this->assertEquals($this->getItemIds(array(1, 2, 4, 5)), array_keys($results->getResultItems()), 'Nested multi-field OR keywords returned correct result.');
     $this->assertIgnored($results);
     $this->assertWarnings($results);
     // Regression tests for #2127001.
     $keys = array('#conjunction' => 'AND', '#negation' => TRUE, 'foo', 'bar');
     $results = $this->buildSearch($keys)->sort('search_api_id', QueryInterface::SORT_ASC)->execute();
     $this->assertEquals(2, $results->getResultCount(), 'Negated AND fulltext search returned correct number of results.');
     $this->assertEquals($this->getItemIds(array(3, 4)), array_keys($results->getResultItems()), 'Negated AND fulltext search returned correct result.');
     $this->assertIgnored($results);
     $this->assertWarnings($results);
     $keys = array('#conjunction' => 'OR', '#negation' => TRUE, 'foo', 'baz');
     $results = $this->buildSearch($keys)->execute();
     $this->assertEquals(1, $results->getResultCount(), 'Negated OR fulltext search returned correct number of results.');
     $this->assertEquals($this->getItemIds(array(3)), array_keys($results->getResultItems()), 'Negated OR fulltext search returned correct result.');
     $this->assertIgnored($results);
     $this->assertWarnings($results);
     $keys = array('#conjunction' => 'AND', 'test', array('#conjunction' => 'AND', '#negation' => TRUE, 'foo', 'bar'));
     $results = $this->buildSearch($keys)->sort('search_api_id', QueryInterface::SORT_ASC)->execute();
     $this->assertEquals(2, $results->getResultCount(), 'Nested NOT AND fulltext search returned correct number of results.');
     $this->assertEquals($this->getItemIds(array(3, 4)), array_keys($results->getResultItems()), 'Nested NOT AND fulltext search returned correct result.');
     $this->assertIgnored($results);
     $this->assertWarnings($results);
     // Regression tests for #2136409.
     $query = $this->buildSearch();
     $query->addCondition('category', NULL);
     $query->sort('search_api_id', QueryInterface::SORT_ASC);
     $results = $query->execute();
     $this->assertEquals(1, $results->getResultCount(), 'NULL filter returned correct number of results.');
     $this->assertEquals($this->getItemIds(array(3)), array_keys($results->getResultItems()), 'NULL filter returned correct result.');
     $query = $this->buildSearch();
     $query->addCondition('category', NULL, '<>');
     $query->sort('search_api_id', QueryInterface::SORT_ASC);
     $results = $query->execute();
     $this->assertEquals(4, $results->getResultCount(), 'NOT NULL filter returned correct number of results.');
     $this->assertEquals($this->getItemIds(array(1, 2, 4, 5)), array_keys($results->getResultItems()), 'NOT NULL filter returned correct result.');
     // Regression tests for #1658964.
     $query = $this->buildSearch();
     $facets['type'] = array('field' => 'type', 'limit' => 0, 'min_count' => 0, 'missing' => TRUE);
     $query->setOption('search_api_facets', $facets);
     $query->addCondition('type', 'article');
     $query->range(0, 0);
     $results = $query->execute();
     $expected = array(array('count' => 2, 'filter' => '"article"'), array('count' => 0, 'filter' => '!'), array('count' => 0, 'filter' => '"item"'));
     $facets = $results->getExtraData('search_api_facets', array())['type'];
     usort($facets, array($this, 'facetCompare'));
     $this->assertEquals($expected, $facets, 'Correct facets were returned');
     // Regression tests for #2469547.
     $query = $this->buildSearch();
     $facets = array();
     $facets['body'] = array('field' => 'body', 'limit' => 0, 'min_count' => 1, 'missing' => FALSE);
     $query->setOption('search_api_facets', $facets);
     $query->addCondition('id', 5, '<>');
     $query->range(0, 0);
     $results = $query->execute();
     $expected = array(array('count' => 4, 'filter' => '"test"'), array('count' => 2, 'filter' => '"Case"'), array('count' => 2, 'filter' => '"casE"'), array('count' => 1, 'filter' => '"bar"'), array('count' => 1, 'filter' => '"case"'), array('count' => 1, 'filter' => '"foobar"'));
     // We can't guarantee the order of returned facets, since "bar" and "foobar"
     // both occur once, so we have to manually sort the returned facets first.
     $facets = $results->getExtraData('search_api_facets', array())['body'];
     usort($facets, array($this, 'facetCompare'));
     $this->assertEquals($expected, $facets, 'Correct facets were returned for a fulltext field.');
     // Regression tests for #1403916.
     $query = $this->buildSearch('test foo');
     $facets = array();
     $facets['type'] = array('field' => 'type', 'limit' => 0, 'min_count' => 1, 'missing' => TRUE);
     $query->setOption('search_api_facets', $facets);
     $query->range(0, 0);
     $results = $query->execute();
     $expected = array(array('count' => 2, 'filter' => '"item"'), array('count' => 1, 'filter' => '"article"'));
     $facets = $results->getExtraData('search_api_facets', array())['type'];
     usort($facets, array($this, 'facetCompare'));
     $this->assertEquals($expected, $facets, 'Correct facets were returned');
     // Regression tests for #2557291.
     $results = $this->buildSearch('case')->execute();
     $this->assertEquals(1, $results->getResultCount(), 'Search for lowercase "case" returned correct number of results.');
     $this->assertEquals($this->getItemIds(array(1)), array_keys($results->getResultItems()), 'Search for lowercase "case" returned correct result.');
     $this->assertIgnored($results);
     $this->assertWarnings($results);
     $results = $this->buildSearch('Case')->sort('search_api_id')->execute();
     $this->assertEquals(2, $results->getResultCount(), 'Search for capitalized "Case" returned correct number of results.');
     $this->assertEquals($this->getItemIds(array(1, 3)), array_keys($results->getResultItems()), 'Search for capitalized "Case" returned correct result.');
     $this->assertIgnored($results);
     $this->assertWarnings($results);
     $results = $this->buildSearch('CASE')->execute();
     $this->assertEquals(0, $results->getResultCount(), 'Search for non-existent uppercase version of "CASE" returned correct number of results.');
     $this->assertEquals(array(), array_keys($results->getResultItems()), 'Search for non-existent uppercase version of "CASE" returned correct result.');
     $this->assertIgnored($results);
     $this->assertWarnings($results);
     $results = $this->buildSearch('föö')->execute();
     $this->assertEquals(1, $results->getResultCount(), 'Search for keywords with umlauts returned correct number of results.');
     $this->assertEquals($this->getItemIds(array(1)), array_keys($results->getResultItems()), 'Search for keywords with umlauts returned correct result.');
     $this->assertIgnored($results);
     $this->assertWarnings($results);
     $results = $this->buildSearch('smile' . json_decode('"\\u1F601"'))->execute();
     $this->assertEquals(1, $results->getResultCount(), 'Search for keywords with umlauts returned correct number of results.');
     $this->assertEquals($this->getItemIds(array(1)), array_keys($results->getResultItems()), 'Search for keywords with umlauts returned correct result.');
     $this->assertIgnored($results);
     $this->assertWarnings($results);
     $results = $this->buildSearch()->addCondition('keywords', 'grape', '<>')->execute();
     $this->assertEquals(2, $results->getResultCount(), 'Negated filter on multi-valued field returned correct number of results.');
     $this->assertEquals($this->getItemIds(array(1, 3)), array_keys($results->getResultItems()), 'Negated filter on multi-valued field returned correct result.');
     $this->assertIgnored($results);
     $this->assertWarnings($results);
     // Regression tests for #2511860.
     $query = $this->buildSearch();
     $query->addCondition('body', 'ab xy');
     $results = $query->execute();
     $this->assertEquals(5, $results->getResultCount(), 'Fulltext filters on short words do not change the result.');
     $query = $this->buildSearch();
     $query->addCondition('body', 'ab ab');
     $results = $query->execute();
     $this->assertEquals(5, $results->getResultCount(), 'Fulltext filters on duplicate short words do not change the result.');
 }
 /**
  * Test that the "Alter processors test backend" actually alters processors.
  *
  * @see https://www.drupal.org/node/2228739
  */
 public function testLimitProcessors()
 {
     $this->loadProcessorsTab();
     $this->assertResponse(200);
     $this->assertText($this->t('Highlight'));
     $this->assertText($this->t('Ignore character'));
     $this->assertText($this->t('Tokenizer'));
     $this->assertText($this->t('Stopwords'));
     // Create a new server with the "search_api_test_backend" backend.
     $server = Server::create(array('id' => 'webtest_server', 'name' => 'WebTest server', 'description' => 'WebTest server', 'backend' => 'search_api_test_backend', 'backend_config' => array()));
     $server->save();
     $key = 'search_api_test_backend.discouraged_processors';
     $processors = array('highlight', 'ignore_character', 'tokenizer', 'stopwords');
     \Drupal::state()->set($key, $processors);
     // Use the newly created server.
     $settings_path = 'admin/config/search/search-api/index/' . $this->indexId . '/edit';
     $this->drupalGet($settings_path);
     $this->drupalPostForm(NULL, array('server' => 'webtest_server'), $this->t('Save'));
     // Load the processors again and check that they are not shown anymore.
     $this->loadProcessorsTab();
     $this->assertResponse(200);
     $this->assertNoText($this->t('Highlight'));
     $this->assertNoText($this->t('Ignore character'));
     $this->assertNoText($this->t('Tokenizer'));
     $this->assertNoText($this->t('Stopwords'));
 }