function EntityQueryTest::testBaseFieldMultipleColumns

Same name in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Entity/EntityQueryTest.php \Drupal\KernelTests\Core\Entity\EntityQueryTest::testBaseFieldMultipleColumns()
  2. 8.9.x core/tests/Drupal/KernelTests/Core/Entity/EntityQueryTest.php \Drupal\KernelTests\Core\Entity\EntityQueryTest::testBaseFieldMultipleColumns()
  3. 11.x 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 1059

Class

EntityQueryTest
Tests Entity Query functionality.

Namespace

Drupal\KernelTests\Core\Entity

Code

public function testBaseFieldMultipleColumns() : void {
    $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));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.