You are here

protected function SerializationTest::createTestQuery in Search API 8

Creates a search query for use in this test.

Return value

\Drupal\search_api\Query\QueryInterface A test query.

2 calls to SerializationTest::createTestQuery()
SerializationTest::testQueryCloning in tests/src/Kernel/System/SerializationTest.php
Tests that cloning of search queries works correctly.
SerializationTest::testQuerySerialization in tests/src/Kernel/System/SerializationTest.php
Tests that serialization of search queries works correctly.

File

tests/src/Kernel/System/SerializationTest.php, line 269

Class

SerializationTest
Tests that various classes can be properly serialized and/or cloned.

Namespace

Drupal\Tests\search_api\Kernel\System

Code

protected function createTestQuery() {
  $query = $this->index
    ->query([
    'foo' => 'bar',
  ]);
  $query
    ->getParseMode()
    ->setConjunction('OR');
  $query
    ->keys('test foobar');
  $query
    ->setFulltextFields([
    'foo',
    'bar',
  ]);
  $query
    ->addCondition('title', 'foo', '<>');
  $condition_group_1 = $query
    ->createConditionGroup('OR', [
    'foobar',
  ]);
  $condition_group_1
    ->addCondition('foo', 'bar');
  $query
    ->addConditionGroup($condition_group_1);
  $condition_group_1
    ->addCondition('bar', [
    1,
    5,
  ], 'BETWEEN');
  $condition_group_2 = $query
    ->createConditionGroup('AND', [
    'baz',
  ]);
  $condition_group_2
    ->addCondition('baz', 2, '>');
  $condition_group_2
    ->addCondition('baz', NULL, '<>');
  $condition_group_1
    ->addConditionGroup($condition_group_2);
  $query
    ->addTag('serialization_test');
  $query
    ->getResults()
    ->addWarning('This query is dumb.');
  return $query;
}