You are here

public function SelectComplexTest::testJoinTwice in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/KernelTests/Core/Database/SelectComplexTest.php \Drupal\KernelTests\Core\Database\SelectComplexTest::testJoinTwice()

Confirms we can join on a single table twice with a dynamic alias.

File

core/tests/Drupal/KernelTests/Core/Database/SelectComplexTest.php, line 329

Class

SelectComplexTest
Tests the Select query builder with more complex queries.

Namespace

Drupal\KernelTests\Core\Database

Code

public function testJoinTwice() {
  $query = $this->connection
    ->select('test')
    ->fields('test');
  $alias = $query
    ->join('test', 'test', '[test].[job] = [%alias].[job]');
  $query
    ->addField($alias, 'name', 'other_name');
  $query
    ->addField($alias, 'job', 'other_job');
  $query
    ->where("[{$alias}].[name] <> [test].[name]");
  $crowded_job = $query
    ->execute()
    ->fetch();
  $this
    ->assertEquals($crowded_job->other_job, $crowded_job->job, 'Correctly joined same table twice.');
  $this
    ->assertNotEquals($crowded_job->other_name, $crowded_job->name, 'Correctly joined same table twice.');
}