function BulkDeleteTest::setUp

Set the default field storage backend for fields created during tests.

Overrides FieldTestBase::setUp

File

drupal/core/modules/field/lib/Drupal/field/Tests/BulkDeleteTest.php, line 94
Definition of Drupal\field\Tests\BulkDeleteTest.

Class

BulkDeleteTest
Unit test class for field bulk delete and batch purge functionality.

Namespace

Drupal\field\Tests

Code

function setUp() {
  parent::setUp();
  $this->fields = array();
  $this->instances = array();
  $this->entities = array();
  $this->entities_by_bundles = array();

  // Create two bundles.
  $this->bundles = array(
    'bb_1' => 'bb_1',
    'bb_2' => 'bb_2',
  );
  foreach ($this->bundles as $name => $desc) {
    field_test_create_bundle($name, $desc);
  }

  // Create two fields.
  $field = array(
    'field_name' => 'bf_1',
    'type' => 'test_field',
    'cardinality' => 1,
  );
  $this->fields[] = field_create_field($field);
  $field = array(
    'field_name' => 'bf_2',
    'type' => 'test_field',
    'cardinality' => 4,
  );
  $this->fields[] = field_create_field($field);

  // For each bundle, create an instance of each field, and 10
  // entities with values for each field.
  $id = 1;
  $this->entity_type = 'test_entity';
  foreach ($this->bundles as $bundle) {
    foreach ($this->fields as $field) {
      $instance = array(
        'field_name' => $field['field_name'],
        'entity_type' => $this->entity_type,
        'bundle' => $bundle,
        'widget' => array(
          'type' => 'test_field_widget',
        ),
      );
      $this->instances[] = field_create_instance($instance);
    }
    for ($i = 0; $i < 10; $i++) {
      $entity = field_test_create_entity($id, $id, $bundle);
      foreach ($this->fields as $field) {
        $entity->{$field['field_name']}[LANGUAGE_NOT_SPECIFIED] = $this
          ->_generateTestFieldValues($field['cardinality']);
      }
      $entity
        ->save();
      $id++;
    }
  }
  $this->entities = entity_load_multiple($this->entity_type, range(1, $id));
  foreach ($this->entities as $entity) {

    // Also keep track of the entities per bundle.
    $this->entities_by_bundles[$entity->fttype][$entity->ftid] = $entity;
  }
}