function CommerceReferenceTableFormatterTest::setUp in Reference Table Formatter 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/
commerce_reference_table_formatter.test, line 14
Class
Code
function setUp() {
$modules = parent::setUpHelper('all');
$modules[] = 'reference_table_formatter';
parent::setUp($modules);
// Create a site admin + store admin user and login.
$this->site_admin = $this
->createUserWithPermissionHelper(array(
'site admin',
'store admin',
));
$this
->drupalLogin($this->site_admin);
// Create a dummy product display content type without product reference
// fields.
$this->display_type = $this
->createDummyProductDisplayContentType('product_display', FALSE);
// Create dummy product entities.
$this->products[1] = $this
->createDummyProduct('PROD-01', 'Product One', 2500);
$this->products[2] = $this
->createDummyProduct('PROD-02', 'Product Two', 3500);
// Access to the manage fields screen.
$this
->drupalGet('admin/structure/types/manage/' . strtr($this->display_type->type, '_', '-') . '/fields');
// Add a new product reference field
$edit = array(
'fields[_add_new_field][label]' => 'Product',
'fields[_add_new_field][field_name]' => 'product',
'fields[_add_new_field][type]' => 'commerce_product_reference',
'fields[_add_new_field][widget_type]' => 'options_select',
);
$this
->drupalPost(NULL, $edit, t('Save'));
$this
->drupalPost(NULL, array(), t('Save field settings'));
// Save the default field instance settings.
$this
->drupalPost(NULL, array(
'field[cardinality]' => FIELD_CARDINALITY_UNLIMITED,
), t('Save settings'));
// Clear field's cache.
field_cache_clear();
cache_clear_all();
// Get the field information just saved.
$this->field_name = 'field_product';
$this->field = field_info_field($this->field_name);
$this->field_instance = field_info_instance('node', $this->field_name, $this->display_type->type);
}