You are here

public function FieldDataCountTest::testCountWithIndex0 in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/field/src/Tests/FieldDataCountTest.php \Drupal\field\Tests\FieldDataCountTest::testCountWithIndex0()

Verify that we can count a table that contains an entry with index 0.

File

core/modules/field/src/Tests/FieldDataCountTest.php, line 150
Contains \Drupal\field\Tests\FieldDataCountTest.

Class

FieldDataCountTest
Tests counting field data records and the hasData() method on FieldStorageConfig entity.

Namespace

Drupal\field\Tests

Code

public function testCountWithIndex0() {

  // Create a field that will require dedicated storage.

  /** @var \Drupal\field\Entity\FieldStorageConfig $field_storage */
  $field_storage = FieldStorageConfig::create(array(
    'field_name' => 'field_int',
    'entity_type' => 'user',
    'type' => 'integer',
    'cardinality' => 2,
  ));
  $field_storage
    ->save();
  FieldConfig::create(array(
    'field_storage' => $field_storage,
    'bundle' => 'user',
  ))
    ->save();

  // Create an entry for the anonymous user, who has user ID 0.
  $user = $this->storageUser
    ->create(array(
    'uid' => 0,
    'name' => 'anonymous',
    'mail' => NULL,
    'status' => FALSE,
    'field_int' => 42,
  ));
  $user
    ->save();

  // Test shared table storage.
  $storage = $user
    ->getFieldDefinition('name')
    ->getFieldStorageDefinition();
  $this
    ->assertIdentical(TRUE, $this->storageUser
    ->countFieldData($storage, TRUE));

  // Test dedicated table storage.
  $storage = $user
    ->getFieldDefinition('field_int')
    ->getFieldStorageDefinition();
  $this
    ->assertIdentical(TRUE, $this->storageUser
    ->countFieldData($storage, TRUE));
}