public function ConditionTest::testCompileWithKnownOperators in Drupal 9
Same name and namespace in other branches
- 8 core/tests/Drupal/Tests/Core/Database/ConditionTest.php \Drupal\Tests\Core\Database\ConditionTest::testCompileWithKnownOperators()
@covers ::compile
@dataProvider dataProviderTestCompileWithKnownOperators()
Parameters
string $expected: The expected generated SQL condition.
string $field: The field to pass into the condition() method.
mixed $value: The value to pass into the condition() method.
string $operator: The operator to pass into the condition() method.
mixed $expected_arguments: (optional) The expected set arguments.
File
- core/
tests/ Drupal/ Tests/ Core/ Database/ ConditionTest.php, line 80
Class
- ConditionTest
- @coversDefaultClass \Drupal\Core\Database\Query\Condition
Namespace
Drupal\Tests\Core\DatabaseCode
public function testCompileWithKnownOperators($expected, $field, $value, $operator, $expected_arguments = NULL) {
$connection = $this
->prophesize(Connection::class);
$connection
->escapeField(Argument::any())
->will(function ($args) {
return preg_replace('/[^A-Za-z0-9_.]+/', '', $args[0]);
});
$connection
->mapConditionOperator(Argument::any())
->willReturn(NULL);
$connection
->condition('AND')
->willReturn(new Condition('AND', FALSE));
$connection = $connection
->reveal();
$query_placeholder = $this
->prophesize(PlaceholderInterface::class);
$counter = 0;
$query_placeholder
->nextPlaceholder()
->will(function () use (&$counter) {
return $counter++;
});
$query_placeholder
->uniqueIdentifier()
->willReturn(4);
$query_placeholder = $query_placeholder
->reveal();
$condition = $connection
->condition('AND');
$condition
->condition($field, $value, $operator);
$condition
->compile($connection, $query_placeholder);
$this
->assertEquals($expected, $condition
->__toString());
if (isset($expected_arguments)) {
$this
->assertEquals($expected_arguments, $condition
->arguments());
}
}