public function CommerceProductUIAdminTest::testCommerceProductUIAddProductType in Commerce Core 7
Test adding a new product type.
File
- modules/
product/ tests/ commerce_product_ui.test, line 365 - Functional tests for the commerce product ui module.
Class
- CommerceProductUIAdminTest
- Test the product and product type CRUD.
Code
public function testCommerceProductUIAddProductType() {
// Login with normal user.
$this
->drupalLogin($this->store_customer);
// Access to the product types add form.
$this
->drupalGet('admin/commerce/products/types/add');
$this
->assertResponse(403, t('Normal user is not able to access the product types add page'));
// Login with store admin.
$this
->drupalLogin($this->store_admin);
// Access to the product types add form.
$this
->drupalGet('admin/commerce/products/types/add');
$this
->assertResponse(200, t('Store admin user can access the product types add page'));
// Create an additional product type.
$edit = array(
'product_type[name]' => 'New Product Type',
'product_type[type]' => 'new_product_type',
);
$this
->drupalPost(NULL, $edit, t('Save product type'));
// Load all product types.
commerce_product_types_reset();
$product_types = commerce_product_types();
// Check if the product type has been created in database and if it appears
// in the product types listing.
$this
->assertTrue(!empty($product_types[$edit['product_type[type]']]), t('Product type has been correctly created'));
$this
->assertEqual($this->url, url('admin/commerce/products/types', array(
'absolute' => TRUE,
)), t('Redirect page after creating a product type is the product types listing'));
$this
->assertText(t('Product type saved'), t('Message after saving a new product type is displayed'));
$this
->assertText($edit['product_type[name]'], t('Product type just created appears in product types listing'));
// Test the Add and save fields.
// Access to the product types add form.
$this
->drupalGet('admin/commerce/products/types/add');
$edit = array(
'product_type[name]' => 'Additional Product Type',
'product_type[type]' => 'additional_product_type',
);
$this
->drupalPost(NULL, $edit, t('Save and add fields'));
$this
->assertEqual($this->url, url('admin/commerce/products/types/' . strtr($edit['product_type[type]'], '_', '-') . '/fields', array(
'absolute' => TRUE,
)), t('Redirect page after creating a product type using \'Save and add fields\' button is the product type field manage screen'));
$this
->assertText(t('Product type saved'), t('Message after saving a new product type is displayed'));
$this
->assertText(t('Product SKU'), t('SKU field is present in the product type manage fields screen'));
$this
->assertText(t('Title'), t('Title field is present in the product type manage fields screen'));
$this
->assertText(t('Status'), t('Status field is present in the product type manage fields screen'));
// Check the field instances for that content type.
field_cache_clear();
$field_instances = field_info_instances('commerce_product', $edit['product_type[type]']);
foreach ($field_instances as $instance) {
$this
->assertText($instance['label'], t('Field %field is present in the product type manage fields screen', array(
'%field' => $instance['label'],
)));
}
}