protected function EntityQueryTest::testCount

Test entity count query.

File

drupal/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryTest.php, line 387
Definition of Drupal\system\Tests\Entity\EntityQueryTest.

Class

EntityQueryTest
Tests the basic Entity API.

Namespace

Drupal\system\Tests\Entity

Code

protected function testCount() {

  // Attach the existing 'figures' field to a second entity type so that we
  // can test whether cross entity type fields produce the correct query.
  $field_name = $this->figures;
  $bundle = $this
    ->randomName();
  $instance = array(
    'field_name' => $field_name,
    'entity_type' => 'test_entity_bundle',
    'bundle' => $bundle,
  );
  field_create_instance($instance);
  $entity = entity_create('test_entity_bundle', array(
    'ftid' => 1,
    'fttype' => $bundle,
  ));
  $entity
    ->enforceIsNew();
  $entity
    ->setNewRevision();
  $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->factory
    ->get('test_entity_bundle')
    ->exists("{$field_name}.color")
    ->count()
    ->execute();
  $this
    ->assertFalse($count);
}