You are here

public function EntityQueryTest::testBaseFieldMultipleColumns in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/KernelTests/Core/Entity/EntityQueryTest.php \Drupal\KernelTests\Core\Entity\EntityQueryTest::testBaseFieldMultipleColumns()
  2. 10 core/tests/Drupal/KernelTests/Core/Entity/EntityQueryTest.php \Drupal\KernelTests\Core\Entity\EntityQueryTest::testBaseFieldMultipleColumns()

Tests base fields with multiple columns.

File

core/tests/Drupal/KernelTests/Core/Entity/EntityQueryTest.php, line 1029

Class

EntityQueryTest
Tests Entity Query functionality.

Namespace

Drupal\KernelTests\Core\Entity

Code

public function testBaseFieldMultipleColumns() {
  $this
    ->enableModules([
    'taxonomy',
  ]);
  $this
    ->installEntitySchema('taxonomy_term');
  Vocabulary::create([
    'vid' => 'tags',
  ]);
  $term1 = Term::create([
    'name' => $this
      ->randomMachineName(),
    'vid' => 'tags',
    'description' => [
      'value' => 'description1',
      'format' => 'format1',
    ],
  ]);
  $term1
    ->save();
  $term2 = Term::create([
    'name' => $this
      ->randomMachineName(),
    'vid' => 'tags',
    'description' => [
      'value' => 'description2',
      'format' => 'format2',
    ],
  ]);
  $term2
    ->save();

  // Test that the properties can be queried directly.
  $ids = $this->container
    ->get('entity_type.manager')
    ->getStorage('taxonomy_term')
    ->getQuery()
    ->accessCheck(FALSE)
    ->condition('description.value', 'description1')
    ->execute();
  $this
    ->assertCount(1, $ids);
  $this
    ->assertEquals($term1
    ->id(), reset($ids));
  $ids = $this->container
    ->get('entity_type.manager')
    ->getStorage('taxonomy_term')
    ->getQuery()
    ->accessCheck(FALSE)
    ->condition('description.format', 'format1')
    ->execute();
  $this
    ->assertCount(1, $ids);
  $this
    ->assertEquals($term1
    ->id(), reset($ids));

  // Test that the main property is queried if no property is specified.
  $ids = $this->container
    ->get('entity_type.manager')
    ->getStorage('taxonomy_term')
    ->getQuery()
    ->accessCheck(FALSE)
    ->condition('description', 'description1')
    ->execute();
  $this
    ->assertCount(1, $ids);
  $this
    ->assertEquals($term1
    ->id(), reset($ids));
}