public function CommerceProductUIAdminTest::testCommerceProductUIDeleteProductTypeWithProducts in Commerce Core 7
Delete a product type that already has products.
File
- modules/
product/ tests/ commerce_product_ui.test, line 498 - Functional tests for the commerce product ui module.
Class
- CommerceProductUIAdminTest
- Test the product and product type CRUD.
Code
public function testCommerceProductUIDeleteProductTypeWithProducts() {
// Create dummy product.
$product = $this
->createDummyProduct('PROD-01', 'Product One');
// Login with store admin.
$this
->drupalLogin($this->store_admin);
// Access to the delete page for a product type.
$this
->drupalGet('admin/commerce/products/types/product/delete');
// Load product types.
$product_types = commerce_product_types();
// As the product type has at least one product, it souldn't permit to be
// deleted.
$this
->pass(t('Product type has at least one product, test the validation messages:'));
$this
->assertTitle(t('Cannot delete the !name product type', array(
'!name' => $product_types['product']['name'],
)) . ' | Drupal', t('Validation title of the page displayed correctly.'));
// Get the count of products of the type
$query = new EntityFieldQuery();
$query
->entityCondition('entity_type', 'commerce_product', '=')
->entityCondition('bundle', $product_types['product']['type'], '=')
->count();
$count = $query
->execute();
$message = format_plural($count, 'There is 1 product of this type. It cannot be deleted.', 'There are @count products of this type. It cannot be deleted.');
$this
->assertText($message, t('Display the reason why the product type cannot be deleted and show the number of products related to it'));
}