public function SerializationTest::testQueryCloning in Search API 8
Tests that cloning of search queries works correctly.
File
- tests/
src/ Kernel/ System/ SerializationTest.php, line 154
Class
- SerializationTest
- Tests that various classes can be properly serialized and/or cloned.
Namespace
Drupal\Tests\search_api\Kernel\SystemCode
public function testQueryCloning() {
$query = $this
->createTestQuery();
// Since Drupal's DB layer sometimes has problems with side-effects of
// __toString(), we here try to make sure this won't happen to us.
$this
->assertIsString((string) $query);
$clone = clone $query;
// Modify the original query. None of this should change the clone in any
// way.
$query
->setOption('test1', 'foo');
$query
->getParseMode()
->setConjunction('AND');
$query
->addCondition('test1', 'bar');
$condition_group_1 = $query
->getConditionGroup()
->getConditions()[1];
$condition_group_2 = $condition_group_1
->getConditions()[2];
$condition_group_3 = $query
->createConditionGroup('AND');
$condition_group_1
->addCondition('test1', 'foobar');
$condition_group_2
->addCondition('test1', 'foobar');
$condition_group_3
->addCondition('test1', 'foobar');
$query
->getResults()
->addWarning('This query is very dumb.');
$query_2 = $this
->createTestQuery();
$this
->assertEquals($query_2, $clone);
$this
->assertNotSame($query
->getResults(), $clone
->getResults());
$this
->assertNotSame($query
->getResults(), $query_2
->getResults());
$this
->assertNotSame($query
->getConditionGroup(), $clone
->getConditionGroup());
$this
->assertNotSame($query
->getConditionGroup(), $query_2
->getConditionGroup());
$this
->assertNotSame($query
->getParseMode(), $clone
->getParseMode());
$this
->assertNotSame($query
->getParseMode(), $query_2
->getParseMode());
}