public function CommerceProductReferenceAdminTest::testCommerceProductReferenceAttachToUser in Commerce Core 7
Test if the field is correctly attached to a user.
File
- modules/
product_reference/ tests/ commerce_product_reference.test, line 152 - Tests for adding and displaying product reference fields.
Class
- CommerceProductReferenceAdminTest
- Functional tests for the Product Reference module.
Code
public function testCommerceProductReferenceAttachToUser() {
// Access user manage fields page.
$this
->drupalGet('admin/config/people/accounts/fields');
// Add a new product reference field
$edit = array(
'fields[_add_new_field][label]' => 'Product',
'fields[_add_new_field][field_name]' => 'user_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 field instance settings.
$this
->drupalPost(NULL, array(
'instance[settings][user_register_form]' => 1,
), t('Save settings'));
// Clear field's cache.
field_cache_clear();
// Check the field at database level.
$field = field_info_field('field_user_product');
$field_instance = field_info_instance('user', 'field_user_product', 'user');
$this
->assertTrue(in_array('user', $field['bundles']['user']), t('Field is present in the user'));
$this
->assertTrue($field_instance['field_name'] == 'field_user_product', t('Field instance is present in the user bundle'));
// Check in the admin page for the user display.
$this
->drupalGet('admin/config/people/accounts/fields');
$this
->assertText('Product', t('Reference product field label found'));
$this
->assertText('field_user_product', t('Reference product field name found'));
// The product selector should appear in the product display creation page.
$this
->drupalGet('admin/people/create');
$this
->assertFieldById('edit-field-user-product-und', NULL, t('Field selector is present in user creation'));
}