function CommerceProductReferenceAdminTest::setUp in Commerce Core 7
Implementation of setUp().
Overrides DrupalWebTestCase::setUp
File
- modules/
product_reference/ tests/ commerce_product_reference.test, line 51 - Tests for adding and displaying product reference fields.
Class
- CommerceProductReferenceAdminTest
- Functional tests for the Product Reference module.
Code
function setUp() {
$modules = parent::setUpHelper('all');
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');
$this->products[2] = $this
->createDummyProduct('PROD-02', 'Product Two');
// 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'));
// Save the field settings, which are empty.
$this
->drupalPost(NULL, array(), t('Save field settings'));
// Save the default field instance settings.
$this
->drupalPost(NULL, array(), t('Save settings'));
// Clear field's cache.
field_cache_clear();
// 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);
}