You are here

public function ConditionTest::testContribCondition in Drupal 8

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/Database/ConditionTest.php \Drupal\Tests\Core\Database\ConditionTest::testContribCondition()
  2. 10 core/tests/Drupal/Tests/Core/Database/ConditionTest.php \Drupal\Tests\Core\Database\ConditionTest::testContribCondition()

Test that the core Condition can be overridden.

File

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

Class

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

Namespace

Drupal\Tests\Core\Database

Code

public function testContribCondition() {
  $mockCondition = $this
    ->getMockBuilder(Condition::class)
    ->setMockClassName('MockCondition')
    ->setConstructorArgs([
    NULL,
  ])
    ->disableOriginalConstructor()
    ->getMock();
  $contrib_namespace = 'Drupal\\Driver\\Database\\mock';
  $mocked_namespace = $contrib_namespace . '\\Condition';
  class_alias('MockCondition', $mocked_namespace);
  $options['namespace'] = $contrib_namespace;
  $options['prefix']['default'] = '';
  $mockPdo = $this
    ->createMock(StubPDO::class);
  $connection = $this
    ->getMockBuilder(Connection::class)
    ->setConstructorArgs([
    $mockPdo,
    $options,
  ])
    ->getMockForAbstractClass();
  $condition = $connection
    ->condition('AND');
  $this
    ->assertSame('MockCondition', get_class($condition));
}