function ConditionTest::testCompileWithFieldSuffixOperator
Same name and namespace in other branches
- main core/tests/Drupal/Tests/Core/Database/ConditionTest.php \Drupal\Tests\Core\Database\ConditionTest::testCompileWithFieldSuffixOperator()
Tests compile with an operator that appends a suffix to the field.
@legacy-covers ::compile
File
-
core/
tests/ Drupal/ Tests/ Core/ Database/ ConditionTest.php, line 193
Class
Namespace
Drupal\Tests\Core\DatabaseCode
public function testCompileWithFieldSuffixOperator() : void {
$connection = $this->createStub(Connection::class);
$connection->method('escapeField')
->willReturnCallback(function (string $field) : string|array|null {
return preg_replace('/[^A-Za-z0-9_.]+/', '', $field);
});
$connection->method('mapConditionOperator')
->willReturn([
'operator' => 'ILIKE',
'field_suffix' => '::text',
]);
$connection->method('condition')
->willReturn(new Condition('AND'));
$query_placeholder = $this->prophesize(PlaceholderInterface::class);
$counter = 0;
$query_placeholder->nextPlaceholder()
->will(function () use (&$counter) : int {
return $counter++;
});
$query_placeholder->uniqueIdentifier()
->willReturn(4);
$query_placeholder = $query_placeholder->reveal();
$condition = $connection->condition('AND');
$condition->condition('name', '%value%', 'LIKE');
$condition->compile($connection, $query_placeholder);
$this->assertEquals('name::text ILIKE :db_condition_placeholder_0', $condition->__toString());
$this->assertEquals([
':db_condition_placeholder_0' => '%value%',
], $condition->arguments());
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.