function ConditionTest::testSimpleCondition

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/Database/ConditionTest.php \Drupal\Tests\Core\Database\ConditionTest::testSimpleCondition()
  2. 8.9.x core/tests/Drupal/Tests/Core/Database/ConditionTest.php \Drupal\Tests\Core\Database\ConditionTest::testSimpleCondition()
  3. 10 core/tests/Drupal/Tests/Core/Database/ConditionTest.php \Drupal\Tests\Core\Database\ConditionTest::testSimpleCondition()

@covers ::compile @dataProvider providerSimpleCondition

File

core/tests/Drupal/Tests/Core/Database/ConditionTest.php, line 42

Class

ConditionTest
@coversDefaultClass \Drupal\Core\Database\Query\Condition

Namespace

Drupal\Tests\Core\Database

Code

public function testSimpleCondition($expected, $field_name) : void {
    $connection = $this->prophesize(Connection::class);
    $connection->escapeField($field_name)
        ->will(function ($args) {
        return preg_replace('/[^A-Za-z0-9_.]+/', '', $args[0]);
    });
    $connection->mapConditionOperator('=')
        ->willReturn([
        'operator' => '=',
    ]);
    $connection->condition('AND')
        ->willReturn(new Condition('AND'));
    $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_name, 'value');
    $condition->compile($connection, $query_placeholder);
    $this->assertEquals($expected, $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.