public function EntityReferenceTaxonomyTestCase::setUp in Entity reference 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
- tests/
entityreference.taxonomy.test, line 15
Class
- EntityReferenceTaxonomyTestCase
- Test for Entity Reference taxonomy integration.
Code
public function setUp() {
parent::setUp('entityreference', 'taxonomy');
// Create an entity reference field.
$field = array(
'entity_types' => array(
'node',
),
'settings' => array(
'handler' => 'base',
'target_type' => 'taxonomy_term',
'handler_settings' => array(
'target_bundles' => array(),
),
),
'field_name' => 'field_entityreference_term',
'type' => 'entityreference',
);
$field = field_create_field($field);
$instance = array(
'field_name' => 'field_entityreference_term',
'bundle' => 'article',
'entity_type' => 'node',
);
// Enable the taxonomy-index behavior.
$instance['settings']['behaviors']['taxonomy-index']['status'] = TRUE;
field_create_instance($instance);
// Create a term reference field.
$field = array(
'translatable' => FALSE,
'entity_types' => array(
'node',
),
'settings' => array(
'allowed_values' => array(
array(
'vocabulary' => 'terms',
'parent' => 0,
),
),
),
'field_name' => 'field_taxonomy_term',
'type' => 'taxonomy_term_reference',
);
$field = field_create_field($field);
$instance = array(
'field_name' => 'field_taxonomy_term',
'bundle' => 'article',
'entity_type' => 'node',
);
field_create_instance($instance);
// Create a terms vocobulary.
$vocabulary = new stdClass();
$vocabulary->name = 'Terms';
$vocabulary->machine_name = 'terms';
taxonomy_vocabulary_save($vocabulary);
// Create term.
for ($i = 1; $i <= 2; $i++) {
$term = new stdClass();
$term->name = "term {$i}";
$term->vid = 1;
taxonomy_term_save($term);
}
}