You are here

public function SelectComplexTest::testJoinTwice in Drupal 8

Same name and namespace in other branches
  1. 9 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 325

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', 'othername');
  $query
    ->addField($alias, 'job', 'otherjob');
  $query
    ->where("{$alias}.name <> test.name");
  $crowded_job = $query
    ->execute()
    ->fetch();
  $this
    ->assertEqual($crowded_job->job, $crowded_job->otherjob, 'Correctly joined same table twice.');
  $this
    ->assertNotEqual($crowded_job->name, $crowded_job->othername, 'Correctly joined same table twice.');
}