You are here

public function CommerceProductUIAdminTest::testCommerceProductUIDeleteProduct in Commerce Core 7

Test deleting a product.

File

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

Class

CommerceProductUIAdminTest
Test the product and product type CRUD.

Code

public function testCommerceProductUIDeleteProduct() {

  // Create dummy product.
  $product = $this
    ->createDummyProduct('PROD-01', 'Product One');

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

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

  // Login with store admin.
  $this
    ->drupalLogin($this->store_admin);

  // Access to the delete product page.
  $this
    ->drupalGet('admin/commerce/products/' . $product->product_id . '/delete');
  $this
    ->assertResponse(200, t('Store admin user can access the product delete page'));

  // Check the integrity of the product delete confirmation form.
  $this
    ->pass('Test the product delete confirmation form:');
  $this
    ->assertTitle(t('Are you sure you want to delete !title?', array(
    '!title' => $product->title,
  )) . ' | Drupal', t('The confirmation message is displayed'));
  $this
    ->assertText($product->sku, t('SKU of the product is present'));
  $this
    ->assertText($product->title, t('Title of the product is present'));
  $this
    ->assertText(t('Deleting this product cannot be undone.', array(
    '@sku' => $product->sku,
  )), 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
  $this
    ->drupalPost(NULL, array(), t('Delete'));

  // Check for the product in database.
  $deleted_product = commerce_product_load_multiple(array(
    $product->product_id,
  ), array(), TRUE);
  $this
    ->assertFalse(reset($deleted_product), t('After deleting it, the product is no more in database'));
  $this
    ->assertTrue($this->url == url('admin/commerce/products', array(
    'absolute' => TRUE,
  )), t('Landing page after deleting a product is the product listing page'));

  // Check if the product is present in the product listing.
  $this
    ->assertRaw(t('%title has been deleted.', array(
    '%title' => $product->title,
  )), t('\'Product has been deleted\' message is displayed'));
  $this
    ->assertNoText($product->sku, t('Product SKU is not present'));
  $this
    ->assertText(t('No products have been created yet.'), t('Empty product listing message is displayed'));
}