public function EntityQueryTest::testCount in Drupal 9
Same name and namespace in other branches
- 8 core/tests/Drupal/KernelTests/Core/Entity/EntityQueryTest.php \Drupal\KernelTests\Core\Entity\EntityQueryTest::testCount()
Tests that count queries are separated across entity types.
File
- core/
tests/ Drupal/ KernelTests/ Core/ Entity/ EntityQueryTest.php, line 533
Class
- EntityQueryTest
- Tests Entity Query functionality.
Namespace
Drupal\KernelTests\Core\EntityCode
public function testCount() {
// Create a field with the same name in a different entity type.
$field_name = $this->figures;
$field_storage = FieldStorageConfig::create([
'field_name' => $field_name,
'entity_type' => 'entity_test',
'type' => 'shape',
'cardinality' => 2,
'translatable' => TRUE,
]);
$field_storage
->save();
$bundle = $this
->randomMachineName();
FieldConfig::create([
'field_storage' => $field_storage,
'bundle' => $bundle,
])
->save();
$entity = EntityTest::create([
'id' => 1,
'type' => $bundle,
]);
$entity
->enforceIsNew();
$entity
->save();
// As the single entity of this type we just saved does not have a value
// in the color field, the result should be 0.
$count = $this->container
->get('entity_type.manager')
->getStorage('entity_test')
->getQuery()
->accessCheck(FALSE)
->exists("{$field_name}.color")
->count()
->execute();
$this
->assertEquals(0, $count);
}