1 field.test FieldBulkDeleteTestCase::setUp()

Sets up a Backdrop site for running functional and integration tests.

Generates a random database prefix and installs Backdrop with the specified installation profile in BackdropWebTestCase::$profile into the prefixed database. Afterwards, installs any additional modules specified by the test.

After installation all caches are flushed and several configuration values are reset to the values of the parent site executing the test, since the default values may be incompatible with the environment in which tests are being executed.

Parameters

...: List of modules to enable for the duration of the test. This can be either a single array or a variable number of string arguments.

Return value

bool: TRUE if set up completes, FALSE if an error occurred.

Overrides BackdropWebTestCase::setUp

See also

BackdropWebTestCase::prepareDatabasePrefix()

BackdropWebTestCase::changeDatabasePrefix()

BackdropWebTestCase::prepareEnvironment()

File

core/modules/field/tests/field.test, line 3237
Tests for field.module.

Class

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

Code

function setUp() {
  parent::setUp('field_test');

  $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 = 0;
  $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_NONE] = $this->_generateTestFieldValues($field['cardinality']);
      }

      $this->entities[$id] = $entity;
      // Also keep track of the entities per bundle.
      $this->entities_by_bundles[$bundle][$id] = $entity;
      field_attach_insert($this->entity_type, $entity);
      $id++;
    }
  }
}