public function MongoDbEntityFieldQueryTestCase::setUp in MongoDB 7
Sets up a Drupal site for running functional and integration tests.
Generates a random database prefix and installs Drupal with the specified installation profile in DrupalWebTestCase::$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.
Overrides DrupalWebTestCase::setUp
See also
DrupalWebTestCase::prepareDatabasePrefix()
DrupalWebTestCase::changeDatabasePrefix()
DrupalWebTestCase::prepareEnvironment()
File
- mongodb_field_storage/
mongodb_field_storage.test, line 55 - Contains MongoDB Field AttachStorage and Query TestCases.
Class
Code
public function setUp() {
parent::setUp(array(
'mongodb',
'mongodb_field_storage',
'field_test',
));
variable_set('field_storage_default', 'mongodb_field_storage');
field_attach_create_bundle('bundle1', 'test_entity_bundle_key');
field_attach_create_bundle('bundle2', 'test_entity_bundle_key');
field_attach_create_bundle('test_bundle', 'test_entity');
field_attach_create_bundle('test_entity_bundle', 'test_entity_bundle');
$instances = array();
$this->fields = array();
$this->field_names[0] = $field_name = drupal_strtolower($this
->randomName() . '_field_name');
$field = array(
'field_name' => $field_name,
'type' => 'test_field',
);
$field = field_create_field($field);
$this->fields[0] = $field;
$instance = array(
'field_name' => $field_name,
'entity_type' => '',
'bundle' => '',
'label' => $this
->randomName() . '_label',
'description' => $this
->randomName() . '_description',
'weight' => mt_rand(0, 127),
'settings' => array(
'test_instance_setting' => $this
->randomName(),
),
'widget' => array(
'type' => 'test_field_widget',
'label' => 'Test Field',
'settings' => array(
'test_widget_setting' => $this
->randomName(),
),
),
);
$instances[0] = $instance;
// Add an instance to that bundle.
$instances[0]['bundle'] = 'bundle1';
$instances[0]['entity_type'] = 'test_entity_bundle_key';
field_create_instance($instances[0]);
$instances[0]['bundle'] = $instances[0]['entity_type'] = 'test_entity_bundle';
field_create_instance($instances[0]);
$this->field_names[1] = $field_name = drupal_strtolower($this
->randomName() . '_field_name');
$field = array(
'field_name' => $field_name,
'type' => 'shape',
'cardinality' => 4,
);
$field = field_create_field($field);
$this->fields[1] = $field;
$instance = array(
'field_name' => $field_name,
'entity_type' => '',
'bundle' => '',
'label' => $this
->randomName() . '_label',
'description' => $this
->randomName() . '_description',
'weight' => mt_rand(0, 127),
'settings' => array(
'test_instance_setting' => $this
->randomName(),
),
'widget' => array(
'type' => 'test_field_widget',
'label' => 'Test Field',
'settings' => array(
'test_widget_setting' => $this
->randomName(),
),
),
);
$instances[1] = $instance;
// Add an instance to that bundle.
$instances[1]['bundle'] = 'bundle2';
$instances[1]['entity_type'] = 'test_entity_bundle_key';
field_create_instance($instances[1]);
$instances[1]['bundle'] = $instances[1]['entity_type'] = 'test_entity_bundle';
field_create_instance($instances[1]);
$this->instances = $instances;
$key = 1;
// Create entities which have a 'bundle key' defined.
for ($i = 1; $i < 7; $i++) {
$entity = new stdClass();
$entity->ftid = $i;
if ($i == 5) {
$key++;
}
$entity->fttype = "bundle{$key}";
$entity->{$this->field_names[$key - 1]}[LANGUAGE_NONE][0]['value'] = $i;
drupal_write_record('test_entity_bundle_key', $entity);
field_attach_insert('test_entity_bundle_key', $entity);
}
$entity = new stdClass();
$entity->ftid = 5;
$entity->fttype = 'bundle2';
$entity->{$this->field_names[1]}[LANGUAGE_NONE][0]['shape'] = 'square';
$entity->{$this->field_names[1]}[LANGUAGE_NONE][0]['color'] = 'red';
$entity->{$this->field_names[1]}[LANGUAGE_NONE][1]['shape'] = 'circle';
$entity->{$this->field_names[1]}[LANGUAGE_NONE][1]['color'] = 'blue';
drupal_write_record('test_entity_bundle', $entity);
field_attach_insert('test_entity_bundle', $entity);
$instances[2] = $instance;
$instances[2]['bundle'] = 'test_bundle';
$instances[2]['field_name'] = $this->field_names[0];
$instances[2]['entity_type'] = 'test_entity';
field_create_instance($instances[2]);
// Create entities with support for revisions.
for ($i = 1; $i < 5; $i++) {
$entity = new stdClass();
$entity->ftid = $i;
$entity->ftvid = $i;
$entity->fttype = 'test_bundle';
$entity->{$this->field_names[0]}[LANGUAGE_NONE][0]['value'] = $i;
drupal_write_record('test_entity', $entity);
field_attach_insert('test_entity', $entity);
drupal_write_record('test_entity_revision', $entity);
}
// Add two revisions to an entity.
for ($i = 100; $i < 102; $i++) {
$entity = new stdClass();
$entity->ftid = 4;
$entity->ftvid = $i;
$entity->fttype = 'test_bundle';
$entity->{$this->field_names[0]}[LANGUAGE_NONE][0]['value'] = $i;
drupal_write_record('test_entity', $entity, 'ftid');
drupal_write_record('test_entity_revision', $entity);
db_update('test_entity')
->fields(array(
'ftvid' => $entity->ftvid,
))
->condition('ftid', $entity->ftid)
->execute();
field_attach_update('test_entity', $entity);
}
}