public function SqlsrvConditionTest::testRegexp in Drupal driver for SQL Server and SQL Azure 4.1.x
Same name and namespace in other branches
- 8.2 tests/src/Unit/SqlsrvConditionTest.php \Drupal\Tests\sqlsrv\Unit\SqlsrvConditionTest::testRegexp()
- 4.2.x tests/src/Unit/SqlsrvConditionTest.php \Drupal\Tests\sqlsrv\Unit\SqlsrvConditionTest::testRegexp()
- 3.0.x tests/src/Unit/SqlsrvConditionTest.php \Drupal\Tests\sqlsrv\Unit\SqlsrvConditionTest::testRegexp()
- 3.1.x tests/src/Unit/SqlsrvConditionTest.php \Drupal\Tests\sqlsrv\Unit\SqlsrvConditionTest::testRegexp()
- 4.0.x tests/src/Unit/SqlsrvConditionTest.php \Drupal\Tests\sqlsrv\Unit\SqlsrvConditionTest::testRegexp()
Test the REGEXP operator string replacement.
@dataProvider dataProviderForTestRegexp
File
- tests/
src/ Unit/ SqlsrvConditionTest.php, line 95
Class
- SqlsrvConditionTest
- Test the behavior of the custom Condition class.
Namespace
Drupal\Tests\sqlsrv\UnitCode
public function testRegexp($expected, $field_name, $operator, $pattern) {
$connection = $this
->prophesize(Connection::class);
$connection
->escapeField($field_name)
->will(function ($args) {
return preg_replace('/[^A-Za-z0-9_.]+/', '', $args[0]);
});
$connection
->mapConditionOperator($operator)
->willReturn([
'operator' => $operator,
]);
$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 = new Condition('AND');
$condition
->condition($field_name, $pattern, $operator);
$condition
->compile($connection, $query_placeholder);
$this
->assertEquals($expected, $condition
->__toString());
$this
->assertEquals([
':db_condition_placeholder_0' => $pattern,
], $condition
->arguments());
}