You are here

protected function EntityQueryRelationshipTest::assertJoinColumn in Dynamic Entity Reference 8.2

Helper method to check which column was joined on.

Parameters

\Drupal\Core\Entity\Query\QueryInterface $query: The executed query.

string $field_name: The field name being used in the join.

string $target_type: The target entity type.

bool $integer_column: TRUE if the expected join column is the `_target_id_int`, FALSE otherwise.

2 calls to EntityQueryRelationshipTest::assertJoinColumn()
EntityQueryRelationshipTest::testEntityQuery in tests/src/Kernel/EntityQueryRelationshipTest.php
Tests entity query for DER for entities with integer IDs.
EntityQueryRelationshipTest::testEntityQueryString in tests/src/Kernel/EntityQueryRelationshipTest.php
Tests entity query for DER for entities with string IDs.

File

tests/src/Kernel/EntityQueryRelationshipTest.php, line 219

Class

EntityQueryRelationshipTest
Tests dynamic entity reference relationship data.

Namespace

Drupal\Tests\dynamic_entity_reference\Kernel

Code

protected function assertJoinColumn(QueryInterface $query, $field_name, $target_type, $integer_column = TRUE) {

  // @todo Is there a better way than reflection?
  $reflection = new \ReflectionObject($query);
  $property = $reflection
    ->getProperty('sqlQuery');
  $property
    ->setAccessible(TRUE);
  $sql = (string) $property
    ->getValue($query);
  if ($integer_column) {
    $this
      ->assertTrue(strpos($sql, "[{$field_name}_target_id_int] AND ") !== FALSE, 'Query joined on target_id_int column.');
  }
  else {
    $this
      ->assertTrue(strpos($sql, "[{$field_name}_target_id] AND ") !== FALSE, 'Query joined on target_id column.');
  }
  $this
    ->assertTrue(strpos($sql, "[{$field_name}_target_type] = '{$target_type}'") !== FALSE, 'Query joined on target_type column.');
}