You are here

public function CommerceProductUIAdminTest::testCommerceProductUISaveAndAddAnother in Commerce Core 7

Test the save and add another product.

File

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

Class

CommerceProductUIAdminTest
Test the product and product type CRUD.

Code

public function testCommerceProductUISaveAndAddAnother() {

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

  // Access to the admin product creation page.
  $this
    ->drupalGet('admin/commerce/products/add/product');

  // Create the product.
  $price = rand(2, 500);
  $edit = array(
    'sku' => 'PROD-01',
    'title' => $this
      ->randomName(10),
    'commerce_price[und][0][amount]' => commerce_currency_amount_to_decimal($price, 'USD'),
    'status' => 1,
  );

  // Save and add another.
  $this
    ->drupalPost(NULL, $edit, t('Save and add another'));

  // Check the product in database
  $product = commerce_product_load_by_sku($edit['sku']);
  $product_wrapper = entity_metadata_wrapper('commerce_product', $product);
  $this
    ->pass(t('Test the product creation in database:'));
  $this
    ->assertTrue($product_wrapper->sku
    ->value() == $edit['sku'], t('SKU stored in database correctly set'));
  $this
    ->assertTrue($product_wrapper->title
    ->value() == $edit['title'], t('Title stored in database correctly set'));
  $this
    ->assertTrue($product_wrapper->commerce_price->amount
    ->value() == $price, t('Amount stored in database correctly set'));
  $this
    ->assertTrue($product->status == $edit['status'], t('Status stored in database correctly set'));

  // Check if we are in the product creation page.
  $this
    ->assertTrue($this->url == url('admin/commerce/products/add/product', array(
    'absolute' => TRUE,
  )), t('Landing page after save and add another is the product creation page'));
}