You are here

public function CommerceProductUIAdminTest::testCommerceProductUIDeleteProductType in Commerce Core 7

Delete a product type.

File

modules/product/tests/commerce_product_ui.test, line 453
Functional tests for the commerce product ui module.

Class

CommerceProductUIAdminTest
Test the product and product type CRUD.

Code

public function testCommerceProductUIDeleteProductType() {

  // Login with normal user.
  $this
    ->drupalLogin($this->store_customer);

  // Access to the delete page for a product type.
  $this
    ->drupalGet('admin/commerce/products/types/product/delete');
  $this
    ->assertResponse(403, t('Normal user is not able to access delete page for the product type'));

  // 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');
  $this
    ->assertResponse(200, t('Store admin can access delete page for the product type'));

  // Load all product types.
  $product_types = commerce_product_types();

  // Check the integrity of the product type delete confirmation form.
  $this
    ->pass('Test the product type delete confirmation form:');
  $this
    ->assertTitle(t('Are you sure you want to delete the !name product type?', array(
    '!name' => $product_types['product']['name'],
  )) . ' | Drupal', t('The confirmation message is displayed'));
  $this
    ->assertText(t('This action cannot be undone'), t('A warning notifying the user about the action can\'t be undone is displayed.'));
  $this
    ->assertFieldById('edit-submit', t('Delete'), t('Delete button is present'));
  $this
    ->assertText(t('Cancel'), t('Cancel is present'));

  // Delete the product type
  $this
    ->drupalPost(NULL, array(), t('Delete'));
  $this
    ->assertTrue($this->url == url('admin/commerce/products/types', array(
    'absolute' => TRUE,
  )), t('Landing page after deleting a product is the product types listing page'));

  // Check if the product is present in the product listing.
  $this
    ->assertRaw(t('The product type %name has been deleted.', array(
    '%name' => $product_types['product']['name'],
  )), t('\'Product type has been deleted\' message is displayed'));

  // Reload all product types.
  commerce_product_types_reset();
  $product_types = commerce_product_types();

  // Look for the product type.
  $this
    ->assertTrue(empty($product_types['product']), t('Product type doesn\'t exist anymore after deletion'));
}